cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r504530 - in /cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa: JtaEntityManagerFactory.java ResourceLocalEntityManagerFactory.java
Date Wed, 07 Feb 2007 12:51:02 GMT
Author: aadamchik
Date: Wed Feb  7 04:51:01 2007
New Revision: 504530

URL: http://svn.apache.org/viewvc?view=rev&rev=504530
Log:
CAY-668: Link Cayenne callback API with JPA provider
(done)

Modified:
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/JtaEntityManagerFactory.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManagerFactory.java

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/JtaEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/JtaEntityManagerFactory.java?view=diff&rev=504530&r1=504529&r2=504530
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/JtaEntityManagerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/JtaEntityManagerFactory.java
Wed Feb  7 04:51:01 2007
@@ -91,8 +91,9 @@
     }
 
     @Override
-    protected EntityManager createEntityManagerInternal(Map map) {
-        EntityManager em = new JtaEntityManager(domain.createDataContext(), this);
+    public EntityManager createEntityManager(Map map) {
+        checkClosed();
+        EntityManager em = new JtaEntityManager(createObjectContext(), this);
 
         if (isActiveTransaction()) {
             em.joinTransaction();

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManagerFactory.java?view=diff&rev=504530&r1=504529&r2=504530
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManagerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManagerFactory.java
Wed Feb  7 04:51:01 2007
@@ -26,7 +26,12 @@
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.spi.PersistenceUnitInfo;
 
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.ObjectStore;
+import org.apache.cayenne.intercept.DataChannelCallbackInterceptor;
+import org.apache.cayenne.intercept.ObjectContextCallbackInterceptor;
 
 /**
  * A Cayenne EntityManagerFactory that supports resource-local transactions.
@@ -95,23 +100,33 @@
     }
 
     /**
-     * Create a new EntityManager with the specified map of properties. Returns a new
-     * EntityManager instance every time it is invoked. The {@link EntityManager#isOpen()}
-     * method will return true of the returned instance.
+     * Creates a new resource-local EntityManager with the specified map of properties.
+     * Returns a new EntityManager instance every time it is invoked. The
+     * {@link EntityManager#isOpen()} method will return true of the returned instance.
+     * Parameter map is ignored as Cayenne provider defines no properties for
+     * EntityManager as of now.
      * 
      * @return a new EntityManager instance.
      */
     public EntityManager createEntityManager(Map map) {
         checkClosed();
-        return createEntityManagerInternal(map);
+        return new ResourceLocalEntityManager(createObjectContext(), this);
     }
 
     /**
-     * Creates a new resource-local EntityManager. Parameter map is ignored as Cayenne
-     * provider defines no properties for EntityManager as of now.
+     * Creates a new Cayenne {@link ObjectContext} based on this factory DataDomain.
+     * Returned context has lifecycle callbacks enabled, as expected in the JPA
+     * environment.
      */
-    protected EntityManager createEntityManagerInternal(Map map) {
-        return new ResourceLocalEntityManager(domain.createDataContext(), this);
+    protected ObjectContext createObjectContext() {
+        DataChannelCallbackInterceptor postInterceptor = new DataChannelCallbackInterceptor();
+        postInterceptor.setChannel(domain);
+        ObjectStore objectStore = new ObjectStore(domain.getSharedSnapshotCache());
+
+        ObjectContextCallbackInterceptor preInterceptor = new ObjectContextCallbackInterceptor();
+        preInterceptor.setContext(new DataContext(postInterceptor, objectStore));
+
+        return preInterceptor;
     }
 
     /**



Mime
View raw message