public class LookupDao<T> extends Object implements ShardedDao<T>
LookupKey
The entity can be retrieved from any shard using the key.| Modifier and Type | Class and Description |
|---|---|
static class |
LookupDao.ReadOnlyContext<T> |
| Constructor and Description |
|---|
LookupDao(List<org.hibernate.SessionFactory> sessionFactories,
Class<T> entityClass,
ShardCalculator<String> shardCalculator,
ShardingBundleOptions shardingOptions,
ShardInfoProvider shardInfoProvider,
TransactionObserver observer)
Creates a new sharded DAO.
|
| Modifier and Type | Method and Description |
|---|---|
List<Long> |
count(org.hibernate.criterion.DetachedCriteria criteria)
Queries using the specified criteria across all shards and returns the counts of rows satisfying the criteria.
|
Optional<T> |
createOrUpdate(String id,
UnaryOperator<T> updater,
Supplier<T> entityGenerator) |
boolean |
delete(String id) |
boolean |
exists(String key)
Check if object with specified key exists in any shard.
|
List<T> |
get(List<String> keys)
Queries across various shards and returns the results.
|
Optional<T> |
get(String key)
Get an object on the basis of key (value of field annotated with
LookupKey) from any shard. |
<U> U |
get(String key,
Function<T,U> handler)
Get an object on the basis of key (value of field annotated with
LookupKey) from any shard
and applies the provided function/lambda to it. |
Optional<T> |
get(String key,
UnaryOperator<org.hibernate.Criteria> criteriaUpdater) |
<U> U |
get(String key,
UnaryOperator<org.hibernate.Criteria> criteriaUpdater,
Function<T,U> handler) |
protected Field |
getKeyField() |
LockedContext<T> |
lockAndGetExecutor(String id) |
LookupDao.ReadOnlyContext<T> |
readOnlyExecutor(String id) |
LookupDao.ReadOnlyContext<T> |
readOnlyExecutor(String id,
Supplier<Boolean> entityPopulator) |
LookupDao.ReadOnlyContext<T> |
readOnlyExecutor(String id,
UnaryOperator<org.hibernate.Criteria> criteriaUpdater) |
LookupDao.ReadOnlyContext<T> |
readOnlyExecutor(String id,
UnaryOperator<org.hibernate.Criteria> criteriaUpdater,
Supplier<Boolean> entityPopulator) |
Map<Integer,List> |
run(org.hibernate.criterion.DetachedCriteria criteria)
Run arbitrary read-only queries on all shards and return results.
|
<U> U |
run(org.hibernate.criterion.DetachedCriteria criteria,
Function<Map<Integer,List>,U> translator)
Run read-only queries on all shards and transform them into required types
|
<U,V> V |
runInSession(BiFunction<Integer,org.hibernate.Session,U> sessionHandler,
Function<Map<Integer,U>,V> translator) |
<U> U |
runInSession(String id,
Function<org.hibernate.Session,U> handler) |
Optional<T> |
save(T entity)
Saves an entity on proper shard based on hash of the value in the key field in the object.
|
<U> U |
save(T entity,
Function<T,U> handler)
Save an object on the basis of key (value of field annotated with
LookupKey) to target shard
and applies the provided function/lambda to it. |
LockedContext<T> |
saveAndGetExecutor(T entity) |
List<T> |
scatterGather(org.hibernate.criterion.DetachedCriteria criteria)
Queries using the specified criteria across all shards and returns the result.
|
ScrollResult<T> |
scrollDown(org.hibernate.criterion.DetachedCriteria inCriteria,
ScrollPointer inPointer,
int pageSize,
@NonNull String sortFieldName)
Provides a scroll api for records across shards.
|
ScrollResult<T> |
scrollUp(org.hibernate.criterion.DetachedCriteria inCriteria,
ScrollPointer inPointer,
int pageSize,
@NonNull String sortFieldName)
Provides a scroll api for records across shards.
|
boolean |
update(String id,
Function<Optional<T>,T> updater) |
boolean |
updateInLock(String id,
Function<Optional<T>,T> updater) |
int |
updateUsingQuery(String id,
UpdateOperationMeta updateOperationMeta) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetShardCalculatorpublic LookupDao(List<org.hibernate.SessionFactory> sessionFactories, Class<T> entityClass, ShardCalculator<String> shardCalculator, ShardingBundleOptions shardingOptions, ShardInfoProvider shardInfoProvider, TransactionObserver observer)
ShardManager.sessionFactories - a session provider for each shardshardCalculator - calculator for shardspublic Optional<T> get(String key) throws Exception
LookupKey) from any shard.
Note: Lazy loading will not work once the object is returned.
If you need lazy loading functionality use the alternate get(String, Function) method.key - The value of the key field to look for.Exception - if backing dao throwspublic Optional<T> get(String key, UnaryOperator<org.hibernate.Criteria> criteriaUpdater) throws Exception
Exceptionpublic <U> U get(String key, Function<T,U> handler) throws Exception
LookupKey) from any shard
and applies the provided function/lambda to it. The return from the handler becomes the return to the get
function.
Note: The transaction is open when handler is applied. So lazy loading will work inside the handler.
Once get returns, lazy loading will nt owrok.key - The value of the key field to look for.handler - Handler function/lambda that receives the retrieved object.Exception - if backing dao throwspublic <U> U get(String key, UnaryOperator<org.hibernate.Criteria> criteriaUpdater, Function<T,U> handler) throws Exception
Exceptionpublic boolean exists(String key) throws Exception
key - id of the element to look forException - if backing dao throwspublic Optional<T> save(T entity) throws Exception
save(Object, Function) for that.entity - Entity to saveException - if backing dao throwspublic <U> U save(T entity, Function<T,U> handler) throws Exception
LookupKey) to target shard
and applies the provided function/lambda to it. The return from the handler becomes the return to the get
function.
Note: Handler is executed in the same transactional context as the save operation.
So any updates made to the object in this context will also get persisted.entity - The value of the key field to look for.handler - Handler function/lambda that receives the retrieved object.Exception - if backing dao throwspublic Optional<T> createOrUpdate(String id, UnaryOperator<T> updater, Supplier<T> entityGenerator)
public int updateUsingQuery(String id, UpdateOperationMeta updateOperationMeta)
public LockedContext<T> lockAndGetExecutor(String id)
public LookupDao.ReadOnlyContext<T> readOnlyExecutor(String id)
public LookupDao.ReadOnlyContext<T> readOnlyExecutor(String id, UnaryOperator<org.hibernate.Criteria> criteriaUpdater)
public LookupDao.ReadOnlyContext<T> readOnlyExecutor(String id, Supplier<Boolean> entityPopulator)
public LookupDao.ReadOnlyContext<T> readOnlyExecutor(String id, UnaryOperator<org.hibernate.Criteria> criteriaUpdater, Supplier<Boolean> entityPopulator)
public LockedContext<T> saveAndGetExecutor(T entity)
public List<T> scatterGather(org.hibernate.criterion.DetachedCriteria criteria)
criteria - The select criteriapublic ScrollResult<T> scrollDown(org.hibernate.criterion.DetachedCriteria inCriteria, ScrollPointer inPointer, int pageSize, @NonNull @NonNull String sortFieldName)
ScrollResult#getResult().
If the passed pointer is null, it will return the first pageSize records with a pointer to be passed to get the
next pageSize set of records.
NOTES: - Do not modify the criteria between subsequent calls - It is important to provide a sort field that is perpetually increasing - Pointer returned can be used to _only_ scroll down
inCriteria - The core criteria for the queryinPointer - Existing ScrollPointer, should be null at start of a scroll sessionpageSize - Count of records per shardsortFieldName - Field to sort by. For correct sorting, the field needs to be an ever-increasing oneScrollResult object that contains a ScrollPointer and a list of results with
max N * pageSize elementspublic ScrollResult<T> scrollUp(org.hibernate.criterion.DetachedCriteria inCriteria, ScrollPointer inPointer, int pageSize, @NonNull @NonNull String sortFieldName)
NOTES: - Do not modify the criteria between subsequent calls - It is important to provide a sort field that is perpetually increasing - Pointer returned can be used to _only_ scroll up
inCriteria - The core criteria for the queryinPointer - Existing ScrollPointer, should be null at start of a scroll sessionpageSize - Count of records per shardsortFieldName - Field to sort by. For correct sorting, the field needs to be an ever-increasing oneScrollResult object that contains a ScrollPointer and a list of results with
max N * pageSize elementspublic List<Long> count(org.hibernate.criterion.DetachedCriteria criteria)
criteria - The select criteriapublic Map<Integer,List> run(org.hibernate.criterion.DetachedCriteria criteria)
criteria - The detached criteria. Typically, a grouping or counting querypublic <U> U run(org.hibernate.criterion.DetachedCriteria criteria,
Function<Map<Integer,List>,U> translator)
U - Return typecriteria - The detached criteria. Typically, a grouping or counting querytranslator - A method to transform results to required typepublic List<T> get(List<String> keys)
keys - The list of lookup keyspublic <U,V> V runInSession(BiFunction<Integer,org.hibernate.Session,U> sessionHandler, Function<Map<Integer,U>,V> translator)
public boolean delete(String id)
protected Field getKeyField()
Copyright © 2016–2023. All rights reserved.