ID_TYPE
- the generic key typeMODEL_TYPE
- the generic model typepublic interface Dao<ID_TYPE,MODEL_TYPE,QUERY_TYPE extends Dao.Query<MODEL_TYPE,QUERY_TYPE>> extends AppContextAware, SecurityContextAware, Destroyable
The Data Access Object interface
Modifier and Type | Interface and Description |
---|---|
static interface |
Dao.Query<MODEL_TYPE,QUERY_TYPE extends Dao.Query<MODEL_TYPE,QUERY_TYPE>> |
Destroyable.Util
Modifier and Type | Method and Description |
---|---|
long |
count()
Returns total number of entities of the model type of this
Dao object. |
long |
countBy(java.lang.String fields,
java.lang.Object... values)
Count the number of entities matches the fields and values specified.
|
QUERY_TYPE |
createQuery()
Alias of
q() |
QUERY_TYPE |
createQuery(java.lang.String fields,
java.lang.Object... values)
Alias of
q(String, Object...) |
void |
delete(MODEL_TYPE entity)
Remove the entity specified
|
void |
delete(QUERY_TYPE query)
Remove entities specified by Query
|
void |
deleteAll()
Delete all entities in the table/collection inferred by this DAO
|
void |
deleteBy(java.lang.String fields,
java.lang.Object... values)
Delete a collection of entities by fields and values.
|
void |
deleteById(ID_TYPE id)
Remove entity by ID
|
void |
drop()
Drop all entities (and optionally all indexes) from persistent storage
|
java.lang.Iterable<MODEL_TYPE> |
findAll()
Find all entities of the collection/table specified by
MODEL_TYPE |
java.util.List<MODEL_TYPE> |
findAllAsList()
Find all entities of the collection/table specified by
MODEL_TYPE |
java.lang.Iterable<MODEL_TYPE> |
findBy(java.lang.String fields,
java.lang.Object... values)
Find a collection of entities by fields and values.
|
MODEL_TYPE |
findById(ID_TYPE id)
Find an entity by id, the primary key
|
java.lang.Iterable<MODEL_TYPE> |
findByIdList(java.util.Collection<ID_TYPE> idList)
Find all entities from a give list of IDs.
|
MODEL_TYPE |
findLastModified()
Find last modified record.
|
MODEL_TYPE |
findLatest()
Find the last created record.
|
MODEL_TYPE |
findOneBy(java.lang.String fields,
java.lang.Object... values)
Find one entity with fields and values specified.
|
ID_TYPE |
getId(MODEL_TYPE entity)
Extract ID value from the give model entity
|
java.lang.Class<ID_TYPE> |
idType()
Returns the identifier type
|
java.lang.Class<MODEL_TYPE> |
modelType()
Returns the class of the Model entity this Dao operates on
|
QUERY_TYPE |
q()
Return a
Dao.Query bound to the MODEL_TYPE |
QUERY_TYPE |
q(java.lang.String fields,
java.lang.Object... values)
Return a
Dao.Query bound to the MODEL_TYPE by fields and value arguments |
java.lang.Class<QUERY_TYPE> |
queryType()
Returns the class of the bounded query type
|
MODEL_TYPE |
reload(MODEL_TYPE entity)
Reload a model entity from persistent storage by it’s
Model._id() . |
java.util.List<MODEL_TYPE> |
save(java.lang.Iterable<MODEL_TYPE> entities)
Batch save entities
|
MODEL_TYPE |
save(MODEL_TYPE entity)
Save new or update existing the entity in persistent layer with all properties of the entity
|
void |
save(MODEL_TYPE entity,
java.lang.String fields,
java.lang.Object... values)
Update existing entity in persistent layer with specified fields and value.
|
setAppContext
setSecurityContext
destroy, isDestroyed, scope
java.lang.Class<ID_TYPE> idType()
Returns the identifier type
java.lang.Class<MODEL_TYPE> modelType()
Returns the class of the Model entity this Dao operates on
java.lang.Class<QUERY_TYPE> queryType()
Returns the class of the bounded query type
MODEL_TYPE findById(ID_TYPE id)
Find an entity by id, the primary key
id
- the id to find the entitynull
if not foundMODEL_TYPE findLatest()
Find the last created record.
MODEL_TYPE findLastModified()
Find last modified record.
java.lang.Iterable<MODEL_TYPE> findBy(java.lang.String fields, java.lang.Object... values) throws java.lang.IllegalArgumentException
Find a collection of entities by fields and values.
The fields is specified in a String
separated by any combination of the following separators
,
;
:
The values are specified in an object array. The number of values must match the number of fields specified. Otherwise IllegalArgumentException
will be thrown out
If entities found then they are returned in an Iterable
. Otherwise an empty Iterable
will be returned
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationIterable
java.lang.IllegalArgumentException
- if fields number and value number doesn’t matchMODEL_TYPE findOneBy(java.lang.String fields, java.lang.Object... values) throws java.lang.IllegalArgumentException
Find one entity with fields and values specified.
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationnull
if not foundjava.lang.IllegalArgumentException
findBy(String, Object...)
java.lang.Iterable<MODEL_TYPE> findByIdList(java.util.Collection<ID_TYPE> idList)
Find all entities from a give list of IDs. If there are certain ID in the list does not have an entity associated with then that ID will be ignored. The order of the returned iterator is not defined and shall be implemented as per specific implementation
idList
- the ID list specifies the entities shall be returnedjava.lang.Iterable<MODEL_TYPE> findAll()
Find all entities of the collection/table specified by MODEL_TYPE
Iterable
java.util.List<MODEL_TYPE> findAllAsList()
Find all entities of the collection/table specified by MODEL_TYPE
List
MODEL_TYPE reload(MODEL_TYPE entity)
Reload a model entity from persistent storage by it’s Model._id()
. This method returns the model been reloaded. Depending on the implementation, it could be the model passed in as parameter if it’s mutable object or a fresh new object instance with the same ID as the model been passed in.
entity
- the model to be reloadedID_TYPE getId(MODEL_TYPE entity)
Extract ID value from the give model entity
entity
- the model entity objectlong count()
Returns total number of entities of the model type of this Dao
object.
long countBy(java.lang.String fields, java.lang.Object... values) throws java.lang.IllegalArgumentException
Count the number of entities matches the fields and values specified. For the rule of fields and value specification, please refer to findBy(String, Object...)
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationjava.lang.IllegalArgumentException
- if fields number and value number doesn’t matchMODEL_TYPE save(MODEL_TYPE entity)
Save new or update existing the entity in persistent layer with all properties of the entity
entity
- the entity to be saved or updatedvoid save(MODEL_TYPE entity, java.lang.String fields, java.lang.Object... values)
Update existing entity in persistent layer with specified fields and value. This allows partial updates of the entity to save the bandwidth.
Note the properties of the entity does not impact the update operation, however the Model._id()
will be used to locate the record/document in the persistent layer corresponding to this entity.
For fields and value specification rule, please refer to findBy(String, Object...)
entity
- the entityfields
- the fields specification in String
values
- the value array corresponding to the fields specificationjava.util.List<MODEL_TYPE> save(java.lang.Iterable<MODEL_TYPE> entities)
Batch save entities
entities
- an iterable to get entities to be savedvoid delete(MODEL_TYPE entity)
Remove the entity specified
entity
- the entity to be removedvoid delete(QUERY_TYPE query)
Remove entities specified by Query
query
- the query specifies entities to be removedvoid deleteById(ID_TYPE id)
Remove entity by ID
id
- the ID of the entity to be removedvoid deleteBy(java.lang.String fields, java.lang.Object... values) throws java.lang.IllegalArgumentException
Delete a collection of entities by fields and values.
The fields is specified in a String
separated by any combination of the following separators
,
;
:
The values are specified in an object array. The number of values must match the number of fields specified. Otherwise IllegalArgumentException
will be thrown out
If entities found then they are returned in an Iterable
. Otherwise an empty Iterable
will be returned
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationjava.lang.IllegalArgumentException
- if fields number and value number doesn’t matchvoid deleteAll()
Delete all entities in the table/collection inferred by this DAO
void drop()
Drop all entities (and optionally all indexes) from persistent storage
QUERY_TYPE q()
Return a Dao.Query
bound to the MODEL_TYPE
Dao.Query
instance on this DaoQUERY_TYPE createQuery()
Alias of q()
Dao.Query
instance on this DaoQUERY_TYPE q(java.lang.String fields, java.lang.Object... values)
Return a Dao.Query
bound to the MODEL_TYPE
by fields and value arguments
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationQUERY_TYPE createQuery(java.lang.String fields, java.lang.Object... values)
Alias of q(String, Object...)
fields
- the fields specification in String
values
- the value array corresponding to the fields specificationq(String, Object...)
Copyright © 2014–2017 ActFramework. All rights reserved.