Package org.datanucleus
Class Configuration
- java.lang.Object
-
- org.datanucleus.properties.PropertyStore
-
- org.datanucleus.Configuration
-
- All Implemented Interfaces:
java.io.Serializable
public class Configuration extends PropertyStore implements java.io.Serializable
Class providing configuration for the context. Properties are defined by the context, and optionally defined in plugin.xml for any datastore/api plugins. Property values are stored in maps.- The first is the default value for the property (where a default is defined). The default comes from either the plugin defining it, or for the API being used (overrides any plugin default).
- The second is the user-provided value (where the user has provided one). This is held in the superclass PropertyStore.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Configuration.PropertyMapping
Convenience class wrapping the plugin property specification information.
-
Field Summary
Fields Modifier and Type Field Description private FrequentlyAccessedProperties
defaultFrequentProperties
private java.util.Map<java.lang.String,java.lang.Object>
defaultProperties
Map of default properties, used as a fallback.private java.util.Map<java.lang.String,java.lang.Object>
managerOverrideableProperties
private NucleusContext
nucCtx
private java.util.Map<java.lang.String,Configuration.PropertyMapping>
propertyMappings
Mapping for the properties of the plugins, PropertyMapping, keyed by the property name.private java.util.Map<java.lang.String,PropertyValidator>
propertyValidators
private static long
serialVersionUID
-
Fields inherited from class org.datanucleus.properties.PropertyStore
frequentProperties, properties
-
-
Constructor Summary
Constructors Constructor Description Configuration(NucleusContext nucCtx)
Create a configuration object for the specified NucleusContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDefaultBooleanProperty(java.lang.String name, java.lang.String internalName, java.lang.Boolean value, boolean datastore, boolean managerOverrideable)
void
addDefaultIntegerProperty(java.lang.String name, java.lang.String internalName, java.lang.Integer value, boolean datastore, boolean managerOverrideable)
void
addDefaultProperty(java.lang.String name, java.lang.String internalName, java.lang.String value, java.lang.String validatorName, boolean datastore, boolean managerOverrideable)
boolean
equals(java.lang.Object obj)
java.lang.String
getCaseSensitiveNameForPropertyName(java.lang.String propName)
Accessor for the case-sensitive name for the passed (lowercase) name.java.util.Map<java.lang.String,java.lang.Object>
getDatastoreProperties()
Convenience method to return all properties that are user-specified and should be specified on the StoreManager.java.lang.String
getInternalNameForProperty(java.lang.String name)
java.util.Set<java.lang.String>
getManagedOverrideablePropertyNames()
Returns the names of the properties that are manager overrideable (using their original cases, not lowercase).java.util.Map<java.lang.String,java.lang.Object>
getManagerOverrideableProperties()
Convenience method to return all properties that are overrideable on the PM/EM.java.util.Map<java.lang.String,java.lang.Object>
getPersistenceProperties()
Accessor for the persistence properties.java.util.Map<java.lang.String,java.lang.Object>
getPersistencePropertiesDefaults()
Accessor for the persistence properties default values.static java.util.Properties
getPropertiesFromPropertiesFile(java.lang.String filename)
Method to return the persistence properties from the specified properties file.java.lang.Object
getProperty(java.lang.String name)
Accessor for the specified property as an Object.java.util.Set<java.lang.String>
getPropertyNamesWithPrefix(java.lang.String prefix)
Accessor for all properties starting with the provided prefix.java.lang.String
getPropertyNameWithInternalPropertyName(java.lang.String propName, java.lang.String propPrefix)
Accessor for the case-sensitive (external) name for the passed (likely lowercase) name and prefix.java.util.Set<java.lang.String>
getSupportedProperties()
Accessor for the names of the supported persistence properties.protected java.lang.Object
getValueForPropertyWithValidator(java.lang.String value, java.lang.String validatorName)
int
hashCode()
boolean
hasProperty(java.lang.String name)
Accessor for whether a particular property is defined (but may be null).private boolean
isPropertyForDatastore(java.lang.String name)
Accessor for whether the specified property name should be stored with the StoreManager.void
removeDatastoreProperties()
Method that removes all properties from this store that are marked as "datastore".void
setDefaultProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Method to set the persistence property defaults based on what is defined for plugins.void
setPersistenceProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Set the properties for this configuration.void
setPropertiesUsingFile(java.lang.String filename)
Method to set the persistence properties using those defined in a file.void
setProperty(java.lang.String name, java.lang.Object value)
Convenience method to set a persistence property.void
validatePropertyValue(java.lang.String name, java.lang.Object value)
private void
validatePropertyValue(java.lang.String name, java.lang.Object value, java.lang.String validatorName)
Convenience method to validate the value for a property using the provided validator.-
Methods inherited from class org.datanucleus.properties.PropertyStore
getBooleanObjectProperty, getBooleanProperty, getBooleanProperty, getFrequentProperties, getIntProperty, getStringProperty, hasPropertyNotNull, setPropertyInternal
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
nucCtx
private NucleusContext nucCtx
-
propertyMappings
private java.util.Map<java.lang.String,Configuration.PropertyMapping> propertyMappings
Mapping for the properties of the plugins, PropertyMapping, keyed by the property name.
-
defaultProperties
private java.util.Map<java.lang.String,java.lang.Object> defaultProperties
Map of default properties, used as a fallback. Key is lower-case.
-
propertyValidators
private java.util.Map<java.lang.String,PropertyValidator> propertyValidators
-
managerOverrideableProperties
private volatile java.util.Map<java.lang.String,java.lang.Object> managerOverrideableProperties
-
defaultFrequentProperties
private FrequentlyAccessedProperties defaultFrequentProperties
-
-
Constructor Detail
-
Configuration
public Configuration(NucleusContext nucCtx)
Create a configuration object for the specified NucleusContext. Initialises all basic properties with suitable defaults, including any specified in meta-data in plugins.- Parameters:
nucCtx
- NucleusContext
-
-
Method Detail
-
getSupportedProperties
public java.util.Set<java.lang.String> getSupportedProperties()
Accessor for the names of the supported persistence properties.- Returns:
- The persistence properties that we support
-
getDatastoreProperties
public java.util.Map<java.lang.String,java.lang.Object> getDatastoreProperties()
Convenience method to return all properties that are user-specified and should be specified on the StoreManager.- Returns:
- Datastore properties
-
removeDatastoreProperties
public void removeDatastoreProperties()
Method that removes all properties from this store that are marked as "datastore".
-
isPropertyForDatastore
private boolean isPropertyForDatastore(java.lang.String name)
Accessor for whether the specified property name should be stored with the StoreManager.- Parameters:
name
- Name of the property- Returns:
- Whether it is for the datastore
-
getInternalNameForProperty
public java.lang.String getInternalNameForProperty(java.lang.String name)
-
getManagerOverrideableProperties
public java.util.Map<java.lang.String,java.lang.Object> getManagerOverrideableProperties()
Convenience method to return all properties that are overrideable on the PM/EM.- Returns:
- PM/EM overrideable properties
-
getManagedOverrideablePropertyNames
public java.util.Set<java.lang.String> getManagedOverrideablePropertyNames()
Returns the names of the properties that are manager overrideable (using their original cases, not lowercase).- Returns:
- The supported manager-overrideable property names
-
getPropertyNameWithInternalPropertyName
public java.lang.String getPropertyNameWithInternalPropertyName(java.lang.String propName, java.lang.String propPrefix)
Accessor for the case-sensitive (external) name for the passed (likely lowercase) name and prefix.- Parameters:
propName
- The (likely lowercase) namepropPrefix
- The prefix for the property name- Returns:
- The case-sensitive (external) property name
-
getCaseSensitiveNameForPropertyName
public java.lang.String getCaseSensitiveNameForPropertyName(java.lang.String propName)
Accessor for the case-sensitive name for the passed (lowercase) name. Works on the basis that the propertyMappings keys are stored in the case-senistive form.- Parameters:
propName
- The (lowercase) name- Returns:
- Case sensitive name
-
setDefaultProperties
public void setDefaultProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Method to set the persistence property defaults based on what is defined for plugins. This should only be called after the other setDefaultProperties method is called, which sets up the mappings- Parameters:
props
- Properties to use in the default set
-
addDefaultBooleanProperty
public void addDefaultBooleanProperty(java.lang.String name, java.lang.String internalName, java.lang.Boolean value, boolean datastore, boolean managerOverrideable)
-
addDefaultIntegerProperty
public void addDefaultIntegerProperty(java.lang.String name, java.lang.String internalName, java.lang.Integer value, boolean datastore, boolean managerOverrideable)
-
addDefaultProperty
public void addDefaultProperty(java.lang.String name, java.lang.String internalName, java.lang.String value, java.lang.String validatorName, boolean datastore, boolean managerOverrideable)
-
getValueForPropertyWithValidator
protected java.lang.Object getValueForPropertyWithValidator(java.lang.String value, java.lang.String validatorName)
-
hasProperty
public boolean hasProperty(java.lang.String name)
Description copied from class:PropertyStore
Accessor for whether a particular property is defined (but may be null).- Overrides:
hasProperty
in classPropertyStore
- Parameters:
name
- Property name- Returns:
- Whether the property is defined
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
Accessor for the specified property as an Object. Returns user-specified value if provided, otherwise the default value, otherwise null.- Overrides:
getProperty
in classPropertyStore
- Parameters:
name
- Name of the property- Returns:
- Value for the property
-
setPropertiesUsingFile
public void setPropertiesUsingFile(java.lang.String filename)
Method to set the persistence properties using those defined in a file.- Parameters:
filename
- Name of the file containing the properties
-
getPersistencePropertiesDefaults
public java.util.Map<java.lang.String,java.lang.Object> getPersistencePropertiesDefaults()
Accessor for the persistence properties default values. This returns the defaulted properties- Returns:
- The persistence properties
-
getPersistenceProperties
public java.util.Map<java.lang.String,java.lang.Object> getPersistenceProperties()
Accessor for the persistence properties. This returns just the user-supplied properties, not the defaulted properties- Returns:
- The persistence properties
-
getPropertyNamesWithPrefix
public java.util.Set<java.lang.String> getPropertyNamesWithPrefix(java.lang.String prefix)
Accessor for all properties starting with the provided prefix.- Parameters:
prefix
- Prefix (lowercase, since all properties are stored in lowercase)- Returns:
- The properties with this prefix
-
setPersistenceProperties
public void setPersistenceProperties(java.util.Map<java.lang.String,java.lang.Object> props)
Set the properties for this configuration. Note : this has this name so it has a getter/setter pair for use by things like Spring.- Parameters:
props
- The persistence properties- See Also:
getPersistenceProperties()
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value)
Convenience method to set a persistence property. Uses any validator defined for the property to govern whether the value is suitable.- Parameters:
name
- Name of the propertyvalue
- Value
-
validatePropertyValue
public void validatePropertyValue(java.lang.String name, java.lang.Object value)
-
validatePropertyValue
private void validatePropertyValue(java.lang.String name, java.lang.Object value, java.lang.String validatorName)
Convenience method to validate the value for a property using the provided validator.- Parameters:
name
- The property namevalue
- The valuevalidatorName
- Name of the validator class- Throws:
java.lang.IllegalArgumentException
- if doesnt validate correctly
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getPropertiesFromPropertiesFile
public static java.util.Properties getPropertiesFromPropertiesFile(java.lang.String filename)
Method to return the persistence properties from the specified properties file. The lines of the file will be of formatmypropertyname=myvalue
- Parameters:
filename
- Name of the file containing the properties- Returns:
- the Persistence Properties in this file
- Throws:
NucleusUserException
- if file not readable
-
-