openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r987321 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/
Date Thu, 19 Aug 2010 21:38:25 GMT
Author: curtisr7
Date: Thu Aug 19 21:38:25 2010
New Revision: 987321

URL: http://svn.apache.org/viewvc?rev=987321&view=rev
Log:
OPENJPA-1770: Fix fetching an Entity with a null embeddable from the DataCache.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCDataImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCDataImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCDataImpl.java?rev=987321&r1=987320&r2=987321&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCDataImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCDataImpl.java Thu
Aug 19 21:38:25 2010
@@ -198,10 +198,18 @@ public class PCDataImpl
     /**
      * Set field-level information into the given state manager.
      */
-    protected void loadField(OpenJPAStateManager sm, FieldMetaData fmd,
-        FetchConfiguration fetch, Object context) {
+    protected void loadField(OpenJPAStateManager sm, FieldMetaData fmd, FetchConfiguration
fetch, Object context) {
         int index = fmd.getIndex();
         Object val = toField(sm, fmd, getData(index), fetch, context);
+        
+        // If val is null, make sure that we don't send back a null Embeddable or ElementCollection...perhaps
others?
+        // Probably should think about trying to shove this data back into the cache at this
point so we don't
+        // continually run through this code.
+        if (val == null && fmd.isEmbeddedPC()) {
+            val = sm.getContext().embed(null, null, sm, fmd).getManagedInstance();
+        } else if (val == null && fmd.isElementCollection()) {
+            val = sm.newProxy(index);
+        }
         sm.storeField(index, val);
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java?rev=987321&r1=987320&r2=987321&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNonTransState.java
Thu Aug 19 21:38:25 2010
@@ -42,7 +42,7 @@ class PNonTransState
         context.clearSavedFields();
 
         // spec says all proxies to second class objects should be reset
-        context.proxyFields(true, true);
+        context.proxyFields(true, false);
     }
 
     PCState delete(StateManagerImpl context) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java?rev=987321&r1=987320&r2=987321&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
Thu Aug 19 21:38:25 2010
@@ -19,7 +19,21 @@
 package org.apache.openjpa.persistence.jdbc.annotations;
 
 
-import javax.persistence.*;
+import java.util.Set;
+
+import javax.persistence.AssociationOverride;
+import javax.persistence.AttributeOverride;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.EntityResult;
+import javax.persistence.FieldResult;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.SqlResultSetMapping;
 
 @Entity
 @SqlResultSetMapping(name = "EmbedMapping", entities = {
@@ -38,6 +52,9 @@ public class EmbedOwner {
         joinColumns = @JoinColumn(name = "OVER_OWNER"))
     protected EmbedValue embed;
 
+    @ElementCollection
+    Set<EmbedValue> embedCollection;
+    
     @Basic
     @Column(name = "OWN_BASIC")
     protected String basic;
@@ -65,4 +82,8 @@ public class EmbedOwner {
     public EmbedValue getEmbed() {
         return embed;
     }
+    
+    public Set<EmbedValue> getEmbedCollection() {
+        return embedCollection;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java?rev=987321&r1=987320&r2=987321&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
Thu Aug 19 21:38:25 2010
@@ -19,6 +19,8 @@
 package org.apache.openjpa.persistence.jdbc.annotations;
 
 import java.sql.Types;
+import java.util.Set;
+
 import javax.persistence.EntityManager;
 
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
@@ -28,10 +30,11 @@ import org.apache.openjpa.jdbc.meta.stra
 import org.apache.openjpa.jdbc.meta.strats.MaxEmbeddedClobFieldStrategy;
 import org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
-import org.apache.openjpa.persistence.JPAFacadeHelper;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Test for embedded
@@ -50,10 +53,13 @@ public class TestEJBEmbedded extends Sin
     }
 
     public void setUp() {
-        setUp(EmbedOwner.class, EmbedValue.class, CLEAR_TABLES);
+        setUp(EmbedOwner.class, EmbedValue.class, CLEAR_TABLES
+        ,"openjpa.Log","SQL=trace"    
+        );
     }
 
     public void testEmbedded() {
+
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         EmbedOwner owner = new EmbedOwner();
@@ -90,25 +96,59 @@ public class TestEJBEmbedded extends Sin
         assertNull(embeddedMeta.getField("transientField"));
     }
 
-    public void testNull() {
-        EntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        EmbedOwner owner = new EmbedOwner();
-        owner.setBasic("foo");
-        em.persist(owner);
-        int pk = owner.getPk();
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        owner = em.find(EmbedOwner.class, pk);
-        assertEquals("foo", owner.getBasic());
-        EmbedValue embed = owner.getEmbed();
-        assertNotNull(embed);
-        assertNull(embed.getClob());
-        assertNull(embed.getBasic());
-        assertNull(embed.getBlob());
-        em.close();
+    private void nullTestLogic(boolean cache) {
+        // A place holder to swap the existing emf back in... maybe unnecessary?
+        OpenJPAEntityManagerFactorySPI tempEmf = null;
+        if (cache) {
+            tempEmf = emf;
+            emf = createEMF("openjpa.DataCache", "true");
+        }
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            
+            EmbedOwner owner = new EmbedOwner();
+            owner.setBasic("foo");
+            
+            assertNull(owner.getEmbed());
+            assertNull(owner.getEmbedCollection());
+            em.persist(owner);
+            assertNull(owner.getEmbed());
+            assertNull(owner.getEmbedCollection());
+            
+            int pk = owner.getPk();
+            em.getTransaction().commit();
+            assertNull(owner.getEmbed());
+            assertNull(owner.getEmbedCollection());
+            em.close();
+            assertNull(owner.getEmbed());            
+            assertNull(owner.getEmbedCollection());
+
+            em = emf.createEntityManager();
+            owner = em.find(EmbedOwner.class, pk);
+            assertEquals("foo", owner.getBasic());
+            EmbedValue embed = owner.getEmbed();
+            assertNotNull(embed);
+            assertNull(embed.getClob());
+            assertNull(embed.getBasic());
+            assertNull(embed.getBlob());
+            
+            Set<EmbedValue> embedCollection = owner.getEmbedCollection(); 
+            assertNotNull(embedCollection);
+            assertEquals(0, embedCollection.size());
+            em.close();
+        } finally {
+            if(tempEmf!=null){
+                emf.close();
+                emf = tempEmf;
+            }
+        }
+    }
+    public void testNullNoCache() {
+        nullTestLogic(false);
+    }
+    public void testNullCacheEnabled() {
+        nullTestLogic(true);
     }
 
     public void testMappingTransferAndOverride() {



Mime
View raw message