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/02/21 23:41:55 UTC

svn commit: r912428 - in /openejb/trunk/openejb3/examples: ./ transaction-rollback/ transaction-rollback/src/ transaction-rollback/src/main/ transaction-rollback/src/main/java/ transaction-rollback/src/main/java/org/ transaction-rollback/src/main/java/...

Author: dblevins
Date: Sun Feb 21 22:41:54 2010
New Revision: 912428

URL: http://svn.apache.org/viewvc?rev=912428&view=rev
Log:
Simple example that shows transaction rollback.

Added:
    openejb/trunk/openejb3/examples/transaction-rollback/
    openejb/trunk/openejb3/examples/transaction-rollback/build.xml   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/pom.xml   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java   (with props)
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/
    openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml   (with props)
Modified:
    openejb/trunk/openejb3/examples/pom.xml

Modified: openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=912428&r1=912427&r2=912428&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Sun Feb 21 22:41:54 2010
@@ -65,6 +65,7 @@
     <module>webservice-security</module>
     <module>webservice-ws-security</module>
     <module>webservice-inheritance</module>
+    <module>transaction-rollback</module>
   </modules>
 
   <profiles>

Added: openejb/trunk/openejb3/examples/transaction-rollback/build.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/build.xml?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/build.xml (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/build.xml Sun Feb 21 22:41:54 2010
@@ -0,0 +1,120 @@
+<?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: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ -->
+
+<project name="MyProject" default="dist" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <!-- ===============================================================
+
+  HOW TO RUN
+
+    Download http://archive.apache.org/dist/maven/binaries/maven-ant-tasks-2.0.9.jar
+    Then execute ant as follows:
+
+    ant -lib maven-ant-tasks-2.0.9.jar
+
+  NOTE
+
+    You do NOT need maven-ant-tasks-2.0.9.jar to use OpenEJB for embedded EJB
+    testing with Ant.  It is simply used in this example to make the build.xml
+    a bit simpler.  As long as OpenEJB and it's required libraries are in the
+    <junit> classpath, the tests will run with OpenEJB embedded.
+
+  ================================================================= -->
+
+  <artifact:remoteRepository id="apache.snapshot.repository" url="http://repository.apache.org/snapshots/" />
+  <artifact:remoteRepository id="m2.repository" url="http://repo1.maven.org/maven2/" />
+
+  <!-- Build Classpath -->
+  <artifact:dependencies pathId="classpath.main">
+    <dependency groupId="org.apache.openejb" artifactId="javaee-api" version="5.0-3-SNAPSHOT"/>
+  </artifact:dependencies>
+
+  <!-- Test Build Classpath -->
+  <artifact:dependencies pathId="classpath.test.build">
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+    <dependency groupId="org.apache.openejb" artifactId="openejb-api" version="3.1.3-SNAPSHOT"/>
+  </artifact:dependencies>
+
+  <!-- Test Run Classpath -->
+  <artifact:dependencies pathId="classpath.test.run">
+    <remoteRepository refid="apache.snapshot.repository" />
+    <remoteRepository refid="m2.repository" />
+
+    <dependency groupId="org.apache.openejb" artifactId="openejb-core" version="3.1.3-SNAPSHOT"/>
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Properties -->
+
+  <property name="src.main.java" location="src/main/java"/>
+  <property name="src.main.resources" location="src/main/resources"/>
+  <property name="src.test.java" location="src/test/java"/>
+  <property name="build.main" location="target/classes"/>
+  <property name="build.test" location="target/test-classes"/>
+  <property name="test.reports" location="target/test-reports"/>
+  <property name="dist" location="target"/>
+
+
+  <target name="init">
+    <mkdir dir="${build.main}"/>
+    <mkdir dir="${build.test}"/>
+    <mkdir dir="${test.reports}"/>
+  </target>
+
+  <target name="compile" depends="init">
+
+    <javac srcdir="${src.main.java}" destdir="${build.main}">
+      <classpath refid="classpath.main" />
+    </javac>
+    <copy todir="${build.main}">
+      <fileset dir="${src.main.resources}"/>
+    </copy>
+
+    <javac srcdir="${src.test.java}" destdir="${build.test}">
+      <classpath location="${build.main}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+    </javac>
+  </target>
+
+  <target name="test" depends="compile">
+    <junit fork="yes" printsummary="yes">
+      <classpath location="${build.main}"/>
+      <classpath location="${build.test}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+      <classpath refid="classpath.test.run"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${src.test.java}">
+          <include name="**/*Test.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="dist" depends="test">
+    <jar jarfile="${dist}/myproject-1.0.jar" basedir="${build.main}"/>
+  </target>
+
+</project>

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/pom.xml?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/pom.xml (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/pom.xml Sun Feb 21 22:41:54 2010
@@ -0,0 +1,95 @@
+<?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>transaction-rollback</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Transaction Rollback</name>
+  <properties>
+    <!--
+       - http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding
+       -->
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>5.0-3-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- openejb container for running tests -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>3.1.3-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+</project>

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java Sun Feb 21 22:41:54 2010
@@ -0,0 +1,69 @@
+/**
+ * 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.txrollback;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity(name = "Movie")
+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;
+    }
+
+
+}

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movie.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java Sun Feb 21 22:41:54 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.txrollback;
+
+import java.util.List;
+
+public interface Movies {
+    void addMovie(Movie movie) throws Exception;
+
+    void deleteMovie(Movie movie) throws Exception;
+
+    List<Movie> getMovies() throws Exception;
+}

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/Movies.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java Sun Feb 21 22:41:54 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.txrollback;
+
+import javax.ejb.Stateful;
+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")
+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();
+    }
+}

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/main/java/org/superbiz/txrollback/MoviesImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml Sun Feb 21 22:41:54 2010
@@ -0,0 +1 @@
+<ejb-jar/>

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/ejb-jar.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml Sun Feb 21 22:41:54 2010
@@ -0,0 +1,30 @@
+<?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" version="1.0">
+  
+  <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.MoviesTest.Movie</class>
+
+    <properties>
+      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+    </properties>
+  </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java Sun Feb 21 22:41:54 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 org.superbiz.txrollback;
+
+import junit.framework.TestCase;
+import org.apache.openejb.api.LocalClient;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.UserTransaction;
+import java.util.List;
+import java.util.Properties;
+
+//START SNIPPET: code
+@LocalClient
+public class MoviesTest extends TestCase {
+
+    @EJB
+    private Movies movies;
+
+    @Resource
+    private UserTransaction userTransaction;
+
+    @PersistenceContext
+    private EntityManager entityManager;
+
+    private InitialContext initialContext;
+
+    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" + System.currentTimeMillis());
+        p.put("openejb.embedded.initialcontext.close", "DESTROY");
+
+        initialContext = new InitialContext(p);
+
+        initialContext.bind("inject", this);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        initialContext.close();
+    }
+
+    public void testCommit() 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());
+
+        } finally {
+            userTransaction.commit();
+        }
+
+        // Transaction was committed
+        List<Movie> list = movies.getMovies();
+        assertEquals("List.size()", 3, list.size());
+
+    }
+
+    public void testRollback() 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());
+
+        } finally {
+            userTransaction.rollback();
+        }
+
+        // Transaction was rolled back
+        List<Movie> list = movies.getMovies();
+        assertEquals("List.size()", 0, list.size());
+
+    }
+
+}
+//END SNIPPET: code

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/test/java/org/superbiz/txrollback/MoviesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml?rev=912428&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml (added)
+++ openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml Sun Feb 21 22:41:54 2010
@@ -0,0 +1 @@
+<application-client/>
\ No newline at end of file

Propchange: openejb/trunk/openejb3/examples/transaction-rollback/src/test/resources/META-INF/application-client.xml
------------------------------------------------------------------------------
    svn:eol-style = native