T - the entity this DAO is used forpublic abstract class AbstractMongoDAO<T extends AEntity> extends Object implements ICrudDAO<T>
mongodb.name has to be set and it denotes the database
used for this DAO.| Modifier and Type | Field and Description |
|---|---|
protected org.jongo.MongoCollection |
collection |
| Constructor and Description |
|---|
AbstractMongoDAO() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterDelete(String id) |
protected void |
afterSave(T object)
override this to do something after the object was saved
|
protected void |
beforeDelete(String id) |
protected void |
beforeSave(T object)
override this to do something before the object was saved
|
protected <P> List<P> |
convertIterable(Iterable<P> as)
|
protected org.jongo.Jongo |
createJongo(com.mongodb.DB db)
creates the Jongo driver instance.
|
protected void |
customInit() |
void |
delete(String id)
deletes the given object using its id.
|
void |
delete(T object)
deletes the given object using its id.
|
T |
findById(String id)
find the element with the given id
|
protected List<T> |
findByQuery(String query,
Object... params)
finds all elements matching the given query
|
protected T |
findFirstByQuery(String query,
String sort,
Object... params)
queries with the given string, sorts the result and returns the first element.
|
List<T> |
findList() |
protected List<T> |
findSortedByQuery(String query,
String sort,
Integer skip,
Integer limit,
Object... params)
finds all elements matching the given query and sorts them accordingly
|
protected <P> List<P> |
findSortedByQuery(String query,
String sort,
Integer skip,
Integer limit,
String projection,
Class<P> as,
Object... params)
finds all elements matching the given query and sorts them accordingly.
|
protected <P> List<P> |
findSortedByQuery(String query,
String sort,
Integer skip,
Integer limit,
String projection,
org.jongo.ResultHandler<P> handler,
Object... params)
finds all elements matching the given query and sorts them accordingly.
|
protected List<T> |
findSortedByQuery(String query,
String sort,
Object... params)
finds all elements matching the given query and sorts them accordingly
|
protected <P> List<P> |
findSortedByQuery(String query,
String sort,
String projection,
Class<P> as,
Object... params)
finds all elements matching the given query and sorts them accordingly.
|
protected <P> List<P> |
findSortedByQuery(String query,
String sort,
String projection,
org.jongo.ResultHandler<P> handler,
Object... params)
finds all elements matching the given query and sorts them accordingly.
|
protected String |
getCollectionName() |
protected abstract Class<T> |
getEntityClass() |
protected com.mongodb.gridfs.GridFS |
getGridFSBucket(String bucket) |
void |
init() |
protected <R> Iterable<R> |
mapReduce(String name,
com.mongodb.DBObject query,
com.mongodb.DBObject sort,
Map<String,Object> scope,
MapReduceResultHandler<R> conv)
runs a map-reduce-job on the collection.
|
protected <R> Iterable<R> |
mapReduce(String name,
MapReduceResultHandler<R> conv)
runs a map-reduce-job on the collection.
|
T |
save(T object)
saves the goven element
|
@PostConstruct public final void init()
protected void customInit()
protected String getCollectionName()
protected final <R> Iterable<R> mapReduce(String name, MapReduceResultHandler<R> conv)
mapReduce(name, null, null, null, conv)R - the type of the result classname - the name of the map-reduce functionsconv - the converter to convert the resultIterable with the result entriesprotected final <R> Iterable<R> mapReduce(String name, com.mongodb.DBObject query, com.mongodb.DBObject sort, Map<String,Object> scope, MapReduceResultHandler<R> conv)
MapReduceResultHandlerR - the type of the result classname - the name of the map-reduce functionsquery - the query to filter the elements used for the map-reducesort - sort query to sort elements before running map-reducescope - the global scope for the JavaScript runconv - the converter to convert the resultIterable with the result entriesRuntimeException - if resources cannot be readprotected final List<T> findByQuery(String query, Object... params)
query - the query to search forparams - the parameters to replace # symbolsprotected final List<T> findSortedByQuery(String query, String sort, Object... params)
query - the query to search forsort - the sort query to applyparams - the parameters to replace # symbolsprotected final <P> List<P> findSortedByQuery(String query, String sort, String projection, Class<P> as, Object... params)
getEntityClass() objects it returns objects of type
asP - the element typequery - the query to search forsort - the sort query to applyprojection - the projection of fields to useas - the target to convert result elements toparams - the parameters to replace # symbolsprotected final <P> List<P> findSortedByQuery(String query, String sort, String projection, org.jongo.ResultHandler<P> handler, Object... params)
getEntityClass() objects it returns objects converted
by the given ResultHandlerP - the element typequery - the query to search forsort - the sort query to applyprojection - the projection of fields to usehandler - the handler to convert result elements withparams - the parameters to replace # symbolsprotected final List<T> findSortedByQuery(String query, String sort, Integer skip, Integer limit, Object... params)
query - the query to search forsort - the sort query to applyskip - the number of elements to skiplimit - the number of elements to fetchparams - the parameters to replace # symbolsprotected final <P> List<P> findSortedByQuery(String query, String sort, Integer skip, Integer limit, String projection, Class<P> as, Object... params)
getEntityClass() objects it returns objects of type
asP - the element typequery - the query to search forsort - the sort query to applyskip - the number of elements to skiplimit - the number of elements to fetchprojection - the projection of fields to useas - the target to convert result elements toparams - the parameters to replace # symbolsprotected final <P> List<P> findSortedByQuery(String query, String sort, Integer skip, Integer limit, String projection, org.jongo.ResultHandler<P> handler, Object... params)
getEntityClass() objects it returns objects converted
by the given ResultHandlerP - the element typequery - the query to search forsort - the sort query to applyskip - the number of elements to skiplimit - the number of elements to fetchprojection - the projection of fields to usehandler - the handler to convert result elements withparams - the parameters to replace # symbolsprotected final T findFirstByQuery(String query, String sort, Object... params)
null is returned if no element is found.query - the query stringsort - the sort stringparams - the parameters to replace # symbolsnull if none is foundpublic final T findById(String id)
ICrudDAOpublic final T save(T object)
ICrudDAOprotected void afterSave(T object)
object - the saved objectprotected void beforeSave(T object)
object - the object to be savedpublic final void delete(T object)
ICrudDAOpublic final void delete(String id)
ICrudDAOprotected void beforeDelete(String id)
protected void afterDelete(String id)
protected com.mongodb.gridfs.GridFS getGridFSBucket(String bucket)
protected org.jongo.Jongo createJongo(com.mongodb.DB db)
db - the database to use with the created JongoCopyright © 2015–2016 Taimos GmbH. All rights reserved.