@Primary @Component(value="core_UnconstrainedDataManager") public class UnconstrainedDataManagerImpl extends java.lang.Object implements UnconstrainedDataManager
| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader> |
crossDataStoreReferenceLoaderProvider |
protected DataStoreFactory |
dataStoreFactory |
protected EntityStates |
entityStates |
protected ExtendedEntities |
extendedEntities |
protected org.springframework.beans.factory.ObjectProvider<FluentLoader> |
fluentLoaderProvider |
protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader> |
fluentValueLoaderProvider |
protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader> |
fluentValuesLoaderProvider |
protected Metadata |
metadata |
protected MetadataTools |
metadataTools |
protected CoreProperties |
properties |
static java.lang.String |
SAVE_TX_PREFIX |
protected Stores |
stores |
protected TransactionManagerLocator |
transactionManagerLocator |
protected static java.util.concurrent.atomic.AtomicLong |
txCount |
| Constructor and Description |
|---|
UnconstrainedDataManagerImpl() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
create(java.lang.Class<T> entityClass)
Creates a new entity instance in memory.
|
protected SaveContext |
createSaveContext(SaveContext context) |
protected org.springframework.transaction.TransactionDefinition |
createTransactionDefinition(boolean isJoinTransaction) |
protected java.util.List<AccessConstraint<?>> |
getAppliedConstraints() |
long |
getCount(LoadContext<?> context)
Returns the number of entity instances for the given query passed in the
LoadContext. |
long |
getCount(ValueLoadContext context)
Returns the number of records for the given query passed in the
ValueLoadContext. |
protected <E> MetaClass |
getEffectiveMetaClassFromContext(LoadContext<E> context) |
<T> T |
getReference(java.lang.Class<T> entityClass,
java.lang.Object id)
Returns an entity instance which can be used as a reference to an object which exists in the data store.
|
<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.
|
protected java.lang.String |
getStoreName(MetaClass metaClass) |
protected java.lang.String |
getStoreName(java.lang.String storeName) |
<E> FluentLoader<E> |
load(java.lang.Class<E> entityClass)
Entry point to the fluent API for loading entities.
|
<E> FluentLoader.ById<E> |
load(Id<E> entityId)
Entry point to the fluent API for loading entities.
|
<E> E |
load(LoadContext<E> context)
Loads a single entity instance.
|
<E> java.util.List<E> |
loadList(LoadContext<E> context)
Loads collection of entity instances.
|
<T> FluentValueLoader<T> |
loadValue(java.lang.String queryString,
java.lang.Class<T> valueClass)
Entry point to the fluent API for loading a single scalar value.
|
FluentValuesLoader |
loadValues(java.lang.String queryString)
Entry point to the fluent API for loading scalar values.
|
java.util.List<KeyValueEntity> |
loadValues(ValueLoadContext context)
Loads list of key-value pairs.
|
protected java.util.List<AccessConstraint<?>> |
mergeConstraints(java.util.List<AccessConstraint<?>> accessConstraints) |
protected void |
readCrossDataStoreReferences(java.util.Collection<?> entities,
FetchPlan fetchPlan,
MetaClass metaClass,
boolean joinTransaction) |
<E> void |
remove(Id<E> entityId)
Removes the entity instance from the data store by its id.
|
void |
remove(java.lang.Object... entities)
Removes the entities from their data stores.
|
<E> E |
save(E entity)
Saves the entity to its data store.
|
EntitySet |
save(java.lang.Object... entities)
Saves entities to their data stores.
|
EntitySet |
save(SaveContext context)
Saves a collection of entity instances to their data stores.
|
protected java.util.Set |
saveContextToStore(java.lang.String store,
SaveContext context) |
protected boolean |
writeCrossDataStoreReferences(java.lang.Object entity,
java.util.Collection<java.lang.Object> allEntities) |
public static final java.lang.String SAVE_TX_PREFIX
protected static final java.util.concurrent.atomic.AtomicLong txCount
@Autowired protected Metadata metadata
@Autowired protected MetadataTools metadataTools
@Autowired protected EntityStates entityStates
@Autowired protected Stores stores
@Autowired protected DataStoreFactory dataStoreFactory
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentLoader> fluentLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValueLoader> fluentValueLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<FluentValuesLoader> fluentValuesLoaderProvider
@Autowired protected org.springframework.beans.factory.ObjectProvider<CrossDataStoreReferenceLoader> crossDataStoreReferenceLoaderProvider
@Autowired protected ExtendedEntities extendedEntities
@Autowired protected CoreProperties properties
@Autowired protected TransactionManagerLocator transactionManagerLocator
@Nullable public <E> E load(LoadContext<E> context)
UnconstrainedDataManagerThe depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext.
load in interface UnconstrainedDataManagercontext - LoadContext object, defining what and how to loadpublic <E> java.util.List<E> loadList(LoadContext<E> context)
UnconstrainedDataManagerThe depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext.
loadList in interface UnconstrainedDataManagercontext - LoadContext object, defining what and how to loadpublic long getCount(LoadContext<?> context)
UnconstrainedDataManagerLoadContext.getCount in interface UnconstrainedDataManagercontext - defines the querypublic EntitySet save(java.lang.Object... entities)
UnconstrainedDataManagersave in interface UnconstrainedDataManagerentities - entities to savepublic <E> E save(E entity)
UnconstrainedDataManagersave in interface UnconstrainedDataManagerentity - entity instancepublic void remove(java.lang.Object... entities)
UnconstrainedDataManagerremove in interface UnconstrainedDataManagerentities - entity instancepublic <E> void remove(Id<E> entityId)
UnconstrainedDataManagerremove in interface UnconstrainedDataManagerentityId - entity idpublic EntitySet save(SaveContext context)
UnconstrainedDataManagersave in interface UnconstrainedDataManagercontext - SaveContext object, containing entities and other informationprotected org.springframework.transaction.TransactionDefinition createTransactionDefinition(boolean isJoinTransaction)
protected java.util.Set saveContextToStore(java.lang.String store,
SaveContext context)
public java.util.List<KeyValueEntity> loadValues(ValueLoadContext context)
UnconstrainedDataManagerloadValues in interface UnconstrainedDataManagercontext - defines a query for scalar values and a list of keys for returned KeyValueEntitypublic long getCount(ValueLoadContext context)
UnconstrainedDataManagerValueLoadContext.getCount in interface UnconstrainedDataManagercontext - defines the querypublic <E> FluentLoader<E> load(java.lang.Class<E> entityClass)
UnconstrainedDataManagerUsage examples:
Customer customer = dataManager.load(Customer.class).id(someId).one();
List<Customer> customers = dataManager.load(Customer.class)
.query("select c from sample$Customer c where c.name = :name")
.parameter("name", "Smith")
.fetchPlan("customer-fetch-plan")
.list();
load in interface UnconstrainedDataManagerentityClass - class of entity that needs to be loadedpublic <E> FluentLoader.ById<E> load(Id<E> entityId)
UnconstrainedDataManagerUsage example:
Customer customer = dataManager.load(customerId).fetchPlan("with-grade").one();
load in interface UnconstrainedDataManagerentityId - Id of entity that needs to be loadedpublic FluentValuesLoader loadValues(java.lang.String queryString)
UnconstrainedDataManagerUsage examples:
List<KeyValueEntity> customerDataList = dataManager.loadValues(
"select c.name, c.status from sample$Customer c where c.name = :n")
.properties("custName", "custStatus")
.parameter("name", "Smith")
.list();
KeyValueEntity customerData = dataManager.loadValues(
"select c.name, count(c) from sample$Customer c group by c.name")
.properties("custName", "custCount")
.one();
loadValues in interface UnconstrainedDataManagerqueryString - query stringpublic <T> FluentValueLoader<T> loadValue(java.lang.String queryString, java.lang.Class<T> valueClass)
UnconstrainedDataManager
Terminal methods of this API (list, one and optional) 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 sample$Customer c", Long.class).one();
loadValue in interface UnconstrainedDataManagerqueryString - query stringvalueClass - type of the returning valueprotected SaveContext createSaveContext(SaveContext context)
public <T> T create(java.lang.Class<T> entityClass)
UnconstrainedDataManagerMetadata.create().create in interface UnconstrainedDataManagerentityClass - entity classpublic <T> T getReference(java.lang.Class<T> entityClass,
java.lang.Object id)
UnconstrainedDataManagerFor 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));
getReference in interface UnconstrainedDataManagerentityClass - entity classid - id of an existing objectpublic <T> T getReference(Id<T> entityId)
UnconstrainedDataManagergetReference in interface UnconstrainedDataManagerentityId - id of an existing objectUnconstrainedDataManager.getReference(Class, Object)protected boolean writeCrossDataStoreReferences(java.lang.Object entity,
java.util.Collection<java.lang.Object> allEntities)
protected void readCrossDataStoreReferences(java.util.Collection<?> entities,
FetchPlan fetchPlan,
MetaClass metaClass,
boolean joinTransaction)
protected java.lang.String getStoreName(MetaClass metaClass)
protected java.lang.String getStoreName(@Nullable
java.lang.String storeName)
protected <E> MetaClass getEffectiveMetaClassFromContext(LoadContext<E> context)
protected java.util.List<AccessConstraint<?>> mergeConstraints(java.util.List<AccessConstraint<?>> accessConstraints)
protected java.util.List<AccessConstraint<?>> getAppliedConstraints()