com.force.sdk.jpa
Class ForceObjectManagerImpl

java.lang.Object
  extended by org.datanucleus.ObjectManagerImpl
      extended by com.force.sdk.jpa.ForceObjectManagerImpl
All Implemented Interfaces:
org.datanucleus.ObjectManager

public class ForceObjectManagerImpl
extends org.datanucleus.ObjectManagerImpl

Object manager that manages the objects being created, updated, or deleted. Special handling for all or nothing operations.

Author:
Fiaz Hossain

Field Summary
 
Fields inherited from class org.datanucleus.ObjectManagerImpl
LOCALISER
 
Constructor Summary
ForceObjectManagerImpl(org.datanucleus.ObjectManagerFactoryImpl omf, Object owner, String userName, String password)
          create an object manager with datastore credentials.
 
Method Summary
 void addToCreateList(com.sforce.soap.partner.sobject.SObject object, org.datanucleus.store.ObjectProvider op)
          add to the current list of entities to be created.
 void addToDeleteList(String id)
          add to the current list of entities to be deleted.
 void addToUpdateList(com.sforce.soap.partner.sobject.SObject object, Calendar version)
          add to the current list of entities to be updated.
 void detachObject(Object obj, org.datanucleus.state.FetchPlanState state)
          We add this method so that we can support detach of a newly created persistent object that has never been saved to the db.
 void flushInternal(boolean flushToDatastore)
          This method flushes all dirty, new, and deleted instances to the datastore.
 com.sforce.soap.partner.sobject.SObject getParentSObject(Object parent)
          Retrieve the Force.com object (SObject) for the given parent.
 boolean isInAllOrNothingMode()
          check for whether an active transaction is currently flushing data to the datastore in all or nothing mode.
 void markDirty(org.datanucleus.StateManager sm, boolean directUpdate)
          Method to mark an object (StateManager) as dirty.
 void postRollback()
          There are some cases when a postrollback tries to detach an object that has not been persisted.
 
Methods inherited from class org.datanucleus.ObjectManagerImpl
acquireThreadContextInfo, addInternalFetchGroup, addListener, addStateManager, assertActiveTransaction, assertClassPersistable, assertDetachable, assertHasImplementationCreator, assertIsOpen, assertNotDetached, assertWritable, attachObject, attachObjectCopy, clearDirty, clearDirty, close, deleteObject, deleteObjectInternal, deleteObjects, detachAll, detachObjectCopy, disconnectLifecycleListener, disconnectSMCache, enlistInTransaction, evictAllObjects, evictFromTransaction, evictObject, evictObjects, exists, findObject, findObject, findObjects, findObjectUsingAID, findStateManager, flush, getApiAdapter, getAttachedObjectForId, getCallbackHandler, getClassLoaderResolver, getCopyOnAttach, getDatastoreReadTimeoutMillis, getDatastoreWriteTimeoutMillis, getDetachAllOnCommit, getDetachAllOnRollback, getDetachOnClose, getExecutionContext, getExtent, getFetchGroupManager, getFetchGroupsWithName, getFetchPlan, getIdentityAsString, getIgnoreCache, getInternalFetchGroup, getLockManager, getManagedObjects, getManagedObjects, getManagedObjects, getManagedObjects, getMetaDataManager, getMultithreaded, getObjectFromCache, getObjectManagerFactory, getOMFContext, getOwner, getReadWriteLock, getSerializeReadForClass, getStateManagerById, getStoreManager, getThreadContextInfo, getTransaction, hasIdentityInCache, hasPersistenceInformationForClass, hereIsStateManager, initialiseLevel1Cache, isClosed, isDelayDatastoreOperationsEnabled, isEnlistedInTransaction, isFlushing, isInserting, isManagingRelations, isObjectModifiedInTransaction, isRunningDetachAllOnCommit, makeObjectNontransactional, makeObjectTransactional, makeObjectTransient, markManagedRelationDirty, newInstance, newObjectId, newObjectId, newQuery, nontransactionalUpdateCommit, performManagedRelationships, persistObject, persistObjectInternal, persistObjects, postBegin, postClose, postCommit, preCommit, preRollback, putObjectIntoCache, putObjectIntoLevel2Cache, putObjectIntoLevel2CacheInternal, refreshAllObjects, refreshObject, releaseThreadContextInfo, removeAllInstanceLifecycleListeners, removeInternalFetchGroup, removeListener, removeObjectFromCache, removeObjectFromLevel2Cache, removeStateManager, replaceObjectId, retrieveObject, setCopyOnAttach, setDatastoreReadTimeoutMillis, setDatastoreWriteTimeoutMillis, setDetachAllOnCommit, setDetachAllOnRollback, setDetachOnClose, setIgnoreCache, setMultithreaded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForceObjectManagerImpl

public ForceObjectManagerImpl(org.datanucleus.ObjectManagerFactoryImpl omf,
                              Object owner,
                              String userName,
                              String password)
create an object manager with datastore credentials.

Parameters:
omf - the object manager factory
owner - the owning persistence manager or entity manager
userName - the username to the datastore
password - the password to the datastore
Method Detail

isInAllOrNothingMode

public boolean isInAllOrNothingMode()
check for whether an active transaction is currently flushing data to the datastore in all or nothing mode.

Returns:
true if all or nothing mode is enabled and we are currently flushing data in this mode

flushInternal

public void flushInternal(boolean flushToDatastore)
This method flushes all dirty, new, and deleted instances to the datastore. It has no effect if a transaction is not active. If a datastore transaction is active, this method synchronizes the cache with the datastore and reports any exceptions. If an optimistic transaction is active, this method obtains a datastore connection and synchronizes the cache with the datastore using this connection. The connection obtained by this method is held until the end of the transaction.

Specified by:
flushInternal in interface org.datanucleus.ObjectManager
Overrides:
flushInternal in class org.datanucleus.ObjectManagerImpl
Parameters:
flushToDatastore - Whether to ensure any changes reach the datastore Otherwise they will be flushed to the datastore manager and leave it to decide the opportune moment to actually flush them to the datastore

getParentSObject

public com.sforce.soap.partner.sobject.SObject getParentSObject(Object parent)
Retrieve the Force.com object (SObject) for the given parent.

Parameters:
parent - Object
Returns:
the Force.com object (SObject) corresponding to the given parent

addToCreateList

public void addToCreateList(com.sforce.soap.partner.sobject.SObject object,
                            org.datanucleus.store.ObjectProvider op)
add to the current list of entities to be created.

Parameters:
object - the object to be created
op - the object provider

addToUpdateList

public void addToUpdateList(com.sforce.soap.partner.sobject.SObject object,
                            Calendar version)
add to the current list of entities to be updated.

Parameters:
object - the object to update (complete with updated fields)
version - this should be the time of modification. Pass in a version if we're checking if-modified-before headers

addToDeleteList

public void addToDeleteList(String id)
add to the current list of entities to be deleted.

Parameters:
id - the id of the entity to delete

markDirty

public void markDirty(org.datanucleus.StateManager sm,
                      boolean directUpdate)
Method to mark an object (StateManager) as dirty.

Specified by:
markDirty in interface org.datanucleus.ObjectManager
Overrides:
markDirty in class org.datanucleus.ObjectManagerImpl
Parameters:
sm - The StateManager
directUpdate - Whether the object has had a direct update made on it (if known)

postRollback

public void postRollback()
There are some cases when a postrollback tries to detach an object that has not been persisted. In the case of detachment the object is attempted to be reloaded which throws an NucleusObjectNotFoundException since the object was never stored in the db. We can ignore that exception.

Specified by:
postRollback in interface org.datanucleus.ObjectManager
Overrides:
postRollback in class org.datanucleus.ObjectManagerImpl

detachObject

public void detachObject(Object obj,
                         org.datanucleus.state.FetchPlanState state)
We add this method so that we can support detach of a newly created persistent object that has never been saved to the db.

Specified by:
detachObject in interface org.datanucleus.ObjectManager
Overrides:
detachObject in class org.datanucleus.ObjectManagerImpl


Copyright © 2011. All Rights Reserved.