public interface DataManager
In case of RdbmsStore
, works with non-managed (new or detached) entities, always starts and commits new
transactions.
When used on the client tier - always applies security restrictions. When used on the middleware - does not apply
security restrictions by default. If you want to apply security, get secure()
instance or set the
cuba.dataManagerChecksSecurityOnMiddleware
application property to use it by default.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME |
Modifier and Type | Method and Description |
---|---|
EntitySet |
commit(CommitContext context)
Commits a collection of new or detached entity instances to the data store.
|
<E extends io.jmix.core.Entity> |
commit(E entity)
Commits the entity to the data store.
|
<E extends io.jmix.core.Entity> |
commit(E entity,
io.jmix.core.FetchPlan fetchPlan)
Commits the entity to the data store.
|
EntitySet |
commit(io.jmix.core.Entity... entities)
Commits new or detached entity instances to the data store.
|
<E extends io.jmix.core.Entity> |
commit(E entity,
java.lang.String fetchPlanName)
Commits the entity to the data store.
|
<T extends io.jmix.core.Entity> |
create(java.lang.Class<T> entityClass)
Creates a new entity instance in memory.
|
long |
getCount(LoadContext<? extends io.jmix.core.Entity> context)
Returns the number of entity instances for the given query passed in the
LoadContext . |
io.jmix.core.UnconstrainedDataManager |
getDelegate() |
<T extends io.jmix.core.Entity,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.
|
<T extends io.jmix.core.Entity,K> |
getReference(Id<T,K> entityId)
Returns an entity instance which can be used as a reference to an object which exists in the database.
|
<E extends io.jmix.core.Entity> |
load(java.lang.Class<E> entityClass)
Entry point to the fluent API for loading entities.
|
<E extends io.jmix.core.Entity,K> |
load(Id<E,K> entityId)
Entry point to the fluent API for loading entities.
|
<E extends io.jmix.core.Entity> |
load(LoadContext<E> context)
Loads a single entity instance.
|
<E extends io.jmix.core.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<io.jmix.core.entity.KeyValueEntity> |
loadValues(ValueLoadContext context)
Loads list of key-value pairs.
|
<E extends io.jmix.core.Entity> |
reload(E entity,
io.jmix.core.FetchPlan fetchPlan)
Reloads the entity instance from data store with the fetch plan specified.
|
<E extends io.jmix.core.Entity> |
reload(E entity,
io.jmix.core.FetchPlan fetchPlan,
io.jmix.core.metamodel.model.MetaClass metaClass)
Reloads the entity instance from data store with the fetch plan specified.
|
<E extends io.jmix.core.Entity> |
reload(E entity,
io.jmix.core.FetchPlan fetchPlan,
io.jmix.core.metamodel.model.MetaClass metaClass,
boolean loadDynamicAttributes)
Reloads the entity instance from data store with the fetch plan specified.
|
<E extends io.jmix.core.Entity> |
reload(E entity,
java.lang.String fetchPlanName)
Reloads the entity instance from data store with the fetch plan specified.
|
void |
remove(io.jmix.core.Entity entity)
Removes the entity instance from the data store.
|
<T extends io.jmix.core.Entity,K> |
remove(Id<T,K> entityId)
Removes the entity instance from the data store by its id.
|
DataManager |
secure()
By default, DataManager does not apply security restrictions on entity operations and attributes, only row-level
constraints take effect.
|
static final java.lang.String NAME
@Nullable <E extends io.jmix.core.Entity> E load(LoadContext<E> context)
The depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext
.
context
- LoadContext
object, defining what and how to load<E extends io.jmix.core.Entity> java.util.List<E> loadList(LoadContext<E> context)
The depth of object graphs, starting from loaded instances, defined by FetchPlan
object passed in LoadContext
.
context
- LoadContext
object, defining what and how to loadlong getCount(LoadContext<? extends io.jmix.core.Entity> context)
LoadContext
.context
- defines the query<E extends io.jmix.core.Entity> E reload(E entity, java.lang.String fetchPlanName)
entity
- reloading instancefetchPlanName
- fetch plan nameio.jmix.core.EntityAccessException
- if the entity cannot be reloaded because it was deleted or access restrictions has been changed<E extends io.jmix.core.Entity> E reload(E entity, io.jmix.core.FetchPlan fetchPlan)
entity
- reloading instancefetchPlan
- fetch plan objectio.jmix.core.EntityAccessException
- if the entity cannot be reloaded because it was deleted or access restrictions has been changed<E extends io.jmix.core.Entity> E reload(E entity, io.jmix.core.FetchPlan fetchPlan, @Nullable io.jmix.core.metamodel.model.MetaClass metaClass)
entity
- reloading instancefetchPlan
- fetch plan objectmetaClass
- desired MetaClass, if null - original entity's metaclass is usedio.jmix.core.EntityAccessException
- if the entity cannot be reloaded because it was deleted or access restrictions has been changed<E extends io.jmix.core.Entity> E reload(E entity, io.jmix.core.FetchPlan fetchPlan, @Nullable io.jmix.core.metamodel.model.MetaClass metaClass, boolean loadDynamicAttributes)
entity
- reloading instancefetchPlan
- fetch plan objectmetaClass
- desired MetaClass, if null - original entity's metaclass is usedloadDynamicAttributes
- whether to load dynamic attributes for the entityio.jmix.core.EntityAccessException
- if the entity cannot be reloaded because it was deleted or access restrictions has been changedEntitySet commit(CommitContext context)
context
- CommitContext
object, containing committing entities and other informationEntitySet commit(io.jmix.core.Entity... entities)
entities
- entities to commit<E extends io.jmix.core.Entity> E commit(E entity, @Nullable io.jmix.core.FetchPlan fetchPlan)
entity
- entity instancefetchPlan
- fetch plan object, affects the returned committed instance<E extends io.jmix.core.Entity> E commit(E entity, @Nullable java.lang.String fetchPlanName)
entity
- entity instancefetchPlanName
- fetch plan name, affects the returned committed instance<E extends io.jmix.core.Entity> E commit(E entity)
entity
- entity instancevoid remove(io.jmix.core.Entity entity)
entity
- entity instance<T extends io.jmix.core.Entity,K> void remove(Id<T,K> entityId)
entityId
- entity idjava.util.List<io.jmix.core.entity.KeyValueEntity> loadValues(ValueLoadContext context)
context
- defines a query for scalar values and a list of keys for returned KeyValueEntityDataManager secure()
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);
io.jmix.core.UnconstrainedDataManager getDelegate()
<E extends io.jmix.core.Entity> FluentLoader<E> load(java.lang.Class<E> entityClass)
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();
entityClass
- class of entity that needs to be loaded<E extends io.jmix.core.Entity,K> FluentLoader.ById<E> load(Id<E,K> entityId)
Usage example:
Customer customer = dataManager.load(customerId).fetchPlan("with-grade").one();
entityId
- Id
of entity that needs to be loadedFluentValuesLoader loadValues(java.lang.String queryString)
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();
queryString
- query string<T> FluentValueLoader<T> loadValue(java.lang.String queryString, java.lang.Class<T> valueClass)
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();
queryString
- query stringvalueClass
- type of the returning value<T extends io.jmix.core.Entity> T create(java.lang.Class<T> entityClass)
Metadata.create()
.entityClass
- entity class<T extends io.jmix.core.Entity,K> T getReference(java.lang.Class<T> entityClass, K id)
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));
entityClass
- entity classid
- id of an existing object<T extends io.jmix.core.Entity,K> T getReference(Id<T,K> entityId)
entityId
- id of an existing objectgetReference(Class, Object)