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 2012/01/27 07:27:33 UTC

svn commit: r1236542 - in /openejb/site/trunk/content: tomcat-activemq.mdtext tomcat-jpa.mdtext

Author: dblevins
Date: Fri Jan 27 06:27:33 2012
New Revision: 1236542

URL: http://svn.apache.org/viewvc?rev=1236542&view=rev
Log:
updated to show JPA usage

Modified:
    openejb/site/trunk/content/tomcat-activemq.mdtext
    openejb/site/trunk/content/tomcat-jpa.mdtext

Modified: openejb/site/trunk/content/tomcat-activemq.mdtext
URL: http://svn.apache.org/viewvc/openejb/site/trunk/content/tomcat-activemq.mdtext?rev=1236542&r1=1236541&r2=1236542&view=diff
==============================================================================
--- openejb/site/trunk/content/tomcat-activemq.mdtext (original)
+++ openejb/site/trunk/content/tomcat-activemq.mdtext Fri Jan 27 06:27:33 2012
@@ -1,4 +1,4 @@
-Title: Tomcat JMS
+Title: Tomcat and ActiveMQ
 
 Tomcat + Java EE = TomEE, the Java Enterprise Edition of Tomcat.  With TomEE you get Tomcat with ActiveMQ added and integrated and ready to go!
 

Modified: openejb/site/trunk/content/tomcat-jpa.mdtext
URL: http://svn.apache.org/viewvc/openejb/site/trunk/content/tomcat-jpa.mdtext?rev=1236542&r1=1236541&r2=1236542&view=diff
==============================================================================
--- openejb/site/trunk/content/tomcat-jpa.mdtext (original)
+++ openejb/site/trunk/content/tomcat-jpa.mdtext Fri Jan 27 06:27:33 2012
@@ -5,49 +5,55 @@ Tomcat + Java EE = TomEE, the Java Enter
 In a plain Servlet, Filter or Listener you can do fun things like injection of JPA EntityManager or EntityManagerFactory:
 
     import javax.annotation.Resource;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
     import javax.servlet.http.HttpServlet;
-    import javax.jms.Topic;
-    import javax.jms.Queue;
-    import javax.jms.ConnectionFactory;
+    import javax.transaction.UserTransaction;
 
     public class MyServet extends HttpServlet {
 
-        @Resource(name = "foo")
-        private Topic fooTopic;
+        @Resource
+        private UserTransaction userTransaction;
 
-        @Resource(name = "bar")
-        private Queue barQueue;
+        @PersistenceContext
+        private EntityManager entityManager;
 
-        @Resource
-        private ConnectionFactory connectionFactory;
 
         @Override
         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
             //...
 
-            Connection connection = connectionFactory.createConnection();
-            connection.start();
-
-            // Create a Session
-            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-            // Create a MessageProducer from the Session to the Topic or Queue
-            MessageProducer producer = session.createProducer(fooTopic);
-            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
-            // Create a message
-            TextMessage message = session.createTextMessage("Hello World!");
+            userTransaction.begin();
 
-            // Tell the producer to send the message
-            producer.send(message);
+            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));
+            } finally {
+                userTransaction.commit();
+            }
 
             //...
         }
 
     }
 
-No need to add even a single library!  In the above scenario even the "foo" Topic and the "bar" Queue would be automatically created with no configuration necessary.
+No need to add even a single library!  To make the above work all you need is a `WEB-INF/persistence.xml` file in your webapp like the following:
+
+    <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>
+
+        <properties>
+          <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+        </properties>
+      </persistence-unit>
+    </persistence>
+
+DataSources will automatically be created if they haven't be configured explicitly.
 
-[Download](downloads.html) TomEE and you're minutes away from a functioning JMS application on Tomcat.
+[Download](downloads.html) TomEE and you're minutes away from a functioning JPA application on Tomcat.
 
 {include:apache-tomee.mdtext}
\ No newline at end of file