All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.code.morphia.dao.DAO Maven / Gradle / Ivy

The newest version!
package com.google.code.morphia.dao;


import java.util.List;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Key;
import com.google.code.morphia.query.Query;
import com.google.code.morphia.query.QueryResults;
import com.google.code.morphia.query.UpdateOperations;
import com.google.code.morphia.query.UpdateResults;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;


public interface DAO {
  /**
   * Starts a query for this DAO entities type
   */
  Query createQuery();

  /**
   * Starts a update-operations def for this DAO entities type
   */
  UpdateOperations createUpdateOperations();

  /**
   * The type of entities for this DAO
   */
  Class getEntityClass();

  /**
   * Saves the entity; either inserting or overriding the existing document
   */
  Key save(T entity);

  /**
   * Saves the entity; either inserting or overriding the existing document
   */
  Key save(T entity, WriteConcern wc);

  /**
   * Updates the first entity matched by the constraints with the modifiers supplied.
   */
  UpdateResults updateFirst(Query q, UpdateOperations ops);

  /**
   * Updates all entities matched by the constraints with the modifiers supplied.
   */
  UpdateResults update(Query q, UpdateOperations ops);

  /**
   * Deletes the entity
   */
  WriteResult delete(T entity);

  /**
   * Deletes the entity
   */
  WriteResult delete(T entity, WriteConcern wc);

  /**
   * Delete the entity by id value
   */
  WriteResult deleteById(K id);

  /**
   * Saves the entities given the query
   */
  WriteResult deleteByQuery(Query q);

  /**
   * Loads the entity by id value
   */
  T get(K id);

  /**
   * Finds the entities Key by the criteria {key:value}
   */
  List findIds(String key, Object value);

  /**
   * Finds the entities Ts
   */
  List findIds();

  /**
   * Finds the entities Ts by the criteria {key:value}
   */
  List findIds(Query q);

  /**
   * checks for entities which match criteria {key:value}
   */
  boolean exists(String key, Object value);

  /**
   * checks for entities which match the criteria
   */
  boolean exists(Query q);

  /**
   * returns the total count
   */
  long count();

  /**
   * returns the count which match criteria {key:value}
   */
  long count(String key, Object value);

  /**
   * returns the count which match the criteria
   */
  long count(Query q);

  /**
   * returns the entity which match criteria {key:value}
   */
  T findOne(String key, Object value);

  /**
   * returns the entity which match the criteria
   */
  T findOne(Query q);

  /**
   * returns the entities
   */
  QueryResults find();

  /**
   * returns the entities which match the criteria
   */
  QueryResults find(Query q);

  /**
   * ensures indexed for this DAO
   */
  void ensureIndexes();

  /**
   * gets the collection
   */
  DBCollection getCollection();

  /**
   * returns the underlying datastore
   */
  Datastore getDatastore();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy