T - the type parameterpublic abstract class AbstractEntityDaoImpl<T extends AbstractEntity> extends Object implements AbstractEntityDao<T>
It supports Multi-tenancy at various levels: Field(Column) Level: Instantiate this class with an appropriate fieldName, containing tenantId, as tenantKey. Collection(Table) Level: Override getCollectionName method to return appropriate Collection Name for the Tenant context. Database Level: In getMongoTemplate method, return appropriate MongoTemplate for the Tenant context.
| Modifier and Type | Field and Description |
|---|---|
Class<T> |
clazz
The Clazz.
|
String |
tenantKey
The Tenant key.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEntityDaoImpl(Class<T> clazz)
Instantiates a new Abstract entity dao.
|
protected |
AbstractEntityDaoImpl(Class<T> clazz,
String tenantKey)
Instantiates a new Abstract entity dao.
|
| Modifier and Type | Method and Description |
|---|---|
protected org.springframework.data.mongodb.core.aggregation.Aggregation |
aggregation(org.springframework.data.mongodb.core.aggregation.AggregationOperation... operations)
Gets @
Aggregation with appropriate @MatchOperation at the beginning |
protected org.springframework.data.mongodb.core.aggregation.Aggregation |
aggregation(List<? extends org.springframework.data.mongodb.core.aggregation.AggregationOperation> operations)
Gets @
Aggregation with appropriate @MatchOperation at the beginning |
org.springframework.data.mongodb.core.BulkOperations |
bulkOperations(org.springframework.data.mongodb.core.BulkOperations.BulkMode bulkMode)
Get the bulk operations.
|
long |
count(org.springframework.data.mongodb.core.query.Query query)
Count long.
|
T |
deleteById(String id)
Delete by id t.
|
<R> List<R> |
distinct(String fieldName,
org.springframework.data.mongodb.core.query.Query query,
Class<R> rClass)
Distinct list.
|
void |
ensureIndex(org.bson.conversions.Bson keys,
com.mongodb.client.model.IndexOptions options)
Ensure index.
|
List<T> |
findAll()
Find all list.
|
List<T> |
findAll(boolean viewedUpdate)
Find all list.
|
List<T> |
findAll(org.springframework.data.mongodb.core.query.Query query)
Find all list.
|
List<T> |
findAll(org.springframework.data.mongodb.core.query.Query query,
boolean viewedUpdate)
Find all list.
|
T |
findAndModify(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
Find and modify t.
|
T |
findAndRemove(org.springframework.data.mongodb.core.query.Query query)
Find and remove t.
|
T |
findAndReplace(org.springframework.data.mongodb.core.query.Query query,
T entity,
boolean returnNew,
boolean upsert)
Find and replace t.
|
T |
findById(String id)
Find by id t.
|
T |
findById(String id,
boolean updateViewed)
Find by id t.
|
T |
findOne(org.springframework.data.mongodb.core.query.Query query)
Find one t.
|
T |
findOne(org.springframework.data.mongodb.core.query.Query query,
boolean updateViewed)
Find one t.
|
String |
getCollectionName()
Gets collection name.
|
protected String |
getCreatedByKey()
Get created by key string.
|
protected String |
getCreatedKey()
Get created key string.
|
org.springframework.data.mongodb.core.query.Criteria |
getCriteria()
Gets the
Criteria containing tenantId and deleted filter. |
protected String |
getDeletedKey()
Get deleted key string.
|
protected String |
getEntityId(T entity)
Gets entity id.
|
protected org.springframework.data.mongodb.core.query.Query |
getIdQuery(String id)
Gets id query.
|
protected org.springframework.data.mongodb.core.aggregation.MatchOperation |
getMatchOperation()
Gets match operation containing tenantId and deleted filter.
|
protected abstract org.springframework.data.mongodb.core.MongoTemplate |
getMongoTemplate()
Gets mongo template.
|
protected Object |
getNow()
Get now object.
|
protected Object |
getTenantId()
Gets tenant id.
|
protected org.springframework.data.mongodb.core.query.Query |
getTenantQuery(org.springframework.data.mongodb.core.query.Query query)
Gets tenant query.
|
protected String |
getUpdatedByKey()
Get updated by key string.
|
protected String |
getUpdatedKey()
Get updated key string.
|
protected String |
getViewedByKey()
Get viewed by key string.
|
protected String |
getViewedKey()
Get viewed key string.
|
Collection<T> |
insert(Collection<T> entities)
Insert collection.
|
T |
insert(T entity)
Insert t.
|
T |
modifyAndFind(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
Modify and find t.
|
protected void |
onFetch(T entity)
Perform any operation after fetching the entity
|
protected void |
onInsert(T entity)
Hook to call on Insert
|
protected void |
onUpdate(T entity)
Hook to call on update.
|
protected void |
onUpdate(org.springframework.data.mongodb.core.query.Update update)
Hook to update on update
|
long |
removeAll(org.springframework.data.mongodb.core.query.Query query)
Remove all int.
|
T |
removeAndInsert(org.springframework.data.mongodb.core.query.Query query,
T entity)
Remove and insert t.
|
List<T> |
save(Iterable<T> iterable)
Save list.
|
T |
save(T entity)
Save t.
|
protected abstract void |
setEntityId(T entity,
String id)
Sets entity id.
|
protected void |
setTenantId(T entity,
Object tenantId)
Sets tenant id.
|
protected org.springframework.data.mongodb.core.query.Update |
setValues(org.springframework.data.mongodb.core.query.Update update)
Sets values.
|
protected void |
setValuesOnInsert(T entity)
Sets values on insert.
|
protected void |
setValuesOnUpdate(T entity)
Sets values on update.
|
T |
updateById(String id,
org.springframework.data.mongodb.core.query.Update update)
Update by id t.
|
long |
updateMulti(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
Update multi.
|
T |
upsert(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
Upsert t.
|
T |
upsertReturnOld(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
Upsert return old t.
|
AbstractEntityDao<T> |
withDirect()
Directly queries and updates, without modifying
Query and Update objects. |
AbstractEntityDao<T> |
withDirectQuery()
Directly queries and updates, without modifying
Query object. |
AbstractEntityDao<T> |
withDirectUpdate()
Directly queries and updates, without modifying
Update object. |
public final Class<T extends AbstractEntity> clazz
public final String tenantKey
protected AbstractEntityDaoImpl(Class<T> clazz)
clazz - the clazzprotected String getEntityId(T entity)
entity - the entityprotected org.springframework.data.mongodb.core.aggregation.MatchOperation getMatchOperation()
AggregationOperation while creating Aggregationpublic org.springframework.data.mongodb.core.query.Criteria getCriteria()
AbstractEntityDaoCriteria containing tenantId and deleted filter.getCriteria in interface AbstractEntityDao<T extends AbstractEntity>protected Object getTenantId()
protected String getDeletedKey()
public T findAndRemove(org.springframework.data.mongodb.core.query.Query query)
findAndRemove in interface AbstractEntityDao<T extends AbstractEntity>query - the querypublic final long removeAll(org.springframework.data.mongodb.core.query.Query query)
AbstractEntityDaoremoveAll in interface AbstractEntityDao<T extends AbstractEntity>query - the queryprotected abstract org.springframework.data.mongodb.core.MongoTemplate getMongoTemplate()
protected org.springframework.data.mongodb.core.query.Query getTenantQuery(org.springframework.data.mongodb.core.query.Query query)
query - the querypublic String getCollectionName()
getCollectionName in interface AbstractEntityDao<T extends AbstractEntity>public AbstractEntityDao<T> withDirect()
AbstractEntityDaoQuery and Update objects.withDirect in interface AbstractEntityDao<T extends AbstractEntity>public AbstractEntityDao<T> withDirectQuery()
AbstractEntityDaoQuery object.withDirectQuery in interface AbstractEntityDao<T extends AbstractEntity>public AbstractEntityDao<T> withDirectUpdate()
AbstractEntityDaoUpdate object.withDirectUpdate in interface AbstractEntityDao<T extends AbstractEntity>protected org.springframework.data.mongodb.core.query.Update setValues(org.springframework.data.mongodb.core.query.Update update)
update - the updateprotected void onUpdate(org.springframework.data.mongodb.core.query.Update update)
update - the updateprotected String getCreatedKey()
protected Object getNow()
protected String getCreatedByKey()
protected String getUpdatedKey()
protected String getUpdatedByKey()
protected String getViewedKey()
protected String getViewedByKey()
public org.springframework.data.mongodb.core.BulkOperations bulkOperations(org.springframework.data.mongodb.core.BulkOperations.BulkMode bulkMode)
AbstractEntityDaobulkOperations in interface AbstractEntityDao<T extends AbstractEntity>bulkMode - the bulk modepublic T findById(String id)
AbstractEntityDaofindById in interface AbstractEntityDao<T extends AbstractEntity>id - the idpublic T findById(String id, boolean updateViewed)
AbstractEntityDaofindById in interface AbstractEntityDao<T extends AbstractEntity>id - the idupdateViewed - the update viewedpublic T findOne(org.springframework.data.mongodb.core.query.Query query)
AbstractEntityDaofindOne in interface AbstractEntityDao<T extends AbstractEntity>query - the querypublic T findOne(org.springframework.data.mongodb.core.query.Query query, boolean updateViewed)
AbstractEntityDaofindOne in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdateViewed - the viewedpublic T insert(T entity)
AbstractEntityDaoinsert in interface AbstractEntityDao<T extends AbstractEntity>entity - the entitypublic Collection<T> insert(Collection<T> entities)
AbstractEntityDaoinsert in interface AbstractEntityDao<T extends AbstractEntity>entities - the entitiesprotected final void setValuesOnInsert(T entity)
entity - the entityprotected void onInsert(T entity)
entity - the entityprotected abstract void setEntityId(T entity, String id)
entity - the entityid - the idprotected final void setValuesOnUpdate(T entity)
entity - the entityprotected void onUpdate(T entity)
entity - the entityprotected final void setTenantId(T entity, Object tenantId)
entity - the entitytenantId - the tenant idpublic T save(T entity)
AbstractEntityDaosave in interface AbstractEntityDao<T extends AbstractEntity>entity - the entitypublic List<T> save(Iterable<T> iterable)
AbstractEntityDaosave in interface AbstractEntityDao<T extends AbstractEntity>iterable - the entitiespublic List<T> findAll()
AbstractEntityDaofindAll in interface AbstractEntityDao<T extends AbstractEntity>public List<T> findAll(boolean viewedUpdate)
AbstractEntityDaofindAll in interface AbstractEntityDao<T extends AbstractEntity>viewedUpdate - the viewed updatepublic List<T> findAll(org.springframework.data.mongodb.core.query.Query query)
AbstractEntityDaofindAll in interface AbstractEntityDao<T extends AbstractEntity>query - the querypublic List<T> findAll(org.springframework.data.mongodb.core.query.Query query, boolean viewedUpdate)
AbstractEntityDaofindAll in interface AbstractEntityDao<T extends AbstractEntity>query - the queryviewedUpdate - the viewed updatepublic T findAndModify(org.springframework.data.mongodb.core.query.Query query, org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaofindAndModify in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdate - the updatepublic T updateById(String id, org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaoupdateById in interface AbstractEntityDao<T extends AbstractEntity>id - the idupdate - the updatepublic T modifyAndFind(org.springframework.data.mongodb.core.query.Query query, org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaomodifyAndFind in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdate - the updatepublic T upsert(org.springframework.data.mongodb.core.query.Query query, org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaoupsert in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdate - the updatepublic T upsertReturnOld(org.springframework.data.mongodb.core.query.Query query, org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaoupsertReturnOld in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdate - the updatepublic T removeAndInsert(org.springframework.data.mongodb.core.query.Query query, T entity)
AbstractEntityDaoremoveAndInsert in interface AbstractEntityDao<T extends AbstractEntity>query - the queryentity - the entitypublic T deleteById(String id)
AbstractEntityDaodeleteById in interface AbstractEntityDao<T extends AbstractEntity>id - the idprotected org.springframework.data.mongodb.core.query.Query getIdQuery(String id)
id - the idpublic long updateMulti(org.springframework.data.mongodb.core.query.Query query,
org.springframework.data.mongodb.core.query.Update update)
AbstractEntityDaoupdateMulti in interface AbstractEntityDao<T extends AbstractEntity>query - the queryupdate - the updatepublic void ensureIndex(org.bson.conversions.Bson keys,
com.mongodb.client.model.IndexOptions options)
AbstractEntityDaoensureIndex in interface AbstractEntityDao<T extends AbstractEntity>keys - the keysoptions - the optionspublic <R> List<R> distinct(String fieldName, org.springframework.data.mongodb.core.query.Query query, Class<R> rClass)
AbstractEntityDaodistinct in interface AbstractEntityDao<T extends AbstractEntity>R - the type parameterfieldName - the field namequery - the queryrClass - The result classpublic long count(org.springframework.data.mongodb.core.query.Query query)
AbstractEntityDaocount in interface AbstractEntityDao<T extends AbstractEntity>query - the queryprotected org.springframework.data.mongodb.core.aggregation.Aggregation aggregation(List<? extends org.springframework.data.mongodb.core.aggregation.AggregationOperation> operations)
Aggregation with appropriate @MatchOperation at the beginningoperations - the operationsprotected org.springframework.data.mongodb.core.aggregation.Aggregation aggregation(org.springframework.data.mongodb.core.aggregation.AggregationOperation... operations)
Aggregation with appropriate @MatchOperation at the beginningoperations - the operationspublic T findAndReplace(org.springframework.data.mongodb.core.query.Query query, T entity, boolean returnNew, boolean upsert)
AbstractEntityDaofindAndReplace in interface AbstractEntityDao<T extends AbstractEntity>query - the queryentity - the entityreturnNew - the return newupsert - the upsertprotected void onFetch(T entity)
entity - the entityCopyright © 2022. All rights reserved.