use of org.datanucleus.store.fieldmanager.SingleValueFieldManager in project datanucleus-core by datanucleus.
the class StateManagerImpl method loadUnloadedRelationFields.
public void loadUnloadedRelationFields() {
int[] fieldsConsidered = cmd.getRelationMemberPositions(myEC.getClassLoaderResolver());
int[] fieldNumbers = ClassUtils.getFlagsSetTo(loadedFields, fieldsConsidered, 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);
}
int[] secondClassMutableFieldNumbers = cmd.getSCOMutableMemberPositions();
for (int i = 0; i < secondClassMutableFieldNumbers.length; i++) {
// Make sure all SCO lazy-loaded relation fields have contents loaded
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(secondClassMutableFieldNumbers[i]);
if (mmd.getRelationType(myEC.getClassLoaderResolver()) != RelationType.NONE) {
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 initialiseForPersistentNew.
/**
* Initialises a state manager to manage a transient instance that is becoming newly persistent.
* A new object ID for the instance is obtained from the store manager and the object is inserted in the data store.
* <p>
* This constructor is used for assigning state managers to existing instances that are transitioning to a persistent state.
* @param pc the instance being make persistent.
* @param preInsertChanges Any changes to make before inserting
*/
public void initialiseForPersistentNew(Persistable pc, FieldValues preInsertChanges) {
myPC = pc;
myLC = myEC.getNucleusContext().getApiAdapter().getLifeCycleState(LifeCycleState.P_NEW);
persistenceFlags = Persistable.READ_OK;
for (int i = 0; i < loadedFields.length; ++i) {
loadedFields[i] = true;
}
// Assign this StateManager to the PC
replaceStateManager(myPC, this);
myPC.dnReplaceFlags();
saveFields();
// Populate all fields that have "value-strategy" and are not datastore populated
populateValueGenerationFields();
if (preInsertChanges != null) {
// Apply any pre-insert field updates
preInsertChanges.fetchFields(this);
}
if (cmd.getIdentityType() == IdentityType.APPLICATION) {
// Make sure any PK fields that are Persistable are persisted first, so we have an id to assign our identity
int[] pkFieldNumbers = cmd.getPKMemberPositions();
for (int i = 0; i < pkFieldNumbers.length; i++) {
int fieldNumber = pkFieldNumbers[i];
AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
if (myEC.getMetaDataManager().getMetaDataForClass(fmd.getType(), getExecutionContext().getClassLoaderResolver()) != null) {
try {
if (myEC.getMultithreaded()) {
myEC.getLock().lock();
lock.lock();
}
FieldManager prevFM = currFM;
try {
currFM = new SingleValueFieldManager();
myPC.dnProvideField(fieldNumber);
Persistable pkFieldPC = (Persistable) ((SingleValueFieldManager) currFM).fetchObjectField(fieldNumber);
if (pkFieldPC == null) {
throw new NucleusUserException(Localiser.msg("026016", fmd.getFullFieldName()));
}
if (!myEC.getApiAdapter().isPersistent(pkFieldPC)) {
// Make sure the PC field is persistent - can cause the insert of our object being managed by this SM via flush() when bidir relation
Object persistedFieldPC = myEC.persistObjectInternal(pkFieldPC, null, null, -1, ObjectProvider.PC);
replaceField(myPC, fieldNumber, persistedFieldPC, false);
}
} finally {
currFM = prevFM;
}
} finally {
if (myEC.getMultithreaded()) {
lock.unlock();
myEC.getLock().unlock();
}
}
}
}
}
// Set the identity of this object
setIdentity(false);
if (myEC.getTransaction().isActive()) {
myEC.enlistInTransaction(this);
}
// Now in PERSISTENT_NEW so call any callbacks/listeners
getCallbackHandler().postCreate(myPC);
if (myEC.getManageRelations()) {
// Managed Relations : register non-null bidir fields for later processing
ClassLoaderResolver clr = myEC.getClassLoaderResolver();
int[] relationPositions = cmd.getRelationMemberPositions(clr);
if (relationPositions != null) {
for (int i = 0; i < relationPositions.length; i++) {
AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(relationPositions[i]);
if (RelationType.isBidirectional(mmd.getRelationType(clr))) {
Object value = provideField(relationPositions[i]);
if (value != null) {
// Store the field with value of null so it gets checked
myEC.getRelationshipManager(this).relationChange(relationPositions[i], null, value);
}
}
}
}
}
}
Aggregations