mirror of https://github.com/apache/openjpa.git
OPENJPA-151.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@511998 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e20afb3134
commit
2a95f80f44
|
@ -945,10 +945,6 @@ public class EmbedFieldStrategy
|
||||||
// StateManager implementation
|
// StateManager implementation
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
public byte replaceFlags() {
|
|
||||||
throw new InternalException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getPCPrimaryKey(Object oid, int field) {
|
public Object getPCPrimaryKey(Object oid, int field) {
|
||||||
throw new InternalException();
|
throw new InternalException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,11 @@ import serp.util.Numbers;
|
||||||
* @author Abe White
|
* @author Abe White
|
||||||
*/
|
*/
|
||||||
public class PCEnhancer {
|
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_NONE = 0;
|
||||||
public static final int ENHANCE_AWARE = 2 << 0;
|
public static final int ENHANCE_AWARE = 2 << 0;
|
||||||
|
@ -716,7 +721,6 @@ public class PCEnhancer {
|
||||||
if (_meta.getPCSuperclass() == null) {
|
if (_meta.getPCSuperclass() == null) {
|
||||||
addStockMethods();
|
addStockMethods();
|
||||||
addGetVersionMethod();
|
addGetVersionMethod();
|
||||||
addReplaceFlagsMethod();
|
|
||||||
addReplaceStateManagerMethod();
|
addReplaceStateManagerMethod();
|
||||||
|
|
||||||
if (_meta.getIdentityType() != ClassMetaData.ID_APPLICATION)
|
if (_meta.getIdentityType() != ClassMetaData.ID_APPLICATION)
|
||||||
|
@ -841,11 +845,6 @@ public class PCEnhancer {
|
||||||
code.aload().setParam(0);
|
code.aload().setParam(0);
|
||||||
code.putfield().setField(SM, SMTYPE);
|
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
|
// copy key fields from oid
|
||||||
if (oid) {
|
if (oid) {
|
||||||
code.aload().setLocal(inst);
|
code.aload().setLocal(inst);
|
||||||
|
@ -1329,35 +1328,6 @@ public class PCEnhancer {
|
||||||
return fmd.getDeclaredType();
|
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}
|
* Adds the {@link PersistenceCapable#pcReplaceStateManager}
|
||||||
* method to the bytecode.
|
* method to the bytecode.
|
||||||
|
@ -2157,6 +2127,9 @@ public class PCEnhancer {
|
||||||
// make the class implement PersistenceCapable
|
// make the class implement PersistenceCapable
|
||||||
_pc.declareInterface(PCTYPE);
|
_pc.declareInterface(PCTYPE);
|
||||||
|
|
||||||
|
// add a version stamp
|
||||||
|
addGetEnhancementContractVersionMethod();
|
||||||
|
|
||||||
// find the default constructor
|
// find the default constructor
|
||||||
BCMethod method = _pc.getDeclaredMethod("<init>", (String[]) null);
|
BCMethod method = _pc.getDeclaredMethod("<init>", (String[]) null);
|
||||||
|
|
||||||
|
@ -2197,8 +2170,6 @@ public class PCEnhancer {
|
||||||
* <li><code>private static byte[] pcFieldFlags</code></li>
|
* <li><code>private static byte[] pcFieldFlags</code></li>
|
||||||
* <li><code>protected transient StateManager pcStateManager</code>
|
* <li><code>protected transient StateManager pcStateManager</code>
|
||||||
* if no PersistenceCapable superclass present)</li>
|
* if no PersistenceCapable superclass present)</li>
|
||||||
* <li><code>protected transient byte pcFlags</code>
|
|
||||||
* if no PersistenceCapable superclass present)</li>
|
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
private void addFields() {
|
private void addFields() {
|
||||||
|
@ -2212,10 +2183,6 @@ public class PCEnhancer {
|
||||||
BCField field = _pc.declareField(SM, SMTYPE);
|
BCField field = _pc.declareField(SM, SMTYPE);
|
||||||
field.makeProtected();
|
field.makeProtected();
|
||||||
field.setTransient(true);
|
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
|
* Adds bytecode modifying the cloning behavior of the class being
|
||||||
* enhanced to correctly replace the <code>pcFlags</code> and
|
* enhanced to correctly replace the <code>pcStateManager</code>
|
||||||
* <code>pcStateManager</code> instance fields of any clone created with
|
* instance fields of any clone created with their default values.
|
||||||
* their default values. Also, if this class is the base PC type
|
* Also, if this class is the base PC type and does not declared
|
||||||
* and does not declared a clone method, one will be added.
|
* a clone method, one will be added.
|
||||||
*/
|
*/
|
||||||
private void addCloningCode() {
|
private void addCloningCode() {
|
||||||
if (_meta.getPCSuperclass() != null)
|
if (_meta.getPCSuperclass() != null)
|
||||||
|
@ -2781,12 +2748,6 @@ public class PCEnhancer {
|
||||||
code.constant().setNull();
|
code.constant().setNull();
|
||||||
code.putfield().setField(SM, SMTYPE);
|
code.putfield().setField(SM, SMTYPE);
|
||||||
|
|
||||||
// ((<type>) 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
|
// if modified, increase stack
|
||||||
code.calculateMaxStack();
|
code.calculateMaxStack();
|
||||||
code.calculateMaxLocals();
|
code.calculateMaxLocals();
|
||||||
|
@ -2860,23 +2821,10 @@ public class PCEnhancer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dfg: if (inst.pcFlags <= 0) return inst.<field>;
|
|
||||||
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.<field>;
|
// if (inst.pcStateManager == null) return inst.<field>;
|
||||||
Instruction ins = loadManagedInstance(code, true);
|
Instruction ins = loadManagedInstance(code, true);
|
||||||
if (ifins != null)
|
|
||||||
ifins.setTarget(ins);
|
|
||||||
code.getfield().setField(SM, SMTYPE);
|
code.getfield().setField(SM, SMTYPE);
|
||||||
ifins = code.ifnonnull();
|
JumpInstruction ifins = code.ifnonnull();
|
||||||
loadManagedInstance(code, true);
|
loadManagedInstance(code, true);
|
||||||
addGetManagedValueCode(code, fmd);
|
addGetManagedValueCode(code, fmd);
|
||||||
code.xreturn().setType(fmd.getDeclaredType());
|
code.xreturn().setType(fmd.getDeclaredType());
|
||||||
|
@ -2919,25 +2867,10 @@ public class PCEnhancer {
|
||||||
// PCEnhancer uses static methods; PCSubclasser does not.
|
// PCEnhancer uses static methods; PCSubclasser does not.
|
||||||
int firstParamOffset = getAccessorParameterOffset();
|
int firstParamOffset = getAccessorParameterOffset();
|
||||||
|
|
||||||
// dfg: if (inst.pcFlags == 0) inst.<field> = 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.<field> = value;
|
// if (inst.pcStateManager == null) inst.<field> = value;
|
||||||
Instruction ins = loadManagedInstance(code, true);
|
Instruction ins = loadManagedInstance(code, true);
|
||||||
if (ifins != null)
|
|
||||||
ifins.setTarget(ins);
|
|
||||||
code.getfield().setField(SM, SMTYPE);
|
code.getfield().setField(SM, SMTYPE);
|
||||||
ifins = code.ifnonnull();
|
JumpInstruction ifins = code.ifnonnull();
|
||||||
loadManagedInstance(code, true);
|
loadManagedInstance(code, true);
|
||||||
code.xload().setParam(firstParamOffset);
|
code.xload().setParam(firstParamOffset);
|
||||||
addSetManagedValueCode(code, fmd);
|
addSetManagedValueCode(code, fmd);
|
||||||
|
@ -3507,6 +3440,19 @@ public class PCEnhancer {
|
||||||
return setter;
|
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
|
* Return the concrete type for the given class, i.e. impl for managed
|
||||||
* interfaces
|
* interfaces
|
||||||
|
|
|
@ -34,6 +34,8 @@ public interface PersistenceCapable {
|
||||||
|
|
||||||
public static final Object DESERIALIZED = new Object();
|
public static final Object DESERIALIZED = new Object();
|
||||||
|
|
||||||
|
int pcGetEnhancementContractVersion();
|
||||||
|
|
||||||
Object pcGetGenericContext();
|
Object pcGetGenericContext();
|
||||||
|
|
||||||
StateManager pcGetStateManager();
|
StateManager pcGetStateManager();
|
||||||
|
@ -48,8 +50,6 @@ public interface PersistenceCapable {
|
||||||
|
|
||||||
void pcReplaceFields(int[] fieldIndex);
|
void pcReplaceFields(int[] fieldIndex);
|
||||||
|
|
||||||
void pcReplaceFlags();
|
|
||||||
|
|
||||||
void pcCopyFields(Object fromObject, int[] fields);
|
void pcCopyFields(Object fromObject, int[] fields);
|
||||||
|
|
||||||
void pcDirty(String fieldName);
|
void pcDirty(String fieldName);
|
||||||
|
|
|
@ -40,11 +40,6 @@ public interface StateManager {
|
||||||
*/
|
*/
|
||||||
public Object getPCPrimaryKey(Object oid, int field);
|
public Object getPCPrimaryKey(Object oid, int field);
|
||||||
|
|
||||||
/**
|
|
||||||
* Change internal flags.
|
|
||||||
*/
|
|
||||||
public byte replaceFlags();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change state manager.
|
* Change state manager.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -334,10 +334,6 @@ public class DetachedStateManager
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte replaceFlags() {
|
|
||||||
return PersistenceCapable.MEDIATE_WRITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getPCPrimaryKey(Object oid, int field) {
|
public Object getPCPrimaryKey(Object oid, int field) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -939,5 +935,5 @@ public class DetachedStateManager
|
||||||
public void unlock() {
|
public void unlock() {
|
||||||
if (_lock != null)
|
if (_lock != null)
|
||||||
_lock.unlock();
|
_lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,10 +403,6 @@ public class DetachedValueStateManager
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte replaceFlags() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StateManager replaceStateManager(StateManager sm) {
|
public StateManager replaceStateManager(StateManager sm) {
|
||||||
return sm;
|
return sm;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,10 +71,6 @@ public class ObjectIdStateManager
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte replaceFlags() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StateManager replaceStateManager(StateManager sm) {
|
public StateManager replaceStateManager(StateManager sm) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,6 @@ public class StateManagerImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.pcSetDetachedState(null);
|
pc.pcSetDetachedState(null);
|
||||||
pc.pcReplaceFlags();
|
|
||||||
_pc = pc;
|
_pc = pc;
|
||||||
|
|
||||||
if (_oid instanceof OpenJPAId)
|
if (_oid instanceof OpenJPAId)
|
||||||
|
|
|
@ -85,10 +85,6 @@ class ProxySetupStateManager
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte replaceFlags() {
|
|
||||||
throw new InternalException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StateManager replaceStateManager(StateManager sm) {
|
public StateManager replaceStateManager(StateManager sm) {
|
||||||
throw new InternalException();
|
throw new InternalException();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue