@Component(value="cuba_TransactionalDataManager") public class TransactionalDataManagerBean extends java.lang.Object implements TransactionalDataManager
Modifier and Type | Field and Description |
---|---|
protected DataManager |
dataManager |
protected TransactionalActionFactory |
transactionalActionFactory |
protected Transactions |
transactions |
NAME
Constructor and Description |
---|
TransactionalDataManagerBean() |
Modifier and Type | Method and Description |
---|---|
TransactionalAction |
commitAction(java.util.function.Supplier<CommitContext> supplier)
Entry point to TransactionalAction API.
|
<T extends Entity> |
create(java.lang.Class<T> entityClass)
Creates a new entity instance.
|
<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.
|
<E extends Entity<K>,K> |
load(java.lang.Class<E> entityClass)
Entry point to the fluent API for loading entities.
|
<E extends Entity<K>,K> |
load(Id<E,K> entityId)
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.
|
void |
remove(Entity entity)
Removes the entity instance from the data store.
|
void |
remove(Entity entity,
boolean softDeletion)
Removes the entity instance from the data store.
|
<E extends Entity> |
save(E entity)
Saves the entity to the data store.
|
EntitySet |
save(Entity... entities)
Saves entity instances to the data store.
|
<E extends Entity> |
save(E entity,
java.lang.String viewName)
Saves the entity to the data store.
|
<E extends Entity> |
save(E entity,
View view)
Saves the entity to the data store.
|
TransactionalDataManager |
secure()
By default, DataManager does not apply security restrictions on entity operations and attributes, only row-level
constraints take effect.
|
Transactions |
transactions()
Returns an entry point to programmatic transaction control.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getReference, remove
@Inject protected DataManager dataManager
@Inject protected Transactions transactions
@Inject protected TransactionalActionFactory transactionalActionFactory
public <E extends Entity<K>,K> FluentLoader<E,K> load(java.lang.Class<E> entityClass)
TransactionalDataManager
Usage examples:
Customer customer = txDataManager.load(Customer.class).id(someId).one(); List<Customer> customers = txDataManager.load(Customer.class) .query("select c from sample$Customer c where c.name = :name") .parameter("name", "Smith") .view("customer-view") .list();
load
in interface TransactionalDataManager
entityClass
- class of entity that needs to be loadedpublic <E extends Entity<K>,K> FluentLoader.ById<E,K> load(Id<E,K> entityId)
TransactionalDataManager
Usage example:
Customer customer = txDataManager.load(customerId).view("with-grade").one();
load
in interface TransactionalDataManager
entityId
- Id
of entity that needs to be loadedpublic FluentValuesLoader loadValues(java.lang.String queryString)
TransactionalDataManager
Usage examples:
List<KeyValueEntity> customerDataList = txDataManager.loadValues( "select c.name, c.status from sample$Customer c where c.name = :n") .properties("custName", "custStatus") .parameter("name", "Smith") .list(); KeyValueEntity customerData = txDataManager.loadValues( "select c.name, count(c) from sample$Customer c group by c.name") .properties("custName", "custCount") .one();
loadValues
in interface TransactionalDataManager
queryString
- query stringpublic <T> FluentValueLoader<T> loadValue(java.lang.String queryString, java.lang.Class<T> valueClass)
TransactionalDataManager
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 = txDataManager.loadValue( "select count(c) from sample$Customer c", Long.class).one();
loadValue
in interface TransactionalDataManager
queryString
- query stringvalueClass
- type of the returning value@Nullable public <E extends Entity> E load(LoadContext<E> context)
TransactionalDataManager
load
in interface TransactionalDataManager
context
- LoadContext
object, defining what and how to loadpublic <E extends Entity> java.util.List<E> loadList(LoadContext<E> context)
TransactionalDataManager
loadList
in interface TransactionalDataManager
context
- LoadContext
object, defining what and how to loadpublic java.util.List<KeyValueEntity> loadValues(ValueLoadContext context)
TransactionalDataManager
loadValues
in interface TransactionalDataManager
context
- defines a query for scalar values and a list of keys for returned KeyValueEntitypublic EntitySet save(Entity... entities)
TransactionalDataManager
save
in interface TransactionalDataManager
entities
- entities to savepublic <E extends Entity> E save(E entity)
TransactionalDataManager
save
in interface TransactionalDataManager
entity
- entity instancepublic <E extends Entity> E save(E entity, @Nullable View view)
TransactionalDataManager
save
in interface TransactionalDataManager
entity
- entity instanceview
- view object which affects the returned instancepublic <E extends Entity> E save(E entity, @Nullable java.lang.String viewName)
TransactionalDataManager
save
in interface TransactionalDataManager
entity
- entity instanceviewName
- name of a view which affects the returned instancepublic void remove(Entity entity)
TransactionalDataManager
remove
in interface TransactionalDataManager
entity
- entity instancepublic void remove(Entity entity, boolean softDeletion)
TransactionalDataManager
remove
in interface TransactionalDataManager
entity
- entity instancesoftDeletion
- whether to use soft deletion for entities implementing SoftDelete
(true by default)public <T extends Entity> T create(java.lang.Class<T> entityClass)
TransactionalDataManager
Metadata.create()
.create
in interface TransactionalDataManager
entityClass
- entity classpublic <T extends BaseGenericIdEntity<K>,K> T getReference(java.lang.Class<T> entityClass, K id)
TransactionalDataManager
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 TransactionalDataManager
entityClass
- entity classid
- id of an existing objectpublic TransactionalDataManager secure()
TransactionalDataManager
This method returns the TransactionalDataManager
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:
txDataManager.secure().load(Customer.class).list();
secure
in interface TransactionalDataManager
public Transactions transactions()
TransactionalDataManager
Usage example:
try (Transaction tx = txDataManager.transactions().create()) { // ... tx.commit(); }
transactions
in interface TransactionalDataManager
public TransactionalAction commitAction(java.util.function.Supplier<CommitContext> supplier)
TransactionalDataManager
commitAction
in interface TransactionalDataManager
supplier
- defines how to retrieve CommitContext
TransactionalAction
without any additional
actions (onSuccess, onFail, beforeCommit, afterCompletion
) and with joinTransaction=true