Interface UnconstrainedDataManager
- All Known Subinterfaces:
DataManager
- All Known Implementing Classes:
DataManagerImpl
,UnconstrainedDataManagerImpl
Delegates to DataStore
implementations, handles references between entities from different stores.
Does not apply registered access constraints. If you want to perform CRUD operations with authorization,
use DataManager
instead.
-
Method Summary
Modifier and TypeMethodDescription<T> T
Creates a new entity instance in memory.long
getCount
(LoadContext<?> context) Returns the number of entity instances for the given query passed in theLoadContext
.long
getCount
(ValueLoadContext context) Returns the number of records for the given query passed in theValueLoadContext
.<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.<T> T
getReference
(Class<T> entityClass, Object id) Returns an entity instance which can be used as a reference to an object which exists in the data store.<E> FluentLoader.ById<E>
Entry point to the fluent API for loading entities.<E> E
load
(LoadContext<E> context) Loads a single entity instance.<E> FluentLoader<E>
Entry point to the fluent API for loading entities.<E> List<E>
loadList
(LoadContext<E> context) Loads collection of entity instances.<T> FluentValueLoader<T>
Entry point to the fluent API for loading a single scalar value.loadValues
(ValueLoadContext context) Loads list of key-value pairs.loadValues
(String queryString) Entry point to the fluent API for loading scalar values.<E> void
Removes the entity instance from the data store by its id.void
Removes the entities from their data stores.<E> E
save
(E entity) Saves the entity to its data store.save
(SaveContext context) Saves a collection of entity instances to their data stores.Saves entities to their data stores.
-
Method Details
-
load
Loads a single entity instance.The depth of object graphs, starting from loaded instances, defined by
FetchPlan
object passed inLoadContext
.- Parameters:
context
-LoadContext
object, defining what and how to load- Returns:
- the loaded object, or null if not found
-
loadList
Loads collection of entity instances.The depth of object graphs, starting from loaded instances, defined by
FetchPlan
object passed inLoadContext
.- Parameters:
context
-LoadContext
object, defining what and how to load- Returns:
- a list of entity instances, or empty list if nothing found
-
getCount
Returns the number of entity instances for the given query passed in theLoadContext
.- Parameters:
context
- defines the query- Returns:
- number of instances in the data store
-
save
Saves a collection of entity instances to their data stores.- Parameters:
context
-SaveContext
object, containing entities and other information- Returns:
- set of saved instances
-
save
Saves entities to their data stores.- Parameters:
entities
- entities to save- Returns:
- set of saved instances
-
save
<E> E save(E entity) Saves the entity to its data store.- Parameters:
entity
- entity instance- Returns:
- saved instance
-
remove
Removes the entities from their data stores.- Parameters:
entity
- entity instance
-
remove
Removes the entity instance from the data store by its id.- Parameters:
entityId
- entity id
-
loadValues
Loads list of key-value pairs.- Parameters:
context
- defines a query for scalar values and a list of keys for returned KeyValueEntity- Returns:
- list of KeyValueEntity instances
-
getCount
Returns the number of records for the given query passed in theValueLoadContext
.- Parameters:
context
- defines the query- Returns:
- number of records
-
load
Entry point to the fluent API for loading entities.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();
- Parameters:
entityClass
- class of entity that needs to be loaded
-
load
Entry point to the fluent API for loading entities.Usage example:
Customer customer = dataManager.load(customerId).fetchPlan("with-grade").one();
- Parameters:
entityId
-Id
of entity that needs to be loaded
-
loadValues
Entry point to the fluent API for loading scalar values.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();
- Parameters:
queryString
- query string
-
loadValue
Entry point to the fluent API for loading a single scalar value.Terminal methods of this API (
list
,one
andoptional
) 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();
- Parameters:
queryString
- query stringvalueClass
- type of the returning value
-
create
Creates a new entity instance in memory. This is a shortcut toMetadata.create()
.- Parameters:
entityClass
- entity class
-
getReference
Returns an entity instance which can be used as a reference to an object which exists in the data store.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));
- Parameters:
entityClass
- entity classid
- id of an existing object
-
getReference
Returns an entity instance which can be used as a reference to an object which exists in the data store.- Parameters:
entityId
- id of an existing object- See Also:
-