TechnoBuzz

A Techno Blog, mainly about Java

JDO with JPOX

JPOX: a free and full compliant JDO implementation released under an open source license.
JPOX Tutorial

JPOX Install info:
Setting up the environment requires EMF, com.versant.eclipse.jdo_0.9.9_e2.zip, com.versant.eclipse.jdo.jpox_0.9.9_e2.zip.
You can download the the JPOX eclipsejdo.org plugins here .
I also grabbed the com.versant.eclipse.jdo.doc.user_0.9.9_e2.zip which I extracted and added the folder to eclipse plugin folder. Note that to access the help after the doc plugin is in effect, do help contents in eclipse.

For my project, needed following Jars: bcel.jar, btree.jar, db2jcc.jar, jdo.jar, jdo-ri.jar, jdori-enhancer.jar, jpox-enhancer.jar, log4j.jar. Instead of using the jpox jar, we referenced a different project which contained the jpox source. In the jpoc source project, had the ant.jar, bcel.jar, btree.jar, connector-api.jar, db2jcc.jar, jdo.jar, jdori.jar, jdori-enhancer.jar, jta.zip, log4j, and the oracle jars.

for the enhancer, I am running using WSAD. In run…, created a new application within my project. The class that is referenced is org.jpox.enhancer.JPOXEnhancer which executes on my projecting.jdo file (argument org/jpox/tutorial/package.jdo)

Reference the logging file to get info on how to set up log4j. I set up a JVM variable for my class : -Dlog4j.configuration=file:org/jpox/tutorial/log4j.properties

One thing to remember is to always run the enhancer after each compile.

Now, the main.java which performs the persistance. One thing I noticed when I ran the class is that it creates the table, but nowhere is the schema indicated. Something I need to find out how to specify.

package org.jpox.tutorial;
import org.jpox.*;
import java.util.Properties;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Transaction;
import model.Person;
public class Main
{
public static void main(String[] args)
{
// Properties for connection
Properties properties = new Properties();

properties.setProperty(“javax.jdo.PersistenceManagerFactoryClass”,”org.jpox.PersistenceManagerFactoryImpl”);
properties.setProperty(“javax.jdo.option.ConnectionDriverName”,”com.ibm.db2.jcc.DB2Driver”);
properties.setProperty(“javax.jdo.option.ConnectionURL”,”jdbc:db2://url:portnum/dsn”);
properties.setProperty(“javax.jdo.option.ConnectionUserName”,”db2inst1″);
properties.setProperty(“javax.jdo.option.ConnectionPassword”,””);
properties.setProperty(“org.jpox.autoCreateSchema”,”true”);
properties.setProperty(“org.jpox.validateTables”,”false”);
properties.setProperty(“org.jpox.validateConstraints”,”false”);

// PMFactory creation and getting the PM instance
PersistenceManagerFactory pmfactory = JDOHelper.getPersistenceManagerFactory(properties);
PersistenceManager pm = pmfactory.getPersistenceManager();

try
{
pm.currentTransaction().begin(); // opening a transaction

Person dude = new Person(); // creates one Person

Product product=new Product(“Sony Discman”,”A standard discman from Sony”,49.99);

pm.makePersistent(product);

pm.currentTransaction().commit(); // committing the transaction

}
finally
{
// if the transaction is still active, rolls it back
if( pm.currentTransaction().isActive() )
{
pm.currentTransaction().rollback();
}
pm.close(); // close the PM
}
}
}


Some of the packages in the jpox jdo include: javax.jdo, org.jpox.

a thesis has been written
comparing JDBC to JDO

Object Identity provides training for the JDO API.

JDO vs SDO

JDO Implementations

OJB or now known as the apache db project.

Advertisements

July 25, 2004 - Posted by | CommonJ, JDO

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: