org.mongodb.morphia.dao.DAO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of morphia Show documentation
Show all versions of morphia Show documentation
Java Object Document Mapper for MongoDB
The newest version!
package org.mongodb.morphia.dao;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.QueryResults;
import org.mongodb.morphia.query.UpdateOperations;
import org.mongodb.morphia.query.UpdateResults;
import java.util.List;
/**
* Defines a basic interface for use in applications
*
* @param The Java type serviced by this DAO
* @param The Key type used by the entity
*/
public interface DAO {
/**
* @return the total count
*/
long count();
/**
* @param key The key to search with
* @param value the value to look for
* @return the count which match criteria {key:value}
*/
long count(String key, Object value);
/**
* @param query the query to use when counting
* @return the count which match the criteria
*/
long count(Query query);
/**
* Starts a query for this DAO entities type
*
* @return the query
*/
Query createQuery();
/**
* Starts a update-operations def for this DAO entities type
*
* @return a new empty UpdateOperations instance
*/
UpdateOperations createUpdateOperations();
/**
* Deletes an entity
*
* @param entity the entity to delete
* @return the results of the deletion
* @see WriteResult
*/
WriteResult delete(T entity);
/**
* Deletes an entity
*
* @param entity the entity to delete
* @param wc the WriteConcern to use when deleting
* @return the results of the deletion
* @see WriteConcern
* @see WriteResult
*/
WriteResult delete(T entity, WriteConcern wc);
/**
* Delete the entity by id value
*
* @param id the ID of the document to delete
* @return the results of the deletion
* @see WriteResult
*/
WriteResult deleteById(K id);
/**
* Delete the entity matching a query
*
* @param query the query to use when finding the documents to delete
* @return the results of the deletion
* @see WriteResult
*/
WriteResult deleteByQuery(Query query);
/**
* ensures indexed for this DAO
*/
void ensureIndexes();
/**
* checks for entities which match criteria {key:value}
*
* @param key the key to query
* @param value the value to search for
* @return true if a document is found with a key matching the value
*/
boolean exists(String key, Object value);
/**
* checks for entities which match the criteria
*
* @param query the query to use when finding the documents
* @return true if a document is found matching the query
*/
boolean exists(Query query);
/**
* Finds all the documents in the collection mapped by the entity class
*
* @return the entities
* @see #getEntityClass()
*/
QueryResults find();
/**
* Finds entities matching a query
*
* @param query the query to use when finding the documents
* @return the entities which match the criteria
*/
QueryResults find(Query query);
/**
* Finds the entities Ts
*
* @return the list of IDs
*/
List findIds();
/**
* Finds the entities Key by the criteria {key:value}
*
* @param key the key to query
* @param value the value to search for
* @return the list of IDs for documents matching the query
*/
List findIds(String key, Object value);
/**
* Finds the entities Ts by the criteria {key:value}
*
* @param query the query to use when finding the documents
* @return the list of IDs for documents matching the query
*/
List findIds(Query query);
/**
* Finds the first entity matching the query.
*
* @param key the key to query
* @param value the value to search for
* @return the entity which match criteria {key:value}
*/
T findOne(String key, Object value);
/**
* Finds the first entity matching the query.
*
* @param query the query to use when finding the documents
* @return the entity which match the criteria
*/
T findOne(Query query);
/**
* Finds the first entity's ID
*
* @return the Key of the first entity
*/
Key findOneId();
/**
* Finds the first entity's ID matching a query
*
* @param key the key to query
* @param value the value to search for
* @return the Key of the first entity
*/
Key findOneId(String key, Object value);
/**
* Finds the first entity's ID
*
* @param query the query to use when finding the documents
* @return the Key of the first entity
*/
Key findOneId(Query query);
/**
* Loads the entity by id value
*
* @param id the ID to search for
* @return the entity with the given ID or null if no document in the database has the given ID
*/
T get(K id);
/**
* @return the collection mapped by the entity class
* @see #getEntityClass()
*/
DBCollection getCollection();
/**
* @return the underlying datastore
*/
Datastore getDatastore();
/**
* The type of entities for this DAO
*
* @return the entity class
*/
Class getEntityClass();
/**
* Saves the entity; either inserting or overriding the existing document
*
* @param entity the entity to save
* @return the key of the entity
*/
Key save(T entity);
/**
* Saves the entity; either inserting or overriding the existing document
*
* @param entity the entity to save
* @param wc the WriteConcern to use when saving
* @return the key of the entity
* @see WriteConcern
*/
Key save(T entity, WriteConcern wc);
/**
* Updates all entities matched by the constraints with the modifiers supplied.
*
* @param query the query used to match the documents to update
* @param ops the update operations to perform
* @return the results of the updates
*/
UpdateResults update(Query query, UpdateOperations ops);
/**
* Updates the first entity matched by the constraints with the modifiers supplied.
*
* @param query the query used to match the document to update
* @param ops the update operations to perform
* @return the results of the update
*/
UpdateResults updateFirst(Query query, UpdateOperations ops);
}