use of org.datanucleus.store.fieldmanager.FieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method replaceFields.
/**
* Called from the StoreManager to refresh data in the Persistable object associated with this StateManager.
* @param fieldNumbers An array of field numbers to be refreshed by the Store
* @param fm The updated values are stored in this object. This object is only valid for the duration of this call.
* @param replaceWhenDirty Whether to replace the fields when they are dirty here
*/
public void replaceFields(int[] fieldNumbers, FieldManager fm, boolean replaceWhenDirty) {
try {
if (myEC.getMultithreaded()) {
myEC.getLock().lock();
lock.lock();
}
FieldManager prevFM = currFM;
currFM = fm;
try {
int[] fieldsToReplace = fieldNumbers;
if (!replaceWhenDirty) {
int numberToReplace = fieldNumbers.length;
for (int i = 0; i < fieldNumbers.length; i++) {
if (dirtyFields[fieldNumbers[i]]) {
numberToReplace--;
}
}
if (numberToReplace > 0 && numberToReplace != fieldNumbers.length) {
fieldsToReplace = new int[numberToReplace];
int n = 0;
for (int i = 0; i < fieldNumbers.length; i++) {
if (!dirtyFields[fieldNumbers[i]]) {
fieldsToReplace[n++] = fieldNumbers[i];
}
}
} else if (numberToReplace == 0) {
fieldsToReplace = null;
}
}
if (fieldsToReplace != null) {
myPC.dnReplaceFields(fieldsToReplace);
}
} finally {
currFM = prevFM;
}
} finally {
if (myEC.getMultithreaded()) {
lock.unlock();
myEC.getLock().unlock();
}
}
}
use of org.datanucleus.store.fieldmanager.FieldManager 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.FieldManager 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.FieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method provideFields.
/**
* Called from the StoreManager after StoreManager.update() is called to obtain updated values from the Persistable associated with this StateManager.
* @param fieldNumbers An array of field numbers to be updated by the Store
* @param fm The updated values are stored in this object. This object is only valid for the duration of this call.
*/
public void provideFields(int[] fieldNumbers, FieldManager fm) {
try {
if (myEC.getMultithreaded()) {
myEC.getLock().lock();
lock.lock();
}
FieldManager prevFM = currFM;
currFM = fm;
try {
// This will respond by calling this.providedXXXFields() with the value of the field
myPC.dnProvideFields(fieldNumbers);
} finally {
currFM = prevFM;
}
} finally {
if (myEC.getMultithreaded()) {
lock.unlock();
myEC.getLock().unlock();
}
}
}
use of org.datanucleus.store.fieldmanager.FieldManager 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