You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mp...@apache.org on 2006/10/28 06:06:12 UTC
svn commit: r468629 - in /incubator/openjpa/trunk: ./ openjpa-examples/
openjpa-examples/src/ openjpa-examples/src/main/
openjpa-examples/src/main/java/ openjpa-examples/src/main/java/META-INF/
openjpa-examples/src/main/java/hellojpa/ openjpa-examples/...
Author: mprudhom
Date: Fri Oct 27 21:06:11 2006
New Revision: 468629
URL: http://svn.apache.org/viewvc?view=rev&rev=468629
Log:
Added very simple openjpa-examples package that contains a helloworld example (which will be included in the distribtion zip file)
Added:
incubator/openjpa/trunk/openjpa-examples/
incubator/openjpa/trunk/openjpa-examples/pom.xml
incubator/openjpa/trunk/openjpa-examples/src/
incubator/openjpa/trunk/openjpa-examples/src/main/
incubator/openjpa/trunk/openjpa-examples/src/main/java/
incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/
incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/persistence.xml
incubator/openjpa/trunk/openjpa-examples/src/main/java/build.xml
incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/
incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Main.java
incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Message.java
incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/build.xml
incubator/openjpa/trunk/openjpa-examples/src/test/
incubator/openjpa/trunk/openjpa-examples/src/test/java/
incubator/openjpa/trunk/openjpa-examples/src/test/java/hellojpa/
Modified:
incubator/openjpa/trunk/openjpa-project/assembly.xml
incubator/openjpa/trunk/openjpa-project/pom.xml
incubator/openjpa/trunk/pom.xml
Added: incubator/openjpa/trunk/openjpa-examples/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/pom.xml?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/pom.xml (added)
+++ incubator/openjpa/trunk/openjpa-examples/pom.xml Fri Oct 27 21:06:11 2006
@@ -0,0 +1,88 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa-examples</artifactId>
+ <packaging>jar</packaging>
+ <name>OpenJPA Persistence Examples</name>
+ <description>OpenJPA Persistence Examples</description>
+ <url>http://incubator.apache.org/projects/openjpa</url>
+ <parent>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <version>0.9.6-incubating-SNAPSHOT</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa-persistence-jdbc</artifactId>
+ <version>${pom.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.1.3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <version>1.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <!-- ###
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>test-compile</phase>
+ <configuration>
+ <tasks>
+ <path id="cp">
+ <path refid="maven.test.classpath"/>
+ <path refid="maven.compile.classpath"/>
+ <path refid="maven.dependency.classpath"/>
+ </path>
+ <taskdef name="openjpac" classname=
+ "org.apache.openjpa.ant.PCEnhancerTask">
+ <classpath refid="cp"/>
+ </taskdef>
+ <fileset id="enhance.path.ref"
+ dir="${project.build.testOutputDirectory}">
+ <include name="**/*.class"/>
+ </fileset>
+ <openjpac>
+ <classpath refid="cp"/>
+ <fileset refid="enhance.path.ref"/>
+ </openjpac>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ -->
+ </plugins>
+ </build>
+</project>
Added: incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/persistence.xml?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/persistence.xml (added)
+++ incubator/openjpa/trunk/openjpa-examples/src/main/java/META-INF/persistence.xml Fri Oct 27 21:06:11 2006
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <!--
+ A persistence unit is a set of listed persistent entities as well
+ the configuration of an EntityManagerFactory. We configure each
+ example in a separate persistence-unit.
+ -->
+ <persistence-unit name="hellojpa" transaction-type="RESOURCE_LOCAL">
+ <!--
+ The default provider can be OpenJPA, or some other product.
+ This element is optional if OpenJPA is the only JPA provider
+ in the current classloading environment.
+ -->
+ <provider>
+ org.apache.openjpa.persistence.PersistenceProviderImpl
+ </provider>
+
+ <!-- We must enumerate each entity in the persistence unit -->
+ <class>hellojpa.Message</class>
+
+ <properties>
+ <!--
+ We can configure the default OpenJPA properties here. They
+ happen to be commented out here since the provided examples
+ all specify the values via System properties.
+ -->
+
+ <!--
+ <property name="openjpa.ConnectionURL"
+ value="jdbc:derby:openjpa-database;create=true"/>
+ <property name="openjpa.ConnectionDriverName"
+ value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <property name="openjpa.ConnectionUserName"
+ value="user"/>
+ <property name="openjpa.ConnectionPassword"
+ value="secret"/>
+ -->
+ </properties>
+ </persistence-unit>
+</persistence>
Added: incubator/openjpa/trunk/openjpa-examples/src/main/java/build.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/src/main/java/build.xml?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/src/main/java/build.xml (added)
+++ incubator/openjpa/trunk/openjpa-examples/src/main/java/build.xml Fri Oct 27 21:06:11 2006
@@ -0,0 +1,89 @@
+<project default="usagewarning">
+
+ <property name="parent" value="${basedir}/.."/>
+ <property name="root" value="${parent}/.."/>
+
+ <target name="usagewarning">
+ <fail>
+Please traverse to a sub-directory and run "ant" from there.
+ </fail>
+ </target>
+
+ <path id="classpath"
+ description="The classpath to use for compiling and running">
+ <pathelement path="${parent}"/>
+ <fileset dir="${root}">
+ <include name="**/*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="javaagent">
+ <fileset dir="${root}">
+ <include name="openjpa-*.jar"/>
+ </fileset>
+ </path>
+ <pathconvert property="javaagent" refid="javaagent"/>
+
+ <target name="clean"
+ description="Clean up compiled files and generated database files">
+ <delete includeemptydirs="true">
+ <fileset dir="${basedir}">
+ <include name="*.class"/>
+ <include name="*.log"/>
+ <include name="${example}-database/**/*"/>
+ <include name="${example}-database"/>
+ </fileset>
+ </delete>
+ </target>
+
+ <target name="compile" description="Compile the example java files">
+ <javac srcdir="${parent}" classpathref="classpath"
+ includes="${example}/**.java"/>
+ </target>
+
+ <target name="run" depends="compile"
+ description="Run the example Main program">
+
+ <java classname="${example}.Main" classpathref="classpath" fork="yes">
+ <!--
+ Specifying the openjpa jar as the javaagent argument is
+ necessary in order for automatic class-enhancement to work.
+ -->
+ <jvmarg value="-javaagent:${javaagent}"/>
+
+ <!--
+ Specify the system properties to use when configuring
+ OpenJPA. Note that these will only be used becuase in the
+ examples, the call to "Persistence.createEntityManagerFactory"
+ is passed "System.getProperties()".
+ -->
+
+ <!--
+ By default, use the stand-alone Derby database (provided).
+ This can easily be changes to use your own database's driver,
+ provided you ensure it is accessible in the classpath.
+ -->
+ <sysproperty key="openjpa.ConnectionDriverName"
+ value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <sysproperty key="openjpa.ConnectionURL"
+ value="jdbc:derby:${example}-database;create=true"/>
+
+ <!--
+ Tell OpenJPA to automatically create tables in the database
+ for entities. Note that this should be disabled when
+ running against a production database, since you probably
+ don't want to be altering the schema at runtime.
+ -->
+ <sysproperty key="openjpa.jdbc.SynchronizeMappings"
+ value="buildSchema"/>
+
+ <!--
+ Output all the SQL for educational purposes, but set the
+ general logging level to only show warnings.
+ -->
+ <sysproperty key="openjpa.Log"
+ value="DefaultLevel=WARN,SQL=TRACE"/>
+ </java>
+ </target>
+</project>
+
Added: incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Main.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Main.java?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Main.java (added)
+++ incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Main.java Fri Oct 27 21:06:11 2006
@@ -0,0 +1,58 @@
+package hellojpa;
+
+import java.util.*;
+import javax.persistence.*;
+
+
+/**
+ * A very simple, stand-alone program that stores a new entity in the
+ * database and then performs a query to retrieve it.
+ */
+public class Main {
+
+ @SuppressWarnings("unchecked")
+ public static void main(String[] args) {
+ // Create a new EntityManagerFactory using the System properties.
+ // The "hellojpa" name will be used to configure based on the
+ // corresponding name in the META-INF/persistence.xml file
+ EntityManagerFactory factory = Persistence.
+ createEntityManagerFactory("hellojpa", System.getProperties());
+
+ // Create a new EntityManager from the EntityManagerFactory. The
+ // EntityManager is the main object in the persistence API, and is
+ // used to create, delete, and query objects, as well as access
+ // the current transaction
+ EntityManager em = factory.createEntityManager();
+
+ // Begin a new local transaction so that we can persist a new entity
+ em.getTransaction().begin();
+
+ // Create and persist a new Message entity
+ em.persist(new Message("Hello Persistence!"));
+
+ // Commit the transaction, which will cause the entity to
+ // be stored in the database
+ em.getTransaction().commit();
+
+ // It is always good practice to close the EntityManager so that
+ // resources are conserved.
+ em.close();
+
+ // Create a fresh, new EntityManager
+ EntityManager em2 = factory.createEntityManager();
+
+ // Perform a simple query for all the Message entities
+ Query q = em2.createQuery("select m from Message m");
+
+ // Go through each of the entities and print out each of their
+ // messages, as well as the date on which it was created
+ for (Message m : (List<Message>)q.getResultList()) {
+ System.out.println(m.getMessage()
+ + " (created on: " + m.getCreated() + ")");
+ }
+
+ // Again, it is always good to clean up after ourselves
+ em2.close();
+ factory.close();
+ }
+}
Added: incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Message.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Message.java?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Message.java (added)
+++ incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/Message.java Fri Oct 27 21:06:11 2006
@@ -0,0 +1,54 @@
+package hellojpa;
+
+import java.util.*;
+import javax.persistence.*;
+
+
+/**
+ * A very simple persistent entity that holds a "message", has a
+ * "created" field that is initialized to the time at which the
+ * object was created, and an id field that is initialized to the
+ * current time.
+ */
+@Entity
+public class Message {
+ @Id
+ private long id = System.currentTimeMillis();
+
+ @Basic
+ private String message;
+
+ @Basic
+ private Date created = new Date();
+
+ public Message() {
+ }
+
+ public Message(String msg) {
+ message = msg;
+ }
+
+ public void setId(long val) {
+ id = val;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setMessage(String msg) {
+ message = msg;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setCreated(Date date) {
+ created = date;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
Added: incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/build.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/build.xml?view=auto&rev=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/build.xml (added)
+++ incubator/openjpa/trunk/openjpa-examples/src/main/java/hellojpa/build.xml Fri Oct 27 21:06:11 2006
@@ -0,0 +1,4 @@
+<project default="run">
+ <property name="example" value="hellojpa"/>
+ <import file="../build.xml"/>
+</project>
Modified: incubator/openjpa/trunk/openjpa-project/assembly.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-project/assembly.xml?view=diff&rev=468629&r1=468628&r2=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-project/assembly.xml (original)
+++ incubator/openjpa/trunk/openjpa-project/assembly.xml Fri Oct 27 21:06:11 2006
@@ -52,6 +52,10 @@
<directory>../target/site/apidocs</directory>
<outputDirectory>docs/javadoc</outputDirectory>
</fileSet>
+ <fileSet>
+ <directory>../openjpa-examples/src/main/java</directory>
+ <outputDirectory>examples</outputDirectory>
+ </fileSet>
</fileSets>
<dependencySets>
<dependencySet>
Modified: incubator/openjpa/trunk/openjpa-project/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-project/pom.xml?view=diff&rev=468629&r1=468628&r2=468629
==============================================================================
--- incubator/openjpa/trunk/openjpa-project/pom.xml (original)
+++ incubator/openjpa/trunk/openjpa-project/pom.xml Fri Oct 27 21:06:11 2006
@@ -370,6 +370,11 @@
<artifactId>openjpa-xmlstore</artifactId>
<version>${pom.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa-examples</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
<!-- included so we can include it in the distribution -->
<dependency>
Modified: incubator/openjpa/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/pom.xml?view=diff&rev=468629&r1=468628&r2=468629
==============================================================================
--- incubator/openjpa/trunk/pom.xml (original)
+++ incubator/openjpa/trunk/pom.xml Fri Oct 27 21:06:11 2006
@@ -110,6 +110,7 @@
<module>openjpa-kernel-4</module>
<module>openjpa-kernel-5</module>
<module>openjpa-jdbc-5</module>
+ <module>openjpa-examples</module>
</modules>
</profile>
<profile>
@@ -208,12 +209,18 @@
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <useFile>false</useFile>
+ </configuration>
+ </plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
-
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<reportSets>