diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java index ef96a9961..aa6ed25ed 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java @@ -945,10 +945,6 @@ public class EmbedFieldStrategy // StateManager implementation /////////////////////////////// - public byte replaceFlags() { - throw new InternalException(); - } - public Object getPCPrimaryKey(Object oid, int field) { throw new InternalException(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index 975ba569d..babbd9882 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -95,6 +95,11 @@ import serp.util.Numbers; * @author Abe White */ public class PCEnhancer { + // Designates a version for maintaining compatbility when PCEnhancer + // modifies enhancement that can break serialization or other contracts + // Each enhanced class will return the value of this field via + // public int getEnhancementContractVersion() + public static final int ENHANCER_VERSION = 2; public static final int ENHANCE_NONE = 0; public static final int ENHANCE_AWARE = 2 << 0; @@ -716,7 +721,6 @@ public class PCEnhancer { if (_meta.getPCSuperclass() == null) { addStockMethods(); addGetVersionMethod(); - addReplaceFlagsMethod(); addReplaceStateManagerMethod(); if (_meta.getIdentityType() != ClassMetaData.ID_APPLICATION) @@ -841,11 +845,6 @@ public class PCEnhancer { code.aload().setParam(0); code.putfield().setField(SM, SMTYPE); - // pc.pcFlags = LOAD_REQUIRED - code.aload().setLocal(inst); - code.constant().setValue(PersistenceCapable.LOAD_REQUIRED); - code.putfield().setField(PRE + "Flags", byte.class); - // copy key fields from oid if (oid) { code.aload().setLocal(inst); @@ -1329,35 +1328,6 @@ public class PCEnhancer { return fmd.getDeclaredType(); } - /** - * Adds the {@link PersistenceCapable#pcReplaceFlags} - * method to the bytecode. - */ - private void addReplaceFlagsMethod() { - // public final void pcReplaceFlags () - BCMethod method = _pc.declareMethod(PRE + "ReplaceFlags", - void.class, null); - Code code = method.getCode(true); - - // if (pcStateManager != null) - loadManagedInstance(code, false); - code.getfield().setField(SM, SMTYPE); - JumpInstruction ifins = code.ifnonnull(); - code.vreturn(); - - // pcFlags = pcStateManager.replaceFlags (); - ifins.setTarget(loadManagedInstance(code, false)); - loadManagedInstance(code, false); - code.getfield().setField(SM, SMTYPE); - code.invokeinterface().setMethod(SMTYPE, "replaceFlags", - byte.class, null); - code.putfield().setField(PRE + "Flags", byte.class); - code.vreturn(); - - code.calculateMaxStack(); - code.calculateMaxLocals(); - } - /** * Adds the {@link PersistenceCapable#pcReplaceStateManager} * method to the bytecode. @@ -2157,6 +2127,9 @@ public class PCEnhancer { // make the class implement PersistenceCapable _pc.declareInterface(PCTYPE); + // add a version stamp + addGetEnhancementContractVersionMethod(); + // find the default constructor BCMethod method = _pc.getDeclaredMethod("", (String[]) null); @@ -2197,8 +2170,6 @@ public class PCEnhancer { *
  • private static byte[] pcFieldFlags
  • *
  • protected transient StateManager pcStateManager * if no PersistenceCapable superclass present)
  • - *
  • protected transient byte pcFlags - * if no PersistenceCapable superclass present)
  • * */ private void addFields() { @@ -2212,10 +2183,6 @@ public class PCEnhancer { BCField field = _pc.declareField(SM, SMTYPE); field.makeProtected(); field.setTransient(true); - - field = _pc.declareField(PRE + "Flags", byte.class); - field.makeProtected(); - field.setTransient(true); } } @@ -2724,10 +2691,10 @@ public class PCEnhancer { /** * Adds bytecode modifying the cloning behavior of the class being - * enhanced to correctly replace the pcFlags and - * pcStateManager instance fields of any clone created with - * their default values. Also, if this class is the base PC type - * and does not declared a clone method, one will be added. + * enhanced to correctly replace the pcStateManager + * instance fields of any clone created with their default values. + * Also, if this class is the base PC type and does not declared + * a clone method, one will be added. */ private void addCloningCode() { if (_meta.getPCSuperclass() != null) @@ -2781,12 +2748,6 @@ public class PCEnhancer { code.constant().setNull(); code.putfield().setField(SM, SMTYPE); - // (() clone).pcFlags = 0; - code.dup(); - code.checkcast().setType(_pc); - code.constant().setValue(PersistenceCapable.READ_WRITE_OK); - code.putfield().setField(PRE + "Flags", byte.class); - // if modified, increase stack code.calculateMaxStack(); code.calculateMaxLocals(); @@ -2860,23 +2821,10 @@ public class PCEnhancer { return; } - // dfg: if (inst.pcFlags <= 0) return inst.; - JumpInstruction ifins = null; - if ((fieldFlag & PersistenceCapable.CHECK_READ) > 0) { - loadManagedInstance(code, true); - code.getfield().setField(PRE + "Flags", byte.class); - ifins = code.ifgt(); - loadManagedInstance(code, true); - addGetManagedValueCode(code, fmd); - code.xreturn().setType(fmd.getDeclaredType()); - } - // if (inst.pcStateManager == null) return inst.; Instruction ins = loadManagedInstance(code, true); - if (ifins != null) - ifins.setTarget(ins); code.getfield().setField(SM, SMTYPE); - ifins = code.ifnonnull(); + JumpInstruction ifins = code.ifnonnull(); loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xreturn().setType(fmd.getDeclaredType()); @@ -2919,25 +2867,10 @@ public class PCEnhancer { // PCEnhancer uses static methods; PCSubclasser does not. int firstParamOffset = getAccessorParameterOffset(); - // dfg: if (inst.pcFlags == 0) inst. = value; - JumpInstruction ifins = null; - byte fieldFlag = getFieldFlag(fmd); - if ((fieldFlag & PersistenceCapable.CHECK_WRITE) > 0) { - loadManagedInstance(code, true); - code.getfield().setField(PRE + "Flags", byte.class); - ifins = code.ifne(); - loadManagedInstance(code, true); - code.xload().setParam(firstParamOffset); - addSetManagedValueCode(code, fmd); - code.vreturn(); - } - // if (inst.pcStateManager == null) inst. = value; Instruction ins = loadManagedInstance(code, true); - if (ifins != null) - ifins.setTarget(ins); code.getfield().setField(SM, SMTYPE); - ifins = code.ifnonnull(); + JumpInstruction ifins = code.ifnonnull(); loadManagedInstance(code, true); code.xload().setParam(firstParamOffset); addSetManagedValueCode(code, fmd); @@ -3507,6 +3440,19 @@ public class PCEnhancer { return setter; } + private void addGetEnhancementContractVersionMethod() { + // public int getEnhancementContractVersion() + BCMethod method = _pc.declareMethod(PRE + + "GetEnhancementContractVersion", int.class, null); + method.makePublic(); + Code code = method.getCode(true); + code.constant().setValue(ENHANCER_VERSION); + code.ireturn(); + code.calculateMaxStack(); + code.calculateMaxLocals(); + return; + } + /** * Return the concrete type for the given class, i.e. impl for managed * interfaces diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PersistenceCapable.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PersistenceCapable.java index 89cea3075..45db3f11b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PersistenceCapable.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PersistenceCapable.java @@ -34,6 +34,8 @@ public interface PersistenceCapable { public static final Object DESERIALIZED = new Object(); + int pcGetEnhancementContractVersion(); + Object pcGetGenericContext(); StateManager pcGetStateManager(); @@ -48,8 +50,6 @@ public interface PersistenceCapable { void pcReplaceFields(int[] fieldIndex); - void pcReplaceFlags(); - void pcCopyFields(Object fromObject, int[] fields); void pcDirty(String fieldName); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/StateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/StateManager.java index 563d8da01..e4f38937e 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/StateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/StateManager.java @@ -40,11 +40,6 @@ public interface StateManager { */ public Object getPCPrimaryKey(Object oid, int field); - /** - * Change internal flags. - */ - public byte replaceFlags(); - /** * Change state manager. */ diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java index 01ce8737d..528e8bf2b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java @@ -334,10 +334,6 @@ public class DetachedStateManager return null; } - public byte replaceFlags() { - return PersistenceCapable.MEDIATE_WRITE; - } - public Object getPCPrimaryKey(Object oid, int field) { throw new UnsupportedOperationException(); } @@ -939,5 +935,5 @@ public class DetachedStateManager public void unlock() { if (_lock != null) _lock.unlock(); - } + } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java index 864142220..7d76cdd02 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java @@ -403,10 +403,6 @@ public class DetachedValueStateManager throw new UnsupportedOperationException(); } - public byte replaceFlags() { - throw new UnsupportedOperationException(); - } - public StateManager replaceStateManager(StateManager sm) { return sm; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java index 7231d262d..6f37ae5c1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java @@ -71,10 +71,6 @@ public class ObjectIdStateManager throw new UnsupportedOperationException(); } - public byte replaceFlags() { - throw new UnsupportedOperationException(); - } - public StateManager replaceStateManager(StateManager sm) { throw new UnsupportedOperationException(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java index 10edaad11..de5192182 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java @@ -287,7 +287,6 @@ public class StateManagerImpl } pc.pcSetDetachedState(null); - pc.pcReplaceFlags(); _pc = pc; if (_oid instanceof OpenJPAId) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java index ea3f1ec20..5d77ebf2b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ProxySetupStateManager.java @@ -85,10 +85,6 @@ class ProxySetupStateManager throw new UnsupportedOperationException(); } - public byte replaceFlags() { - throw new InternalException(); - } - public StateManager replaceStateManager(StateManager sm) { throw new InternalException(); }