Class UnconstrainedDataManagerImpl
- All Implemented Interfaces:
UnconstrainedDataManager
- Direct Known Subclasses:
DataManagerImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader>protected DataStoreFactoryprotected EntityStatesprotected ExtendedEntitiesprotected org.springframework.beans.factory.ObjectProvider<FluentLoader>protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader>protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader>protected Metadataprotected MetadataToolsprotected CorePropertiesstatic final Stringprotected Storesprotected TransactionManagerLocatorprotected static final AtomicLong -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TCreates a new entity instance in memory.protected SaveContextcreateSaveContext(SaveContext context) protected org.springframework.transaction.TransactionDefinitioncreateTransactionDefinition(boolean isJoinTransaction) protected List<AccessConstraint<?>>longgetCount(LoadContext<?> context) Returns the number of entity instances for the given query passed in theLoadContext.longgetCount(ValueLoadContext context) Returns the number of records for the given query passed in theValueLoadContext.protected <E> MetaClassgetEffectiveMetaClassFromContext(LoadContext<E> context) <T> TgetReference(Id<T> entityId) Returns an entity instance which can be used as a reference to an object which exists in the data store.<T> TgetReference(Class<T> entityClass, Object id) Returns an entity instance which can be used as a reference to an object which exists in the data store.protected StringgetStoreName(MetaClass metaClass) protected StringgetStoreName(String storeName) <E> FluentLoader.ById<E>Entry point to the fluent API for loading entities.<E> Eload(LoadContext<E> context) Loads a single entity instance.<E> FluentLoader<E>Entry point to the fluent API for loading entities.<E> List<E>loadList(LoadContext<E> context) Loads collection of entity instances.<T> FluentValueLoader<T>Entry point to the fluent API for loading a single scalar value.loadValues(ValueLoadContext context) Loads list of key-value pairs.loadValues(String queryString) Entry point to the fluent API for loading scalar values.protected List<AccessConstraint<?>>mergeConstraints(List<AccessConstraint<?>> accessConstraints) protected voidreadCrossDataStoreReferences(Collection<?> entities, FetchPlan fetchPlan, MetaClass metaClass, boolean joinTransaction) <E> voidRemoves the entity instance from the data store by its id.voidRemoves the entities from their data stores.<E> Esave(E entity) Saves the entity to its data store.save(SaveContext context) Saves a collection of entity instances to their data stores.Saves entities to their data stores.protected SetsaveContextToStore(String store, SaveContext context) protected booleanwriteCrossDataStoreReferences(Object entity, Collection<Object> allEntities)
-
Field Details
-
SAVE_TX_PREFIX
- See Also:
-
txCount
-
metadata
-
metadataTools
-
entityStates
-
stores
-
dataStoreFactory
-
fluentLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentLoader> fluentLoaderProvider -
fluentValueLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader> fluentValueLoaderProvider -
fluentValuesLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader> fluentValuesLoaderProvider -
crossDataStoreReferenceLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader> crossDataStoreReferenceLoaderProvider -
extendedEntities
-
properties
-
transactionManagerLocator
-
-
Constructor Details
-
UnconstrainedDataManagerImpl
public UnconstrainedDataManagerImpl()
-
-
Method Details
-
load
Description copied from interface:UnconstrainedDataManagerLoads a single entity instance.The depth of object graphs, starting from loaded instances, defined by
FetchPlanobject passed inLoadContext.- Specified by:
loadin interfaceUnconstrainedDataManager- Parameters:
context-LoadContextobject, defining what and how to load- Returns:
- the loaded object, or null if not found
-
loadList
Description copied from interface:UnconstrainedDataManagerLoads collection of entity instances.The depth of object graphs, starting from loaded instances, defined by
FetchPlanobject passed inLoadContext.- Specified by:
loadListin interfaceUnconstrainedDataManager- Parameters:
context-LoadContextobject, defining what and how to load- Returns:
- a list of entity instances, or empty list if nothing found
-
getCount
Description copied from interface:UnconstrainedDataManagerReturns the number of entity instances for the given query passed in theLoadContext.- Specified by:
getCountin interfaceUnconstrainedDataManager- Parameters:
context- defines the query- Returns:
- number of instances in the data store
-
save
Description copied from interface:UnconstrainedDataManagerSaves entities to their data stores.- Specified by:
savein interfaceUnconstrainedDataManager- Parameters:
entities- entities to save- Returns:
- set of saved instances
-
save
public <E> E save(E entity) Description copied from interface:UnconstrainedDataManagerSaves the entity to its data store.- Specified by:
savein interfaceUnconstrainedDataManager- Parameters:
entity- entity instance- Returns:
- saved instance
-
remove
Description copied from interface:UnconstrainedDataManagerRemoves the entities from their data stores.- Specified by:
removein interfaceUnconstrainedDataManager- Parameters:
entities- entity instance
-
remove
Description copied from interface:UnconstrainedDataManagerRemoves the entity instance from the data store by its id.- Specified by:
removein interfaceUnconstrainedDataManager- Parameters:
entityId- entity id
-
save
Description copied from interface:UnconstrainedDataManagerSaves a collection of entity instances to their data stores.- Specified by:
savein interfaceUnconstrainedDataManager- Parameters:
context-SaveContextobject, containing entities and other information- Returns:
- set of saved instances
-
createTransactionDefinition
protected org.springframework.transaction.TransactionDefinition createTransactionDefinition(boolean isJoinTransaction) -
saveContextToStore
-
loadValues
Description copied from interface:UnconstrainedDataManagerLoads list of key-value pairs.- Specified by:
loadValuesin interfaceUnconstrainedDataManager- Parameters:
context- defines a query for scalar values and a list of keys for returned KeyValueEntity- Returns:
- list of KeyValueEntity instances
-
getCount
Description copied from interface:UnconstrainedDataManagerReturns the number of records for the given query passed in theValueLoadContext.- Specified by:
getCountin interfaceUnconstrainedDataManager- Parameters:
context- defines the query- Returns:
- number of records
-
load
Description copied from interface:UnconstrainedDataManagerEntry point to the fluent API for loading entities.Usage examples:
Customer customer = dataManager.load(Customer.class).id(someId).one(); List<Customer> customers = dataManager.load(Customer.class) .query("select c from Customer c where c.name = :name") .parameter("name", "Smith") .maxResults(100) .list();- Specified by:
loadin interfaceUnconstrainedDataManager- Parameters:
entityClass- class of the loaded entity
-
load
Description copied from interface:UnconstrainedDataManagerEntry point to the fluent API for loading entities.Usage example:
Customer customer = dataManager.load(customerId).one();
- Specified by:
loadin interfaceUnconstrainedDataManager- Parameters:
entityId-Idof the loaded entity
-
loadValues
Description copied from interface:UnconstrainedDataManagerEntry point to the fluent API for loading scalar values.Usage examples:
List<KeyValueEntity> customerDataList = dataManager.loadValues( "select c.name, c.status from Customer c where c.name = :n") .properties("custName", "custStatus") .parameter("name", "Smith") .list(); KeyValueEntity customerData = dataManager.loadValues( "select c.name, count(c) from Customer c group by c.name") .properties("custName", "custCount") .one();- Specified by:
loadValuesin interfaceUnconstrainedDataManager- Parameters:
queryString- query string
-
loadValue
Description copied from interface:UnconstrainedDataManagerEntry point to the fluent API for loading a single scalar value.Terminal methods of this API (
list,oneandoptional) return a single value from the first column of the query result set. You should provide the expected type of this value in the second parameter. Number types will be converted appropriately, so for example if the query returns Long and you expected Integer, the returned value will be automatically converted from Long to Integer.Usage examples:
Long customerCount = dataManager.loadValue( "select count(c) from Customer c", Long.class).one();- Specified by:
loadValuein interfaceUnconstrainedDataManager- Parameters:
queryString- query stringvalueClass- type of the returning value
-
createSaveContext
-
create
Description copied from interface:UnconstrainedDataManagerCreates a new entity instance in memory. This is a shortcut toMetadata.create().- Specified by:
createin interfaceUnconstrainedDataManager- Parameters:
entityClass- entity class
-
getReference
Description copied from interface:UnconstrainedDataManagerReturns an entity instance which can be used as a reference to an object which exists in the data store.For example, if you are creating a User, you have to set a Group the user belongs to. If you know the group id, you could load it from the database and set to the user. This method saves you from unneeded database round trip:
user.setGroup(dataManager.getReference(Group.class, groupId)); dataManager.commit(user);
A reference can also be used to delete an existing object by id:dataManager.remove(dataManager.getReference(Customer.class, customerId));
- Specified by:
getReferencein interfaceUnconstrainedDataManager- Parameters:
entityClass- entity classid- id of an existing object
-
getReference
Description copied from interface:UnconstrainedDataManagerReturns an entity instance which can be used as a reference to an object which exists in the data store.- Specified by:
getReferencein interfaceUnconstrainedDataManager- Parameters:
entityId- id of an existing object- See Also:
-
writeCrossDataStoreReferences
-
readCrossDataStoreReferences
protected void readCrossDataStoreReferences(Collection<?> entities, FetchPlan fetchPlan, MetaClass metaClass, boolean joinTransaction) -
getStoreName
-
getStoreName
-
getEffectiveMetaClassFromContext
-
mergeConstraints
-
getAppliedConstraints
-