Class ProviderBasedDataObjectService

java.lang.Object
org.kuali.rice.krad.data.provider.impl.ProviderBasedDataObjectService
All Implemented Interfaces:
DataObjectService

public class ProviderBasedDataObjectService extends Object implements DataObjectService
DataObjectService implementation backed by the ProviderRegistry.
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Details

    • providerRegistry

      protected ProviderRegistry providerRegistry
      The provider registry.
    • metadataRepository

      protected MetadataRepository metadataRepository
      The metadata repository.
    • referenceLinker

      protected ReferenceLinker referenceLinker
      The reference linker.
  • Constructor Details

    • ProviderBasedDataObjectService

      public ProviderBasedDataObjectService()
  • Method Details

    • find

      public <T> T find(Class<T> type, Object id)
      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, a CompoundKey can be passed in order to encapsulate these into a single argument.
      Specified by:
      find in interface DataObjectService
      Type Parameters:
      T - the data object class type
      Parameters:
      type - the type of the data object to find
      id - 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

      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.
      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:
      findMatching in interface DataObjectService
      Type Parameters:
      T - the data object class type
      Parameters:
      type - the type of the data objects to query
      queryByCriteria - 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

      public <T> org.kuali.rice.core.api.criteria.QueryResults<T> findAll(Class<T> type)
      Executes a query for the given data object returning all data objects for the given type.
      Specified by:
      findAll in interface DataObjectService
      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 an IncorrectResultSizeDataAccessException will be thrown.
      Specified by:
      findUnique in interface DataObjectService
      Type Parameters:
      T - the data object class type
      Parameters:
      type - the type of the data object to query
      queryByCriteria - query object defining the criteria for the query
      Returns:
      the single result of the query, or null if no objects were matched
    • delete

      public void delete(Object dataObject)
      Deletes a given data object.
      Specified by:
      delete in interface DataObjectService
      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:
      deleteMatching in interface DataObjectService
      Parameters:
      type - the type of data objects to delete
      queryByCriteria - query object
    • deleteAll

      public <T> void deleteAll(Class<T> type)
      Removes all records for the given data object type
      Specified by:
      deleteAll in interface DataObjectService
      Type Parameters:
      T - the data object class type.
      Parameters:
      type - the type of data objects
    • save

      public <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.

      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:
      save in interface DataObjectService
      Type Parameters:
      T - the data object class type
      Parameters:
      dataObject - the data object to save
      options - 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

      protected void pushOneToOneKeysToChildObjects(Object dataObject)
    • getMetadataRepository

      public MetadataRepository getMetadataRepository()
      Returns the MetadataRepository which provides access to all data object metadata known to the system.
      Specified by:
      getMetadataRepository in interface DataObjectService
      Returns:
      the MetadataRepository
    • copyInstance

      public <T> T copyInstance(T dataObject, CopyOption... options)
      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:
      copyInstance in interface DataObjectService
      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

      public <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.
      Specified by:
      wrap in interface DataObjectService
      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

      public <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.
      Specified by:
      supports in interface DataObjectService
      Parameters:
      type - the data object type
      Returns:
      whether the DataObjectService supports the given type
    • persistenceProviderForType

      protected PersistenceProvider persistenceProviderForType(Class<?> type)
      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

      protected PersistenceProvider persistenceProviderForObject(Object object)
      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

      public void flush(Class<?> type)
      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:
      flush in interface DataObjectService
      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

      public void setProviderRegistry(ProviderRegistry providerRegistry)
      Setter for the provider registry.
      Parameters:
      providerRegistry - the provider registry to set.
    • setMetadataRepository

      public void setMetadataRepository(MetadataRepository metadataRepository)
      Setter for the metadata repository.
      Parameters:
      metadataRepository - the metadata repository to set.
    • getReferenceLinker

      public ReferenceLinker getReferenceLinker()
      Gets the reference linker.
      Returns:
      the reference linker.
    • setReferenceLinker

      public void setReferenceLinker(ReferenceLinker referenceLinker)
      Setter for the reference linker.
      Parameters:
      referenceLinker - the reference linker to set.