org.iternine.jeppetto.dao.mongodb
Class MongoDBQueryModelDAO<T,ID>

java.lang.Object
  extended by org.iternine.jeppetto.dao.mongodb.MongoDBQueryModelDAO<T,ID>
All Implemented Interfaces:
AccessControlDAO<T,ID>, GenericDAO<T,ID>, QueryModelDAO<T,ID>

public class MongoDBQueryModelDAO<T,ID>
extends Object
implements QueryModelDAO<T,ID>, AccessControlDAO<T,ID>

Provides a QueryModelDAO implementation for Mongo.

This QueryModelDAO implementation for MongoDB provides bi-directional ODM (Object to Document Mapping) as well as the rich query capabilities found in the core org.iternine.jeppetto.dao package. Instantiation requires a daoProperties Map that will look for the following keys (and expected values):

Key Required? Description
db Yes Instance of a configured com.mongodb.DB
collection No Name of the backing collection for this object. Defaults to the name of the entity class.
viewOf No Name of the a class of which this DAO's entity class is a view.
uniqueIndexes No List of various MongoDB index values that will be ensured to exist and must be unique.
nonUniqueIndexes No List of various MongoDB index values that will be ensured to exist and need not be unique.
optimisticLockEnabled No Boolean to indicate if instances of the tracked type should be protected by a Jeppetto-managed lock version field.
shardKeyPattern No A comma-separated string of fields that are used to determine the shard key(s) for the collection.
saveNulls No Boolean to indicate whether null fields should be included in MongoDB documents.
writeConcern No String, one of the values as indicated at http://www.mongodb.org/display/DOCS/Replica+Set+Semantics. If not specified, the DAO defaults to "SAFE".
showQueries No Boolean to indicate if executed queries should be logged. Note that logging will need to be enabled for the DAO's package as well.


Constructor Summary
protected MongoDBQueryModelDAO(Class<T> entityClass, Map<String,Object> daoProperties)
           
protected MongoDBQueryModelDAO(Class<T> entityClass, Map<String,Object> daoProperties, AccessControlContextProvider accessControlContextProvider)
           
 
Method Summary
protected  com.mongodb.DBObject augmentObjectCacheKey(com.mongodb.DBObject key)
          This method allows subclasses an opportunity to add any important data to a cache key, such as the __acl from the AccessControlMongoDAO.
 Condition buildCondition(String conditionField, ConditionType conditionType, Iterator argsIterator)
           
protected  com.mongodb.DBObject buildIdentifyingQuery(com.mongodb.DBObject dbo)
           
protected  com.mongodb.DBObject buildIdentifyingQuery(ID... ids)
           
 Projection buildProjection(String projectionField, ProjectionType projectionType, Iterator argsIterator)
           
protected  com.mongodb.DBObject[] createIdentifyingQueries(com.mongodb.DBObject dbo)
           
 void delete(T entity)
           
 void deleteById(ID id)
           
protected  void deleteByIdentifyingQuery(com.mongodb.DBObject identifyingQuery)
           
 void deleteByIds(ID... ids)
           
 void deleteUsingQueryModel(QueryModel queryModel)
           
 Iterable<T> findAll()
           
 T findById(ID id)
           
 Iterable<T> findByIds(ID... ids)
           
 T findUniqueUsingQueryModel(QueryModel queryModel)
           
 Iterable<T> findUsingQueryModel(QueryModel queryModel)
           
 void flush()
           
 AccessControlContextProvider getAccessControlContextProvider()
           
protected  Class<T> getCollectionClass()
           
protected  com.mongodb.DBCollection getDbCollection()
           
 Map<String,AccessType> getGrantedAccesses(ID id)
           
 Map<String,AccessType> getGrantedAccesses(ID id, AccessControlContext accessControlContext)
           
 void grantAccess(ID id, String accessId, AccessType accessType)
           
 void grantAccess(ID id, String accessId, AccessType accessType, AccessControlContext accessControlContext)
           
 Object projectUsingQueryModel(QueryModel queryModel)
           
 ReferenceSet<T> referenceByIds(ID... ids)
           
 ReferenceSet<T> referenceUsingQueryModel(QueryModel queryModel)
           
 void revokeAccess(ID id, String accessId)
           
 void revokeAccess(ID id, String accessId, AccessControlContext accessControlContext)
           
 void save(T entity)
           
 void save(T object, AccessControlContext accessControlContext)
           
protected  void trueRemove(com.mongodb.DBObject identifyingQuery)
           
protected  void trueSave(com.mongodb.DBObject identifyingQuery, DirtyableDBObject dbo)
           
 void updateReferences(ReferenceSet<T> referenceSet, T updateObject)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoDBQueryModelDAO

protected MongoDBQueryModelDAO(Class<T> entityClass,
                               Map<String,Object> daoProperties)

MongoDBQueryModelDAO

protected MongoDBQueryModelDAO(Class<T> entityClass,
                               Map<String,Object> daoProperties,
                               AccessControlContextProvider accessControlContextProvider)
Method Detail

findById

public T findById(ID id)
           throws NoSuchItemException,
                  JeppettoException
Specified by:
findById in interface GenericDAO<T,ID>
Throws:
NoSuchItemException
JeppettoException

findByIds

public Iterable<T> findByIds(ID... ids)
                      throws JeppettoException
Specified by:
findByIds in interface GenericDAO<T,ID>
Throws:
JeppettoException

findAll

public Iterable<T> findAll()
                    throws JeppettoException
Specified by:
findAll in interface GenericDAO<T,ID>
Throws:
JeppettoException

save

public void save(T entity)
          throws OptimisticLockException,
                 JeppettoException
Specified by:
save in interface GenericDAO<T,ID>
Throws:
OptimisticLockException
JeppettoException

delete

public void delete(T entity)
            throws JeppettoException
Specified by:
delete in interface GenericDAO<T,ID>
Throws:
JeppettoException

deleteById

public void deleteById(ID id)
                throws JeppettoException
Specified by:
deleteById in interface GenericDAO<T,ID>
Throws:
JeppettoException

deleteByIds

public void deleteByIds(ID... ids)
                 throws JeppettoException
Specified by:
deleteByIds in interface GenericDAO<T,ID>
Throws:
JeppettoException

referenceByIds

public ReferenceSet<T> referenceByIds(ID... ids)
Specified by:
referenceByIds in interface GenericDAO<T,ID>

updateReferences

public void updateReferences(ReferenceSet<T> referenceSet,
                             T updateObject)
                      throws JeppettoException
Specified by:
updateReferences in interface GenericDAO<T,ID>
Throws:
JeppettoException

flush

public void flush()
           throws JeppettoException
Specified by:
flush in interface GenericDAO<T,ID>
Throws:
JeppettoException

findUniqueUsingQueryModel

public T findUniqueUsingQueryModel(QueryModel queryModel)
                            throws NoSuchItemException,
                                   TooManyItemsException,
                                   JeppettoException
Specified by:
findUniqueUsingQueryModel in interface QueryModelDAO<T,ID>
Throws:
NoSuchItemException
TooManyItemsException
JeppettoException

findUsingQueryModel

public Iterable<T> findUsingQueryModel(QueryModel queryModel)
                                throws JeppettoException
Specified by:
findUsingQueryModel in interface QueryModelDAO<T,ID>
Throws:
JeppettoException

projectUsingQueryModel

public Object projectUsingQueryModel(QueryModel queryModel)
                              throws JeppettoException
Specified by:
projectUsingQueryModel in interface QueryModelDAO<T,ID>
Throws:
JeppettoException

deleteUsingQueryModel

public void deleteUsingQueryModel(QueryModel queryModel)
                           throws JeppettoException
Specified by:
deleteUsingQueryModel in interface QueryModelDAO<T,ID>
Throws:
JeppettoException

referenceUsingQueryModel

public ReferenceSet<T> referenceUsingQueryModel(QueryModel queryModel)
                                         throws JeppettoException
Specified by:
referenceUsingQueryModel in interface QueryModelDAO<T,ID>
Throws:
JeppettoException

buildCondition

public Condition buildCondition(String conditionField,
                                ConditionType conditionType,
                                Iterator argsIterator)
Specified by:
buildCondition in interface QueryModelDAO<T,ID>

buildProjection

public Projection buildProjection(String projectionField,
                                  ProjectionType projectionType,
                                  Iterator argsIterator)
Specified by:
buildProjection in interface QueryModelDAO<T,ID>

save

public void save(T object,
                 AccessControlContext accessControlContext)
          throws OptimisticLockException,
                 AccessControlException,
                 JeppettoException
Specified by:
save in interface AccessControlDAO<T,ID>
Throws:
OptimisticLockException
AccessControlException
JeppettoException

grantAccess

public void grantAccess(ID id,
                        String accessId,
                        AccessType accessType)
                 throws NoSuchItemException,
                        AccessControlException
Specified by:
grantAccess in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

grantAccess

public void grantAccess(ID id,
                        String accessId,
                        AccessType accessType,
                        AccessControlContext accessControlContext)
                 throws NoSuchItemException,
                        AccessControlException
Specified by:
grantAccess in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

revokeAccess

public void revokeAccess(ID id,
                         String accessId)
                  throws NoSuchItemException,
                         AccessControlException
Specified by:
revokeAccess in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

revokeAccess

public void revokeAccess(ID id,
                         String accessId,
                         AccessControlContext accessControlContext)
                  throws NoSuchItemException,
                         AccessControlException
Specified by:
revokeAccess in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

getGrantedAccesses

public Map<String,AccessType> getGrantedAccesses(ID id)
                                          throws NoSuchItemException,
                                                 AccessControlException
Specified by:
getGrantedAccesses in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

getGrantedAccesses

public Map<String,AccessType> getGrantedAccesses(ID id,
                                                 AccessControlContext accessControlContext)
                                          throws NoSuchItemException,
                                                 AccessControlException
Specified by:
getGrantedAccesses in interface AccessControlDAO<T,ID>
Throws:
NoSuchItemException
AccessControlException

getAccessControlContextProvider

public AccessControlContextProvider getAccessControlContextProvider()
Specified by:
getAccessControlContextProvider in interface AccessControlDAO<T,ID>

augmentObjectCacheKey

protected com.mongodb.DBObject augmentObjectCacheKey(com.mongodb.DBObject key)
This method allows subclasses an opportunity to add any important data to a cache key, such as the __acl from the AccessControlMongoDAO. TODO: revisit these methods...

Parameters:
key - key to augment
Returns:
augmented key

createIdentifyingQueries

protected com.mongodb.DBObject[] createIdentifyingQueries(com.mongodb.DBObject dbo)

buildIdentifyingQuery

protected final com.mongodb.DBObject buildIdentifyingQuery(com.mongodb.DBObject dbo)

buildIdentifyingQuery

protected final com.mongodb.DBObject buildIdentifyingQuery(ID... ids)

deleteByIdentifyingQuery

protected final void deleteByIdentifyingQuery(com.mongodb.DBObject identifyingQuery)

trueSave

protected final void trueSave(com.mongodb.DBObject identifyingQuery,
                              DirtyableDBObject dbo)

trueRemove

protected final void trueRemove(com.mongodb.DBObject identifyingQuery)

getDbCollection

protected final com.mongodb.DBCollection getDbCollection()

getCollectionClass

protected final Class<T> getCollectionClass()


Copyright © 2012. All Rights Reserved.