use of org.datanucleus.state.StateManagerImpl in project motech by motech.
the class StateManagerUtil method setTransactionVersion.
/**
* Sets the given transaction version to the instance state manager.
*
* @param instance the instance from which state manager will be retrieved
* @param version the transaction version
* @param versionFieldName the name of the version field
*/
public static void setTransactionVersion(Object instance, Object version, String versionFieldName) {
try {
StateManagerImpl stateManager = getStateManager(instance);
stateManager.setVersion(version);
AbstractClassMetaData cmd = stateManager.getClassMetaData();
int fieldPosition = cmd.getAbsolutePositionOfMember(versionFieldName);
boolean[] dirtyFields = getDirtyFields(stateManager);
// we must mark version field as non dirty
dirtyFields[fieldPosition] = false;
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new MdsException("Cannot set proper transaction version", e);
}
}
use of org.datanucleus.state.StateManagerImpl in project motech by motech.
the class StateManagerUtil method getStateManager.
private static StateManagerImpl getStateManager(Object instance) throws IllegalAccessException {
java.lang.reflect.Field dnStateManagerField;
Class clazz = instance.getClass();
do {
dnStateManagerField = getFieldSafe(clazz, "dnStateManager");
clazz = clazz.getSuperclass();
} while (clazz.getSuperclass() != null || dnStateManagerField == null);
dnStateManagerField.setAccessible(true);
StateManagerImpl stateManager = (StateManagerImpl) dnStateManagerField.get(instance);
dnStateManagerField.setAccessible(false);
return stateManager;
}
Aggregations