T
- base class or interface to restrict all entities that are stored to (e.g.
Object
or Serializable
for instance.@ParametersAreNonnullByDefault public class EntityDataStore<T> extends Object implements BlockingEntityStore<T>
BlockingEntityStore
that persists and makes queryable
Entity
instances through standard JDBC database connections.Constructor and Description |
---|
EntityDataStore(Configuration configuration)
Creates a new
EntityDataStore with the given configuration. |
EntityDataStore(DataSource dataSource,
EntityModel model)
|
EntityDataStore(DataSource dataSource,
EntityModel model,
Mapping mapping)
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkClosed() |
protected void |
checkConnectionMetadata() |
void |
close()
Close the entity store.
|
protected io.requery.sql.EntityContext<T> |
context() |
<E extends T> |
count(Class<E> type)
Initiates a query to count the number of entities of a given type.
|
Selection<? extends Scalar<Integer>> |
count(QueryAttribute<?,?>... attributes)
Initiates a query to count a given selection.
|
Deletion<? extends Scalar<Integer>> |
delete()
Initiates a delete query against this data store.
|
<E extends T> |
delete(Class<E> type)
Initiates an delete query for a type.
|
<E extends T> |
delete(E entity)
Deletes the given entity from the store.
|
<E extends T> |
delete(Iterable<E> entities)
Deletes multiple entities.
|
<E extends T,K> |
findByKey(Class<E> type,
K key)
Find an entity by the given key.
|
<E extends T> |
insert(Class<E> type)
Initiates an insert operation for a type.
|
<E extends T> |
insert(E entity)
Inserts the given entity.
|
<K,E extends T> |
insert(E entity,
Class<K> keyClass)
Inserts the given entity returning the generated key after the entity is inserted.
|
<E extends T> |
insert(Iterable<E> entities)
Insert a collection of entities.
|
<K,E extends T> |
insert(Iterable<E> entities,
Class<K> keyClass)
Insert a collection of entities returning the generated keys for the inserted entities in
the order they were inserted.
|
<E extends T> |
raw(Class<E> type,
String query,
Object... parameters)
Executes a raw query against the data store mapping on to a specific entity type.
|
Result<Tuple> |
raw(String query,
Object... parameters)
Executes a raw query against the data store.
|
<E extends T> |
refresh(E entity)
Refresh the given entity.
|
<E extends T> |
refresh(E entity,
Attribute<?,?>... attributes)
Refresh the given entity on specific attributes.
|
<E extends T> |
refresh(Iterable<E> entities,
Attribute<?,?>... attributes)
Refresh the given entities on specific attributes.
|
<E extends T> |
refreshAll(E entity)
Refresh the given entity on all of its attributes including relational ones.
|
<V> V |
runInTransaction(Callable<V> callable)
Runs the given callable in a transaction.
|
<V> V |
runInTransaction(Callable<V> callable,
TransactionIsolation isolation)
Runs the given callable in a transaction.
|
<E extends T> |
select(Class<E> type,
QueryAttribute<?,?>... attributes)
Initiates a query against a set of expression values return a specific entity type in a
Result . |
<E extends T> |
select(Class<E> type,
Set<? extends QueryAttribute<E,?>> attributes)
Initiates a query against a set of expression values return a specific entity type in a
Result . |
Selection<? extends Result<Tuple>> |
select(Expression<?>... expressions)
Initiates a query against a set of expression values.
|
Selection<? extends Result<Tuple>> |
select(Set<? extends Expression<?>> expressions)
Initiates a query against a set of expression values.
|
BlockingEntityStore<T> |
toBlocking() |
Transaction |
transaction() |
Update<? extends Scalar<Integer>> |
update()
Initiates an update query against this data store.
|
<E extends T> |
update(Class<E> type)
Initiates an update query for a type.
|
<E extends T> |
update(E entity)
Update the given entity.
|
<E extends T> |
update(E entity,
Attribute<?,?>... attributes)
Update specific attributes of entity regardless of any modification state.
|
<E extends T> |
update(Iterable<E> entities)
Updates a collection of entities.
|
<E extends T> |
upsert(E entity)
Upserts (insert or update) the given entity.
|
<E extends T> |
upsert(Iterable<E> entities)
Upserts (inserts or updates) a collection of entities.
|
public EntityDataStore(DataSource dataSource, EntityModel model)
dataSource
- to usemodel
- to usepublic EntityDataStore(DataSource dataSource, EntityModel model, @Nullable Mapping mapping)
dataSource
- to usemodel
- to usemapping
- to usepublic EntityDataStore(Configuration configuration)
EntityDataStore
with the given configuration.configuration
- to usepublic <E extends T> E insert(E entity)
EntityStore
PersistenceException
may be thrown.insert
in interface BlockingEntityStore<T>
insert
in interface EntityStore<T,Object>
E
- entity typeentity
- non null entity to insertpublic <K,E extends T> K insert(E entity, @Nullable Class<K> keyClass)
EntityStore
PersistenceException
may be thrown.insert
in interface BlockingEntityStore<T>
insert
in interface EntityStore<T,Object>
K
- key typeE
- entity typeentity
- non null entity to insertkeyClass
- key classpublic <E extends T> Iterable<E> insert(Iterable<E> entities)
EntityStore
insert
in interface BlockingEntityStore<T>
insert
in interface EntityStore<T,Object>
E
- entity typeentities
- to insertpublic <K,E extends T> Iterable<K> insert(Iterable<E> entities, @Nullable Class<K> keyClass)
EntityStore
insert
in interface BlockingEntityStore<T>
insert
in interface EntityStore<T,Object>
K
- key typeE
- entity typeentities
- to insertkeyClass
- key classpublic <E extends T> E update(E entity)
EntityStore
update
in interface BlockingEntityStore<T>
update
in interface EntityStore<T,Object>
E
- entity typeentity
- to updatepublic <E extends T> E update(E entity, Attribute<?,?>... attributes)
EntityStore
update
in interface BlockingEntityStore<T>
update
in interface EntityStore<T,Object>
E
- entity typeentity
- to refreshattributes
- attributes to update, attributes should be of type Epublic <E extends T> Iterable<E> update(Iterable<E> entities)
EntityStore
update
in interface BlockingEntityStore<T>
update
in interface EntityStore<T,Object>
E
- entity typeentities
- to updatepublic <E extends T> E upsert(E entity)
EntityStore
upsert
in interface BlockingEntityStore<T>
upsert
in interface EntityStore<T,Object>
E
- entity typeentity
- non null entity to insertpublic <E extends T> Iterable<E> upsert(Iterable<E> entities)
EntityStore
upsert
in interface BlockingEntityStore<T>
upsert
in interface EntityStore<T,Object>
E
- entity typeentities
- to updatepublic <E extends T> E refresh(E entity)
EntityStore
refresh
in interface BlockingEntityStore<T>
refresh
in interface EntityStore<T,Object>
E
- entity typeentity
- to insertpublic <E extends T> E refresh(E entity, Attribute<?,?>... attributes)
EntityStore
refresh
in interface BlockingEntityStore<T>
refresh
in interface EntityStore<T,Object>
E
- entity typeentity
- to refreshattributes
- attributes to refresh, attributes should be of type E
(not enforced due to erasure)public <E extends T> Iterable<E> refresh(Iterable<E> entities, Attribute<?,?>... attributes)
EntityStore
refresh
in interface BlockingEntityStore<T>
refresh
in interface EntityStore<T,Object>
E
- entity typeentities
- to refreshattributes
- attributes to refresh, attributes should be of type E
(not enforced due to erasure)public <E extends T> E refreshAll(E entity)
EntityStore
refreshAll
in interface BlockingEntityStore<T>
refreshAll
in interface EntityStore<T,Object>
E
- entity typeentity
- to refreshpublic <E extends T> Void delete(E entity)
EntityStore
delete
in interface BlockingEntityStore<T>
delete
in interface EntityStore<T,Object>
E
- entity type.entity
- to deletepublic <E extends T> Void delete(Iterable<E> entities)
EntityStore
delete
in interface BlockingEntityStore<T>
delete
in interface EntityStore<T,Object>
E
- entity typeentities
- to deletepublic <E extends T,K> E findByKey(Class<E> type, K key)
EntityStore
EntityCache
if available may be checked first for the object. If an entity is
found in the cache it will be returned and potentially no query will be made.findByKey
in interface BlockingEntityStore<T>
findByKey
in interface EntityStore<T,Object>
E
- entity typeK
- key typetype
- non null entity class typekey
- non null key valuepublic Transaction transaction()
transaction
in interface Transactionable<Object>
public void close()
EntityStore
Result
instances may throw a PersistenceException
.close
in interface EntityStore<T,Object>
close
in interface AutoCloseable
public Selection<? extends Result<Tuple>> select(Expression<?>... expressions)
Queryable
public Selection<? extends Result<Tuple>> select(Set<? extends Expression<?>> expressions)
Queryable
public Update<? extends Scalar<Integer>> update()
Queryable
Return.get()
to perform the operation. The result is the number of rows
affected by the call. Note that aggregate update queries will not affect existing entity
objects in memory.public Deletion<? extends Scalar<Integer>> delete()
Queryable
Return.get()
to perform the operation. The result is the number of rows
affected by the call. Note that aggregate update queries will not affect existing entity
objects in memory.public <E extends T> Selection<? extends Result<E>> select(Class<E> type, QueryAttribute<?,?>... attributes)
Queryable
Result
.public <E extends T> Selection<? extends Result<E>> select(Class<E> type, Set<? extends QueryAttribute<E,?>> attributes)
Queryable
Result
.public <E extends T> Insertion<? extends Result<Tuple>> insert(Class<E> type)
Queryable
Return.get()
to perform the operation. If the type has no generated key values the
result is a tuple containing a single element with the number of rows affected by the
operation. Otherwise if the type has generated keys those keys are returned as the result.public <E extends T> Update<? extends Scalar<Integer>> update(Class<E> type)
Queryable
Return.get()
to perform the operation. The result is the number of rows
affected by the call. Note that aggregate update queries will not affect existing entity
objects in memory.public <E extends T> Deletion<? extends Scalar<Integer>> delete(Class<E> type)
Queryable
Return.get()
to perform the operation. Note that aggregate delete queries
will not affect existing entity objects in memory or in the EntityCache
associated
with the store.public <E extends T> Selection<? extends Scalar<Integer>> count(Class<E> type)
Queryable
public Selection<? extends Scalar<Integer>> count(QueryAttribute<?,?>... attributes)
Queryable
public Result<Tuple> raw(String query, Object... parameters)
Queryable
raw
in interface Queryable<T>
query
- raw query to executeparameters
- query arguments, the number of arguments must match the number of place
holder values in the query or a PersistenceException
will be
thrown.Tuple
.public <E extends T> Result<E> raw(Class<E> type, String query, Object... parameters)
Queryable
raw
in interface Queryable<T>
E
- entity typetype
- entity typequery
- raw query to executeparameters
- query arguments, the number of arguments must match the number of place
holder values in the query or a PersistenceException
will be
thrown.public <V> V runInTransaction(Callable<V> callable, @Nullable TransactionIsolation isolation)
Transactionable
runInTransaction
in interface BlockingEntityStore<T>
runInTransaction
in interface Transactionable<Object>
V
- call result typecallable
- to runisolation
- isolation level for the transactionpublic <V> V runInTransaction(Callable<V> callable)
Transactionable
runInTransaction
in interface BlockingEntityStore<T>
runInTransaction
in interface Transactionable<Object>
V
- call result typecallable
- to runpublic BlockingEntityStore<T> toBlocking()
toBlocking
in interface EntityStore<T,Object>
BlockingEntityStore
version of this entity store. If the implementation
is already blocking may return itself.protected void checkConnectionMetadata()
protected void checkClosed()
protected io.requery.sql.EntityContext<T> context()