Process Explorer – Tool which provides Unix/Linux lsof command functionality for Windows
lsof command available in Unix and Linux operating system provides insight to running program. As explained in previous blog, the command is helpful to find the list of jars loaded by a Java application.
To do the same on Windows operating system, use the Process Explorer program available at http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx.
Start the Process Explorer, select the process which you want to analyze and enter CTRL + L. This brings up a lower pane that displays all system resources accessed by the process including files, threads, directories, port, etc. Filter the type column and you will be able to find all currently open files used by the application.
The following image displays the list of jar files accessed by Eclipse IDE.

lsof and Unclosed file handlers
After checking out a blog entry about analyzing Classpath of a running Java program by Thilina Mahesh Buddhika, i decided to try the command on the Java Web server used at my organization. To my surprise, i was able to find unclosed file handlers in the application hosted on the Web server.

The command lsof -p lists all open sockets, files and pipes. By analyzing the output of the command, i was able to check all the files opened by the application and able to reason why it was open by going through the application code. This also helped me in fixing unclosed file handlers.
Try out the command and try figuring out why the files are referred to. This gives an insight to functioning of the application.
Check out the usage of the command @ following link http://sial.org/howto/debug/unix/lsof/
Generating the DDL(Create and DROP) Statements of JPA Entities in EclipseLink
This blog is about generating the DDL Statements (CREATE and DROP DDL) for the entities managed by the JPA. The JPA implementation used here is EclipseLink.
I have used the following Person class to be managed as Entity.
package com.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
int id;
String fName;
String lName;
int age;
//the setter, getter, methods for each of the attributes, toString,
//hashCode, equals and default constructor are not shown here.
}
The persistence.xml file is as follows.
<?xml version="1.0" encoding="UTF-8"?> <persistence:persistence version="1.0" xmlns:persistence="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence ../../persistence_1_0.xsd "> <persistence:persistence-unit name="simplePersistenceUnit"> <persistence:provider>org.eclipse.persistence.jpa.PersistenceProvider</persistence:provider> <persistence:class>com.entities.Person</persistence:class> <persistence:properties> <persistence:property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver"/> <persistence:property name="eclipselink.jdbc.url" value="jdbc:mysql://localhost:3306/default"/> <persistence:property name="eclipselink.jdbc.user" value="root"/> <persistence:property name="eclipselink.jdbc.password" value="developer"/> </persistence:properties> </persistence:persistence-unit> </persistence:persistence>
The persistence.xml contains information about the database.
The DDL generation information is provided to the persistence manager via a java.util.Map object.
package com.test;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.Before;
import org.junit.Test;
public class TestExampleJPA {
EntityManager em;
@Test
public void testDDLGeneration() {
Map<String, String> persistProperties = new HashMap<String, String>();
persistProperties.put(PersistenceUnitProperties.DDL_GENERATION, "create-tables");
persistProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, "sql-script");
persistProperties.put(PersistenceUnitProperties.APP_LOCATION, "C:\MyFolder\temp");
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "simplePersistenceUnit", persistProperties);
em = emf.createEntityManager();
}
}
I have specified the database information in the persistence.xml file and DDL generation information into a Map object and providing it at runtime when creating the EntityManagerFactory object. Both the information can be provided fully either as part of persistence.xml or Map object. I have combined both approaches for providing configuration information to JPA.
On executing the above test case the following sql files which contains the DDL for CREATE and DROP are created in C:\MyFolder\temp folder.

References:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=72dd77e7-6c5f-4aa6-b684-a68d5b1d4f12)
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=a3c97381-e882-4723-9acb-56dc5cbcc1d3)

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=b4430830-8678-489f-953e-fa3abc4c44eb)

