org.mongodb.morphia
Class Morphia

java.lang.Object
  extended by org.mongodb.morphia.Morphia

public class Morphia
extends Object

Author:
Olafur Gauti Gudmundsson, Scott Hernandez

Constructor Summary
Morphia()
           
Morphia(Mapper mapper)
           
Morphia(Mapper mapper, Set<Class> classesToMap)
           
Morphia(Set<Class> classesToMap)
           
 
Method Summary
 Datastore createDatastore(MongoClient mongoClient, Mapper mapper, String dbName)
          Creates a new Datastore for interacting with MongoDB using POJOs
 Datastore createDatastore(MongoClient mongoClient, String dbName)
          It is best to use a Mongo singleton instance here.
<T> T
fromDBObject(Class<T> entityClass, DBObject dbObject)
           
<T> T
fromDBObject(Class<T> entityClass, DBObject dbObject, EntityCache cache)
           
 Mapper getMapper()
           
 boolean getUseBulkWriteOperations()
           
 boolean isMapped(Class entityClass)
          Check whether a specific class is mapped by this instance.
 boolean isUseBulkWriteOperations()
           
 Morphia map(Class... entityClasses)
           
 Morphia map(Set<Class> entityClasses)
           
 Morphia mapPackage(String packageName)
          Tries to map all classes in the package specified.
 Morphia mapPackage(String packageName, boolean ignoreInvalidClasses)
          Tries to map all classes in the package specified.
 Morphia mapPackageFromClass(Class clazz)
           
 void setUseBulkWriteOperations(boolean useBulkWriteOperations)
           
 DBObject toDBObject(Object entity)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Morphia

public Morphia()

Morphia

public Morphia(Mapper mapper)

Morphia

public Morphia(Set<Class> classesToMap)

Morphia

public Morphia(Mapper mapper,
               Set<Class> classesToMap)
Method Detail

map

public Morphia map(Class... entityClasses)

map

public Morphia map(Set<Class> entityClasses)

mapPackageFromClass

public Morphia mapPackageFromClass(Class clazz)

mapPackage

public Morphia mapPackage(String packageName)
Tries to map all classes in the package specified. Fails if one of the classes is not valid for mapping.

Parameters:
packageName - the name of the package to process
Returns:
the Morphia instance

mapPackage

public Morphia mapPackage(String packageName,
                          boolean ignoreInvalidClasses)
Tries to map all classes in the package specified.

Parameters:
packageName - the name of the package to process
ignoreInvalidClasses - specifies whether to ignore classes in the package that cannot be mapped
Returns:
the Morphia instance

isMapped

public boolean isMapped(Class entityClass)
Check whether a specific class is mapped by this instance.

Parameters:
entityClass - the class we want to check
Returns:
true if the class is mapped, else false

fromDBObject

public <T> T fromDBObject(Class<T> entityClass,
                          DBObject dbObject)

fromDBObject

public <T> T fromDBObject(Class<T> entityClass,
                          DBObject dbObject,
                          EntityCache cache)

toDBObject

public DBObject toDBObject(Object entity)

getMapper

public Mapper getMapper()

createDatastore

public Datastore createDatastore(MongoClient mongoClient,
                                 String dbName)
It is best to use a Mongo singleton instance here.

Parameters:
mongoClient - the representations of the connection to a MongoDB instance
dbName - the name of the database
Returns:
a Datastore that you can use to interact with MongoDB

createDatastore

public Datastore createDatastore(MongoClient mongoClient,
                                 Mapper mapper,
                                 String dbName)
Creates a new Datastore for interacting with MongoDB using POJOs

Parameters:
mongoClient - the representations of the connection to a MongoDB instance
mapper - a pre-configured Mapper for your POJOs
dbName - the name of the database
Returns:
a Datastore that you can use to interact with MongoDB

getUseBulkWriteOperations

public boolean getUseBulkWriteOperations()

isUseBulkWriteOperations

public boolean isUseBulkWriteOperations()

setUseBulkWriteOperations

public void setUseBulkWriteOperations(boolean useBulkWriteOperations)