Author: dblevins
Date: Mon Aug 4 19:49:11 2008
New Revision: 682566
URL: http://svn.apache.org/viewvc?rev=682566&view=rev
Log:
Example using EclipseLink. The dir name is wrong, need to rename it
Added:
openejb/trunk/openejb3/examples/jpa-toplink/
- copied from r682552, openejb/trunk/openejb3/examples/jpa-hibernate/
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movie.java
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movies.java
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/MoviesImpl.java
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/MoviesTest.java
Removed:
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/injection/h3jpa/
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/injection/h3jpa/
Modified:
openejb/trunk/openejb3/examples/jpa-toplink/pom.xml
openejb/trunk/openejb3/examples/jpa-toplink/src/main/resources/META-INF/persistence.xml
Modified: openejb/trunk/openejb3/examples/jpa-toplink/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/pom.xml?rev=682566&r1=682552&r2=682566&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/jpa-toplink/pom.xml (original)
+++ openejb/trunk/openejb3/examples/jpa-toplink/pom.xml Mon Aug 4 19:49:11 2008
@@ -1,31 +1,31 @@
-<?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.
--->
-
-<!-- $Rev: 636494 $ $Date: 2008-03-12 21:24:02 +0100 (Wed, 12 Mar 2008) $ -->
-
+<?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.
+-->
+
+<!-- $Rev: 636494 $ $Date: 2008-03-12 21:24:02 +0100 (Wed, 12 Mar 2008) $ -->
+
<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.superbiz</groupId>
- <artifactId>jpa-hibernate</artifactId>
+ <artifactId>jpa-eclipselink</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
- <name>OpenEJB :: Examples :: JPA with Hibernate</name>
+ <name>OpenEJB :: Examples :: JPA with EclipseLink</name>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
@@ -44,6 +44,11 @@
<name>Apache Snapshot Repository</name>
<url>http://people.apache.org/repo/m2-snapshot-repository/</url>
</repository>
+ <repository>
+ <id>eclipselink-repo</id>
+ <name>EclipseLink Repository</name>
+
<url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url>
+ </repository>
</repositories>
<dependencies>
@@ -70,47 +75,14 @@
<scope>test</scope>
</dependency>
- <!-- hibernate dependencies -->
+ <!-- toplink dependencies -->
<dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate</artifactId>
- <version>3.2.5.ga</version>
- <exclusions>
- <exclusion>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.transaction</groupId>
- <artifactId>jta</artifactId>
- </exclusion>
- </exclusions>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib-nodep</artifactId>
- <version>2.1_3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>2.2.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>3.2.1.ga</version>
- <exclusions>
- <exclusion>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>eclipselink</artifactId>
+ <version>1.0.1</version>
<scope>test</scope>
</dependency>
+
</dependencies>
</project>
\ No newline at end of file
Added:
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movie.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movie.java?rev=682566&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movie.java
(added)
+++
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movie.java
Mon Aug 4 19:49:11 2008
@@ -0,0 +1,66 @@
+/**
+ * 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 org.superbiz.eclipselink;
+
+import javax.persistence.*;
+
[EMAIL PROTECTED]
+public class Movie {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private long id;
+
+ private String director;
+ private String title;
+ private int year;
+
+ public Movie() {
+ }
+
+ public Movie(String director, String title, int year) {
+ this.director = director;
+ this.title = title;
+ this.year = year;
+ }
+
+ public String getDirector() {
+ return director;
+ }
+
+ public void setDirector(String director) {
+ this.director = director;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public int getYear() {
+ return year;
+ }
+
+ public void setYear(int year) {
+ this.year = year;
+ }
+
+
+}
Added:
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movies.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movies.java?rev=682566&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movies.java
(added)
+++
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/Movies.java
Mon Aug 4 19:49:11 2008
@@ -0,0 +1,32 @@
+/**
+ * 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 org.superbiz.eclipselink;
+
+import org.superbiz.eclipselink.Movie;
+
+import java.util.List;
+
+/**
+ * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec
2007) $
+ */
+public interface Movies {
+ void addMovie(Movie movie) throws Exception ;
+
+ void deleteMovie(Movie movie) throws Exception ;
+
+ List<Movie> getMovies() throws Exception ;
+}
Added:
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/MoviesImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/MoviesImpl.java?rev=682566&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/MoviesImpl.java
(added)
+++
openejb/trunk/openejb3/examples/jpa-toplink/src/main/java/org/superbiz/eclipselink/MoviesImpl.java
Mon Aug 4 19:49:11 2008
@@ -0,0 +1,49 @@
+/**
+ * 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 org.superbiz.eclipselink;
+
+import org.superbiz.eclipselink.Movie;
+import org.superbiz.eclipselink.Movies;
+
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.PersistenceUnit;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import java.util.List;
+
[EMAIL PROTECTED](name = "Movies")
+public class MoviesImpl implements Movies {
+
+ @PersistenceContext(unitName = "movie-unit", type =
PersistenceContextType.EXTENDED)
+ private EntityManager entityManager;
+
+ public void addMovie(Movie movie) throws Exception {
+ entityManager.persist(movie);
+ }
+
+ public void deleteMovie(Movie movie) throws Exception {
+ entityManager.remove(movie);
+ }
+
+ public List<Movie> getMovies() throws Exception {
+ Query query = entityManager.createQuery("SELECT m from Movie as m");
+ return query.getResultList();
+ }
+
+}
Modified:
openejb/trunk/openejb3/examples/jpa-toplink/src/main/resources/META-INF/persistence.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/src/main/resources/META-INF/persistence.xml?rev=682566&r1=682552&r2=682566&view=diff
==============================================================================
---
openejb/trunk/openejb3/examples/jpa-toplink/src/main/resources/META-INF/persistence.xml
(original)
+++
openejb/trunk/openejb3/examples/jpa-toplink/src/main/resources/META-INF/persistence.xml
Mon Aug 4 19:49:11 2008
@@ -21,13 +21,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="movie-unit">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>movieDatabase</jta-data-source>
<non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
<properties>
- <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
- <property name="hibernate.transaction.manager_lookup_class"
- value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
+ <property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.HSQLPlatform"/>
+ <property name="eclipselink.ddl-generation" value="create-tables"/>
+ <property name="eclipselink.ddl-generation.output-mode"
value="database"/>
</properties>
</persistence-unit>
</persistence>
Added:
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/MoviesTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/MoviesTest.java?rev=682566&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/MoviesTest.java
(added)
+++
openejb/trunk/openejb3/examples/jpa-toplink/src/test/java/org/superbiz/eclipselink/MoviesTest.java
Mon Aug 4 19:49:11 2008
@@ -0,0 +1,60 @@
+/**
+ * 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 org.superbiz.eclipselink;
+
+import junit.framework.TestCase;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec
2007) $
+ */
+public class MoviesTest extends TestCase {
+
+ public void test() throws Exception {
+ Properties p = new Properties();
+ p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
+ p.put("movieDatabase", "new://Resource?type=DataSource");
+ p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+
+ p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
+ p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+ p.put("movieDatabaseUnmanaged.JtaManaged", "false");
+
+ Context context = new InitialContext(p);
+
+ Movies movies = (Movies) context.lookup("MoviesLocal");
+
+ movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs",
1992));
+ movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
+ movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
+
+ List<Movie> list = movies.getMovies();
+ assertEquals("List.size()", 3, list.size());
+
+ for (Movie movie : list) {
+ movies.deleteMovie(movie);
+ }
+
+ assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+ }
+}