public abstract class PropertyManager extends Object
This handles operations at the higher functional level; an instance is created per-session and drives queries and updates in a transactional manner.
The manager ties the property schemas into one namespace; all property maps it handles must and will use one of its known schema.
The manager class needs to be registered with its namespace as key
Since a collection of properties are stored in a map, to avoid hitting the persistence store for each update - which would mean rewriting the map multiple times - the manager keeps track of dirty maps whilst serving as transaction manager. This way, when importing multiple properties targeting different elements (think setting properties for different tables), each impacted map is only rewritten once by the persistence layer during commit. This also allows multiple calls to participate to one transactions.
| Modifier and Type | Class and Description |
|---|---|
static class |
PropertyManager.MapWrapper
JEXL adapter.
|
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,PropertyMap> |
dirtyMaps
The set of dirty maps.
|
static org.slf4j.Logger |
LOGGER
The logger.
|
protected String |
namespace
This manager namespace.
|
protected PropertyStore |
store
The property map store.
|
| Modifier | Constructor and Description |
|---|---|
protected |
PropertyManager(String ns,
PropertyStore store)
Creates a manager instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
commit()
Saves all pending updates to store.
|
static PropertyManager |
create(String namespace,
PropertyStore store)
Creates an instance of manager using its declared namespace.
|
static boolean |
declare(String ns,
Class<? extends PropertyManager> pmClazz)
Declares a property manager class.
|
boolean |
dropProperties(String mapName)
Drops a property map.
|
String |
exportPropertyValue(String key)
Fetches and formats a property value.
|
protected int |
getMapNameLength(String[] keys) |
Object |
getProperty(String key)
Gets a property value.
|
Object |
getProperty(String[] keys)
Gets a property value.
|
Object |
getPropertyValue(String key)
Gets a property value.
|
Object |
getPropertyValue(String[] keys)
Gets a property value.
|
PropertySchema |
getSchema(String name)
Gets a schema by name.
|
void |
importDefaultValues(Properties importsp)
Imports a set of default values into this store"s schema.
|
protected String |
mapKey(String name)
Compose a property map key from a property map name.
|
protected String |
mapKey(String[] keys)
Compose a property map key from property key fragments.
|
protected String |
mapKey(String[] keys,
int maxkl)
Compose a property map key from property key fragments.
|
protected String |
mapName(String key)
Extract a property map name from a property map key.
|
protected String |
propertyName(String[] keys)
Compose a property name from property key fragments.
|
protected String |
propertyName(String[] keys,
int maxkl)
Compose a property name from property key fragments.
|
void |
rollback()
Forget all pending updates.
|
Object |
runScript(String src)
Runs a JEXL script using this manager as context.
|
protected PropertySchema |
schemaOf(String[] keys)
Determines the schema from the property key fragments.
|
Map<String,PropertyMap> |
selectProperties(String namePrefix,
Function<PropertyMap,PropertyMap> selector)
Selects a set of properties.
|
Map<String,PropertyMap> |
selectProperties(String namePrefix,
org.apache.commons.jexl3.JexlExpression predicate,
List<String> projectStr)
Selects a set of properties.
|
Map<String,PropertyMap> |
selectProperties(String namePrefix,
org.apache.commons.jexl3.JexlExpression predicate,
String... projectStr)
Selects a set of properties.
|
Map<String,PropertyMap> |
selectProperties(String namePrefix,
String predicateStr,
List<String> projectStr)
Selects a set of properties.
|
Map<String,PropertyMap> |
selectProperties(String namePrefix,
String predicateStr,
String... projectStr)
Selects a set of properties.
|
void |
setProperties(Map<String,?> map)
Injects a set of properties.
|
void |
setProperties(Properties map)
Imports a set of property values.
|
protected void |
setProperty(String[] keys,
Object value)
Sets a property value.
|
void |
setProperty(String key,
Object value)
Sets a property value.
|
protected String[] |
splitKey(String key)
Splits a property key into its fragments.
|
public static final org.slf4j.Logger LOGGER
protected final Map<String,PropertyMap> dirtyMaps
protected final String namespace
protected final PropertyStore store
protected PropertyManager(String ns, PropertyStore store)
store - the store instance which must use an appropriate property map factory (probably use createMap).public static boolean declare(String ns, Class<? extends PropertyManager> pmClazz)
ns - the namespacepmClazz - the property manager classpublic static PropertyManager create(String namespace, PropertyStore store) throws MetaException, NoSuchObjectException
namespace - the manager"s namespacestore - the property storeMetaException - if the manager creation failsNoSuchObjectException - if the store is null or no constructor was declaredpublic void commit()
public void rollback()
public void importDefaultValues(Properties importsp)
importsp - the propertiespublic void setProperties(Properties map)
Transactional call that requires calling commit() or rollback().
map - the properties key=valuepublic void setProperties(Map<String,?> map)
Transactional call that requires calling commit() or rollback().
map - the map of properties to inject.public void setProperty(String key, Object value)
Transactional call that requires calling commit() or rollback().
key - the property keyvalue - the property value or null to unsetpublic Object runScript(String src) throws PropertyException
src - the script sourcePropertyException - if any error occurs in JEXLpublic Object getProperty(String key)
key - the property keypublic String exportPropertyValue(String key)
key - the property keypublic Object getPropertyValue(String key)
key - the property keyprotected String[] splitKey(String key)
key - the property keypublic PropertySchema getSchema(String name)
Only used by importDefaultValues(Properties)
name - schema nameprotected PropertySchema schemaOf(String[] keys)
keys - the key fragmentsPropertySchema.NONE if no such schema is knownprotected int getMapNameLength(String[] keys)
keys - property key fragmentsprotected String mapKey(String name)
name - the property map name, may be null or emptyprotected String mapName(String key)
key - property map keyprotected String mapKey(String[] keys)
keys - the key fragmentsprotected String mapKey(String[] keys, int maxkl)
keys - the property key fragmentsmaxkl - the maximum number of fragments in the map keyprotected String propertyName(String[] keys)
keys - the key fragmentsprotected String propertyName(String[] keys, int maxkl)
keys - the key fragmentsmaxkl - the maximum number of fragments in the map namepublic Object getProperty(String[] keys)
keys - the key fragmentspublic Object getPropertyValue(String[] keys)
keys - the key fragmentspublic boolean dropProperties(String mapName)
Transactional call that requires calling commit() or rollback().
mapName - the map nameprotected void setProperty(String[] keys, Object value)
keys - the key fragmentsvalue - the new value or null if mapping should be removedpublic Map<String,PropertyMap> selectProperties(String namePrefix, String predicateStr, String... projectStr)
namePrefix - the map name prefixpredicateStr - the condition selecting mapsprojectStr - the projection property names or scriptpublic Map<String,PropertyMap> selectProperties(String namePrefix, Function<PropertyMap,PropertyMap> selector)
namePrefix - the map name prefixselector - the selector/transformer functionpublic Map<String,PropertyMap> selectProperties(String namePrefix, String predicateStr, List<String> projectStr)
namePrefix - the map name prefixpredicateStr - the condition selecting mapsprojectStr - the projection property names or scriptpublic Map<String,PropertyMap> selectProperties(String namePrefix, org.apache.commons.jexl3.JexlExpression predicate, String... projectStr)
namePrefix - the map name prefixpredicate - the condition selecting mapsprojectStr - the projection property names or scriptpublic Map<String,PropertyMap> selectProperties(String namePrefix, org.apache.commons.jexl3.JexlExpression predicate, List<String> projectStr)
namePrefix - the map name prefixpredicate - the condition selecting mapsprojectStr - the projection property names or scriptCopyright © 2024 The Apache Software Foundation. All rights reserved.