Class UnconstrainedDataManagerImpl
- All Implemented Interfaces:
UnconstrainedDataManager
- Direct Known Subclasses:
DataManagerImpl
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader>
protected DataStoreFactory
protected EntityStates
protected ExtendedEntities
protected org.springframework.beans.factory.ObjectProvider<FluentLoader>
protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader>
protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader>
protected Metadata
protected MetadataTools
protected CoreProperties
static final String
protected Stores
protected TransactionManagerLocator
protected static final AtomicLong
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
Creates a new entity instance in memory.protected SaveContext
createSaveContext
(SaveContext context) protected org.springframework.transaction.TransactionDefinition
createTransactionDefinition
(boolean isJoinTransaction) protected List<AccessConstraint<?>>
long
getCount
(LoadContext<?> context) Returns the number of entity instances for the given query passed in theLoadContext
.long
getCount
(ValueLoadContext context) Returns the number of records for the given query passed in theValueLoadContext
.protected <E> MetaClass
getEffectiveMetaClassFromContext
(LoadContext<E> context) <T> T
getReference
(Id<T> entityId) Returns an entity instance which can be used as a reference to an object which exists in the data store.<T> T
getReference
(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 String
getStoreName
(MetaClass metaClass) protected String
getStoreName
(String storeName) <E> FluentLoader.ById<E>
Entry point to the fluent API for loading entities.<E> E
load
(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 void
readCrossDataStoreReferences
(Collection<?> entities, FetchPlan fetchPlan, MetaClass metaClass, boolean joinTransaction) <E> void
Removes the entity instance from the data store by its id.void
Removes the entities from their data stores.<E> E
save
(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 Set
saveContextToStore
(String store, SaveContext context) protected boolean
writeCrossDataStoreReferences
(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:UnconstrainedDataManager
Loads a single entity instance.The depth of object graphs, starting from loaded instances, defined by
FetchPlan
object passed inLoadContext
.- Specified by:
load
in interfaceUnconstrainedDataManager
- Parameters:
context
-LoadContext
object, defining what and how to load- Returns:
- the loaded object, or null if not found
-
loadList
Description copied from interface:UnconstrainedDataManager
Loads collection of entity instances.The depth of object graphs, starting from loaded instances, defined by
FetchPlan
object passed inLoadContext
.- Specified by:
loadList
in interfaceUnconstrainedDataManager
- Parameters:
context
-LoadContext
object, defining what and how to load- Returns:
- a list of entity instances, or empty list if nothing found
-
getCount
Description copied from interface:UnconstrainedDataManager
Returns the number of entity instances for the given query passed in theLoadContext
.- Specified by:
getCount
in interfaceUnconstrainedDataManager
- Parameters:
context
- defines the query- Returns:
- number of instances in the data store
-
save
Description copied from interface:UnconstrainedDataManager
Saves entities to their data stores.- Specified by:
save
in interfaceUnconstrainedDataManager
- Parameters:
entities
- entities to save- Returns:
- set of saved instances
-
save
public <E> E save(E entity) Description copied from interface:UnconstrainedDataManager
Saves the entity to its data store.- Specified by:
save
in interfaceUnconstrainedDataManager
- Parameters:
entity
- entity instance- Returns:
- saved instance
-
remove
Description copied from interface:UnconstrainedDataManager
Removes the entities from their data stores.- Specified by:
remove
in interfaceUnconstrainedDataManager
- Parameters:
entities
- entity instance
-
remove
Description copied from interface:UnconstrainedDataManager
Removes the entity instance from the data store by its id.- Specified by:
remove
in interfaceUnconstrainedDataManager
- Parameters:
entityId
- entity id
-
save
Description copied from interface:UnconstrainedDataManager
Saves a collection of entity instances to their data stores.- Specified by:
save
in interfaceUnconstrainedDataManager
- Parameters:
context
-SaveContext
object, 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:UnconstrainedDataManager
Loads list of key-value pairs.- Specified by:
loadValues
in 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:UnconstrainedDataManager
Returns the number of records for the given query passed in theValueLoadContext
.- Specified by:
getCount
in interfaceUnconstrainedDataManager
- Parameters:
context
- defines the query- Returns:
- number of records
-
load
Description copied from interface:UnconstrainedDataManager
Entry 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:
load
in interfaceUnconstrainedDataManager
- Parameters:
entityClass
- class of the loaded entity
-
load
Description copied from interface:UnconstrainedDataManager
Entry point to the fluent API for loading entities.Usage example:
Customer customer = dataManager.load(customerId).one();
- Specified by:
load
in interfaceUnconstrainedDataManager
- Parameters:
entityId
-Id
of the loaded entity
-
loadValues
Description copied from interface:UnconstrainedDataManager
Entry 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:
loadValues
in interfaceUnconstrainedDataManager
- Parameters:
queryString
- query string
-
loadValue
Description copied from interface:UnconstrainedDataManager
Entry point to the fluent API for loading a single scalar value.Terminal methods of this API (
list
,one
andoptional
) 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:
loadValue
in interfaceUnconstrainedDataManager
- Parameters:
queryString
- query stringvalueClass
- type of the returning value
-
createSaveContext
-
create
Description copied from interface:UnconstrainedDataManager
Creates a new entity instance in memory. This is a shortcut toMetadata.create()
.- Specified by:
create
in interfaceUnconstrainedDataManager
- Parameters:
entityClass
- entity class
-
getReference
Description copied from interface:UnconstrainedDataManager
Returns 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:
getReference
in interfaceUnconstrainedDataManager
- Parameters:
entityClass
- entity classid
- id of an existing object
-
getReference
Description copied from interface:UnconstrainedDataManager
Returns an entity instance which can be used as a reference to an object which exists in the data store.- Specified by:
getReference
in 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
-