Return-Path: Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: (qmail 15856 invoked from network); 20 Nov 2010 05:52:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 20 Nov 2010 05:52:28 -0000 Received: (qmail 50336 invoked by uid 500); 20 Nov 2010 05:52:59 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 50285 invoked by uid 500); 20 Nov 2010 05:52:59 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 50278 invoked by uid 99); 20 Nov 2010 05:52:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Nov 2010 05:52:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Nov 2010 05:52:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5321F238897F; Sat, 20 Nov 2010 05:51:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1037116 - in /openjpa/sandboxes/jest/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/ Date: Sat, 20 Nov 2010 05:51:42 -0000 To: commits@openjpa.apache.org From: ppoddar@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101120055142.5321F238897F@eris.apache.org> Author: ppoddar Date: Sat Nov 20 05:51:41 2010 New Revision: 1037116 URL: http://svn.apache.org/viewvc?rev=1037116&view=rev Log: OPENJPA-1859: The demo for JEST Added: openjpa/sandboxes/jest/openjpa-examples/jest/ openjpa/sandboxes/jest/openjpa-examples/jest/build.properties (with props) openjpa/sandboxes/jest/openjpa-examples/jest/build.xml (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml (with props) openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html (with props) Added: openjpa/sandboxes/jest/openjpa-examples/jest/build.properties URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/build.properties?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/build.properties (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/build.properties Sat Nov 20 05:51:41 2010 @@ -0,0 +1,55 @@ +# 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 +# +# ------------------------------------------------------------------------------- +# Directory location of maven repository +maven.repos=${user.home}/.m2/repository +# OpenJPA runtime artifact +openjpa.version=2.1.0-SNAPSHOT + +# This is the variable of interest. +# Notice that the variable points to a directory, not a *.jar file. +# All *.jar files under the directory will be included in compilation. +# Though the varaible value is expressed in terms of other variables here, +# you can specify the value directly. +openjpa.lib=${maven.repos}/org/apache/openjpa/openjpa-all/${openjpa.version} + + +jpa.jar.dir=${maven.repos}/org/apache/geronimo/specs/geronimo-jpa_2.0_spec/1.0 +jpa.jar=geronimo-jpa_2.0_spec-1.0.jar +jta.jar.dir=${maven.repos}/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.1.1 +jta.jar=geronimo-jta_1.1_spec-1.1.1.jar +openjpa.jar.dir=c:/wspace/jest +openjpa.jar=openjpa.jar +jdbc.jar.dir=c:/mysql/mysql-connector-java-5.1.6 +jdbc.jar=mysql-connector-java-5.1.6-bin.jar +coll.jar.dir=${maven.repos}/commons-collections/commons-collections/3.2.1 +coll.jar=commons-collections-3.2.1.jar +lang.jar.dir=${maven.repos}/commons-lang/commons-lang/2.4 +lang.jar=commons-lang-2.4.jar +serp.jar.dir=${maven.repos}/net/sourceforge/serp/serp/1.14.2 +serp.jar=serp-1.14.2.jar +servlet.jar.dir=c:/apache-tomcat-6.0.29/lib +servlet.jar=servlet-api.jar + + +tomcat.server=localhost +tomcat.manager.url=http://${tomcat.server}:8080/manager +tomcat.username=admin +tomcat.password=admin Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/build.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/build.xml URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/build.xml?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/build.xml (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/build.xml Sat Nov 20 05:51:41 2010 @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/build.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java Sat Nov 20 05:51:41 2010 @@ -0,0 +1,100 @@ +/* + * 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; + +/** + * A persistent entity with singular and plural association. + * + * @author Pinaki Poddar + * + */ +@Entity +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 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 getMovies() { + return movies; + } + + public void addMovie(Movie movie) { + if (movies == null) + movies = new HashSet(); + movies.add(movie); + } +} Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Actor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java Sat Nov 20 05:51:41 2010 @@ -0,0 +1,77 @@ +/* + * 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.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +/** + * @author Pinaki Poddar + * + */ + +@Entity +public class Movie { + @Id + @GeneratedValue + private long id; + private String title; + private int year; + @OneToMany(fetch=FetchType.EAGER) + private Set actors; + + protected Movie() { + + } + public Movie(String title, int year) { + super(); + this.title = title; + this.year = year; + } + + public long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void addActor(Actor a) { + if (actors == null) + actors = new HashSet(); + actors.add(a); + } + + public Set getActors() { + return actors; + } + + public int getYear() { + return year; + } + +} Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/Movie.java ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java Sat Nov 20 05:51:41 2010 @@ -0,0 +1,172 @@ +/* + * 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 { + + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + String unit = config.getInitParameter("persistence.unit"); + config.getServletContext().log("SimpleApp initializing with persistence unit [" + unit + "]"); + Map props = new HashMap(); + props.put("openjpa.EntityManagerFactoryPool", "true"); + EntityManagerFactory emf = Persistence.createEntityManagerFactory(unit, props); + config.getServletContext().getContextPath(); + populate(emf.createEntityManager(), config.getServletContext()); + } + + @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); + } + } + + + public void populate(EntityManager em, ServletContext ctx) { + Long count = em.createQuery("select count(m) from Movie m", Long.class).getSingleResult(); + if (count != null && count.longValue() > 0) { + ctx.log("Found " + count + " Movie records in the database"); + return; + } + ctx.log("Populating Movie database with " + MOVIE_DATA.length + " movies and " + ACTOR_DATA.length + " actors"); + + List actors = createActors(); + List movies = createMovies(); + linkActorAndMovie(actors, movies); + makePartner(actors); + em.getTransaction().begin(); + for (Actor a : actors) { + em.persist(a); + } + for (Movie m : movies) { + em.persist(m); + } + em.getTransaction().commit(); + } + + List createActors() { + List actors = new ArrayList(); + for (Object[] a : ACTOR_DATA) { + Actor actor = new Actor((String)a[0], (String)a[1], (String)a[2], (Actor.Gender)a[3], (Date)a[4]); + actors.add(actor); + } + return actors; + } + + List createMovies() { + List movies = new ArrayList(); + for (Object[] m : MOVIE_DATA) { + Movie movie = new Movie((String)m[0], (Integer)m[1]); + movies.add(movie); + } + return movies; + } + + void linkActorAndMovie(List actors, List movies) { + for (Actor a : actors) { + int n = rng.nextInt(movies.size()); + for (int i = 0; i < n; i++) { + Movie m = random(movies); + a.addMovie(m); + m.addActor(a); + } + } + } + + void makePartner(List actors) { + for (Actor p : actors) { + if (p.getPartner() != null) + continue; + Actor f = random(actors); + if (f.getPartner() == null && p.getGender() != f.getGender()) { + p.setPartner(f); + f.setPartner(p); + } + } + } + + /** + * Select a random element from the given list. + */ + private T random(List list) { + return list.get(rng.nextInt(list.size())); + } + + private static Random rng = new Random(); + + public static Object[][] MOVIE_DATA = { + new Object[] {"One flew over the cuckoo's nest", 1980}, + new Object[] {"Everyone Says I Love You", 1980}, + new Object[] {"Where Eagles Dare", 1980}, + new Object[] {"Fight Club", 1980}, + new Object[] {"Horse Whisperer", 1980}, + }; + + @SuppressWarnings("deprecation") + public static Object[][] ACTOR_DATA = { + new Object[] {"m01", "Robert", "Redford", Actor.Gender.Male, new Date(1950, 1, 12)}, + new Object[] {"m02", "Robert", "De Niro", Actor.Gender.Male, new Date(1940, 4, 14)}, + new Object[] {"m03", "Al", "Pacino", Actor.Gender.Male, new Date(1950, 1, 12)}, + new Object[] {"m04", "Brad", "Pitt", Actor.Gender.Male, new Date(1940, 4, 14)}, + new Object[] {"m05", "Clint", "Eastwood",Actor.Gender.Male, new Date(1950, 1, 12)}, + + new Object[] {"f01", "Meryl", "Streep", Actor.Gender.Female, new Date(1940, 4, 14)}, + new Object[] {"f02", "Anglina", "Jolie", Actor.Gender.Female, new Date(1950, 1, 12)}, + new Object[] {"f03", "Goldie", "Hawn", Actor.Gender.Female, new Date(1940, 4, 14)}, + new Object[] {"f04", "Diane", "Keaton", Actor.Gender.Female, new Date(1950, 1, 12)}, + new Object[] {"f05", "Catherine", "Hepburn", Actor.Gender.Female, new Date(1940, 4, 14)}, + }; + + +} Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/java/demo/SimpleApp.java ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml Sat Nov 20 05:51:41 2010 @@ -0,0 +1,43 @@ + + + + + + + org.apache.openjpa.persistence.PersistenceProviderImpl + + demo.Movie + demo.Actor + + + + + + + + + + + + + + + Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/META-INF/persistence.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml Sat Nov 20 05:51:41 2010 @@ -0,0 +1,75 @@ + + + + + Demo Application with JEST Servlet + + An example of deploying a simple web application with JEST servlet. + This descriptor specifies the Demo Application servlet as well as JEST servlet. + + + + + 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. + + + demo + demo.SimpleApp + + + demo + /app/* + + + + + + 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. + + jest + org.apache.openjpa.persistence.jest.JESTServlet + + persistence.unit + jestdemo + + + + jest + /jest/* + + + Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html?rev=1037116&view=auto ============================================================================== --- openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html (added) +++ openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html Sat Nov 20 05:51:41 2010 @@ -0,0 +1,16 @@ + + +

Welcome to a do-nothing application

+
+ This do-nothing application initializes a JPA persistence unit with OpenJPA as provider and its only + response + is the page you are reading now. +
+ This application is used to demonstrate JEST. +
+ This application is deployed along with a JEST Servlet within the same module scope. + As long as JEST servlet knows the name of the persistence unit of this do-nothing + application, JEST Servlet can browse the domain model, execute query or find in + a generic fashion. + + \ No newline at end of file Propchange: openjpa/sandboxes/jest/openjpa-examples/jest/src/main/resources/demo/index.html ------------------------------------------------------------------------------ svn:eol-style = native