com.google.code.morphia
Interface Datastore

All Known Subinterfaces:
AdvancedDatastore
All Known Implementing Classes:
DatastoreImpl

public interface Datastore

Datastore interface to get/delete/save objects


Method Summary
<T> Query<T>
createQuery(Class<T> kind)
          Returns a new query bound to the kind (a specific DBCollection)
<T> UpdateOperations<T>
createUpdateOperations(Class<T> kind)
          The builder for all update operations
<T,V> void
delete(Class<T> clazz, Iterable<V> ids)
          Deletes the given entities (by id)
<T,V> void
delete(Class<T> clazz, V id)
          Deletes the given entity (by id)
<T> void
delete(Query<T> q)
          Deletes the given entities based on the query
<T> void
delete(Query<T> q, com.mongodb.WriteConcern wc)
          Deletes the given entities based on the query, with the WriteConcern
<T> void
delete(T entity)
          Deletes the given entity (by @Id)
<T> void
delete(T entity, com.mongodb.WriteConcern wc)
          Deletes the given entity (by @Id), with the WriteConcern
 void ensureCaps()
          ensure capped DBCollections for Entity(s)
<T> void
ensureIndex(Class<T> clazz, IndexFieldDef... fields)
          Deprecated. 
<T> void
ensureIndex(Class<T> clazz, String fields)
          Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})
<T> void
ensureIndex(Class<T> clazz, String field, IndexDirection dir)
          Ensures (creating if necessary) the index and direction
<T> void
ensureIndex(Class<T> clazz, String name, IndexFieldDef[] fields, boolean unique, boolean dropDupsOnCreate)
          Deprecated. 
<T> void
ensureIndex(Class<T> clazz, String name, String fields, boolean unique, boolean dropDupsOnCreate)
          Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})
 void ensureIndexes()
          Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes)
 void ensureIndexes(boolean background)
          Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes), possibly in the background
<T> void
ensureIndexes(Class<T> clazz)
          Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes)
<T> void
ensureIndexes(Class<T> clazz, boolean background)
          Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes), possibly in the background
 Key<?> exists(Object keyOrEntity)
          Does a query to check if the keyOrEntity exists in mongodb
<T> Query<T>
find(Class<T> clazz)
          Find all instances by type
<T,V> Query<T>
find(Class<T> clazz, String property, V value)
           Find all instances by collectionName, and filter property.
<T,V> Query<T>
find(Class<T> clazz, String property, V value, int offset, int size)
           Find all instances by collectionName, and filter property.
<T> T
findAndDelete(Query<T> q)
          Deletes the given entities based on the query (first item only).
<T> T
findAndModify(Query<T> q, UpdateOperations<T> ops)
          Find the first Entity from the Query, and modify it.
<T> T
findAndModify(Query<T> q, UpdateOperations<T> ops, boolean oldVersion)
          Find the first Entity from the Query, and modify it.
<T> T
findAndModify(Query<T> q, UpdateOperations<T> ops, boolean oldVersion, boolean createIfMissing)
          Find the first Entity from the Query, and modify it.
<T,V> Query<T>
get(Class<T> clazz, Iterable<V> ids)
          Find the given entities (by id); shorthand for find("_id in", ids)
<T,V> T
get(Class<T> clazz, V id)
          Find the given entity (by id); shorthand for find("_id ", id)
<T> T
get(T entity)
          Find the given entity (by collectionName/id); think of this as refresh
<T> T
getByKey(Class<T> clazz, Key<T> key)
          Find the given entity (by collectionName/id);
<T> List<T>
getByKeys(Class<T> clazz, Iterable<Key<T>> keys)
          Find the given entities (by id), verifying they are of the correct type; shorthand for find("_id in", ids)
<T> List<T>
getByKeys(Iterable<Key<T>> keys)
          Find the given entities (by id); shorthand for find("_id in", ids)
 com.mongodb.DBCollection getCollection(Class<?> c)
           
<T> long
getCount(Class<T> clazz)
          Gets the count this kind (DBCollection)
<T> long
getCount(Query<T> query)
          Gets the count of items returned by this query; same as query.countAll()
<T> long
getCount(T entity)
          Gets the count this kind (DBCollection)
 com.mongodb.DB getDB()
           
 com.mongodb.WriteConcern getDefaultWriteConcern()
           
<T> Key<T>
getKey(T entity)
          Creates a (type-safe) reference to the entity; if stored this will become a DBRef
 com.mongodb.Mongo getMongo()
           
<T> MapreduceResults<T>
mapReduce(MapreduceType type, Query q, String map, String reduce, String finalize, Map<String,Object> scopeFields, Class<T> outputType)
           
<T> Key<T>
merge(T entity)
          Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.
<T> Key<T>
merge(T entity, com.mongodb.WriteConcern wc)
          Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.
<T> Iterable<Key<T>>
save(Iterable<T> entities)
          Saves the entities (Objects) and updates the @Id field
<T> Iterable<Key<T>>
save(Iterable<T> entities, com.mongodb.WriteConcern wc)
          Saves the entities (Objects) and updates the @Id field, with the WriteConcern
<T> Iterable<Key<T>>
save(T... entities)
          Saves the entities (Objects) and updates the @Id field
<T> Key<T>
save(T entity)
          Saves the entity (Object) and updates the @Id field
<T> Key<T>
save(T entity, com.mongodb.WriteConcern wc)
          Saves the entity (Object) and updates the @Id field, with the WriteConcern
 void setDefaultWriteConcern(com.mongodb.WriteConcern wc)
           
<T> UpdateResults<T>
update(Key<T> key, UpdateOperations<T> ops)
          updates the entity with the operations; this is an atomic operation
<T> UpdateResults<T>
update(Query<T> query, UpdateOperations<T> ops)
          updates all entities found with the operations; this is an atomic operation per entity
<T> UpdateResults<T>
update(Query<T> query, UpdateOperations<T> ops, boolean createIfMissing)
          updates all entities found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity
<T> UpdateResults<T>
update(Query<T> query, UpdateOperations<T> ops, boolean createIfMissing, com.mongodb.WriteConcern wc)
           
<T> UpdateResults<T>
update(T ent, UpdateOperations<T> ops)
          updates the entity with the operations; this is an atomic operation
<T> UpdateResults<T>
updateFirst(Query<T> query, T entity, boolean createIfMissing)
          updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity
<T> UpdateResults<T>
updateFirst(Query<T> query, UpdateOperations<T> ops)
          updates the first entity found with the operations; this is an atomic operation
<T> UpdateResults<T>
updateFirst(Query<T> query, UpdateOperations<T> ops, boolean createIfMissing)
          updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity
<T> UpdateResults<T>
updateFirst(Query<T> query, UpdateOperations<T> ops, boolean createIfMissing, com.mongodb.WriteConcern wc)
           
 

Method Detail

getKey

<T> Key<T> getKey(T entity)
Creates a (type-safe) reference to the entity; if stored this will become a DBRef


exists

Key<?> exists(Object keyOrEntity)
Does a query to check if the keyOrEntity exists in mongodb


delete

<T,V> void delete(Class<T> clazz,
                  V id)
Deletes the given entity (by id)


delete

<T,V> void delete(Class<T> clazz,
                  Iterable<V> ids)
Deletes the given entities (by id)


delete

<T> void delete(Query<T> q)
Deletes the given entities based on the query


delete

<T> void delete(Query<T> q,
                com.mongodb.WriteConcern wc)
Deletes the given entities based on the query, with the WriteConcern


delete

<T> void delete(T entity)
Deletes the given entity (by @Id)


delete

<T> void delete(T entity,
                com.mongodb.WriteConcern wc)
Deletes the given entity (by @Id), with the WriteConcern


find

<T> Query<T> find(Class<T> clazz)
Find all instances by type


find

<T,V> Query<T> find(Class<T> clazz,
                    String property,
                    V value)

Find all instances by collectionName, and filter property.

This is the same as: find(clazzOrEntity).filter(property, value);


find

<T,V> Query<T> find(Class<T> clazz,
                    String property,
                    V value,
                    int offset,
                    int size)

Find all instances by collectionName, and filter property.

This is the same as: find(clazzOrEntity).filter(property, value).offset(offset).limit(size);


get

<T,V> Query<T> get(Class<T> clazz,
                   Iterable<V> ids)
Find the given entities (by id); shorthand for find("_id in", ids)


get

<T,V> T get(Class<T> clazz,
            V id)
Find the given entity (by id); shorthand for find("_id ", id)


get

<T> T get(T entity)
Find the given entity (by collectionName/id); think of this as refresh


getByKeys

<T> List<T> getByKeys(Class<T> clazz,
                      Iterable<Key<T>> keys)
Find the given entities (by id), verifying they are of the correct type; shorthand for find("_id in", ids)


getByKeys

<T> List<T> getByKeys(Iterable<Key<T>> keys)
Find the given entities (by id); shorthand for find("_id in", ids)


getByKey

<T> T getByKey(Class<T> clazz,
               Key<T> key)
Find the given entity (by collectionName/id);


getCount

<T> long getCount(T entity)
Gets the count this kind (DBCollection)


getCount

<T> long getCount(Class<T> clazz)
Gets the count this kind (DBCollection)


getCount

<T> long getCount(Query<T> query)
Gets the count of items returned by this query; same as query.countAll()


save

<T> Iterable<Key<T>> save(Iterable<T> entities)
Saves the entities (Objects) and updates the @Id field


save

<T> Iterable<Key<T>> save(Iterable<T> entities,
                          com.mongodb.WriteConcern wc)
Saves the entities (Objects) and updates the @Id field, with the WriteConcern


save

<T> Iterable<Key<T>> save(T... entities)
Saves the entities (Objects) and updates the @Id field


save

<T> Key<T> save(T entity)
Saves the entity (Object) and updates the @Id field


save

<T> Key<T> save(T entity,
                com.mongodb.WriteConcern wc)
Saves the entity (Object) and updates the @Id field, with the WriteConcern


merge

<T> Key<T> merge(T entity)
Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.


merge

<T> Key<T> merge(T entity,
                 com.mongodb.WriteConcern wc)
Work as if you did an update with each field in the entity doing a $set; Only at the top level of the entity.


update

<T> UpdateResults<T> update(T ent,
                            UpdateOperations<T> ops)
updates the entity with the operations; this is an atomic operation


update

<T> UpdateResults<T> update(Key<T> key,
                            UpdateOperations<T> ops)
updates the entity with the operations; this is an atomic operation


update

<T> UpdateResults<T> update(Query<T> query,
                            UpdateOperations<T> ops)
updates all entities found with the operations; this is an atomic operation per entity


update

<T> UpdateResults<T> update(Query<T> query,
                            UpdateOperations<T> ops,
                            boolean createIfMissing)
updates all entities found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity


update

<T> UpdateResults<T> update(Query<T> query,
                            UpdateOperations<T> ops,
                            boolean createIfMissing,
                            com.mongodb.WriteConcern wc)

updateFirst

<T> UpdateResults<T> updateFirst(Query<T> query,
                                 UpdateOperations<T> ops)
updates the first entity found with the operations; this is an atomic operation


updateFirst

<T> UpdateResults<T> updateFirst(Query<T> query,
                                 UpdateOperations<T> ops,
                                 boolean createIfMissing)
updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity


updateFirst

<T> UpdateResults<T> updateFirst(Query<T> query,
                                 UpdateOperations<T> ops,
                                 boolean createIfMissing,
                                 com.mongodb.WriteConcern wc)

updateFirst

<T> UpdateResults<T> updateFirst(Query<T> query,
                                 T entity,
                                 boolean createIfMissing)
updates the first entity found with the operations, if nothing is found insert the update as an entity if "createIfMissing" is true; this is an atomic operation per entity


findAndDelete

<T> T findAndDelete(Query<T> q)
Deletes the given entities based on the query (first item only).

Returns:
the deleted Entity

findAndModify

<T> T findAndModify(Query<T> q,
                    UpdateOperations<T> ops)
Find the first Entity from the Query, and modify it.

Returns:
The modified Entity (the result of the update)

findAndModify

<T> T findAndModify(Query<T> q,
                    UpdateOperations<T> ops,
                    boolean oldVersion)
Find the first Entity from the Query, and modify it.

Parameters:
q - the query to find the Entity with; You are not allowed to offset/skip in the query.
oldVersion - indicated the old version of the Entity should be returned
Returns:
The Entity (the result of the update if oldVersion is false)

findAndModify

<T> T findAndModify(Query<T> q,
                    UpdateOperations<T> ops,
                    boolean oldVersion,
                    boolean createIfMissing)
Find the first Entity from the Query, and modify it.

Parameters:
q - the query to find the Entity with; You are not allowed to offset/skip in the query.
oldVersion - indicated the old version of the Entity should be returned
createIfMissing - if the query returns no results, then a new object will be created (sets upsert=true)
Returns:
The Entity (the result of the update if oldVersion is false)

mapReduce

<T> MapreduceResults<T> mapReduce(MapreduceType type,
                                  Query q,
                                  String map,
                                  String reduce,
                                  String finalize,
                                  Map<String,Object> scopeFields,
                                  Class<T> outputType)

createUpdateOperations

<T> UpdateOperations<T> createUpdateOperations(Class<T> kind)
The builder for all update operations


createQuery

<T> Query<T> createQuery(Class<T> kind)
Returns a new query bound to the kind (a specific DBCollection)


ensureIndex

<T> void ensureIndex(Class<T> clazz,
                     String field,
                     IndexDirection dir)
Ensures (creating if necessary) the index and direction


ensureIndex

@Deprecated
<T> void ensureIndex(Class<T> clazz,
                                IndexFieldDef... fields)
Deprecated. 

Ensures (creating if necessary) the index including the field(s) + directions


ensureIndex

@Deprecated
<T> void ensureIndex(Class<T> clazz,
                                String name,
                                IndexFieldDef[] fields,
                                boolean unique,
                                boolean dropDupsOnCreate)
Deprecated. 

Ensures (creating if necessary) the index including the field(s) + directions


ensureIndex

<T> void ensureIndex(Class<T> clazz,
                     String fields)
Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})


ensureIndex

<T> void ensureIndex(Class<T> clazz,
                     String name,
                     String fields,
                     boolean unique,
                     boolean dropDupsOnCreate)
Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})


ensureIndexes

void ensureIndexes()
Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes)


ensureIndexes

void ensureIndexes(boolean background)
Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes), possibly in the background


ensureIndexes

<T> void ensureIndexes(Class<T> clazz)
Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes)


ensureIndexes

<T> void ensureIndexes(Class<T> clazz,
                       boolean background)
Ensures (creating if necessary) the indexes found during class mapping (using @Indexed, @Indexes), possibly in the background


ensureCaps

void ensureCaps()
ensure capped DBCollections for Entity(s)


getDB

com.mongodb.DB getDB()

getMongo

com.mongodb.Mongo getMongo()

getCollection

com.mongodb.DBCollection getCollection(Class<?> c)

getDefaultWriteConcern

com.mongodb.WriteConcern getDefaultWriteConcern()

setDefaultWriteConcern

void setDefaultWriteConcern(com.mongodb.WriteConcern wc)


Copyright © 2011. All Rights Reserved.