@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, waitgetReference, 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)
TransactionalDataManagerUsage 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 TransactionalDataManagerentityClass - class of entity that needs to be loadedpublic <E extends Entity<K>,K> FluentLoader.ById<E,K> load(Id<E,K> entityId)
TransactionalDataManagerUsage example:
Customer customer = txDataManager.load(customerId).view("with-grade").one();
load in interface TransactionalDataManagerentityId - Id of entity that needs to be loadedpublic FluentValuesLoader loadValues(java.lang.String queryString)
TransactionalDataManagerUsage 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 TransactionalDataManagerqueryString - 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 TransactionalDataManagerqueryString - query stringvalueClass - type of the returning value@Nullable public <E extends Entity> E load(LoadContext<E> context)
TransactionalDataManagerload in interface TransactionalDataManagercontext - LoadContext object, defining what and how to loadpublic <E extends Entity> java.util.List<E> loadList(LoadContext<E> context)
TransactionalDataManagerloadList in interface TransactionalDataManagercontext - LoadContext object, defining what and how to loadpublic java.util.List<KeyValueEntity> loadValues(ValueLoadContext context)
TransactionalDataManagerloadValues in interface TransactionalDataManagercontext - defines a query for scalar values and a list of keys for returned KeyValueEntitypublic EntitySet save(Entity... entities)
TransactionalDataManagersave in interface TransactionalDataManagerentities - entities to savepublic <E extends Entity> E save(E entity)
TransactionalDataManagersave in interface TransactionalDataManagerentity - entity instancepublic <E extends Entity> E save(E entity, @Nullable View view)
TransactionalDataManagersave in interface TransactionalDataManagerentity - entity instanceview - view object which affects the returned instancepublic <E extends Entity> E save(E entity, @Nullable java.lang.String viewName)
TransactionalDataManagersave in interface TransactionalDataManagerentity - entity instanceviewName - name of a view which affects the returned instancepublic void remove(Entity entity)
TransactionalDataManagerremove in interface TransactionalDataManagerentity - entity instancepublic void remove(Entity entity, boolean softDeletion)
TransactionalDataManagerremove in interface TransactionalDataManagerentity - 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)
TransactionalDataManagerMetadata.create().create in interface TransactionalDataManagerentityClass - entity classpublic <T extends BaseGenericIdEntity<K>,K> T getReference(java.lang.Class<T> entityClass, K id)
TransactionalDataManagerFor 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 TransactionalDataManagerentityClass - 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 TransactionalDataManagerpublic Transactions transactions()
TransactionalDataManagerUsage example:
try (Transaction tx = txDataManager.transactions().create()) {
// ...
tx.commit();
}
transactions in interface TransactionalDataManagerpublic TransactionalAction commitAction(java.util.function.Supplier<CommitContext> supplier)
TransactionalDataManagercommitAction in interface TransactionalDataManagersupplier - defines how to retrieve CommitContextTransactionalAction without any additional
actions (onSuccess, onFail, beforeCommit, afterCompletion) and with joinTransaction=true