You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2010/12/10 18:10:50 UTC

svn commit: r1044446 - in /openjpa/trunk/openjpa-examples/jest: ./ src/ src/main/ src/main/java/ src/main/java/demo/ src/main/resources/ src/main/resources/META-INF/ src/main/resources/WEB-INF/ src/main/resources/demo/

Author: ppoddar
Date: Fri Dec 10 17:10:50 2010
New Revision: 1044446

URL: http://svn.apache.org/viewvc?rev=1044446&view=rev
Log:
OPENJPA-1859: Relocate JEST demo on trunk

Added:
    openjpa/trunk/openjpa-examples/jest/
    openjpa/trunk/openjpa-examples/jest/README.html   (with props)
    openjpa/trunk/openjpa-examples/jest/build.properties   (with props)
    openjpa/trunk/openjpa-examples/jest/build.xml   (with props)
    openjpa/trunk/openjpa-examples/jest/src/
    openjpa/trunk/openjpa-examples/jest/src/main/
    openjpa/trunk/openjpa-examples/jest/src/main/java/
    openjpa/trunk/openjpa-examples/jest/src/main/java/demo/
    openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/resources/
    openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/
    openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/
    openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml   (with props)
    openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/
    openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html   (with props)

Added: openjpa/trunk/openjpa-examples/jest/README.html
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/README.html?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/README.html (added)
+++ openjpa/trunk/openjpa-examples/jest/README.html Fri Dec 10 17:10:50 2010
@@ -0,0 +1,113 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.   
+-->
+<html>
+<head>
+<style type="text/css">
+code {
+	color: brown;
+	font-family: "Courier New";
+	font-weight: bold;
+	text-align: center;
+	border: 1px solid black;
+	background: lightgray;
+}
+tt {
+	color: green;
+	font-family: "Courier New";
+	font-weight: bold;
+}
+.warn {
+  color:red;
+  font-weight: bold;
+}
+</style>
+</head>
+<body>
+  <h3>Instructions to build, deploy and run JEST demo</h3>
+  <hr>
+  
+  <dl>
+  <dt><b>Step 1: Download OpenJPA binary</b></dt> 
+  <dd> OpenJPA binaries are available from OpenJPA 
+       <a href="http://openjpa.apache.org/downloads.html" target="_blank">download site</a>.
+       The nightly snapshots of version <tt>2.2.0</tt> that includes JEST are ready for 
+       <a href="https://repository.apache.org/snapshots/org/apache/openjpa/apache-openjpa/2.2.0-SNAPSHOT/" 
+       target="_blank">download</a> at lower half of the page. 
+  </dd> 
+  <br>
+  <dt><b>Step 2: Get the JEST demo application</b></dt>
+  <dd> A simple servlet based application is used to demonstrate JEST usage. This simple
+       application merely defines a persistent unit with two persistent classes: <tt>Actor</tt>
+       and <tt>Movie</tt>. The source code, persistence unit descriptor 
+       <tt>META-INF/persistence.xml</tt>, deployment descriptor <tt>WEB-INF/web.xml</tt>
+       and Ant-based build script are available from OpenJPA svn repository.<br>
+       Checkout these source files from the repository to a local directory.
+       The following command:<br>
+       <code>$ svn co https://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/jest .</code><br>
+       will bring the code to the current directory, for example.
+  </dd>
+  <br>
+  <dt><b>Step 3: Configure for your environment</b></dt>
+  <dd>
+      The persistence unit descriptor <tt>META-INF/persistence.xml</tt> for the example application
+      needs to be configured with database details. By default, it is configured for a MySQL database. 
+      <br>
+      The build script requires the location of openjpa library and servlet API library jar. 
+      Edit <tt>build.properties</tt> file to set the variables to locations appropriate for
+      your environment. 
+  </dd>
+  <br>
+  <dt><b>Step 4: Build the application</b></dt>
+  <dd>
+      Just run good old Ant.<br>
+      <code> $ ant</code> </br>
+      The build script <tt>buid.xml</tt> will compile few Java classes of the application, enhance
+      the persistent classes and package them into a web archive <tt>demo.war</tt> for deployment.
+      <br>
+      The deployment descriptor <tt>WEB-INF/web.xml</tt> for this web archive specifies two servlets:
+      one for this simple application and the other is JEST servlet. It may be instructive to take a
+      look at the <tt>WEB-INF/web.xml</tt> to see how JEST is deployed.
+      <br>
+      The web archive packages the openjpa library as well in <tt>WEB-INF/lib</tt>. You may prefer
+      other deployment options such as placing openjpa library in a shared library of your favorite
+      application server or servlet container. You do need to modify the build script in that case.
+  </dd>
+  <br>
+  <dt><b>Step 5: Deploy the web archive</b></dt>
+  <dd>
+      Once the web archive is ready, deploy it in an application server or servlet container by
+      following standard practice. Needless to say, the database driver specified in 
+      <tt>META-INF/persistence.xml</tt> should also be available in the deployment environment.
+  </dd>
+  <br>
+  <dt><b>Step 6: Browse with JEST</b></dt>
+  <dd>
+      Once the web archive has been deployed, you can verify by visiting the home page (and the only page)
+      of the sample application in your browser<br>
+		<code>http://localhost:8080/demo/</code>  <br>
+      The context path of the deployed servlet is <tt>demo</tt> as you may have noticed in <tt>WEB-INF/web.xml</tt>. 
+      The JEST servlet is just next door at<br>
+		<code>http://localhost:8080/demo/jest/</code>  <br>
+	  <span class="warn">notice the trailing forward slash in the URL above</span><br>
+	  Now you should see JEST home page with colorful icons. Enjoy browsing!
+	  
+  </dd>
+  </dl>
+</body>
+</html>

Propchange: openjpa/trunk/openjpa-examples/jest/README.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/README.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/build.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/build.properties?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/build.properties (added)
+++ openjpa/trunk/openjpa-examples/jest/build.properties Fri Dec 10 17:10:50 2010
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# ---------------------------------------------------------------------------------
+# Environment variables to build JEST Demo
+#
+# The script builds a simple application servlet using OpenJPA as its JPA provider.
+# See src/main/java/demo/SimpleApp.java and src/main/resources/demo/index.html
+# on what this simple servlet application does.
+# ---------------------------------------------------------------------------------
+# Directory location of maven repository
+maven.repos=${user.home}/.m2/repository
+# OpenJPA version
+openjpa.version=2.2.0-SNAPSHOT
+
+# The variable of interest are openjpa.dir and openjpa.jar. 
+# Though the varaible value is expressed in terms of other variables here, you can specify the value directly.
+openjpa.dir=${maven.repos}/org/apache/openjpa/openjpa-all/${openjpa.version}
+openjpa.jar=openjpa-all-${openjpa.version}.jar
+
+# You need servlet jar to compile the application servlet.
+servlet.jar=C:/apache-tomcat-6.0.29/lib/servlet-api.jar
+

Propchange: openjpa/trunk/openjpa-examples/jest/build.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-examples/jest/build.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/build.xml?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/build.xml (added)
+++ openjpa/trunk/openjpa-examples/jest/build.xml Fri Dec 10 17:10:50 2010
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.   
+-->
+<!-- ====================================================================== -->
+<!--                                                                        -->
+<!--               Ant build script for JEST Demo                           -->
+<!--                                                                        -->
+<!-- Creates a web archieve for a simple application                        -->
+<!-- Web deployment descriptor (WEB-INF/web.xml) of this simple application -->
+<!-- includes JEST servlet.                                                 -->
+<!-- ====================================================================== -->
+
+<project name="jest" default="war">
+
+	<!-- ================================================================== -->
+	<property file="build.properties" />
+	<!-- ================================================================== -->
+	<!-- root directory of Java Source files                                -->
+	<property name="src.dir" value="${basedir}/src/main/java" />
+	<!-- ================================================================== -->
+	<!-- root directory of resource files e.g web.xml or persistence.xml    -->
+	<property name="rsrc.dir" value="${basedir}/src/main/resources" />
+	<!-- ================================================================== -->
+	<!-- JPA configuration file anchored by the persistence unit name       -->
+	<property name="jpa.properties" value="META-INF/persistence.xml#jestdemo" />
+	<!-- ================================================================== -->
+	<!-- Root directory of all derived artifacts                            -->
+	<property name="target.dir" value="${basedir}/target" />
+	<!-- ================================================================== -->
+	<!-- root directory of compiled class files                             -->
+	<property name="classes.dir" value="${target.dir}/classes" />
+	<!-- ================================================================== -->
+	<!-- war archive for the demo                                           -->
+	<property name="webapp.war" value="demo.war" />
+	<!-- ================================================================== -->
+
+	<path id="compile.classpath" description="Compilation classpath requires OpenJPA specific library 
+		because of bytecode enhancement">
+		<pathelement location="${src.dir}" />
+		<pathelement location="${classes.dir}" />
+		<pathelement location="${rsrc.dir}" />
+		<pathelement location="${openjpa.dir}/${openjpa.jar}" />
+		<pathelement location="${servlet.jar}" />
+	</path>
+
+
+	<target name="clean" description="Removes all derived targets">
+		<delete dir="${target.dir}" failonerror="false" />
+	</target>
+
+	<target name="compile" description="Compile classes.">
+		<mkdir dir="${classes.dir}" />
+		<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true">
+			<classpath refid="compile.classpath" />
+			<exclude name="**/Test*.java" />
+		</javac>
+	</target>
+
+	<target name="enhance" depends="compile" description="Enhance persistent domain classes.">
+		<echo message="Enhancing ${jpa.properties}" />
+		<java classname="org.apache.openjpa.enhance.PCEnhancer" fork="true">
+			<arg value="-properties" />
+			<arg value="${jpa.properties}" />
+			<classpath refid="compile.classpath" />
+		</java>
+	</target>
+
+	<target name="war" depends="clean,enhance">
+		<delete file="${webapp.war}" failonerror="false">
+		</delete>
+		<echo message="Creating web application archieve ${webapp.war}" />
+		<war destfile="${webapp.war}" filesonly="true" webxml="${rsrc.dir}/WEB-INF/web.xml">
+			<fileset dir="${basedir}">
+				<exclude name="*.*" />
+				<exclude name="**/*.*" />
+			</fileset>
+			<classes dir="${classes.dir}">
+				<include name="**/*.class" />
+			</classes>
+			<classes dir="${rsrc.dir}">
+				<include name="META-INF/persistence.xml" />
+				<include name="**/index.html" />
+			</classes>
+
+			<lib dir="${openjpa.dir}">
+				<include name="${openjpa.jar}" />
+			</lib>
+		</war>
+	</target>
+</project>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-examples/jest/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java Fri Dec 10 17:10:50 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package demo;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+import org.apache.openjpa.persistence.FetchAttribute;
+import org.apache.openjpa.persistence.FetchGroup;
+import org.apache.openjpa.persistence.FetchGroups;
+
+/**
+ * A persistent entity with singular and plural association.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+@FetchGroups({
+    @FetchGroup(name="OnlyName", attributes={
+        @FetchAttribute(name="firstName"),
+        @FetchAttribute(name="lastName")
+    })
+})
+public class Actor {
+    public static enum Gender {Male, Female}; 
+    @Id
+    private String id;
+    private String firstName;
+    private String lastName;
+    private Gender gender;
+    private Date dob;
+    @OneToOne
+    private Actor partner;
+    @OneToMany
+    private Set<Movie> movies;
+    
+    protected Actor() {
+        
+    }
+    
+    public Actor(String id, String firstName, String lastName, Gender gender, Date dob) {
+        super();
+        this.id = id;
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.gender = gender;
+        this.dob = dob;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public Gender getGender() {
+        return gender;
+    }
+
+    public Date getDob() {
+        return dob;
+    }
+    public Actor getPartner() {
+        return partner;
+    }
+
+    public void setPartner(Actor partner) {
+        this.partner = partner;
+    }
+
+    public Set<Movie> getMovies() {
+        return movies;
+    }
+
+    public void addMovie(Movie movie) {
+        if (movies == null)
+            movies = new HashSet<Movie>();
+        movies.add(movie);
+    }
+}

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Actor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java Fri Dec 10 17:10:50 2010
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package demo;
+
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Loads some example Actor-Movie data.
+ *  
+ * @author Pinaki Poddar
+ *
+ */
+public class DataLoader {
+    // Hand-tuned data for Testing
+    @SuppressWarnings("deprecation")
+    public static Object[][] ACTOR_DATA = {
+        new Object[] {"m1", "Robert", "Redford",  Actor.Gender.Male, new Date(50, 1, 12)},
+        new Object[] {"m2", "Robert", "De Niro",  Actor.Gender.Male, new Date(40, 4, 14)},
+        new Object[] {"m3", "Al",     "Pacino",   Actor.Gender.Male, new Date(50, 1, 12)},
+        new Object[] {"m4", "Jack",   "Nichelson",Actor.Gender.Male, new Date(40, 4, 14)},
+        new Object[] {"m5", "Clint",  "Eastwood", Actor.Gender.Male, new Date(50, 1, 12)},
+        
+        new Object[] {"f1", "Meryl",   "Streep",    Actor.Gender.Female, new Date(40, 4, 14)},
+        new Object[] {"f2", "Fay",     "Dunaway",   Actor.Gender.Female, new Date(50, 1, 12)},
+        new Object[] {"f3", "Jodie",   "Foster",    Actor.Gender.Female, new Date(40, 4, 14)},
+        new Object[] {"f4", "Diane",   "Keaton",    Actor.Gender.Female, new Date(50, 1, 12)},
+        new Object[] {"f5", "Catherine", "Hepburn", Actor.Gender.Female, new Date(40, 4, 14)},
+    };
+    
+    public static Object[][] MOVIE_DATA = {
+        new Object[] {"1", "China Town", 1980},
+        new Object[] {"2", "Taxi Driver", 1980},
+        new Object[] {"3", "Where Eagles Dare", 1980},
+        new Object[] {"4", "Godfather", 1980},
+        new Object[] {"5", "Horse Whisperer", 1980},
+    };
+    
+    public static int[][] MOVIE_ACTORS = {
+        new int[] {3,6},
+        new int[] {1,7},
+        new int[] {4},
+        new int[] {2,3,8},
+        new int[] {0}
+    };
+    
+    public static int[][] PARTNERS = {
+        new int[] {3,6},
+        new int[] {1,7},
+        new int[] {3,8},
+    };
+
+    public void populate(EntityManager em) throws Exception {
+        Long count = em.createQuery("select count(m) from Movie m", Long.class).getSingleResult();
+        if (count != null && count.longValue() > 0) {
+            System.err.println("Found " + count + " Movie records in the database");
+            return;
+        }
+        
+        
+        Actor[] actors = createActors();
+        Movie[] movies = createMovies();
+        linkActorAndMovie(movies, actors);
+        makePartner(actors);
+        em.getTransaction().begin();
+        for (Actor a : actors) {
+            em.persist(a);
+        }
+        for (Movie m : movies) {
+            em.persist(m);
+        }
+        em.getTransaction().commit();
+    }
+    
+    Actor[] createActors() {
+        Actor[] actors = new Actor[ACTOR_DATA.length];
+        for (int i = 0; i < ACTOR_DATA.length; i++) {
+            Object[] a = ACTOR_DATA[i];
+            actors[i] = new Actor((String)a[0], (String)a[1], (String)a[2], (Actor.Gender)a[3], (Date)a[4]);
+        }
+        return actors;
+    }
+    
+    Movie[] createMovies() {
+        Movie[] movies = new Movie[MOVIE_DATA.length];
+        for (int i = 0; i < MOVIE_DATA.length; i++) {
+            Object[] m = MOVIE_DATA[i];
+            movies[i] = new Movie((String)m[0], (String)m[1], (Integer)m[2]);
+        }
+        return movies;
+    }
+    
+    void linkActorAndMovie(Movie[] movies, Actor[] actors) {
+        for (int i = 0; i < MOVIE_ACTORS.length; i++) {
+            int[] roles = MOVIE_ACTORS[i];
+            Movie m = movies[i];
+            for (int j = 0; j < roles.length; j++) {
+                Actor a = actors[roles[j]];
+                a.addMovie(m);
+                m.addActor(a);
+            }
+        }
+    }
+    
+    void makePartner(Actor[] actors) {
+        for (int i = 0; i < PARTNERS.length; i++) {
+            int[] partners = PARTNERS[i];
+            Actor a1 = actors[partners[0]];
+            Actor a2 = actors[partners[1]];
+            a1.setPartner(a2);
+            a2.setPartner(a1);
+       }
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/DataLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java Fri Dec 10 17:10:50 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package demo;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.apache.openjpa.persistence.FetchAttribute;
+import org.apache.openjpa.persistence.FetchGroup;
+import org.apache.openjpa.persistence.FetchGroups;
+
+/**
+ * @author Pinaki Poddar
+ *
+ */
+
+@Entity
+@FetchGroups({
+    @FetchGroup(name="OnlyTitle", attributes={
+        @FetchAttribute(name="title")
+    })
+})
+public class Movie {
+    @Id
+    private String id;
+    private String title;
+    private int year;
+    @OneToMany(fetch=FetchType.EAGER)
+    private Set<Actor> actors;
+    
+    protected Movie() {
+        
+    }
+    
+    public Movie(String id, String title, int year) {
+        super();
+        this.id = id;
+        this.title = title;
+        this.year = year;
+    }
+    
+    public String getId() {
+        return id;
+    }
+    
+    public String getTitle() {
+        return title;
+    }
+    
+    public void addActor(Actor a) {
+        if (actors == null)
+            actors = new HashSet<Actor>();
+        actors.add(a);
+    }
+    
+    public Set<Actor> getActors() {
+        return actors;
+    }
+    
+    public int getYear() {
+        return year;
+    }
+    
+}

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/Movie.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java Fri Dec 10 17:10:50 2010
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package demo;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A very simple servlet that is initialized with some example Actor-Movie records.
+ *  
+ * @author Pinaki Poddar
+ *
+ */
+@SuppressWarnings("serial")
+public class SimpleApp extends HttpServlet {
+    EntityManagerFactory _emf;
+    private static String UNIT_NAME = "jestdemo";
+    
+    @Override 
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        config.getServletContext().log("Initializing persistence unit [" + UNIT_NAME + "]");
+        try {
+            Map<String,Object> props = new HashMap<String, Object>();
+            props.put("openjpa.EntityManagerFactoryPool", "true");
+            _emf = Persistence.createEntityManagerFactory(UNIT_NAME, props);
+            new DataLoader().populate(_emf.createEntityManager());
+        } catch (Exception e) {
+            throw new ServletException(e);
+        }
+        config.getServletContext().log("Initialized with persistence unit [" + UNIT_NAME + "]");
+    }
+    
+    /**
+     * The only response by this application is an <code>index.html</code> file.
+     */
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        resp.setContentType("text/html");
+        OutputStream out = resp.getOutputStream();
+        InputStream in = getClass().getResourceAsStream("index.html");
+        for (int c = 0; (c = in.read()) != -1;) {
+            out.write((char)c);
+        }
+    }
+    
+    @Override
+    public void destroy() {
+        if (_emf != null) {
+            _emf.close();
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/java/demo/SimpleApp.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml Fri Dec 10 17:10:50 2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.   
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    version="1.0">
+    
+    <persistence-unit name="jestdemo">
+    
+    	<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+    	
+        <class>demo.Movie</class>
+        <class>demo.Actor</class>
+        
+        <properties>
+        <property name="javax.persistence.jdbc.driver"   value="com.mysql.jdbc.Driver"/>
+        <property name="javax.persistence.jdbc.url"      value="jdbc:mysql://localhost/jest"/>
+        <property name="javax.persistence.jdbc.user"     value="root"/>
+        <property name="javax.persistence.jdbc.password" value=""/>
+        <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true"/>
+        <property name="openjpa.Log" value="Tool=Trace,SQL=TRACE,Remote=TRACE"/>
+        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+        </properties>
+    </persistence-unit>
+    
+    
+</persistence>
+

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml Fri Dec 10 17:10:50 2010
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<web-app version="2.4" 
+         xmlns="http://java.sun.com/xml/ns/j2ee" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+  <display-name>Demo Application with JEST Servlet</display-name>  
+  <welcome-file-list>
+		<welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+  <description>
+    An example of deploying a simple web application with JEST servlet.
+    This descriptor specifies the Demo Application servlet as well as JEST servlet.
+  </description>
+  
+   	<servlet>
+   		<description> 
+   		This is the Demo Application Servlet.
+   		The servlet is mapped to URL pattern /app/* so this servlet can be accessed as
+   		                  http://host:port/demo/app/ 
+   		where "demo" is the name of the deployed web application.
+   		                  
+   		Assume that the Demo Application Servlet is using a persistence unit named 
+   		'jestdemo'. The JEST Servlet will require the persistence unit name to
+   		browse the Demo Application.                  
+   		</description>
+   		
+		<servlet-name>demo</servlet-name>
+		<servlet-class>demo.SimpleApp</servlet-class>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>demo</servlet-name>
+		<url-pattern>/*</url-pattern>
+	</servlet-mapping>
+  
+    <!-- Deployment descriptor for JESTServlet.                                           -->
+  	<servlet>
+  		<description>
+  		This is the JEST servlet. 
+  		JEST Servlet needs to know the name of the persistence unit used by the Demo Application.
+  		The unit name is specified by mandatory "persistence.unit" parameter during initialization.
+  		
+  		The JEST servlet is mapped to URL pattern /jest/* in servlet mapping section. So to access
+  		JEST servlet, use the following URI
+  		    http://host:port/demo/jest/
+  		Notice the trailing forward slash character is significant.     
+  		</description>
+		<servlet-name>jest</servlet-name>
+		<servlet-class>org.apache.openjpa.persistence.jest.JESTServlet</servlet-class>
+		<init-param>
+			<param-name>persistence.unit</param-name>
+			<param-value>jestdemo</param-value>
+		</init-param>
+		<init-param>
+			<param-name>debug</param-name>
+			<param-value>true</param-value>
+		</init-param>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>jest</servlet-name>
+		<url-pattern>/jest/*</url-pattern>
+	</servlet-mapping>
+  
+</web-app>

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html?rev=1044446&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html (added)
+++ openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html Fri Dec 10 17:10:50 2010
@@ -0,0 +1,93 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html>
+<head>
+<style type="text/css">
+p {margin-left:20px;}
+body {background-image:url("images/back40.gif");
+.tag {
+  color:green;
+  font-weight:bold;
+}
+</style>
+</head>
+<body>
+  <h1>DNA: Do-Nothing Application</h1>  
+  <hr>
+  <span style="font-size:1.2em;color:green;font-weight:bold">DNA application is used to demonstrate </span> 
+  <A HREF="./jest/">JEST</A>.
+  <br>
+  DNA application is deployed as a HTTP Servlet.<br>
+  
+  The servlet creates an OpenJPA persistence unit at initialization.<br>
+  
+  It does nothing else, other than serving this single web page you are reading now.
+  The fact that you are reading this page means the persistence unit has been initialized. 
+  <p>
+  
+  
+  <h2>Requirement for enabling JEST</h2>
+  
+  The requirements for an application to enable JEST are
+  
+  <p>
+  &#9658; JEST Servlet must be <A href="#web.xml">deployed</A> within the same module scope of the application.  <br>
+  &#9658; The unit name of the persistence unit used by the application must be known to JEST Servlet  <br>
+  &#9658; The persistence unit must be configured with <br>
+  &nbsp;&nbsp; <span style="color:green;font-weight:bold;text-align:center;background-color: #EEEEEE"><tt>openjpa.EntityManagerFactoryPool=true</tt></span> 
+  <p>
+  Once JEST servlet knows the name of the persistence unit, it can <br>
+  
+  &#9658; browse the domain model<br>
+  &#9658; execute query <br>
+  from any web browser in a <em>meta-data driven</em>, <em>generic</em> fashion 
+  i.e. without knowing anything further about he application. 
+  <p>
+  <p>
+  <hr>
+  <a name="web.xml"></a>
+  <h5>WEB-INF/web.xml : Deployment Descriptor for JEST-enabled Application</h5>
+  <div style="border:1px solid black; width:700px;background-color:#EEEEEE">
+  <pre>
+ <span style="color:gray;font-weight:bold;">&lt;servlet></span>
+   <span style="color:gray;font-weight:bold;">&lt;servlet-name></span><span style="color:blue;">demo</span><span style="color:gray;font-weight:bold;">&lt;/servlet-name>
+   &lt;servlet-class></span><span style="color:blue;">demo.SimpleApp</span><span style="color:gray;font-weight:bold;">&lt;/servlet-class>
+ &lt;/servlet>
+   &lt;servlet-mapping>
+   &lt;servlet-name></span><span style="color:blue;">demo</span><span style="color:gray;font-weight:bold;">&lt;/servlet-name>
+ &lt;url-pattern></span><span style="color:blue;">/*</span><span style="color:gray;font-weight:bold;">&lt;/url-pattern>
+ &lt;/servlet-mapping>
+  
+ <span style="color:green;font-weight:bold;">&lt;!-- Deployment descriptor for JESTServlet. --></span>
+ &lt;servlet>
+   &lt;servlet-name></span><span style="color:red;">jest</span><span style="color:gray;font-weight:bold;">&lt;/servlet-name>
+   &lt;servlet-class></span><span style="color:red;font-weight:bold;">org.apache.openjpa.persistence.jest.JESTServlet</span><span style="color:gray;font-weight:bold;">&lt;/servlet-class>
+   &lt;init-param>
+     &lt;param-name></span><span style="color:red;">persistence.unit</span><span style="color:gray;font-weight:bold;">&lt;/param-name>
+     &lt;param-value></span><span style="color:red;font-weight:bold;">jestdemo</span><span style="color:gray;font-weight:bold;">&lt;/param-value>
+   &lt;/init-param>
+ &lt;/servlet>
+ &lt;servlet-mapping>
+   &lt;servlet-name></span><span style="color:red;">jest</span><span style="color:gray;font-weight:bold;">&lt;/servlet-name>
+   &lt;url-pattern></span><span style="color:red;font-weight:bold;">/jest/*</span><span style="color:gray;font-weight:bold;">&lt;/url-pattern>
+ &lt;/servlet-mapping></span>
+</pre>
+  </div>
+</body>
+</html>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/trunk/openjpa-examples/jest/src/main/resources/demo/index.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain