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.LockedContext<T>
A context for a shard
|
| Constructor and Description |
|---|
LookupDao(List<org.hibernate.SessionFactory> sessionFactories,
Class<T> entityClass,
ShardCalculator<String> shardCalculator)
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.
|
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. |
protected Field |
getKeyField() |
LookupDao.LockedContext<T> |
lockAndGetExecutor(String id) |
<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. |
LookupDao.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.
|
boolean |
update(String id,
Function<Optional<T>,T> updater) |
boolean |
updateInLock(String id,
Function<Optional<T>,T> updater) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetShardCalculatorpublic LookupDao(List<org.hibernate.SessionFactory> sessionFactories, Class<T> entityClass, ShardCalculator<String> shardCalculator)
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 <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 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 LookupDao.LockedContext<T> lockAndGetExecutor(String id)
public LookupDao.LockedContext<T> saveAndGetExecutor(T entity)
public List<T> scatterGather(org.hibernate.criterion.DetachedCriteria criteria)
criteria - The selct criteriapublic List<Long> count(org.hibernate.criterion.DetachedCriteria criteria)
criteria - The select criteriapublic List<T> get(List<String> keys)
keys - The list of lookup keyspublic boolean delete(String id)
protected Field getKeyField()
Copyright © 2016–2020. All rights reserved.