public class Morphia extends Object
| Constructor and Description |
|---|
Morphia()
Creates a Morphia instance with a default Mapper and an empty class set.
|
Morphia(Mapper mapper)
Creates a Morphia instance with the given Mapper
|
Morphia(Mapper mapper,
Set<Class> classesToMap)
Creates a Morphia instance with the given Mapper and class set.
|
Morphia(Set<Class> classesToMap)
Creates a Morphia instance with the given classes
|
| Modifier and Type | Method and Description |
|---|---|
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(Datastore datastore,
Class<T> entityClass,
DBObject dbObject)
Creates an entity and populates its state based on the dbObject given.
|
<T> T |
fromDBObject(Datastore datastore,
Class<T> entityClass,
DBObject dbObject,
EntityCache cache)
Creates an entity and populates its state based on the dbObject given.
|
Mapper |
getMapper() |
boolean |
getUseBulkWriteOperations() |
boolean |
isMapped(Class entityClass)
Check whether a specific class is mapped by this instance.
|
boolean |
isUseBulkWriteOperations() |
Morphia |
map(Class... entityClasses)
Maps a set of classes
|
Morphia |
map(Set<Class> entityClasses)
Maps a set of classes
|
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)
Maps all the classes found in the package to which the given class belongs.
|
void |
setUseBulkWriteOperations(boolean useBulkWriteOperations)
Configures Morphia to use bulk writes.
|
DBObject |
toDBObject(Object entity)
Converts an entity to a DBObject.
|
public Morphia()
public Morphia(Mapper mapper, Set<Class> classesToMap)
mapper - the Mapper to useclassesToMap - the classes to mappublic Morphia(Mapper mapper)
mapper - the Mapper to usepublic Datastore createDatastore(MongoClient mongoClient, String dbName)
mongoClient - the representations of the connection to a MongoDB instancedbName - the name of the databasepublic Datastore createDatastore(MongoClient mongoClient, Mapper mapper, String dbName)
mongoClient - the representations of the connection to a MongoDB instancemapper - a pre-configured Mapper for your POJOsdbName - the name of the databasepublic <T> T fromDBObject(Datastore datastore, Class<T> entityClass, DBObject dbObject)
T - type of the entitydatastore - the Datastore to use when fetching this referenceentityClass - type to createdbObject - the object state to usepublic <T> T fromDBObject(Datastore datastore, Class<T> entityClass, DBObject dbObject, EntityCache cache)
T - type of the entitydatastore - the Datastore to use when fetching this referenceentityClass - type to createdbObject - the object state to usecache - the EntityCache to use to prevent multiple loads of the same entities over and overpublic Mapper getMapper()
public boolean getUseBulkWriteOperations()
public boolean isMapped(Class entityClass)
entityClass - the class we want to checkpublic boolean isUseBulkWriteOperations()
public void setUseBulkWriteOperations(boolean useBulkWriteOperations)
useBulkWriteOperations - true if Morphia should use bulk writespublic Morphia map(Class... entityClasses)
entityClasses - the classes to mappublic Morphia map(Set<Class> entityClasses)
entityClasses - the classes to mappublic Morphia mapPackage(String packageName)
packageName - the name of the package to processpublic Morphia mapPackage(String packageName, boolean ignoreInvalidClasses)
packageName - the name of the package to processignoreInvalidClasses - specifies whether to ignore classes in the package that cannot be mappedpublic Morphia mapPackageFromClass(Class clazz)
clazz - the class to use when trying to find others to map