You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2010/07/19 22:02:24 UTC

svn commit: r965610 - in /openjpa/branches/2.0.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/persistence/detach/serializable/

Author: mikedd
Date: Mon Jul 19 20:02:23 2010
New Revision: 965610

URL: http://svn.apache.org/viewvc?rev=965610&view=rev
Log:
OPENJPA-1704: Fix PCEnhancer to generate proper readExternal method. Merged to 2.0.x - submitted by Rick Curtis

Added:
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java   (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java   (with props)
Modified:
    openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml

Modified: openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=965610&r1=965609&r2=965610&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java (original)
+++ openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java Mon Jul 19 20:02:23 2010
@@ -117,7 +117,7 @@ public class PCEnhancer {
     // public int getEnhancementContractVersion()
     public static final int ENHANCER_VERSION = 2;
     
-    boolean _addVersionInitFlag = true;
+    boolean _addVersionInitFlag = true; 
 
     public static final int ENHANCE_NONE = 0;
     public static final int ENHANCE_AWARE = 2 << 0;
@@ -2772,7 +2772,7 @@ public class PCEnhancer {
         _pc.declareField(PRE + "FieldTypes", Class[].class).setStatic(true);
         _pc.declareField(PRE + "FieldFlags", byte[].class).setStatic(true);
         _pc.declareField(SUPER, Class.class).setStatic(true);
-        if(_addVersionInitFlag && _meta.getVersionField()!=null){
+        if (_addVersionInitFlag && _meta.getVersionField() != null) {
             // protected transient boolean pcVersionInit;
             BCField field = _pc.declareField(VERSION_INIT_STR, boolean.class);
             field.makeProtected();
@@ -3229,17 +3229,15 @@ public class PCEnhancer {
             if (!_addVersionInitFlag){
                 // else return false;
                 ifins.setTarget(code.getstatic().setField(Boolean.class, "FALSE", Boolean.class));
-            }else{
-                FieldMetaData versionInit = _meta.getDeclaredField(VERSION_INIT_STR);
-                
+            }else{              
                 // noop
                 ifins.setTarget(code.nop());
                 // if (pcVersionInit != false)
                 // return true
                 // else return false;
                 loadManagedInstance(code, false);
-                getfield(code, null, versionInit.getName());
-                ifins = ifDefaultValue(code, versionInit);
+                getfield(code, null, VERSION_INIT_STR);
+                ifins = code.ifeq();
                 code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
                 code.areturn();
                 ifins.setTarget(code.nop());
@@ -3709,12 +3707,10 @@ public class PCEnhancer {
         addSetManagedValueCode(code, fmd);
         if(fmd.isVersion()==true && _addVersionInitFlag){
             // if we are setting the version, flip the versionInit flag to true
-            FieldMetaData v = _meta.addDeclaredField(VERSION_INIT_STR, boolean.class);
-            v.setTransient(true);
             loadManagedInstance(code, true);
             code.constant().setValue(1);
             // pcVersionInit = true;
-            putfield(code, null, v.getName(), v.getDeclaredType());   
+            putfield(code, null, VERSION_INIT_STR, boolean.class);   
         }
         code.vreturn();
 

Modified: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=965610&r1=965609&r2=965610&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Mon Jul 19 20:02:23 2010
@@ -75,6 +75,7 @@
                  dir="${project.build.testOutputDirectory}">
             <include name="**/*.class" />
             <exclude name="**/inheritance/serializable/*.class" />
+            <exclude name="**/detach/serializable/*.class" />
             <exclude name="**/xml/*.class" />
             <exclude name="**/Unenhanced*.class" />
             <exclude name="**/AbstractUnenhanced*.class" />
@@ -92,6 +93,7 @@
             <classpath refid="cp" />
             <fileset dir="${project.build.testOutputDirectory}">
                 <include name="**/inheritance/serializable/*.class" />
+                <include name="**/detach/serializable/*.class" />
                 <!--  include files from orm.xml -->
                 <include name="**/xml/*.class" />
 				<exclude name="**/persistence/delimited/identifiers/xml/*.class"/>

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java?rev=965610&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java (added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java Mon Jul 19 20:02:23 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.detach.serializable;
+
+import java.io.Serializable;
+import java.sql.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Version;
+
+@Entity  
+public class SerializableDetachedStateManager implements Serializable { 
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 80701492251635740L;
+
+    @Id
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    int id;
+
+    @Version
+    int version;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    Date zDate;
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/SerializableDetachedStateManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java?rev=965610&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java (added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java Mon Jul 19 20:02:23 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.detach.serializable;
+
+import java.sql.Date;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSerializableDetachedStateManager extends SingleEMFTestCase {
+    public void setUp() {
+        setUp(CLEAR_TABLES, SerializableDetachedStateManager.class, DROP_TABLES, "openjpa.DetachState",
+            "fgs(DetachedStateField=true)");
+    }
+    
+    public void testRoundTrip() throws Exception {
+        SerializableDetachedStateManager c = new SerializableDetachedStateManager();
+        c.zDate = new Date(System.currentTimeMillis());
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        
+        em.getTransaction().begin();
+        em.persist(c);
+        em.getTransaction().commit();
+        em.close();
+        AbstractPersistenceTestCase.roundtrip(c);
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/serializable/TestSerializableDetachedStateManager.java
------------------------------------------------------------------------------
    svn:eol-style = native