use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method loadUnloadedFields.
/**
* Fetch from the database all fields that are not currently loaded regardless of whether
* they are in the current fetch group or not. Called by lifecycle transitions.
*/
public void loadUnloadedFields() {
int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, cmd.getAllMemberPositions(), false);
if (fieldNumbers == null || fieldNumbers.length == 0) {
// All loaded so return
return;
}
if (preDeleteLoadedFields != null && ((myLC.isDeleted() && myEC.isFlushing()) || activity == ActivityState.DELETING)) {
// During deletion process so we know what is really loaded so only load if necessary
fieldNumbers = ClassUtils.getFlagsSetTo(preDeleteLoadedFields, fieldNumbers, false);
}
if (fieldNumbers != null && fieldNumbers.length > 0) {
boolean callPostLoad = myFP.isToCallPostLoadFetchPlan(this.loadedFields);
int[] unloadedFieldNumbers = loadFieldsFromLevel2Cache(fieldNumbers);
if (unloadedFieldNumbers != null) {
loadFieldsFromDatastore(unloadedFieldNumbers);
}
// Make sure all SCO lazy-loaded fields have contents loaded
int[] secondClassMutableFieldNumbers = cmd.getSCOMutableMemberPositions();
for (int i = 0; i < secondClassMutableFieldNumbers.length; i++) {
SingleValueFieldManager sfv = new SingleValueFieldManager();
provideFields(new int[] { secondClassMutableFieldNumbers[i] }, sfv);
Object value = sfv.fetchObjectField(i);
if (value instanceof SCOContainer) {
((SCOContainer) value).load();
}
}
updateLevel2CacheForFields(fieldNumbers);
if (callPostLoad) {
postLoad();
}
}
}
use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method replaceField.
/**
* Method to change the value of a field in the PC object.
* @param pc The PC object
* @param fieldNumber Number of field
* @param value The new value of the field
*/
protected void replaceField(Persistable pc, int fieldNumber, Object value) {
try {
if (myEC.getMultithreaded()) {
myEC.getLock().lock();
lock.lock();
}
// Update the field in our PC object
FieldManager prevFM = currFM;
currFM = new SingleValueFieldManager();
try {
currFM.storeObjectField(fieldNumber, value);
pc.dnReplaceField(fieldNumber);
} finally {
currFM = prevFM;
}
} finally {
if (myEC.getMultithreaded()) {
lock.unlock();
myEC.getLock().unlock();
}
}
}
use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-rdbms by datanucleus.
the class PersistableMapping method getValueForDatastoreMapping.
/**
* Method to return the value to be stored in the specified datastore index given the overall value for this java type.
* @param nucleusCtx Context
* @param index The datastore index
* @param value The overall value for this java type
* @return The value for this datastore index
*/
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) {
ExecutionContext ec = nucleusCtx.getApiAdapter().getExecutionContext(value);
if (cmd == null) {
cmd = nucleusCtx.getMetaDataManager().getMetaDataForClass(getType(), ec != null ? ec.getClassLoaderResolver() : nucleusCtx.getClassLoaderResolver(null));
}
if (cmd.getIdentityType() == IdentityType.APPLICATION) {
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(cmd.getPKMemberPositions()[index]);
ObjectProvider op = null;
if (ec != null) {
op = ec.findObjectProvider(value);
}
if (op == null) {
// Transient or detached maybe, so use reflection to get PK field values
if (mmd instanceof FieldMetaData) {
return ClassUtils.getValueOfFieldByReflection(value, mmd.getName());
}
return ClassUtils.getValueOfMethodByReflection(value, ClassUtils.getJavaBeanGetterName(mmd.getName(), false));
}
if (!mmd.isPrimaryKey()) {
// Make sure the field is loaded
op.isLoaded(mmd.getAbsoluteFieldNumber());
}
FieldManager fm = new SingleValueFieldManager();
op.provideFields(new int[] { mmd.getAbsoluteFieldNumber() }, fm);
return fm.fetchObjectField(mmd.getAbsoluteFieldNumber());
} else if (cmd.getIdentityType() == IdentityType.DATASTORE) {
Object id = nucleusCtx.getApiAdapter().getIdForObject(value);
return id != null ? IdentityUtils.getTargetKeyForDatastoreIdentity(id) : null;
}
return null;
}
use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-rdbms by datanucleus.
the class ExpressionUtils method getValueForMemberOfObject.
/**
* Get the value of a managed field/property in the provided object.
* @param ec execution context
* @param mmd metadata for the field/property
* @param object the pc object
* @return The field value
*/
public static Object getValueForMemberOfObject(ExecutionContext ec, AbstractMemberMetaData mmd, Object object) {
if (ec == null) {
// Transient or detached maybe
return ClassUtils.getValueOfFieldByReflection(object, mmd.getName());
// TODO What if this is a property?
}
ObjectProvider sm = ec.findObjectProvider(object);
if (!mmd.isPrimaryKey()) {
// Make sure the field is loaded
sm.isLoaded(mmd.getAbsoluteFieldNumber());
}
FieldManager fm = new SingleValueFieldManager();
sm.provideFields(new int[] { mmd.getAbsoluteFieldNumber() }, fm);
return fm.fetchObjectField(mmd.getAbsoluteFieldNumber());
}
use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method provideField.
/**
* Method to retrieve the value of a field from the PC object. Assumes that it is loaded.
* @param pc The PC object
* @param fieldNumber Number of field
* @return The value of the field
*/
protected Object provideField(Persistable pc, int fieldNumber) {
Object obj;
try {
if (myEC.getMultithreaded()) {
myEC.getLock().lock();
lock.lock();
}
FieldManager prevFM = currFM;
currFM = new SingleValueFieldManager();
try {
pc.dnProvideField(fieldNumber);
obj = currFM.fetchObjectField(fieldNumber);
} finally {
currFM = prevFM;
}
} finally {
if (myEC.getMultithreaded()) {
lock.unlock();
myEC.getLock().unlock();
}
}
return obj;
}
Aggregations