// if (sm != null)
// return (sm.isDetached ()) ? Boolean.TRUE : Boolean.FALSE;
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnull();
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.invokeinterface().setMethod(SMTYPE, "isDetached",
boolean.class, null);
JumpInstruction iffalse = code.ifeq();
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
iffalse.setTarget(code.getstatic().setField(Boolean.class, "FALSE",
Boolean.class));
code.areturn();
// if we use detached state:
// if (pcGetDetachedState () != null
// && pcGetDetachedState != DESERIALIZED)
// return Boolean.TRUE;
Boolean state = _meta.usesDetachedState();
JumpInstruction notdeser = null;
Instruction target;
if (state != Boolean.FALSE) {
ifins.setTarget(loadManagedInstance(code, false));
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
ifins = code.ifnull();
loadManagedInstance(code, false);
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
code.getstatic().setField(PersistenceCapable.class,
"DESERIALIZED", Object.class);
notdeser = code.ifacmpeq();
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
if (state == Boolean.TRUE) {
// if we have to use detached state:
// return Boolean.FALSE;
target = code.getstatic().setField(Boolean.class, "FALSE",
Boolean.class);
ifins.setTarget(target);
notdeser.setTarget(target);
code.areturn();
return false;
}
}
// create artificial target to simplify
target = code.nop();
ifins.setTarget(target);
if (notdeser != null)
notdeser.setTarget(target);
// allow users with version or auto-assigned pk fields to manually
// construct a "detached" instance, so check these before taking into
// account non-existent detached state
// consider detached if version is non-default
FieldMetaData version = _meta.getVersionField();
if (state != Boolean.TRUE && version != null) {
// if (<version> != <default>)
// return true;
loadManagedInstance(code, false);
addGetManagedValueCode(code, version);
ifins = ifDefaultValue(code, version);
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
if (!_addVersionInitFlag){
// else return false;
ifins.setTarget(code.getstatic().setField(Boolean.class, "FALSE", Boolean.class));
}else{
FieldMetaData versionInit = _meta.getDeclaredField(VERSION_INIT_STR);
// noop
ifins.setTarget(code.nop());
// if (pcVersionInit)
// return true
// else return false;
loadManagedInstance(code, false);
getfield(code, null, versionInit.getName());
ifins = ifDefaultValue(code, versionInit);
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
ifins.setTarget(code.nop());
code.getstatic().setField(Boolean.class, "FALSE", Boolean.class);
}
code.areturn();
return false;
}
// consider detached if auto-genned primary keys are non-default
ifins = null;
JumpInstruction ifins2 = null;
boolean hasAutoAssignedPK = false;
if (state != Boolean.TRUE
&& _meta.getIdentityType() == ClassMetaData.ID_APPLICATION) {
// for each pk field:
// if (<pk> != <default> [&& !"".equals (<pk>)])
// return Boolean.TRUE;
FieldMetaData[] pks = _meta.getPrimaryKeyFields();
for (int i = 0; i < pks.length; i++) {
if (pks[i].getValueStrategy() == ValueStrategies.NONE)
continue;
target = loadManagedInstance(code, false);
if (ifins != null)
ifins.setTarget(target);
if (ifins2 != null)
ifins2.setTarget(target);
ifins2 = null;
addGetManagedValueCode(code, pks[i]);
ifins = ifDefaultValue(code, pks[i]);
if (pks[i].getDeclaredTypeCode() == JavaTypes.STRING) {
code.constant().setValue("");
loadManagedInstance(code, false);
addGetManagedValueCode(code, pks[i]);
code.invokevirtual().setMethod(String.class, "equals",
boolean.class, new Class[]{ Object.class });
ifins2 = code.ifne();
}
code.getstatic().setField(Boolean.class, "TRUE",
Boolean.class);
code.areturn();
}
}
// create artificial target to simplify
target = code.nop();
if (ifins != null)
ifins.setTarget(target);
if (ifins2 != null)
ifins2.setTarget(target);
// if has auto-assigned pk and we get to this point, must have default
// value, so must be new instance
if (hasAutoAssignedPK) {
code.getstatic().setField(Boolean.class, "FALSE", Boolean.class);