如何使用 Datanucleus 配置 Google Web Toolkit 应用程序 + PostgreSQL

发布于 2024-09-14 16:47:29 字数 283 浏览 4 评论 0原文

我使用 GWT 创建了一个应用程序并支持 Google Datastore,但现在我正在尝试将我的应用程序移动到我自己的服务器,并且我还尝试将我的应用程序与 Google App Engine 和 Datastore 分离。

更准确地说:我想停止使用 Google Datastore 并开始使用 JDO 和 Datanucleus,但使用 PostgreSQL(或其他关系数据库)。我尝试在 Datanucleus.org 中搜索,但没有简单的教程可供我使用。

请问有人可以帮助我吗?

非常感谢! =)

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!
=)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-09-21 16:47:29

我已经发现了如何做到这一点,但我认为它应该更容易呵呵。
如下:

1)首先我们必须设置 PostgreSQL 服务器;

2) 使用 webAppCreator(来自 GWT SDK)创建我们的 Web 应用程序;

3) 由于我们必须增强我们的域类以供 datanucleus 和 JDO 使用,因此我们有多种选择来做到这一点。我使用了 Apache Ant 任务(来自 Google App Engine SDK)。如果我们这样做,我们可以使用 App Engine 中好的部分(简单的类增强),但我们的应用程序将不会受到 App Engine 的限制。
使用 webAppCreator 创建的 build.xml 添加的内容:

<!-- 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) 从官方网站下载 PostgreSQL JDBC 驱动程序;

5)从官方sourceforge页面下载datanucleus-rdbms.jar文件;

6)将这些jar添加到项目类路径中;

7) 创建一个包含以下内容的文件:

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) 创建一个 PersistenceManagerFactory,如下所示:

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

9) 创建域类并运行新的 Ant Target datanucleusenhance

10) 这将创建增强的类以及与关系数据库的连接,并将信息存储在 PostgreSQL 的表中。

11)如果我没有记错并且我没有忘记任何事情那就仅此而已:)

感谢您阅读问题。
请问,如果您发现任何问题,可以告诉我吗?这是我第一次来这里 :P

====一些参考资料====
http://code.google.com/ intl/zh-CN/appengine/docs/java/tools/ant.html#Enhancing_JDO_Classes

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文