public class ProviderBasedDataObjectService extends Object implements DataObjectService
ProviderRegistry
.Modifier and Type | Field and Description |
---|---|
protected MetadataRepository |
metadataRepository
The metadata repository.
|
protected ProviderRegistry |
providerRegistry
The provider registry.
|
protected ReferenceLinker |
referenceLinker
The reference linker.
|
Constructor and Description |
---|
ProviderBasedDataObjectService() |
Modifier and Type | Method and Description |
---|---|
<T> T |
copyInstance(T dataObject,
CopyOption... options)
Returns a copy of the given data object instance.
|
void |
delete(Object dataObject)
Deletes a given data object.
|
<T> void |
deleteAll(Class<T> type)
Removes all records for the given data object type
|
<T> void |
deleteMatching(Class<T> type,
QueryByCriteria queryByCriteria)
Deletes records for the given type and matching the given criteria.
|
<T> T |
find(Class<T> type,
Object id)
Invoked to retrieve a data object instance by a single primary key field or id object.
|
<T> QueryResults<T> |
findAll(Class<T> type)
Executes a query for the given data object returning all data objects for the given type.
|
<T> QueryResults<T> |
findMatching(Class<T> type,
QueryByCriteria queryByCriteria)
Executes a query for the given data object.
|
<T> T |
findUnique(Class<T> type,
QueryByCriteria queryByCriteria)
Executes a query for the data object matching the given queryByCriteria and expecting a single unique result to
be returned.
|
void |
flush(Class<?> type)
Flushes any outstanding work to the backend data store.
|
MetadataRepository |
getMetadataRepository()
Returns the MetadataRepository which provides access to all data object metadata known to the system.
|
ReferenceLinker |
getReferenceLinker()
Gets the reference linker.
|
protected PersistenceProvider |
persistenceProviderForObject(Object object)
Gets the PersistenceProvider returned by the ProviderRegistry for the given object.
|
protected PersistenceProvider |
persistenceProviderForType(Class<?> type)
Gets the PersistenceProvider returned by the ProviderRegistry for the given type.
|
protected void |
pushOneToOneKeysToChildObjects(Object dataObject) |
protected Object |
reduceCompoundKey(Object id)
If the given id object is an instance of CompoundKey but there is only one entry in the key map, then just grab
that single value and treat it as a single id.
|
<T> T |
save(T dataObject,
PersistenceOption... options)
Saves the given data object, determining whether or not this is a new data object which is being created, or an
existing one which should be updated.
|
void |
setMetadataRepository(MetadataRepository metadataRepository)
Setter for the metadata repository.
|
void |
setProviderRegistry(ProviderRegistry providerRegistry)
Setter for the provider registry.
|
void |
setReferenceLinker(ReferenceLinker referenceLinker)
Setter for the reference linker.
|
<T> boolean |
supports(Class<T> type)
Returns whether the DataObjectService supports the given type, where
"supports" means that there is at least one PersistenceProvider that handles the given type.
|
<T> DataObjectWrapper<T> |
wrap(T dataObject)
Wraps the given data object in an accessor which provides numerous utility and helper methods related to
accessing data and attributes on the data object.
|
protected ProviderRegistry providerRegistry
protected MetadataRepository metadataRepository
protected ReferenceLinker referenceLinker
public ProviderBasedDataObjectService()
public <T> T find(Class<T> type, Object id)
CompoundKey
can be passed in order to encapsulate these into a single argument.find
in interface DataObjectService
T
- the data object class typetype
- the type of the data object to findid
- the id representing the primary key of the data object to findCompoundKey
protected Object reduceCompoundKey(Object id)
id
- the potentially CompoundKey to reducepublic <T> QueryResults<T> findMatching(Class<T> type, QueryByCriteria queryByCriteria)
findMatching
in interface DataObjectService
T
- the data object class typetype
- the type of the data objects to queryqueryByCriteria
- query object, can contain sorting and page request configurationpublic <T> QueryResults<T> findAll(Class<T> type)
findAll
in interface DataObjectService
T
- the data object class typetype
- tye type of data objects to querypublic <T> T findUnique(Class<T> type, QueryByCriteria queryByCriteria)
IncorrectResultSizeDataAccessException
will be
thrown.findUnique
in interface DataObjectService
T
- the data object class typetype
- the type of the data object to queryqueryByCriteria
- query object defining the criteria for the querypublic void delete(Object dataObject)
delete
in interface DataObjectService
dataObject
- the data object to deletepublic <T> void deleteMatching(Class<T> type, QueryByCriteria queryByCriteria)
deleteMatching
in interface DataObjectService
type
- the type of data objects to deletequeryByCriteria
- query objectpublic <T> void deleteAll(Class<T> type)
deleteAll
in interface DataObjectService
T
- the data object class type.type
- the type of data objectspublic <T> T save(T dataObject, PersistenceOption... options)
Optional persistence options can be passed to indicate whether or not linking should be performed prior to persistence. By default, linking is performed.
save
in interface DataObjectService
T
- the data object class typedataObject
- the data object to saveoptions
- the options to use when saving the data objectprotected void pushOneToOneKeysToChildObjects(Object dataObject)
public MetadataRepository getMetadataRepository()
getMetadataRepository
in interface DataObjectService
public <T> T copyInstance(T dataObject, CopyOption... options)
The method of copying is provider dependent, and will handle instances (including nested) using whatever measures might be required to deal with the quirks of said provider (e.g. fetching lazy loaded relations).
copyInstance
in interface DataObjectService
T
- the type of the data objectdataObject
- the data object to copypublic <T> DataObjectWrapper<T> wrap(T dataObject)
wrap
in interface DataObjectService
T
- the type of the data objectdataObject
- the data object to wrap, must be non-nullpublic <T> boolean supports(Class<T> type)
supports
in interface DataObjectService
type
- the data object typeprotected PersistenceProvider persistenceProviderForType(Class<?> type)
type
- the type for which to get the provider.RuntimeException
- if not PersistenceProvider handles given type.protected PersistenceProvider persistenceProviderForObject(Object object)
object
- the object for which to get the provider.RuntimeException
- if not PersistenceProvider handles given type.IllegalArgumentException
- if null object passed in.public void flush(Class<?> type)
Depending on the backend persistence implementation for the given type, this method may or may not do anything.
flush
in interface DataObjectService
type
- the type of the data object for which to perform the flush. This is primarily used to identify the
context in which to perform the flush.public void setProviderRegistry(ProviderRegistry providerRegistry)
providerRegistry
- the provider registry to set.public void setMetadataRepository(MetadataRepository metadataRepository)
metadataRepository
- the metadata repository to set.public ReferenceLinker getReferenceLinker()
public void setReferenceLinker(ReferenceLinker referenceLinker)
referenceLinker
- the reference linker to set.Copyright © 2005–2014 The Kuali Foundation. All rights reserved.