views:

163

answers:

1

Hello there! =)

I created an application using GWT and support for the Google Datastore but now i'm trying to move my application to my own server and i'm also trying to detach my app from Google App Engine and from Datastore.

To be more precise: I want to stop using Google Datastore and start using JDO and Datanucleus but with PostgreSQL (or other relational database). I tried searching in Datanucleus.org but there was no simple tutorial for me to use.

Please, can someone help me?

Thank you very much! =)

A: 

Hello again! :)

I've discovered how to do it though I think it should be more easy eheheh.
Here it goes:

1) First we must setup PostgreSQL server;

2) Create our web application with webAppCreator (from GWT SDK);

3) Since we must enhance our domain classes for them to be used by datanucleus and JDO, we have multiple options to do it. I used an Apache Ant task ( from Google App Engine SDK). If we do this we can use the good parts from app engine (simple class enhancement) but our application won't be tied to the restrictions of App Engine.
The additions to the build.xml created with webAppCreator:

<!-- this refers to the location of my Google AppEngine SDK -->
<property name="sdk.dir" location="C:/Projects/appengine-java-sdk" />
<import file="${sdk.dir}/config/user/ant-macros.xml" />

<target name="copyjars"
  description="Copies the App Engine JARs to the WAR.">
  <copy
    todir="war/WEB-INF/lib"
    flatten="true">
    <fileset dir="${sdk.dir}/lib/user">
       <include name="**/*.jar" />
    </fileset>
  </copy>
</target>

<target name="compile" depends="copyjars"
  description="Compiles Java source and copies other source files to the WAR.">
  <mkdir dir="war/WEB-INF/classes" />
  <copy todir="war/WEB-INF/classes">
     <fileset dir="src">
        <exclude name="**/*.java" />
     </fileset>
  </copy>
  <javac
     srcdir="src"
     destdir="war/WEB-INF/classes"
     classpathref="project.class.path"
     debug="on" />
</target>

<target name="datanucleusenhance" depends="compile"
        description="Performs JDO enhancement on compiled data classes.">
    <enhance_war war="war" />
</target>

4) Download the PostgreSQL JDBC Driver from the official site;

5) Download the datanucleus-rdbms.jar file from the official sourceforge page;

6) Add these jars to the Project Classpath;

7) Create a file with the following content:

javax.jdo.PersistenceManagerFactoryClass=org.datanucleus.jdo.JDOPersistenceManagerFactory
javax.jdo.option.ConnectionDriverName=org.postgres.jdbc.Driver
javax.jdo.option.ConnectionURL=jdbc:postgres://localhost:5432/myschool
javax.jdo.option.ConnectionUserName=root
javax.jdo.option.ConnectionPassword=rootroot
datanucleus.autoCreateTables=true

8) Create a PersistenceManagerFactory like this:

File propsFile = new File("Insert the location of the properties file here");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(propsFile);

9) Create the domain classes and run the new Ant Target datanucleusenhance;

10) This will create enhanced classes and the connection with the relational database and also store the information in the PostgreSQL's tables.

11) If I'm not mistaken and if I didn't forget anything than that's all :)





Thank you for reading the question. Please, if you notice anything wrong, can you tell me? It's my first time here :P

==== Some References ====
http://code.google.com/intl/en/appengine/docs/java/tools/ant.html#Enhancing_JDO_Classes

João Dias Amaro