Package dev.morphia
Class Morphia
- java.lang.Object
-
- dev.morphia.Morphia
-
public class Morphia extends java.lang.Object
- Author:
- Olafur Gauti Gudmundsson, Scott Hernandez
-
-
Constructor Summary
Constructors Constructor 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 MapperMorphia(Mapper mapper, java.util.Set<java.lang.Class> classesToMap)
Creates a Morphia instance with the given Mapper and class set.Morphia(java.util.Set<java.lang.Class> classesToMap)
Creates a Morphia instance with the given classes
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Datastore
createDatastore(com.mongodb.MongoClient mongoClient, Mapper mapper, java.lang.String dbName)
Creates a new Datastore for interacting with MongoDB using POJOsDatastore
createDatastore(com.mongodb.MongoClient mongoClient, java.lang.String dbName)
It is best to use a Mongo singleton instance here.<T> T
fromDBObject(Datastore datastore, java.lang.Class<T> entityClass, com.mongodb.DBObject dbObject)
Creates an entity and populates its state based on the dbObject given.<T> T
fromDBObject(Datastore datastore, java.lang.Class<T> entityClass, com.mongodb.DBObject dbObject, EntityCache cache)
Creates an entity and populates its state based on the dbObject given.Mapper
getMapper()
boolean
getUseBulkWriteOperations()
Deprecated.boolean
isMapped(java.lang.Class entityClass)
Check whether a specific class is mapped by this instance.boolean
isUseBulkWriteOperations()
Deprecated.Morphia
map(java.lang.Class... entityClasses)
Maps a set of classesMorphia
map(java.util.Set<java.lang.Class> entityClasses)
Maps a set of classesMorphia
mapPackage(java.lang.String packageName)
Tries to map all classes in the package specified.Morphia
mapPackage(java.lang.String packageName, boolean ignoreInvalidClasses)
Tries to map all classes in the package specified.Morphia
mapPackageFromClass(java.lang.Class clazz)
Maps all the classes found in the package to which the given class belongs.void
setUseBulkWriteOperations(boolean useBulkWriteOperations)
Deprecated.Setting this value has no value functionally or performance-wise.com.mongodb.DBObject
toDBObject(java.lang.Object entity)
Converts an entity to a DBObject.
-
-
-
Constructor Detail
-
Morphia
public Morphia()
Creates a Morphia instance with a default Mapper and an empty class set.
-
Morphia
public Morphia(Mapper mapper, java.util.Set<java.lang.Class> classesToMap)
Creates a Morphia instance with the given Mapper and class set.- Parameters:
mapper
- the Mapper to useclassesToMap
- the classes to map
-
Morphia
public Morphia(Mapper mapper)
Creates a Morphia instance with the given Mapper- Parameters:
mapper
- the Mapper to use
-
Morphia
public Morphia(java.util.Set<java.lang.Class> classesToMap)
Creates a Morphia instance with the given classes- Parameters:
classesToMap
- the classes to map
-
-
Method Detail
-
createDatastore
public Datastore createDatastore(com.mongodb.MongoClient mongoClient, java.lang.String dbName)
It is best to use a Mongo singleton instance here.- Parameters:
mongoClient
- the representations of the connection to a MongoDB instancedbName
- the name of the database- Returns:
- a Datastore that you can use to interact with MongoDB
-
createDatastore
public Datastore createDatastore(com.mongodb.MongoClient mongoClient, Mapper mapper, java.lang.String dbName)
Creates a new Datastore for interacting with MongoDB using POJOs- Parameters:
mongoClient
- the representations of the connection to a MongoDB instancemapper
- a pre-configured Mapper for your POJOsdbName
- the name of the database- Returns:
- a Datastore that you can use to interact with MongoDB
-
fromDBObject
public <T> T fromDBObject(Datastore datastore, java.lang.Class<T> entityClass, com.mongodb.DBObject dbObject)
Creates an entity and populates its state based on the dbObject given. This method is primarily an internal method. Reliance on this method may break your application in future releases.- Type Parameters:
T
- type of the entity- Parameters:
datastore
- the Datastore to use when fetching this referenceentityClass
- type to createdbObject
- the object state to use- Returns:
- the newly created and populated entity
-
fromDBObject
public <T> T fromDBObject(Datastore datastore, java.lang.Class<T> entityClass, com.mongodb.DBObject dbObject, EntityCache cache)
Creates an entity and populates its state based on the dbObject given. This method is primarily an internal method. Reliance on this method may break your application in future releases.- Type Parameters:
T
- type of the entity- Parameters:
datastore
- 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 over- Returns:
- the newly created and populated entity
-
getMapper
public Mapper getMapper()
- Returns:
- the mapper used by this instance of Morphia
-
getUseBulkWriteOperations
@Deprecated public boolean getUseBulkWriteOperations()
Deprecated.- Returns:
- false. Setting this value has no value functionally or performance-wise.
- See Also:
- Issue #1052
-
isMapped
public boolean isMapped(java.lang.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
-
isUseBulkWriteOperations
@Deprecated public boolean isUseBulkWriteOperations()
Deprecated.- Returns:
- false. Setting this value has no value functionally or performance-wise.
- See Also:
- Issue #1052
-
setUseBulkWriteOperations
@Deprecated public void setUseBulkWriteOperations(boolean useBulkWriteOperations)
Deprecated.Setting this value has no value functionally or performance-wise.Configures Morphia to use bulk writes. Only useful with MongoDB 2.6+.- Parameters:
useBulkWriteOperations
- true if Morphia should use bulk writes- See Also:
- Issue #1052
-
map
public Morphia map(java.lang.Class... entityClasses)
Maps a set of classes- Parameters:
entityClasses
- the classes to map- Returns:
- this
-
map
public Morphia map(java.util.Set<java.lang.Class> entityClasses)
Maps a set of classes- Parameters:
entityClasses
- the classes to map- Returns:
- this
-
mapPackage
public Morphia mapPackage(java.lang.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(java.lang.String packageName, boolean ignoreInvalidClasses)
Tries to map all classes in the package specified.- Parameters:
packageName
- the name of the package to processignoreInvalidClasses
- specifies whether to ignore classes in the package that cannot be mapped- Returns:
- the Morphia instance
-
mapPackageFromClass
public Morphia mapPackageFromClass(java.lang.Class clazz)
Maps all the classes found in the package to which the given class belongs.- Parameters:
clazz
- the class to use when trying to find others to map- Returns:
- this
-
toDBObject
public com.mongodb.DBObject toDBObject(java.lang.Object entity)
Converts an entity to a DBObject. This method is primarily an internal method. Reliance on this method may break your application in future releases.- Parameters:
entity
- the entity to convert- Returns:
- the DBObject
-
-