openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpala...@apache.org
Subject svn commit: r1171949 - in /openjpa/branches/1.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
Date Sat, 17 Sep 2011 11:27:11 GMT
Author: rpalache
Date: Sat Sep 17 11:27:11 2011
New Revision: 1171949

URL: http://svn.apache.org/viewvc?rev=1171949&view=rev
Log:
OPENJPA-733: Updated state manager to use actual oid instead of owner oid. Merging Jeremy's
change to 1.1.x

Modified:
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1171949&r1=1171948&r2=1171949&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Sat Sep 17 11:27:11 2011
@@ -311,7 +311,8 @@ public class StateManagerImpl
 
         // initialize our state and add ourselves to the broker's cache
         setPCState(state);
-        if (_broker.getStateManagerImplById(getObjectId(), false) == null) {
+        if ( _oid == null ||
+            _broker.getStateManagerImplById(_oid, false) == null) {
             _broker.setStateManager(_id, this, BrokerImpl.STATUS_INIT);
         }
         if (state == PCState.PNEW)

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java?rev=1171949&r1=1171948&r2=1171949&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
Sat Sep 17 11:27:11 2011
@@ -18,7 +18,9 @@
  */
 package org.apache.openjpa.persistence.embed;
 
+import java.util.List;
 import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
 import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
@@ -28,6 +30,73 @@ public class TestEmbedded extends SQLLis
                 CLEAR_TABLES);
     }
 
+    /*
+     * This variation verifies that an embedded entity can be accessed after
+     * being detached.  An entity /w embedded is persisted and then queried.
+     * The em is closed, detaching the entities, and then a getter is called
+     * on the embeddeded.  If the embedded is still attached (it should not be)
+     * an IllegalStateException will be thrown.    
+     * 
+     * JIRA Ref: OPENJPA-733
+     * Authors: Chris Tillman, Jeremy Bauer
+     */    
+    public void testDetachedQueryEmbedded() {
+        Address a = new Address();
+        a.setStreetAddress("456 Main St");
+        a.setCity("New York");
+        a.setState("NY");
+        a.setZip(12955);
+        Geocode g = new Geocode();
+        g.setLatitude(1.0f);
+        g.setLongtitude(2.0f);
+        a.setGeocode(g);
+    
+        persistAddress(a);
+    
+        Address a2 = queryAddresses(
+            "select address from Address address" +
+            " where address.streetAddress = '456 Main St'").get(0);
+    
+        assertEquals(a2.getGeocode().getLatitude(),1.0f);
+    }
+
+    private void persistAddress(Address address) {
+        final EntityManager em = emf.createEntityManager();
+        final EntityTransaction tx = em.getTransaction();
+
+        tx.begin();
+
+        try {
+            em.persist(address);
+            tx.commit();
+        } finally {
+            if (tx.isActive()) {
+                tx.rollback();
+            }
+            em.close();
+        }
+        assertEquals(address.getGeocode().getLatitude(),1.0f);
+    }
+
+    private List<Address> queryAddresses(String query) {
+        final EntityManager em = emf.createEntityManager();
+        final EntityTransaction tx = em.getTransaction();
+
+        tx.begin();
+
+        try {
+            final List<Address> list = (List<Address>) em.createQuery(query)
+                        .getResultList();
+            tx.commit();
+            return list;
+        } finally {
+            if (tx.isActive()) {
+                tx.rollback();
+            }
+            em.close();
+        }
+    }
+
     public void testInsertEmbedded() {
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -85,4 +154,5 @@ public class TestEmbedded extends SQLLis
         assertEquals(1, sql.size());
     }
 
-}
\ No newline at end of file
+}
+



Mime
View raw message