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 2011/02/16 03:12:28 UTC
svn commit: r1071123 - in /openjpa/trunk: ./
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/resources/...
Author: mikedd
Date: Wed Feb 16 02:12:28 2011
New Revision: 1071123
URL: http://svn.apache.org/viewvc?rev=1071123&view=rev
Log:
OPENJPA-1912: Generate externalizable methods correctly for super and subclasses.
Submitted By: Mark Struberg
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml (with props)
Modified:
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
openjpa/trunk/pom.xml
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=1071123&r1=1071122&r2=1071123&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java Wed Feb 16 02:12:28 2011
@@ -4037,7 +4037,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);
@@ -4070,12 +4073,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();
@@ -4227,12 +4262,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/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml?rev=1071123&r1=1071122&r2=1071123&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/ant/enhancer.xml Wed Feb 16 02:12:28 2011
@@ -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" />
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java?rev=1071123&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java Wed Feb 16 02:12:28 2011
@@ -0,0 +1,41 @@
+/*
+ * 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.enhance;
+
+
+import javax.persistence.Entity;
+import java.io.Serializable;
+
+/**
+ * @see TestClassHierarchyEnhancement
+ */
+@Entity
+public class EnhancedSubClass extends EnhancedSuperClass implements Serializable {
+ private static final long serialVersionUID = 2311337663046757789L;
+ private String valueInSubclass;
+
+ public String getValueInSubclass() {
+ return valueInSubclass;
+ }
+
+ public void setValueInSubclass(String valueInSubclass) {
+ this.valueInSubclass = valueInSubclass;
+ }
+}
+
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSubClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java?rev=1071123&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java Wed Feb 16 02:12:28 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.enhance;
+
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+/**
+ * @see TestClassHierarchyEnhancement
+ */
+@Entity
+public class EnhancedSuperClass implements Serializable {
+ private static final long serialVersionUID = -4276267285828916940L;
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String valueInSuperclass;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getValueInSuperclass() {
+ return valueInSuperclass;
+ }
+
+ public void setValueInSuperclass(String valueInSuperclass) {
+ this.valueInSuperclass = valueInSuperclass;
+ }
+}
+
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/EnhancedSuperClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml?rev=1071123&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml Wed Feb 16 02:12:28 2011
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="1.0"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+ http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+
+ <persistence-unit name="enhancertest-pu">
+ <class>org.apache.openjpa.enhance.EnhancedSuperClass</class>
+ <class>org.apache.openjpa.enhance.EnhancedSubClass</class>
+ <properties>
+ <property name="openjpa.DynamicEnhancementAgent" value="false"/>
+ <property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/>
+ <property name="openjpa.jdbc.SynchronizeMappings"
+ value="buildSchema(ForeignKeys=true)"/>
+ </properties>
+ </persistence-unit>
+
+</persistence>
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/enhance/persistence1.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/pom.xml?rev=1071123&r1=1071122&r2=1071123&view=diff
==============================================================================
--- openjpa/trunk/pom.xml (original)
+++ openjpa/trunk/pom.xml Wed Feb 16 02:12:28 2011
@@ -839,7 +839,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
- <version>1.1</version>
+ <version>1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>