You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/10/05 00:12:24 UTC
svn commit: r1004457 - in /openejb/branches/openejb-3.1.x/examples: ./
application-composer/
application-composer/src/main/java/org/superbiz/composed/
application-composer/src/main/java/org/superbiz/testinjection/
application-composer/src/main/resource...
Author: dblevins
Date: Mon Oct 4 22:12:23 2010
New Revision: 1004457
URL: http://svn.apache.org/viewvc?rev=1004457&view=rev
Log:
Example for OPENEJB-1364
Added:
openejb/branches/openejb-3.1.x/examples/application-composer/
- copied from r1004172, openejb/branches/openejb-3.1.x/examples/testcase-injection/
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java (with props)
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java (with props)
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java (with props)
openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/
openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java (with props)
Removed:
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/testinjection/
openejb/branches/openejb-3.1.x/examples/application-composer/src/main/resources/META-INF/
openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/testinjection/
openejb/branches/openejb-3.1.x/examples/application-composer/src/test/resources/META-INF/
Modified:
openejb/branches/openejb-3.1.x/examples/application-composer/pom.xml
openejb/branches/openejb-3.1.x/examples/pom.xml
Modified: openejb/branches/openejb-3.1.x/examples/application-composer/pom.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/application-composer/pom.xml?rev=1004457&r1=1004172&r2=1004457&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/application-composer/pom.xml (original)
+++ openejb/branches/openejb-3.1.x/examples/application-composer/pom.xml Mon Oct 4 22:12:23 2010
@@ -22,10 +22,10 @@
<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>testcase-injection</artifactId>
+ <artifactId>application-composer</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
- <name>OpenEJB :: Examples :: TestCase Injection</name>
+ <name>OpenEJB :: Examples :: Application Composer</name>
<properties>
<!--
- http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding
@@ -61,7 +61,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.1</version>
+ <version>4.5</version>
<scope>test</scope>
</dependency>
Added: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java?rev=1004457&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java (added)
+++ openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java Mon Oct 4 22:12:23 2010
@@ -0,0 +1,62 @@
+/**
+ * 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.composed;
+
+import javax.persistence.Entity;
+
+@Entity
+public class Movie {
+
+ 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;
+ }
+
+
+}
Propchange: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java?rev=1004457&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java (added)
+++ openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java Mon Oct 4 22:12:23 2010
@@ -0,0 +1,30 @@
+/**
+ * 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.composed;
+
+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 ;
+}
Propchange: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java?rev=1004457&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java (added)
+++ openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java Mon Oct 4 22:12:23 2010
@@ -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.composed;
+
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import static javax.ejb.TransactionAttributeType.MANDATORY;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.Query;
+import java.util.List;
+
+//START SNIPPET: code
+@Stateful(name = "Movies")
+@TransactionAttribute(MANDATORY)
+public class MoviesImpl implements Movies {
+
+ @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION)
+ 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();
+ }
+}
+//END SNIPPET: code
Propchange: openejb/branches/openejb-3.1.x/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java?rev=1004457&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java (added)
+++ openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java Mon Oct 4 22:12:23 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 org.superbiz.composed;
+
+import junit.framework.TestCase;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatefulBean;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.UserTransaction;
+import java.util.List;
+import java.util.Properties;
+
+//START SNIPPET: code
+@RunWith(ApplicationComposer.class)
+public class MoviesTest extends TestCase {
+
+ @EJB
+ private Movies movies;
+
+ @Resource
+ private UserTransaction userTransaction;
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Module
+ public PersistenceUnit persistence() {
+ PersistenceUnit unit = new PersistenceUnit("movie-unit");
+ unit.setJtaDataSource("movieDatabase");
+ unit.setNonJtaDataSource("movieDatabaseUnmanaged");
+ unit.getClazz().add(Movie.class.getName());
+ unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+ return unit;
+ }
+
+ @Module
+ public EjbJar beans() {
+ EjbJar ejbJar = new EjbJar("movie-beans");
+ ejbJar.addEnterpriseBean(new StatefulBean(MoviesImpl.class));
+ return ejbJar;
+ }
+
+ @Configuration
+ public Properties config() throws Exception {
+ Properties p = new Properties();
+ p.put("movieDatabase", "new://Resource?type=DataSource");
+ p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+ return p;
+ }
+
+ @Test
+ public void test() throws Exception {
+
+ userTransaction.begin();
+
+ try {
+ entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
+ entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
+ entityManager.persist(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());
+
+ } finally {
+ userTransaction.commit();
+ }
+ }
+}
+//END SNIPPET: code
Propchange: openejb/branches/openejb-3.1.x/examples/application-composer/src/test/java/org/superbiz/composed/MoviesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openejb/branches/openejb-3.1.x/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/examples/pom.xml?rev=1004457&r1=1004456&r2=1004457&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/examples/pom.xml (original)
+++ openejb/branches/openejb-3.1.x/examples/pom.xml Mon Oct 4 22:12:23 2010
@@ -67,6 +67,7 @@
<module>webservice-inheritance</module>
<module>transaction-rollback</module>
<module>troubleshooting</module>
+ <module>application-composer</module>
</modules>
<profiles>