Class ObjectStore
java.lang.Object
com.gargoylesoftware.base.objectstore.ObjectStore
- Direct Known Subclasses:
DispatchingObjectStore
,ReflectedObjectStore
This is a wrapper for the data layer in an application. Any code that
accesses a database or some other form of data should be in a subclass of
ObjectStore
- Version:
- $Revision: 1.4 $
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
assertNotNull
(String fieldName, Object object) Throw an exception if the specified object is nullfinal Object
execute
(ObjectStoreCommand command) Perform the actions specified by the key and return a value.protected abstract Object
executeImpl
(ObjectStoreCommand command) Override this to provide the actual processing of the object store.protected final Object
getResource
(String name) Return a resource from the specified factoryfinal ResourceManager
Gets the resource managerprivate ResourceManager
Return the resource manager.protected Object
handleError
(Error error) Handle an exception that occured during the processing of executeImpl().protected Object
handleException
(Exception exception) Handle an exception that occured during the processing of executeImpl().protected final void
releaseResource
(ManagedResource object) Release the specified resourcefinal void
setResourceFactoryMap
(Map inputMap) Set the resource map.final void
setResourceManager
(ResourceManager resourceManager) Set the resource manager
-
Field Details
-
resourceManager_
-
-
Constructor Details
-
ObjectStore
protected ObjectStore()Create an instance
-
-
Method Details
-
setResourceFactoryMap
Set the resource map. This defines what class is used when a specific resource factory is requested.
It is recommended to use
setResourceManager(ResourceManager)
instead- Parameters:
inputMap
- A map containing string/class pairs.
-
setResourceManager
Set the resource manager- Parameters:
resourceManager
- The new resource manager
-
getResourceManager
Gets the resource manager- Returns:
- The resource manager or null if a resource manager has not been set.
-
execute
public final Object execute(ObjectStoreCommand command) throws ObjectStoreCommandNotSupportedException, ObjectStoreException Perform the actions specified by the key and return a value. The subclasses will perform the actual work in overridden versions of executeImpl()- Parameters:
command
- The object that tells the object store what to do- Returns:
- The results of the actions or null if there are no results
- Throws:
ObjectStoreCommandNotSupportedException
- If the command is not supported by this storeObjectStoreException
- If an error occurs during processing of this command.- See Also:
-
handleException
protected Object handleException(Exception exception) throws ObjectStoreException, ObjectStoreCommandNotSupportedException Handle an exception that occured during the processing of executeImpl(). Usually these exceptions will be rethrown after logging them to some error logThe default behaviour is to rethrow any ObjectStoreExceptions or ObjectStoreCommandNotSupportedExceptions. All other exceptions are wrapped in a new ObjectStoreException and then that wrapper is thown
- Parameters:
exception
- the exception that had been thrown- Returns:
- The object to return from execute in those cases where an exception is not thrown out of this method
- Throws:
ObjectStoreException
- The exception to be thrown back out of execute()ObjectStoreCommandNotSupportedException
- the exception to be thrown back out of execute()
-
handleError
Handle an exception that occured during the processing of executeImpl(). Usually these exceptions will be rethrown after logging them to some error logThe default behaviour is to rethrow the error
- Parameters:
error
- The error that had been thrown- Returns:
- The object to return from execute in those cases where an exception is not thrown out of this method
-
getResource
Return a resource from the specified factory- Parameters:
name
- The name of the factory- Returns:
- The specified resource
- See Also:
-
executeImpl
protected abstract Object executeImpl(ObjectStoreCommand command) throws Throwable, ObjectStoreCommandNotSupportedException Override this to provide the actual processing of the object store.- Parameters:
command
- The object that tells the object store what to do- Returns:
- The results of the actions or null if there are no results
- Throws:
ObjectStoreCommandNotSupportedException
- If the specified command is not understood by the object storeThrowable
- If an error occurs- See Also:
-
releaseResource
Release the specified resource- Parameters:
object
- The resource to release
-
getResourceManagerOrDie
Return the resource manager. If a resource manager has not been specified then throw an exception.- Returns:
- The resource manager
-
assertNotNull
Throw an exception if the specified object is null- Parameters:
fieldName
- The name of the paremeter we are checkingobject
- The value of the parameter we are checking
-