@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)
UnconstrainedDataManager
The depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext
.
load
in interface UnconstrainedDataManager
context
- LoadContext
object, defining what and how to loadpublic <E> java.util.List<E> loadList(LoadContext<E> context)
UnconstrainedDataManager
The depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext
.
loadList
in interface UnconstrainedDataManager
context
- LoadContext
object, defining what and how to loadpublic long getCount(LoadContext<?> context)
UnconstrainedDataManager
LoadContext
.getCount
in interface UnconstrainedDataManager
context
- defines the querypublic EntitySet save(java.lang.Object... entities)
UnconstrainedDataManager
save
in interface UnconstrainedDataManager
entities
- entities to savepublic <E> E save(E entity)
UnconstrainedDataManager
save
in interface UnconstrainedDataManager
entity
- entity instancepublic void remove(java.lang.Object... entities)
UnconstrainedDataManager
remove
in interface UnconstrainedDataManager
entities
- entity instancepublic <E> void remove(Id<E> entityId)
UnconstrainedDataManager
remove
in interface UnconstrainedDataManager
entityId
- entity idpublic EntitySet save(SaveContext context)
UnconstrainedDataManager
save
in interface UnconstrainedDataManager
context
- 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)
UnconstrainedDataManager
loadValues
in interface UnconstrainedDataManager
context
- defines a query for scalar values and a list of keys for returned KeyValueEntitypublic long getCount(ValueLoadContext context)
UnconstrainedDataManager
ValueLoadContext
.getCount
in interface UnconstrainedDataManager
context
- defines the querypublic <E> FluentLoader<E> load(java.lang.Class<E> entityClass)
UnconstrainedDataManager
Usage 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 UnconstrainedDataManager
entityClass
- class of entity that needs to be loadedpublic <E> FluentLoader.ById<E> load(Id<E> entityId)
UnconstrainedDataManager
Usage example:
Customer customer = dataManager.load(customerId).fetchPlan("with-grade").one();
load
in interface UnconstrainedDataManager
entityId
- Id
of entity that needs to be loadedpublic FluentValuesLoader loadValues(java.lang.String queryString)
UnconstrainedDataManager
Usage 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 UnconstrainedDataManager
queryString
- 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 UnconstrainedDataManager
queryString
- query stringvalueClass
- type of the returning valueprotected SaveContext createSaveContext(SaveContext context)
public <T> T create(java.lang.Class<T> entityClass)
UnconstrainedDataManager
Metadata.create()
.create
in interface UnconstrainedDataManager
entityClass
- entity classpublic <T> T getReference(java.lang.Class<T> entityClass, java.lang.Object id)
UnconstrainedDataManager
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));
getReference
in interface UnconstrainedDataManager
entityClass
- entity classid
- id of an existing objectpublic <T> T getReference(Id<T> entityId)
UnconstrainedDataManager
getReference
in interface UnconstrainedDataManager
entityId
- 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()