Class ProviderBasedDataObjectService
java.lang.Object
org.kuali.rice.krad.data.provider.impl.ProviderBasedDataObjectService
- All Implemented Interfaces:
DataObjectService
DataObjectService implementation backed by the
ProviderRegistry.- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MetadataRepositoryThe metadata repository.protected ProviderRegistryThe provider registry.protected ReferenceLinkerThe reference linker. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TcopyInstance(T dataObject, CopyOption... options) Returns a copy of the given data object instance.voidDeletes a given data object.<T> voidRemoves all records for the given data object type<T> voiddeleteMatching(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Deletes records for the given type and matching the given criteria.<T> TInvoked to retrieve a data object instance by a single primary key field or id object.<T> org.kuali.rice.core.api.criteria.QueryResults<T> Executes a query for the given data object returning all data objects for the given type.<T> org.kuali.rice.core.api.criteria.QueryResults<T> findMatching(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Executes a query for the given data object.<T> TfindUnique(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Executes a query for the data object matching the given queryByCriteria and expecting a single unique result to be returned.voidFlushes any outstanding work to the backend data store.Returns the MetadataRepository which provides access to all data object metadata known to the system.Gets the reference linker.protected PersistenceProviderpersistenceProviderForObject(Object object) Gets the PersistenceProvider returned by the ProviderRegistry for the given object.protected PersistenceProviderpersistenceProviderForType(Class<?> type) Gets the PersistenceProvider returned by the ProviderRegistry for the given type.protected voidpushOneToOneKeysToChildObjects(Object dataObject) protected ObjectIf 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> Tsave(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.voidsetMetadataRepository(MetadataRepository metadataRepository) Setter for the metadata repository.voidsetProviderRegistry(ProviderRegistry providerRegistry) Setter for the provider registry.voidsetReferenceLinker(ReferenceLinker referenceLinker) Setter for the reference linker.<T> booleanReturns 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.
-
Field Details
-
providerRegistry
The provider registry. -
metadataRepository
The metadata repository. -
referenceLinker
The reference linker.
-
-
Constructor Details
-
ProviderBasedDataObjectService
public ProviderBasedDataObjectService()
-
-
Method Details
-
find
Invoked to retrieve a data object instance by a single primary key field or id object. In the case of a compound primary key consisting of multiple attributes on the data object, aCompoundKeycan be passed in order to encapsulate these into a single argument.- Specified by:
findin interfaceDataObjectService- Type Parameters:
T- the data object class type- Parameters:
type- the type of the data object to findid- the id representing the primary key of the data object to find- Returns:
- the entity with the given primary key or null if none found
- See Also:
-
reduceCompoundKey
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.- Parameters:
id- the potentially CompoundKey to reduce- Returns:
- the single value from the CompoundKey map if the given id is a CompoundKey with a single entry, otherwise the original id that was passed in is returned
-
findMatching
public <T> org.kuali.rice.core.api.criteria.QueryResults<T> findMatching(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Executes a query for the given data object. If the given QueryByCriteria is empty or null, then all data objects for the given type will be returned. Depending on the given criteria and the implementation for the query execution, not all matching results may be returned. The QueryResults will contain information on whether or not there are additional results which can be used for paging and similar functionality.- Specified by:
findMatchingin interfaceDataObjectService- Type Parameters:
T- the data object class type- Parameters:
type- the type of the data objects to queryqueryByCriteria- query object, can contain sorting and page request configuration- Returns:
- the results of the query, will never return null but may return empty results
-
findAll
Executes a query for the given data object returning all data objects for the given type.- Specified by:
findAllin interfaceDataObjectService- Type Parameters:
T- the data object class type- Parameters:
type- tye type of data objects to query- Returns:
- the results of the query, will never return null but may return empty results.
-
findUnique
public <T> T findUnique(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Executes a query for the data object matching the given queryByCriteria and expecting a single unique result to be returned. If no results match the given criteria, then null will be returned. If the given criteria matches more than one result, then anIncorrectResultSizeDataAccessExceptionwill be thrown.- Specified by:
findUniquein interfaceDataObjectService- Type Parameters:
T- the data object class type- Parameters:
type- the type of the data object to queryqueryByCriteria- query object defining the criteria for the query- Returns:
- the single result of the query, or null if no objects were matched
-
delete
Deletes a given data object.- Specified by:
deletein interfaceDataObjectService- Parameters:
dataObject- the data object to delete
-
deleteMatching
public <T> void deleteMatching(Class<T> type, org.kuali.rice.core.api.criteria.QueryByCriteria queryByCriteria) Deletes records for the given type and matching the given criteria. If the given type is null then an IllegalArgumentException will be thrown. If the given criteria is null or empty an IllegalArgumentException is also thrown to help prevent table truncations.- Specified by:
deleteMatchingin interfaceDataObjectService- Parameters:
type- the type of data objects to deletequeryByCriteria- query object
-
deleteAll
Removes all records for the given data object type- Specified by:
deleteAllin interfaceDataObjectService- Type Parameters:
T- the data object class type.- Parameters:
type- the type of data objects
-
save
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.Optional persistence options can be passed to indicate whether or not linking should be performed prior to persistence. By default, linking is performed.
- Specified by:
savein interfaceDataObjectService- Type Parameters:
T- the data object class type- Parameters:
dataObject- the data object to saveoptions- the options to use when saving the data object- Returns:
- the saved data object, calling code should always use the reference the object returned from this method for future operations after calling the save since it could have been updated
-
pushOneToOneKeysToChildObjects
-
getMetadataRepository
Returns the MetadataRepository which provides access to all data object metadata known to the system.- Specified by:
getMetadataRepositoryin interfaceDataObjectService- Returns:
- the MetadataRepository
-
copyInstance
Returns a copy of the given data object instance.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).
- Specified by:
copyInstancein interfaceDataObjectService- Type Parameters:
T- the type of the data object- Parameters:
dataObject- the data object to copy- Returns:
- a copy of the given data object
-
wrap
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.- Specified by:
wrapin interfaceDataObjectService- Type Parameters:
T- the type of the data object- Parameters:
dataObject- the data object to wrap, must be non-null- Returns:
- an accessor which wraps the given data object and it's associated metadata and provides utility and methods useful when accessing data and attributes on the data object
-
supports
Returns whether the DataObjectService supports the given type, where "supports" means that there is at least one PersistenceProvider that handles the given type.- Specified by:
supportsin interfaceDataObjectService- Parameters:
type- the data object type- Returns:
- whether the DataObjectService supports the given type
-
persistenceProviderForType
Gets the PersistenceProvider returned by the ProviderRegistry for the given type.- Parameters:
type- the type for which to get the provider.- Returns:
- the PersistenceProvider returned by the ProviderRegistry for the given type.
- Throws:
RuntimeException- if not PersistenceProvider handles given type.
-
persistenceProviderForObject
Gets the PersistenceProvider returned by the ProviderRegistry for the given object.- Parameters:
object- the object for which to get the provider.- Returns:
- the PersistenceProvider returned by the ProviderRegistry for the given object.
- Throws:
RuntimeException- if not PersistenceProvider handles given type.IllegalArgumentException- if null object passed in.
-
flush
Flushes any outstanding work to the backend data store.Depending on the backend persistence implementation for the given type, this method may or may not do anything.
- Specified by:
flushin interfaceDataObjectService- Parameters:
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.
-
setProviderRegistry
Setter for the provider registry.- Parameters:
providerRegistry- the provider registry to set.
-
setMetadataRepository
Setter for the metadata repository.- Parameters:
metadataRepository- the metadata repository to set.
-
getReferenceLinker
Gets the reference linker.- Returns:
- the reference linker.
-
setReferenceLinker
Setter for the reference linker.- Parameters:
referenceLinker- the reference linker to set.
-