use of org.datanucleus.ExecutionContext in project datanucleus-api-jdo by datanucleus.
the class NucleusJDOHelper method getDirtyFields.
/**
* Accessor for the names of the dirty fields of the persistable object.
* @param obj The persistable object
* @param pm The Persistence Manager (only required if the object is detached)
* @return Names of the dirty fields
*/
public static String[] getDirtyFields(Object obj, PersistenceManager pm) {
if (obj == null || !(obj instanceof Persistable)) {
return null;
}
Persistable pc = (Persistable) obj;
if (isDetached(pc)) {
ExecutionContext ec = ((JDOPersistenceManager) pm).getExecutionContext();
// Temporarily attach a StateManager to access the detached field information
ObjectProvider op = ec.getNucleusContext().getObjectProviderFactory().newForDetached(ec, pc, getObjectId(pc), null);
pc.dnReplaceStateManager(op);
op.retrieveDetachState(op);
String[] dirtyFieldNames = op.getDirtyFieldNames();
pc.dnReplaceStateManager(null);
return dirtyFieldNames;
}
ExecutionContext ec = ((JDOPersistenceManager) pm).getExecutionContext();
ObjectProvider op = ec.findObjectProvider(pc);
if (op == null) {
return null;
}
return op.getDirtyFieldNames();
}
use of org.datanucleus.ExecutionContext in project datanucleus-api-jdo by datanucleus.
the class NucleusJDOHelper method getLoadedFields.
/**
* Accessor for the names of the loaded fields of the persistable object.
* @param obj Persistable object
* @param pm The Persistence Manager (only required if the object is detached)
* @return Names of the loaded fields
*/
public static String[] getLoadedFields(Object obj, PersistenceManager pm) {
if (obj == null || !(obj instanceof Persistable)) {
return null;
}
Persistable pc = (Persistable) obj;
if (isDetached(pc)) {
// Temporarily attach a StateManager to access the detached field information
ExecutionContext ec = ((JDOPersistenceManager) pm).getExecutionContext();
ObjectProvider op = ec.getNucleusContext().getObjectProviderFactory().newForDetached(ec, pc, getObjectId(pc), null);
pc.dnReplaceStateManager(op);
op.retrieveDetachState(op);
String[] loadedFieldNames = op.getLoadedFieldNames();
pc.dnReplaceStateManager(null);
return loadedFieldNames;
}
ExecutionContext ec = ((JDOPersistenceManager) pm).getExecutionContext();
ObjectProvider op = ec.findObjectProvider(pc);
if (op == null) {
return null;
}
return op.getLoadedFieldNames();
}
use of org.datanucleus.ExecutionContext in project datanucleus-api-jdo by datanucleus.
the class JDOCallbackHandler method preStore.
/**
* Callback before the object is stored.
* @param pc The Object
*/
public void preStore(Object pc) {
for (LifecycleListenerForClass listener : getListenersWorkingCopy()) {
if (listener.forClass(pc.getClass()) && listener.getListener() instanceof StoreLifecycleListener) {
ExecutionContext ec = nucleusCtx.getApiAdapter().getExecutionContext(pc);
String[] fieldNames = null;
// PRE_STORE will return the fields being stored (DataNucleus extension)
ObjectProvider op = ec.findObjectProvider(pc);
fieldNames = op.getDirtyFieldNames();
if (fieldNames == null) {
// Must be persisting so just return all loaded fields
fieldNames = op.getLoadedFieldNames();
}
((StoreLifecycleListener) listener.getListener()).preStore(new FieldInstanceLifecycleEvent(pc, InstanceLifecycleEvent.STORE, null, fieldNames));
}
}
if (pc instanceof StoreCallback) {
try {
((StoreCallback) pc).jdoPreStore();
} catch (Exception e) {
throw new JDOUserCallbackException(Localiser.msg("025001", "jdoPreStore"), e);
}
}
if (beanValidationHandler != null) {
ObjectProvider op = nucleusCtx.getApiAdapter().getExecutionContext(pc).findObjectProvider(pc);
if (!op.getLifecycleState().isNew()) {
// Don't fire this when persisting new since we will have done prePersist
beanValidationHandler.preStore(pc);
}
}
}
use of org.datanucleus.ExecutionContext in project tests by datanucleus.
the class FetchPlanTest method getFetchPlan.
/**
* Convenience accessor for a new FetchPlan.
* @return The FetchPlan
*/
private FetchPlan getFetchPlan() {
JDOPersistenceManager pm = (JDOPersistenceManager) pmf.getPersistenceManager();
ExecutionContext ec = pm.getExecutionContext();
return new FetchPlan(ec, ec.getClassLoaderResolver());
}
use of org.datanucleus.ExecutionContext in project datanucleus-rdbms by datanucleus.
the class RDBMSPersistenceHandler method insertObject.
/**
* Inserts a persistent object into the database.
* The insert can take place in several steps, one insert per table that it is stored in.
* e.g When persisting an object that uses "new-table" inheritance for each level of the inheritance tree
* then will get an INSERT into each table. When persisting an object that uses "complete-table"
* inheritance then will get a single INSERT into its table.
* @param op The ObjectProvider of the object to be inserted.
* @throws NucleusDataStoreException when an error occurs in the datastore communication
*/
public void insertObject(ObjectProvider op) {
// Check if read-only so update not permitted
assertReadOnlyForUpdateOfObject(op);
// Check if we need to do any updates to the schema before inserting this object
checkForSchemaUpdatesForFieldsOfObject(op, op.getLoadedFieldNumbers());
ExecutionContext ec = op.getExecutionContext();
ClassLoaderResolver clr = op.getExecutionContext().getClassLoaderResolver();
String className = op.getClassMetaData().getFullClassName();
DatastoreClass dc = getDatastoreClass(className, clr);
if (dc == null) {
if (op.getClassMetaData().getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE) {
throw new NucleusUserException(Localiser.msg("032013", className));
}
throw new NucleusException(Localiser.msg("032014", className, op.getClassMetaData().getInheritanceMetaData().getStrategy())).setFatal();
}
if (ec.getStatistics() != null) {
ec.getStatistics().incrementInsertCount();
}
insertObjectInTable(dc, op, clr);
}
Aggregations