openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1483996 - in /openjpa/branches/2.1.x: ./ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-persistence-jdbc/src/main/ant/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/ openjpa-persistence-jdbc/src/test/r...
Date Fri, 17 May 2013 21:23:43 GMT
Author: hthomann
Date: Fri May 17 21:23:43 2013
New Revision: 1483996

URL: http://svn.apache.org/r1483996
Log:
OPENJPA-1912: Generate externalizable methods correctly for super and subclasses - back ported
to 2.1.x Mark Struberg's trunk changes.

Added:
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java
      - copied unchanged from r1071123, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java
      - copied unchanged from r1071123, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
  (contents, props changed)
      - copied, changed from r1221801, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/
      - copied from r1071123, openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml
      - copied unchanged from r1071123, openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml
Modified:
    openjpa/branches/2.1.x/   (props changed)
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml

Propchange: openjpa/branches/2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/trunk:r1071123,1221801,1221839,1222185

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=1483996&r1=1483995&r2=1483996&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Fri May 17 21:23:43 2013
@@ -4041,7 +4041,10 @@ public class PCEnhancer { 
         Code code = meth.getCode(true);
 
         // super.readExternal (in);
-        Class sup = _meta.getDescribedType().getSuperclass();
+        // not sure if this works: this is depending on the order of the enhancement!
+        // if the subclass gets enhanced first, then the superclass misses
+        // the Externalizable at this point!
+        Class<?> sup = _meta.getDescribedType().getSuperclass();
         if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) {
             loadManagedInstance(code, false);
             code.aload().setParam(0);
@@ -4074,12 +4077,44 @@ public class PCEnhancer { 
                 void.class, new Class[]{ StateManager.class });
         }
 
+        addReadExternalFields();
+
+        // readExternalFields(in.readObject ());
+        loadManagedInstance(code, false);
+        code.aload().setParam(0);
+        code.invokevirtual().setMethod("readExternalFields",
+            void.class, inargs);
+
+        code.vreturn();
+        code.calculateMaxStack();
+        code.calculateMaxLocals();
+    }
+
+    private void addReadExternalFields() throws NoSuchMethodException {
+        Class<?>[] inargs = new Class[]{ ObjectInput.class };
+        BCMethod meth = _pc.declareMethod("readExternalFields", void.class, inargs);
+        meth.setAccessFlags(Constants.ACCESS_PROTECTED);
+        Exceptions exceps = meth.getExceptions(true);
+        exceps.addException(IOException.class);
+        exceps.addException(ClassNotFoundException.class);
+        Code code = meth.getCode(true);
+
+        Class<?> sup = _meta.getPCSuperclass();
+        if (sup != null) {
+            //add a call to super.readExternalFields()
+            loadManagedInstance(code, false);
+            code.aload().setParam(0);
+            code.invokespecial().setMethod(sup, "readExternalFields", void.class, inargs);
+        }
+
         // read managed fields
-        FieldMetaData[] fmds = _meta.getFields();
-        for (int i = 0; i < fmds.length; i++)
-            if (!fmds[i].isTransient())
+        FieldMetaData[] fmds = _meta.getDeclaredFields();
+        for (int i = 0; i < fmds.length; i++) {
+            if (!fmds[i].isTransient()) {
                 readExternal(code, fmds[i].getName(),
                     fmds[i].getDeclaredType(), fmds[i]);
+            }
+        }
 
         code.vreturn();
         code.calculateMaxStack();
@@ -4231,12 +4266,44 @@ public class PCEnhancer { 
         if (go2 != null)
             go2.setTarget(code.nop());
 
-        // write managed fields
-        FieldMetaData[] fmds = _meta.getFields();
-        for (int i = 0; i < fmds.length; i++)
-            if (!fmds[i].isTransient())
+        addWriteExternalFields();
+
+        loadManagedInstance(code, false);
+        code.aload().setParam(0);
+        code.invokevirtual().setMethod("writeExternalFields",
+            void.class, outargs);
+
+        // return
+        code.vreturn();
+        code.calculateMaxStack();
+        code.calculateMaxLocals();
+    }
+
+
+    private void addWriteExternalFields()
+        throws NoSuchMethodException {
+        Class<?>[] outargs = new Class[]{ ObjectOutput.class };
+        BCMethod meth = _pc.declareMethod("writeExternalFields", void.class, outargs);
+        meth.setAccessFlags(Constants.ACCESS_PROTECTED);
+        Exceptions exceps = meth.getExceptions(true);
+        exceps.addException(IOException.class);
+        Code code = meth.getCode(true);
+
+        Class<?> sup = _meta.getPCSuperclass();
+        if (sup != null) {
+            // add a call to super.readExternalFields()
+            loadManagedInstance(code, false);
+            code.aload().setParam(0);
+            code.invokespecial().setMethod(sup, "writeExternalFields", void.class, outargs);
+        }
+
+        FieldMetaData[] fmds = _meta.getDeclaredFields();
+        for (int i = 0; i < fmds.length; i++) {
+            if (!fmds[i].isTransient()) {
                 writeExternal(code, fmds[i].getName(),
                     fmds[i].getDeclaredType(), fmds[i]);
+            }
+        }
 
         // return
         code.vreturn();

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=1483996&r1=1483995&r2=1483996&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Fri May 17 21:23:43
2013
@@ -79,6 +79,8 @@
             <exclude name="**/proxy/entities/*.class" />
             <exclude name="**/xml/*.class" />
             <exclude name="**/Unenhanced*.class" />
+            <exclude name="org/apache/openjpa/enhance/EnhancedSuperClass.class"/>
+            <exclude name="org/apache/openjpa/enhance/EnhancedSubClass.class"/>
             <exclude name="**/AbstractUnenhanced*.class" />
             <exclude name="**/unenhanced/*.class" />
 			<exclude name="**/persistence/property/AccessModsEntity.class"/>
@@ -120,6 +122,16 @@
             </fileset>
             <config log="${openjpa.Log}" />
         </openjpac>
+        <!-- Enhance with DetachedStateField=true option -->
+        <openjpac>
+            <config propertiesFile="${project.build.testOutputDirectory}/org/apache/openjpa/enhance/persistence1.xml"
/>
+            <classpath refid="cp" />
+            <fileset dir="${project.build.testOutputDirectory}">
+                <include name="org/apache/openjpa/enhance/EnhancedSuperClass.class"/>
+                <include name="org/apache/openjpa/enhance/EnhancedSubClass.class"/>
+            </fileset>
+            <config log="${openjpa.Log}" />
+        </openjpac>
 		<!-- Enhance delimited identifiers XML-based entities separately -->
         <openjpac>
             <config propertiesFile="${project.build.testOutputDirectory}/META-INF/delim_persistence.xml"
/>

Copied: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
(from r1221801, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java)
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java?p2=openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java&p1=openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java&r1=1221801&r2=1483996&rev=1483996&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
Fri May 17 21:23:43 2013
@@ -31,8 +31,6 @@ import java.io.ObjectOutputStream;
 /**
  * This unit test checks the enhancement of a superclass/subclass
  * constellation.
- *
- * @author <a href="mailto:struberg@apache.org>Mark Struberg</a>
  */
 public class TestClassHierarchyEnhancement extends SingleEMFTestCase {
 

Propchange: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/TestClassHierarchyEnhancement.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message