openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1172911 - in /openjpa/branches/1.2.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/
Date Tue, 20 Sep 2011 00:02:38 GMT
Author: hthomann
Date: Tue Sep 20 00:02:37 2011
New Revision: 1172911

URL: http://svn.apache.org/viewvc?rev=1172911&view=rev
Log:
OPENJPA-1226: Back ported Fay's changes to 1.2.x and created small test for 1.2.x since Fay's
test won't run on 1.2.x (too many 2.0.x dependancies).

Added:
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java
  (with props)
Modified:
    openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
    openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Geocode.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java

Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java?rev=1172911&r1=1172910&r2=1172911&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
(original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
Tue Sep 20 00:02:37 2011
@@ -115,7 +115,7 @@ public class DetachedStateManager
 
         // pre-load for efficiency: current field values for restore, dependent
         // for delete
-        FieldMetaData[] fields = meta.getFields();
+        FieldMetaData[] fields = sm.getMetaData().getFields(); 
         int restore = broker.getRestoreState();
         if (_dirty.length() > 0) {
             BitSet load = new BitSet(fields.length);

Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java?rev=1172911&r1=1172910&r2=1172911&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
(original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
Tue Sep 20 00:02:37 2011
@@ -146,7 +146,7 @@ class VersionAttachStrategy
         int detach = (isNew) ? DETACH_ALL : broker.getDetachState();
         FetchConfiguration fetch = broker.getFetchConfiguration();
         try {
-            FieldMetaData[] fmds = meta.getFields();
+            FieldMetaData[] fmds = sm.getMetaData().getFields(); 
             for (int i = 0; i < fmds.length; i++) {
                 switch (detach) {
                     case DETACH_ALL:

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Geocode.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Geocode.java?rev=1172911&r1=1172910&r2=1172911&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Geocode.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/Geocode.java
Tue Sep 20 00:02:37 2011
@@ -29,6 +29,8 @@ import javax.persistence.*;
 @Embeddable
 public class Geocode extends BaseEntity {
     float latitude, longtitude;
+    
+    NestedEmbeddable nestedEmbed;
 
     public float getLatitude() {
         return latitude;
@@ -45,4 +47,12 @@ public class Geocode extends BaseEntity 
     public void setLongtitude(float longtitude) {
         this.longtitude = longtitude;
     }
+    
+    public NestedEmbeddable getNestedEmbed() {
+    	return nestedEmbed;
+    }
+    
+	public void setNestedEmbed(NestedEmbeddable ne) {
+		this.nestedEmbed = ne;
+	}    
 }
\ No newline at end of file

Added: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java?rev=1172911&view=auto
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java
(added)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java
Tue Sep 20 00:02:37 2011
@@ -0,0 +1,27 @@
+package org.apache.openjpa.persistence.embed;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class NestedEmbeddable
+{
+  private String field1;
+  private String field2;
+
+  public String getField1()
+  {
+    return this.field1;
+  }
+
+  public void setField1(String field1) {
+    this.field1 = field1;
+  }
+
+  public String getField2() {
+    return this.field2;
+  }
+
+  public void setField2(String field2) {
+    this.field2 = field2;
+  }
+}

Propchange: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/NestedEmbeddable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java?rev=1172911&r1=1172910&r2=1172911&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbedded.java
Tue Sep 20 00:02:37 2011
@@ -27,7 +27,7 @@ import org.apache.openjpa.persistence.te
 
 public class TestEmbedded extends SingleEMFTestCase {
     public void setUp() {
-        super.setUp(BaseEntity.class, Address.class, Geocode.class,
+        super.setUp(BaseEntity.class, Address.class, Geocode.class, NestedEmbeddable.class,
                 CLEAR_TABLES);
     }
 
@@ -76,6 +76,79 @@ public class TestEmbedded extends Single
 
         assertEquals(a2.getGeocode().getLatitude(), 1.0f);
     }
+    
+    /**
+     * JIRA Ref: OPENJPA-1226: Create and persist a NestedEmbeddable, then
+     * update and merge the NestedEmbeddable in order to verify an 
+     * 'ArgumentException' is not caused during the merge.
+     */
+    public void testNestedEmbeddable_UpdateExistingEmbed() {
+        Address a = new Address();
+        a.setStreetAddress("456 Main St");
+        Geocode g = new Geocode();
+        g.setLatitude(1.0f);
+        NestedEmbeddable ne = new NestedEmbeddable();
+        ne.setField1("test");
+        g.setNestedEmbed(ne);
+        a.setGeocode(g);
+
+        persistAddress(a);
+
+        g = a.getGeocode();       
+        ne = g.getNestedEmbed();
+        ne.setField1("test2");
+        ne.setField2("test3");
+        
+        g.setNestedEmbed(ne);
+        a.setGeocode(g);
+        
+        mergeAddress(a);      
+ 	
+        a =
+                 queryAddresses(
+                "select address from Address address"
+                    + " where address.streetAddress = '456 Main St'").get(0);
+        
+        ne = a.getGeocode().getNestedEmbed();
+        
+        assertEquals(ne.getField1(),"test2");
+        assertEquals(ne.getField2(),"test3");
+    }
+     
+    /**
+     * JIRA Ref: OPENJPA-1226: Create a NestedEmbeddable, and add it to an
+     * existing Address/Geocode, and then merge the NestedEmbeddable in
+     * order to verify an 'ArgumentException' is not caused during the merge.
+     */
+    public void testNestedEmbeddable_AddNewEmbed() {
+        Address a = new Address();
+        a.setStreetAddress("456 Main St");
+        Geocode g = new Geocode();
+        g.setLatitude(1.0f);
+        a.setGeocode(g);
+
+        persistAddress(a);
+
+        g = a.getGeocode();       
+
+        NestedEmbeddable ne = new NestedEmbeddable();
+        ne.setField1("test");
+        
+        g.setNestedEmbed(ne);       
+        a.setGeocode(g);
+        
+        mergeAddress(a);      
+ 	
+        a =
+            queryAddresses(
+                "select address from Address address"
+                    + " where address.streetAddress = '456 Main St'").get(0);
+        
+        ne = a.getGeocode().getNestedEmbed();
+        
+        assertEquals(ne.getField1(),"test");
+        assertEquals(ne.getField2(),null);
+    }    
 
     private void persistAddress(Address address) {
         final EntityManager em = emf.createEntityManager();
@@ -95,6 +168,23 @@ public class TestEmbedded extends Single
         assertEquals(address.getGeocode().getLatitude(), 1.0f);
     }
 
+    private void mergeAddress(Address address) {
+        final EntityManager em = emf.createEntityManager();
+        final EntityTransaction tx = em.getTransaction();
+
+        tx.begin();
+
+        try {
+            em.merge(address);
+            tx.commit();
+        } finally {
+            if (tx.isActive()) {
+                tx.rollback();
+            }
+            em.close();
+        }
+    }
+    
     private List<Address> queryAddresses(String query) {
         final EntityManager em = emf.createEntityManager();
         final EntityTransaction tx = em.getTransaction();



Mime
View raw message