@Component(value="cuba_DataManager") public class DataManagerBean extends java.lang.Object implements DataManager
Modifier and Type | Field and Description |
---|---|
protected EntityLogAPI |
entityLog |
protected EntityStates |
entityStates |
protected Metadata |
metadata |
protected MetadataTools |
metadataTools |
protected ServerConfig |
serverConfig |
protected StoreFactory |
storeFactory |
NAME
Constructor and Description |
---|
DataManagerBean() |
Modifier and Type | Method and Description |
---|---|
protected void |
adjustState(Entity committedEntity) |
EntitySet |
commit(CommitContext context)
Commits a collection of new or detached entity instances to the data store.
|
<E extends Entity> |
commit(E entity)
Commits the entity to the data store.
|
EntitySet |
commit(Entity... entities)
Commits new or detached entity instances to the data store.
|
<E extends Entity> |
commit(E entity,
java.lang.String viewName)
Commits the entity to the data store.
|
<E extends Entity> |
commit(E entity,
View view)
Commits the entity to the data store.
|
<T> T |
create(java.lang.Class<T> entityClass)
Creates a new entity instance in memory.
|
protected CommitContext |
createCommitContext(CommitContext context) |
protected boolean |
entityHasDynamicAttributes(Entity entity) |
long |
getCount(LoadContext<? extends Entity> context)
Returns the number of entity instances for the given query passed in the
LoadContext . |
<T extends BaseGenericIdEntity<K>,K> |
getReference(java.lang.Class<T> entityClass,
K id)
Returns an entity instance which can be used as a reference to an object which exists in the database.
|
protected java.lang.String |
getStoreName(com.haulmont.chile.core.model.MetaClass metaClass) |
protected java.lang.String |
getStoreName(java.lang.String storeName) |
<E extends Entity<K>,K> |
load(java.lang.Class<E> entityClass)
Entry point to the fluent API for loading entities.
|
<E extends Entity> |
load(LoadContext<E> context)
Loads a single entity instance.
|
<E extends Entity> |
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 void |
readCrossDataStoreReferences(java.util.Collection<? extends Entity> entities,
View view,
com.haulmont.chile.core.model.MetaClass metaClass,
boolean joinTransaction) |
<E extends Entity> |
reload(E entity,
java.lang.String viewName)
Reloads the entity instance from data store with the view specified.
|
<E extends Entity> |
reload(E entity,
View view)
Reloads the entity instance from data store with the view specified.
|
<E extends Entity> |
reload(E entity,
View view,
com.haulmont.chile.core.model.MetaClass metaClass)
Reloads the entity instance from data store with the view specified.
|
<E extends Entity> |
reload(E entity,
View view,
com.haulmont.chile.core.model.MetaClass metaClass,
boolean loadDynamicAttributes)
Reloads the entity instance from data store with the view specified.
|
void |
remove(Entity entity)
Removes the entity instance from the data store.
|
DataManager |
secure()
By default, DataManager does not apply security restrictions on entity operations and attributes, only row-level
constraints take effect.
|
protected boolean |
writeCrossDataStoreReferences(Entity entity,
java.util.Collection<Entity> allEntities) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
load
@Inject protected Metadata metadata
@Inject protected MetadataTools metadataTools
@Inject protected EntityStates entityStates
@Inject protected ServerConfig serverConfig
@Inject protected StoreFactory storeFactory
@Inject protected EntityLogAPI entityLog
@Nullable public <E extends Entity> E load(LoadContext<E> context)
DataManager
The depth of object graphs, starting from loaded instances, defined by View
object passed in LoadContext
.
load
in interface DataManager
context
- LoadContext
object, defining what and how to loadpublic <E extends Entity> java.util.List<E> loadList(LoadContext<E> context)
DataManager
The depth of object graphs, starting from loaded instances, defined by View
object passed in LoadContext
.
loadList
in interface DataManager
context
- LoadContext
object, defining what and how to loadpublic long getCount(LoadContext<? extends Entity> context)
DataManager
LoadContext
.getCount
in interface DataManager
context
- defines the querypublic <E extends Entity> E reload(E entity, java.lang.String viewName)
DataManager
reload
in interface DataManager
entity
- reloading instanceviewName
- view namepublic <E extends Entity> E reload(E entity, View view)
DataManager
reload
in interface DataManager
entity
- reloading instanceview
- view objectpublic <E extends Entity> E reload(E entity, View view, @Nullable com.haulmont.chile.core.model.MetaClass metaClass)
DataManager
reload
in interface DataManager
entity
- reloading instanceview
- view objectmetaClass
- desired MetaClass, if null - original entity's metaclass is usedpublic <E extends Entity> E reload(E entity, View view, @Nullable com.haulmont.chile.core.model.MetaClass metaClass, boolean loadDynamicAttributes)
DataManager
reload
in interface DataManager
entity
- reloading instanceview
- view objectmetaClass
- desired MetaClass, if null - original entity's metaclass is usedloadDynamicAttributes
- whether to load dynamic attributes for the entitypublic EntitySet commit(CommitContext context)
DataManager
commit
in interface DataManager
context
- CommitContext
object, containing committing entities and other informationprotected void adjustState(Entity committedEntity)
public EntitySet commit(Entity... entities)
DataManager
commit
in interface DataManager
entities
- entities to commitpublic <E extends Entity> E commit(E entity, @Nullable View view)
DataManager
commit
in interface DataManager
entity
- entity instanceview
- view object, affects the returned committed instancepublic <E extends Entity> E commit(E entity, @Nullable java.lang.String viewName)
DataManager
commit
in interface DataManager
entity
- entity instanceviewName
- view name, affects the returned committed instancepublic <E extends Entity> E commit(E entity)
DataManager
commit
in interface DataManager
entity
- entity instancepublic void remove(Entity entity)
DataManager
remove
in interface DataManager
entity
- entity instancepublic java.util.List<KeyValueEntity> loadValues(ValueLoadContext context)
DataManager
loadValues
in interface DataManager
context
- defines a query for scalar values and a list of keys for returned KeyValueEntityprotected boolean entityHasDynamicAttributes(Entity entity)
protected CommitContext createCommitContext(CommitContext context)
public DataManager secure()
DataManager
This method returns the DataManager
implementation that applies security restrictions on entity operations.
Attribute permissions will be enforced only if you additionally set the cuba.entityAttributePermissionChecking
application property to true.
Usage example:
AppBeans.get(DataManager.class).secure().load(context);
secure
in interface DataManager
public <E extends Entity<K>,K> FluentLoader<E,K> load(java.lang.Class<E> entityClass)
DataManager
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") .view("customer-view") .list();
load
in interface DataManager
entityClass
- class of entity that needs to be loadedpublic FluentValuesLoader loadValues(java.lang.String queryString)
DataManager
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 DataManager
queryString
- query stringpublic <T> FluentValueLoader<T> loadValue(java.lang.String queryString, java.lang.Class<T> valueClass)
DataManager
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 DataManager
queryString
- query stringvalueClass
- type of the returning valuepublic <T> T create(java.lang.Class<T> entityClass)
DataManager
Metadata.create()
.create
in interface DataManager
entityClass
- entity classpublic <T extends BaseGenericIdEntity<K>,K> T getReference(java.lang.Class<T> entityClass, K id)
DataManager
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 DataManager
entityClass
- entity classid
- id of an existing objectprotected boolean writeCrossDataStoreReferences(Entity entity, java.util.Collection<Entity> allEntities)
protected void readCrossDataStoreReferences(java.util.Collection<? extends Entity> entities, View view, com.haulmont.chile.core.model.MetaClass metaClass, boolean joinTransaction)
protected java.lang.String getStoreName(com.haulmont.chile.core.model.MetaClass metaClass)
protected java.lang.String getStoreName(@Nullable java.lang.String storeName)