package org.mongodb.morphia.mapping;
import org.mongodb.morphia.ObjectFactory;
import org.mongodb.morphia.annotations.Reference;
import org.mongodb.morphia.logging.Logger;
import org.mongodb.morphia.logging.MorphiaLoggerFactory;
import org.mongodb.morphia.mapping.cache.DefaultEntityCacheFactory;
import org.mongodb.morphia.mapping.cache.EntityCacheFactory;
Options to control mapping behavior.
Author: Scott Hernandez
/**
* Options to control mapping behavior.
*
* @author Scott Hernandez
*/
@SuppressWarnings("deprecation")
public class MapperOptions {
private static final Logger LOG = MorphiaLoggerFactory.get(MapperOptions.class);
Deprecated: this is actually the default and proper behavior. this setting is redundant
/**
* @deprecated this is actually the default and proper behavior. this setting is redundant
*/
@Deprecated
private boolean actLikeSerializer;
private boolean ignoreFinals; //ignore final fields.
private boolean storeNulls;
private boolean storeEmpties;
private boolean useLowerCaseCollectionNames;
private boolean cacheClassLookups = false;
private boolean mapSubPackages = false;
private ObjectFactory objectFactory = new DefaultCreator(this);
private EntityCacheFactory cacheFactory = new DefaultEntityCacheFactory();
private CustomMapper embeddedMapper = new EmbeddedMapper();
private CustomMapper defaultMapper = embeddedMapper;
private CustomMapper referenceMapper = new ReferenceMapper();
private CustomMapper valueMapper = new ValueMapper();
private org.mongodb.morphia.mapping.lazy.DatastoreProvider datastoreProvider = null;
Creates a default options instance.
/**
* Creates a default options instance.
*/
public MapperOptions() {
}
Copy Constructor
Params: - options – the MapperOptions to copy
/**
* Copy Constructor
*
* @param options the MapperOptions to copy
*/
public MapperOptions(final MapperOptions options) {
setActLikeSerializer(options.isActLikeSerializer());
setIgnoreFinals(options.isIgnoreFinals());
setStoreNulls(options.isStoreNulls());
setStoreEmpties(options.isStoreEmpties());
setUseLowerCaseCollectionNames(options.isUseLowerCaseCollectionNames());
setCacheClassLookups(options.isCacheClassLookups());
setObjectFactory(options.getObjectFactory());
setCacheFactory(options.getCacheFactory());
setEmbeddedMapper(options.getEmbeddedMapper());
setDefaultMapper(options.getDefaultMapper());
setReferenceMapper(options.getReferenceMapper());
setValueMapper(options.getValueMapper());
}
Returns: the factory to create an EntityCache
/**
* @return the factory to create an EntityCache
*/
public EntityCacheFactory getCacheFactory() {
return cacheFactory;
}
Sets the factory to create an EntityCache
Params: - cacheFactory – the factory
/**
* Sets the factory to create an EntityCache
*
* @param cacheFactory the factory
*/
public void setCacheFactory(final EntityCacheFactory cacheFactory) {
this.cacheFactory = cacheFactory;
}
Returns: the DatastoreProvider Morphia should use Deprecated: unused
/**
* @return the DatastoreProvider Morphia should use
* @deprecated unused
*/
@Deprecated
public org.mongodb.morphia.mapping.lazy.DatastoreProvider getDatastoreProvider() {
return datastoreProvider;
}
Sets the DatastoreProvider Morphia should use
Params: - datastoreProvider – the DatastoreProvider to use
Deprecated: unused
/**
* Sets the DatastoreProvider Morphia should use
*
* @param datastoreProvider the DatastoreProvider to use
* @deprecated unused
*/
@Deprecated
public void setDatastoreProvider(final org.mongodb.morphia.mapping.lazy.DatastoreProvider datastoreProvider) {
LOG.warning("DatastoreProviders are no longer needed or used.");
this.datastoreProvider = datastoreProvider;
}
Returns: the mapper to use for top level entities
/**
* @return the mapper to use for top level entities
*/
public CustomMapper getDefaultMapper() {
return defaultMapper;
}
Sets the mapper to use for top level entities
Params: - pDefaultMapper – the mapper to use
/**
* Sets the mapper to use for top level entities
*
* @param pDefaultMapper the mapper to use
*/
public void setDefaultMapper(final CustomMapper pDefaultMapper) {
defaultMapper = pDefaultMapper;
}
Returns: the mapper to use for embedded entities
/**
* @return the mapper to use for embedded entities
*/
public CustomMapper getEmbeddedMapper() {
return embeddedMapper;
}
Sets the mapper to use for embedded entities
Params: - pEmbeddedMapper – the mapper to use
/**
* Sets the mapper to use for embedded entities
*
* @param pEmbeddedMapper the mapper to use
*/
public void setEmbeddedMapper(final CustomMapper pEmbeddedMapper) {
embeddedMapper = pEmbeddedMapper;
}
Returns: the factory to use when creating new instances
/**
* @return the factory to use when creating new instances
*/
public ObjectFactory getObjectFactory() {
return objectFactory;
}
Sets the ObjectFactory to use when instantiating entity classes. The default factory is a simple reflection based factory but this
could be used, e.g., to provide a Guice-based factory such as what morphia-guice provides.
Params: - objectFactory – the factory to use
/**
* Sets the ObjectFactory to use when instantiating entity classes. The default factory is a simple reflection based factory but this
* could be used, e.g., to provide a Guice-based factory such as what morphia-guice provides.
*
* @param objectFactory the factory to use
*/
public void setObjectFactory(final ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
}
See Also: Returns: the mapper to use for references
/**
* @return the mapper to use for references
* @see Reference
*/
public CustomMapper getReferenceMapper() {
return referenceMapper;
}
Sets the mapper to use for references
Params: - pReferenceMapper – the mapper to use
See Also:
/**
* Sets the mapper to use for references
*
* @param pReferenceMapper the mapper to use
* @see Reference
*/
public void setReferenceMapper(final CustomMapper pReferenceMapper) {
referenceMapper = pReferenceMapper;
}
Returns: the mapper to use when processing values
/**
* @return the mapper to use when processing values
*/
public CustomMapper getValueMapper() {
return valueMapper;
}
Sets the mapper to use when processing values
Params: - pValueMapper – the mapper to use
/**
* Sets the mapper to use when processing values
*
* @param pValueMapper the mapper to use
*/
public void setValueMapper(final CustomMapper pValueMapper) {
valueMapper = pValueMapper;
}
Returns: true if Morphia should ignore transient fields Deprecated: this is actually the default and proper behavior. this setting is redundant
/**
* @return true if Morphia should ignore transient fields
* @deprecated this is actually the default and proper behavior. this setting is redundant
*/
@Deprecated
public boolean isActLikeSerializer() {
return actLikeSerializer;
}
Instructs Morphia to follow JDK serialization semantics and ignore values marked up with the transient keyword
Params: - actLikeSerializer – true if Morphia should ignore transient fields
Deprecated: this is actually the default and proper behavior. this setting is redundant
/**
* Instructs Morphia to follow JDK serialization semantics and ignore values marked up with the transient keyword
*
* @param actLikeSerializer true if Morphia should ignore transient fields
* @deprecated this is actually the default and proper behavior. this setting is redundant
*/
@Deprecated
public void setActLikeSerializer(final boolean actLikeSerializer) {
this.actLikeSerializer = actLikeSerializer;
}
Returns: true if Morphia should cache name -> Class lookups
/**
* @return true if Morphia should cache name -> Class lookups
*/
public boolean isCacheClassLookups() {
return cacheClassLookups;
}
Sets whether Morphia should cache name -> Class lookups
Params: - cacheClassLookups – true if the lookup results should be cached
/**
* Sets whether Morphia should cache name -> Class lookups
*
* @param cacheClassLookups true if the lookup results should be cached
*/
public void setCacheClassLookups(final boolean cacheClassLookups) {
this.cacheClassLookups = cacheClassLookups;
}
Returns: true if Morphia should ignore final fields
/**
* @return true if Morphia should ignore final fields
*/
public boolean isIgnoreFinals() {
return ignoreFinals;
}
Controls if final fields are stored.
Params: - ignoreFinals – true if Morphia should ignore final fields
/**
* Controls if final fields are stored.
*
* @param ignoreFinals true if Morphia should ignore final fields
*/
public void setIgnoreFinals(final boolean ignoreFinals) {
this.ignoreFinals = ignoreFinals;
}
Returns: true if Morphia should store empty values for lists/maps/sets/arrays
/**
* @return true if Morphia should store empty values for lists/maps/sets/arrays
*/
public boolean isStoreEmpties() {
return storeEmpties;
}
Controls if Morphia should store empty values for lists/maps/sets/arrays
Params: - storeEmpties – true if Morphia should store empty values for lists/maps/sets/arrays
/**
* Controls if Morphia should store empty values for lists/maps/sets/arrays
*
* @param storeEmpties true if Morphia should store empty values for lists/maps/sets/arrays
*/
public void setStoreEmpties(final boolean storeEmpties) {
this.storeEmpties = storeEmpties;
}
Returns: true if Morphia should store null values
/**
* @return true if Morphia should store null values
*/
public boolean isStoreNulls() {
return storeNulls;
}
Controls if null are stored.
Params: - storeNulls – true if Morphia should store null values
/**
* Controls if null are stored.
*
* @param storeNulls true if Morphia should store null values
*/
public void setStoreNulls(final boolean storeNulls) {
this.storeNulls = storeNulls;
}
Returns: true if Morphia should use lower case values when calculating collection names
/**
* @return true if Morphia should use lower case values when calculating collection names
*/
public boolean isUseLowerCaseCollectionNames() {
return useLowerCaseCollectionNames;
}
Controls if default entity collection name should be lowercase.
Params: - useLowerCaseCollectionNames – true if Morphia should use lower case values when calculating collection names
/**
* Controls if default entity collection name should be lowercase.
*
* @param useLowerCaseCollectionNames true if Morphia should use lower case values when calculating collection names
*/
public void setUseLowerCaseCollectionNames(final boolean useLowerCaseCollectionNames) {
this.useLowerCaseCollectionNames = useLowerCaseCollectionNames;
}
Returns: true if Morphia should map classes from the sub-packages as well
/**
* @return true if Morphia should map classes from the sub-packages as well
*/
public boolean isMapSubPackages() {
return mapSubPackages;
}
Controls if classes from sub-packages should be mapped.
Params: - mapSubPackages – true if Morphia should map classes from the sub-packages as well
/**
* Controls if classes from sub-packages should be mapped.
* @param mapSubPackages true if Morphia should map classes from the sub-packages as well
*/
public void setMapSubPackages(final boolean mapSubPackages) {
this.mapSubPackages = mapSubPackages;
}
}