Author: dblevins
Date: Tue Jun 2 23:28:49 2009
New Revision: 781210
URL: http://svn.apache.org/viewvc?rev=781210&view=rev
Log:
Example that shows the alternate deployment descriptor functionality
Added:
openejb/trunk/openejb3/examples/alternate-descriptors/
- copied from r780161, openejb/trunk/openejb3/examples/testcase-injection/
openejb/trunk/openejb3/examples/alternate-descriptors/build.xml
- copied unchanged from r780182,
openejb/trunk/openejb3/examples/testcase-injection/build.xml
openejb/trunk/openejb3/examples/alternate-descriptors/pom.xml
- copied, changed from r780182,
openejb/trunk/openejb3/examples/testcase-injection/pom.xml
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/MoviesImpl.java
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
(contents, props changed)
- copied, changed from r780161,
openejb/trunk/openejb3/examples/testcase-injection/src/main/resources/META-INF/ejb-jar.xml
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java
Removed:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/testinjection/
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/testinjection/
Modified:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/persistence.xml
openejb/trunk/openejb3/examples/pom.xml
openejb/trunk/openejb3/examples/webapps/pom.xml
Copied: openejb/trunk/openejb3/examples/alternate-descriptors/pom.xml (from
r780182, openejb/trunk/openejb3/examples/testcase-injection/pom.xml)
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/pom.xml?p2=openejb/trunk/openejb3/examples/alternate-descriptors/pom.xml&p1=openejb/trunk/openejb3/examples/testcase-injection/pom.xml&r1=780182&r2=781210&rev=781210&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/testcase-injection/pom.xml (original)
+++ openejb/trunk/openejb3/examples/alternate-descriptors/pom.xml Tue Jun 2
23:28:49 2009
@@ -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>alternate-descriptors</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
- <name>OpenEJB :: Examples :: TestCase Injection</name>
+ <name>OpenEJB :: Examples :: Alternate Descriptors</name>
<properties>
<!--
-
http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding
Added:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java?rev=781210&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java
(added)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java
Tue Jun 2 23:28:49 2009
@@ -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.altdd;
+
+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;
+ }
+
+
+}
Added:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java?rev=781210&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java
(added)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java
Tue Jun 2 23:28:49 2009
@@ -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.altdd;
+
+import org.superbiz.altdd.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/alternate-descriptors/src/main/java/org/superbiz/altdd/MoviesImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/MoviesImpl.java?rev=781210&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/MoviesImpl.java
(added)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/MoviesImpl.java
Tue Jun 2 23:28:49 2009
@@ -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.altdd;
+
+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
Modified:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/persistence.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/persistence.xml?rev=781210&r1=780161&r2=781210&view=diff
==============================================================================
---
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/persistence.xml
(original)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/persistence.xml
Tue Jun 2 23:28:49 2009
@@ -21,7 +21,7 @@
<persistence-unit name="movie-unit">
<jta-data-source>movieDatabase</jta-data-source>
<non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
- <class>org.superbiz.testinjection.Movie</class>
+ <class>org.superbiz.altdd.Movie</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
Copied:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
(from r780161,
openejb/trunk/openejb3/examples/testcase-injection/src/main/resources/META-INF/ejb-jar.xml)
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml?p2=openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml&p1=openejb/trunk/openejb3/examples/testcase-injection/src/main/resources/META-INF/ejb-jar.xml&r1=780161&r2=781210&rev=781210&view=diff
==============================================================================
---
openejb/trunk/openejb3/examples/testcase-injection/src/main/resources/META-INF/ejb-jar.xml
(original)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
Tue Jun 2 23:28:49 2009
@@ -1 +1,9 @@
-<ejb-jar/>
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+ <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee">
+ <assembly-descriptor>
+ <interceptor-binding>
+ <ejb-name>Movies</ejb-name>
+
<interceptor-class>org.superbiz.altdd.MoviesTest$Interceptor</interceptor-class>
+ </interceptor-binding>
+ </assembly-descriptor>
+ </ejb-jar>
Propchange:
openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Jun 2 23:28:49 2009
@@ -0,0 +1 @@
+/openejb/branches/openejb-3.1.1/examples/alternate-descriptors/src/main/resources/META-INF/ejb-jar.xml:779593
Added:
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java?rev=781210&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java
(added)
+++
openejb/trunk/openejb3/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java
Tue Jun 2 23:28:49 2009
@@ -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.
+ */
+package org.superbiz.altdd;
+
+import junit.framework.TestCase;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.ejb.EJB;
+import javax.ejb.SessionContext;
+import javax.transaction.UserTransaction;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.annotation.Resource;
+import javax.annotation.PostConstruct;
+import javax.persistence.PersistenceContext;
+import javax.persistence.EntityManager;
+import javax.interceptor.InvocationContext;
+import javax.interceptor.AroundInvoke;
+import java.util.Properties;
+import java.util.List;
+
+import org.superbiz.altdd.Movie;
+import org.superbiz.altdd.Movies;
+import org.apache.openejb.api.LocalClient;
+
+//START SNIPPET: code
+...@localclient
+public class MoviesTest extends TestCase {
+
+ @EJB
+ private Movies movies;
+
+ @Resource
+ private UserTransaction userTransaction;
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ public void setUp() 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("openejb.altdd.prefix", "test");
+
+ InitialContext initialContext = new InitialContext(p);
+
+ // Here's the fun part
+ initialContext.bind("inject", this);
+ }
+
+ 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 {
+ try {
+ userTransaction.commit();
+ fail("Transaction should have been rolled back");
+ } catch (RollbackException e) {
+ // Good, we don't want to clean up the db
+ }
+ }
+ }
+
+ public static class Interceptor {
+
+ @Resource
+ private SessionContext sessionContext;
+
+ @AroundInvoke
+ public Object invoke(InvocationContext context) throws Exception {
+
+ sessionContext.setRollbackOnly();
+
+ return context.proceed();
+ }
+ }
+}
+//END SNIPPET: code
Modified: openejb/trunk/openejb3/examples/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=781210&r1=781209&r2=781210&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Tue Jun 2 23:28:49 2009
@@ -49,6 +49,7 @@
<module>testing-security</module>
<module>testing-security-2</module>
<module>testcase-injection</module>
+ <module>alternate-descriptors</module>
<module>ear-testing</module>
<module>interceptors</module>
<module>custom-injection</module>
Modified: openejb/trunk/openejb3/examples/webapps/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/pom.xml?rev=781210&r1=781209&r2=781210&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/pom.xml (original)
+++ openejb/trunk/openejb3/examples/webapps/pom.xml Tue Jun 2 23:28:49 2009
@@ -35,6 +35,7 @@
<module>ejb-webservice</module>
<module>jsf</module>
<module>struts</module>
+ <module>moviefun</module>
</modules>
</project>