This section gives an overview the generic parameter system in BASE that is used to store annotation values, plugin configuration values, job parameter values, etc.
The parameter system is a generic system that can store almost
any kind of simple values (string, numbers, dates, etc.) and
also links to other items. It is, for example, used to store configuration
parameters to plug-ins and jobs as well as annotation values to annotatable items.
The ParameterValueData
class is an abstract base class that can hold multiple values (all must be of the
same type). Unless only a specific type of values should be stored, this is
the class that should be used when creating references for storing parameter
values. It makes it possible for a single relation to use any kind of
values or for a collection reference to mix multiple types of values.
A typical use case maps a Map
with the
parameter name as the key:
private Map<String, ParameterValueData<?>> configurationValues; /** Link parameter name with it's values. @hibernate.map table="`PluginConfigurationValues`" lazy="true" cascade="all" @hibernate.collection-key column="`pluginconfiguration_id`" @hibernate.collection-index column="`name`" type="string" length="255" @hibernate.collection-many-to-many column="`value_id`" class="net.sf.basedb.core.data.ParameterValueData" */ public Map<String, ParameterValueData<?>> getConfigurationValues() { return configurationValues; } void setConfigurationValues(Map<String, ParameterValueData<?>> configurationValues) { this.configurationValues = configurationValues; }
Now it is possible for the collection to store all types of values:
Map<String, ParameterValueData<?>> config = ... config.put("names", new StringParameterValueData("A", "B", "C")); config.put("sizes", new IntegerParameterValueData(10, 20, 30)); // When you later load those values again you have to cast // them to the correct class. List<String> names = (List<String>)config.get("names").getValues(); List<Integer> sizes = (List<Integer>)config.get("sizes").getValues();