Liferay announced a powerful feature that reminds me of Dropbox: Document synchronization.
It will allow you to access your files on- and offline on a various list of devices. Read the press release here: Liferay Sync
If you have any questions then feel free to comment..
Cheers..
Ujjwal Soni
Thursday, June 28, 2012
Friday, June 22, 2012
Difference between FetchType LAZY and EAGER in Java persistence
Sometimes you have two entities and there's a relationship between them. For example, you might have an entity called University and another entity called Student.
The University entity might have some basic properties such as id, name, address, etc. as well as a property called students:
Now when you load a University from the database, JPA loads its id, name, and address fields for you. But you have two options for students: to load it together with the rest of the fields (i.e. eagerly) or to load it on-demand (i.e. lazily) when you call the university's getStudents() method.
When a university has many students it is not efficient to load all of its students with it when they are not needed. So in suchlike cases, you can declare that you want students to be loaded when they are actually needed. This is called lazy loading.
The University entity might have some basic properties such as id, name, address, etc. as well as a property called students:
public class University { private String id; private String name; private String address; private Liststudents; // setters and getters }
Now when you load a University from the database, JPA loads its id, name, and address fields for you. But you have two options for students: to load it together with the rest of the fields (i.e. eagerly) or to load it on-demand (i.e. lazily) when you call the university's getStudents() method.
When a university has many students it is not efficient to load all of its students with it when they are not needed. So in suchlike cases, you can declare that you want students to be loaded when they are actually needed. This is called lazy loading.
Thursday, June 14, 2012
Display link mailto / Href in alert box javascript
Hi,
Below is the code i implemented for displaying link in href alert box ::
Below is the code i implemented for displaying link in href alert box ::
<!doctype html> <html> <meta charset="utf-8"> <title>Basic usage of the jQuery UI dialog</title> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var $dialog = $('<div></div>') .html('Welcome, Please click on the Link to display blog <a href='http://ujjwalbsoni.blogspot.com'>Visit blog</a>') .dialog({ autoOpen: false, title: 'Basic Dialog' }); $('#opener').click(function() { $dialog.dialog('open'); // prevent the default action, e.g., following a link return false; }); }); </script> </head> <body> <p>This is an example from the Ujjwal's Blog</a>.</p> <button id="opener">Show Dialog</button> </body> </html>
Wednesday, June 13, 2012
Beginning Liferay - Installation and Execution
Hi,
I recently begin my Liferay learning by installing letest version of Liferay Portal 6.1 Community Edition from www.liferay.com. I downloaded and extracted it in macosx. I downloaded tomcat bundled installation.
After extracting it in a specific folder run the below file from terminal (in mac osx)::
LIFERAY_PORTAL/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/bin/startup.sh
If you are running it in windows, you can run startup.bat file.
I have just installed liferay on my machine, now i will begin learning portlets and development using life ray.
Keep reading my blog for more updates
thanks,
Ujjwal soni
I recently begin my Liferay learning by installing letest version of Liferay Portal 6.1 Community Edition from www.liferay.com. I downloaded and extracted it in macosx. I downloaded tomcat bundled installation.
After extracting it in a specific folder run the below file from terminal (in mac osx)::
LIFERAY_PORTAL/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/bin/startup.sh
If you are running it in windows, you can run startup.bat file.
I have just installed liferay on my machine, now i will begin learning portlets and development using life ray.
Keep reading my blog for more updates
thanks,
Ujjwal soni
Monday, June 11, 2012
org.hibernate.InvalidMappingException: Could not parse mapping document
Hi,
If you get below exception in your struts hibernate application
org.hibernate.InvalidMappingException: Could not parse mapping document from resource ujjwal/home/homes.hbm.xml
The reason behind this exception could be
1) wrong package name in hibernate.cfg.xml file
2) wrong package name in homes.hbm.xml
for example
As you can see in above example, we are having package name ujjwal.homes.Homes under class name which is totally incorrect, it should be ujjwal.home.homes.Homes instead.
If you still face this issue, feel free to comment
Thanks,
Ujjwal Soni
If you get below exception in your struts hibernate application
org.hibernate.InvalidMappingException: Could not parse mapping document from resource ujjwal/home/homes.hbm.xml
The reason behind this exception could be
1) wrong package name in hibernate.cfg.xml file
2) wrong package name in homes.hbm.xml
for example
<class name="ujjwal.homes.Homes" table="homes" schema="myhomes">
As you can see in above example, we are having package name ujjwal.homes.Homes under class name which is totally incorrect, it should be ujjwal.home.homes.Homes instead.
If you still face this issue, feel free to comment
Thanks,
Ujjwal Soni
java.lang.NoSuchMethodError: antlr.collections.AST.getLine() Struts Hibernate exception
Hi,
I recently got an error java.lang.NoSuchMethodError: antlr.collections.AST.getLine()
This error comes when there is a conflict in antlr jar file with struts 1.3 and hibernate 3. You need to remove antlr 2.7.2 jar file from struts 1.3 by clicking on myeclipse preferences > libraries.
If any questions, feel free to comment.
Thanks,
Ujjwal Soni
I recently got an error java.lang.NoSuchMethodError: antlr.collections.AST.getLine()
This error comes when there is a conflict in antlr jar file with struts 1.3 and hibernate 3. You need to remove antlr 2.7.2 jar file from struts 1.3 by clicking on myeclipse preferences > libraries.
If any questions, feel free to comment.
Thanks,
Ujjwal Soni
Saturday, June 9, 2012
Killing idle sessions in Postgresql
Recently, i faced an issue with Postgresql with one table where it got locked due to some reason. I followed below steps to unlock it ::
1) connect to Postgresql using below command
2) Find idle processes using below command
Identify the process and note its id
3) connect to database using PG Admin tool
Fire below command from sql window
Thanks,
Ujjwal Soni
1) connect to Postgresql using below command
ssh -L 5432:127.0.0.1:5432 DEMO@server.com
2) Find idle processes using below command
ps -ef | grep postgres
Identify the process and note its id
3) connect to database using PG Admin tool
Fire below command from sql window
pg_cancel_backend(‘procpid’)
Thanks,
Ujjwal Soni
Friday, June 1, 2012
Playing movies and music over SSH
If you want to remotely access your SSH account (e.g. NAS in home) and listen to the music or watch some movies without downloading them in the first place, you can use the following command:
It will connect to your.host.com, log into the user account, invoke the cat command on the given mediaFile.avi and transfer the output (stream of bytes) to your local mplayer.
The mplayer - says that it should read the data from the standard input — which in this case is the result of the cat command.
When you finish watching or listening — just break the connection and no traces are left on your local device.
Alternatively, you can also mount your remote ssh location using the sshfs.
ssh user@your.host.com cat mediaFile.avi | mplayer -
It will connect to your.host.com, log into the user account, invoke the cat command on the given mediaFile.avi and transfer the output (stream of bytes) to your local mplayer.
The mplayer - says that it should read the data from the standard input — which in this case is the result of the cat command.
When you finish watching or listening — just break the connection and no traces are left on your local device.
Alternatively, you can also mount your remote ssh location using the sshfs.
Labels:
ssh audio,
ssh movies,
ssh streaming,
ssh video streaming
Executing SSH commands from ANT
ou can easily achieve remote command invocation, using an ANT Task sshexec. An example of its usage could be this snippet (note that remote.* variables are taken from the *.properties file in this case):
You can read about more detailed examples here.
To add this feature to your ANT installation, you need to download the JSch – Java Secure Channel library and include the jsch jar file into ANT classpath (i.e. in your ANT_HOME/lib/ or — if you’re using an Eclipse — into Eclipse Ant classpath).
I found this feature quite useful as it reduced time I needed to build and deploy an application.
<sshexec host="${remote.host}" username="${remote.user}" password="${remote.pass}" trust="true" command="rm -rf ${remote.webapps.path}/ROOT*" />
You can read about more detailed examples here.
To add this feature to your ANT installation, you need to download the JSch – Java Secure Channel library and include the jsch jar file into ANT classpath (i.e. in your ANT_HOME/lib/ or — if you’re using an Eclipse — into Eclipse Ant classpath).
I found this feature quite useful as it reduced time I needed to build and deploy an application.
Compiling Java Source File From Running Java Application
Hi All,
id you know that you can compile Java source code from your running Java Application? It’s not even so hard and the JavaCompiler javadoc is quite verbose.
Try it for yourself:
id you know that you can compile Java source code from your running Java Application? It’s not even so hard and the JavaCompiler javadoc is quite verbose.
Try it for yourself:
package com.piotrnowicki.javacompiler; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; public class Executor { public static void main(String[] args) { JavaCompiler jcp = ToolProvider.getSystemJavaCompiler(); // Compile pointed *.java file jcp.run(null, null, null, "/home/piotr/MyClass.java"); } }Now imagine that you can compile your Java code from a Java application that compiles your Java code. Why…? Because we can and because it’s so inception!
Fun with music in Java
Music programming in Java is now easy with jfugue.
Netbeans: File > “Project” Properties > Libraries > Add JAR/Folder
JDeveloper: Tools > Project Properties… > Libraries and Classpath > Add JAR/Directory…
The sound API of JDK really needed this comfortable boost. Congratulations to David Koelle for creating this tool!
Step 1. Download
Go to jfugue.org → Download → jfugue-4.0.3.jarStep 2. Place it in the classpath
Eclipse: Project > Java Build Path > Libraries > Add External JARs…Netbeans: File > “Project” Properties > Libraries > Add JAR/Folder
JDeveloper: Tools > Project Properties… > Libraries and Classpath > Add JAR/Directory…
Step 3. Have fun
Play a note
new Player().play("C");
Play a note on a different octave
// 7th octave of the piano new Player().play("C7");
Play a note with different duration
// w means whole = 4/4 new Player().play("Cw");
Play two notes
new Player().play("C D");
Use a rest
new Player().play("C R D");
Play some notes together
// h means half = 2/4 new Player().play("C5h+E5h+G5h+C6h");
Pick a different instrument
new Player().play("I[HARMONICA] C D E");
Play a simple song
new Player().play("I[BLOWN_BOTTLE] Gh Eq Cq | Gw | Gh Eq Cq | Gw");
Play a simple song with different tempo
new Player().play("T[220] I[KALIMBA] Gh Eq Cq | Gw | Gh Eq Cq | Gw");
Create a rythm!
Rhythm rhythm = new Rhythm(); rhythm.setLayer(1, "...*...*...*...*"); rhythm.setLayer(2, "----------------"); rhythm.addSubstitution('.', "Ri"); rhythm.addSubstitution('*', "[SKAKUHACHI]i"); rhythm.addSubstitution('-', "[PEDAL_HI_HAT]s Rs"); new Player().play(rhythm.getPattern());
Conclusion
At last, it’s easy to program some music for our games and create sounds for our applications.The sound API of JDK really needed this comfortable boost. Congratulations to David Koelle for creating this tool!
Labels:
java music,
java sound,
jfugue,
music,
play sound in java,
sound java
Subscribe to:
Posts (Atom)