public class DatabaseCurrent extends AbstractDataCollector implements Initializable, ExitCleaning
SensorRepository to a postgresql database.
The mapping of sensor names to data events provided by the repository is
used
in the following way. Mappings pointed to with the KEY_PRINCIPAL
property are key-traversed. Each key found is used in the data map to
grab a DataEvent which is then assigned to the database field
given by the value mapped to. For this map, the physical value is used.
The structure of the KEY_MINIMA and KEY_MAXIMA tables
is similar, but here either the minimal or the maximal physical value
encountered is used. All mappings obtained are combined in a mapping of
fields to float values, unless specified differently in the
KEY_FORMAT mapping, where data base fields might be mapped to java
class names. Whenever a sql-field is found in this mapping, the mapped value
is taken as a java class name. A new instance of this class is then
constructed using a single-string constructor. If no mapping is found, the
default class KEY_DATACLASS is used.
The DataEvent.getTimeOfMeasure() is entered
with the KEY_DATEFIELD. The current weather condition is inserted
as a string using the KEY_WEATHERFIELD sql field.
The mapping finally obtained is inserted
into the database with the GenericSql#insert method.
On 2014, 21th Oct, 13:10 UTC, the digital measurements had been replaced
by analog ones, 0.0175 corresponding roughly to digital 1.| Modifier and Type | Field and Description |
|---|---|
private static int |
DATABASESHUTDOWN
The default priority of the sql&weather shutdown.
|
private Class<?> |
datadef
The default class to use if no mapping is specified.
|
private static String |
DEFBADFLAG
The default setting of the bad-weather indicator.
|
private static Class<Float> |
DEFDATACLASS
The default data class for sensor data.
|
private static String |
DEFDATEFIELD
The default binding name of the weather trigger.
|
private static String |
DEFGOODFLAG
The default setting of the non-valid-reading indicator.
|
private static long |
DEFINTERVAL
The default notification period in ms.
|
private static String |
DEFMAXIMA
The default mapping of STELLA sensor maxima to sql fields.
|
private static String |
DEFPRINCIPAL
The default mapping of STELLA sensor names to sql fields.
|
private static boolean |
DEFSTRICT
The default adding to file behaviour on incomplete sets.
|
private Map<String,Constructor<?>> |
format
The mapping of sql field names to java constructors.
|
static String |
KEY_BADFLAG
The key to the bad-weather string.
|
static String |
KEY_DATACLASS
The default data class to use if no mapping is found in KEY_FORMAT.
|
static String |
KEY_DATEFIELD
The key to the sql date-field name.
|
static String |
KEY_DEVIATION
The mapping of STELLA sensor names to sql data fields.
|
static String |
KEY_FORMAT
The mapping of sql-field names to the java data types.
|
static String |
KEY_GOODFLAG
The key to the good-weather string.
|
static String |
KEY_MAXIMA
The mapping of STELLA sensor maximas to sql data fields.
|
static String |
KEY_MINIMA
The mapping of STELLA sensor minimas to sql data fields.
|
static String |
KEY_PRINCIPAL
The mapping of STELLA sensor names to sql data fields.
|
static String |
KEY_STRICT
If true, only data sets containing all sensors are writtn.
|
static String |
KEY_WEATHERFIELD
The key to the sql weather-field name.
|
private Map<String,String> |
maxima
The mapping of STELLA sensors maximas to sql field names.
|
private Map<String,String> |
minima
The mapping of STELLA sensors minimas to sql field names.
|
private Map<String,String> |
principal
The mapping of STELLA sensors values to sql field names.
|
private Map<String,String> |
sigma
The mapping of STELLA sensors standard deviations to sql fields.
|
private EnvironmentSql |
sql
The database access object.
|
private Map<String,DataEvent> |
validread
A mapping of sensor names to last valid readings.
|
KEY_CLASS, KEY_INTERVAL, KEY_RMIDATACOLLECTKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORCONFIG| Constructor and Description |
|---|
DatabaseCurrent(Map<String,String> prop)
Constructs a new database collector.
|
| Modifier and Type | Method and Description |
|---|---|
void |
exit()
Performs an orderly exit by invoking the exit methods of the
database and the weather trigger.
|
private DataEvent |
getDataEvent(String sensor,
Map<String,DataEvent> data)
Checks the data event found in the sensor-name-to-data map supplied for
validity.
|
long |
getInterval()
Returns the notification interval.
|
private Object |
getSqlEntry(Object sqlfield,
String init)
Returns a new instance of a data sensor measurement, as an instance of
KEY_DATACLASS or, if found in KEY_FORMAT, as an
instance of the appropriate type. |
void |
init()
Initializes the database current object as well as the database access
object.
|
private boolean |
initSql()
Initializes the sql-connection.
|
void |
processData(Map<String,DataEvent> sensor,
boolean weather)
The file collector writes out all the data it received in a single
file.
|
createDataCollectoraugment, augment, augment, augment, augment, clone, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, initProperties, isNew, parseObject, parseObject, reload, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringProperties, toStringpublic static final String KEY_PRINCIPAL
public static final String KEY_DEVIATION
public static final String KEY_MINIMA
public static final String KEY_MAXIMA
public static final String KEY_FORMAT
public static final String KEY_DATACLASS
public static final String KEY_DATEFIELD
public static final String KEY_WEATHERFIELD
public static final String KEY_BADFLAG
public static final String KEY_GOODFLAG
public static final String KEY_STRICT
private static final long DEFINTERVAL
private static final String DEFPRINCIPAL
private static final String DEFMAXIMA
private static final String DEFDATEFIELD
private static final String DEFBADFLAG
private static final String DEFGOODFLAG
private static final boolean DEFSTRICT
private static final int DATABASESHUTDOWN
private Map<String,String> principal
private Map<String,String> sigma
private Map<String,Constructor<?>> format
private EnvironmentSql sql
private Class<?> datadef
public DatabaseCurrent(Map<String,String> prop)
GenericSql class must also be
present here if non-default values are wanted. Additionally, the weather
trigger stub is constructed here with the generic properties of the
collector.public void init()
principal, minima, and
maxima) are assigned. Additionally, the format look-up table
is constructed using the class names pointed to in the
KEY_FORMAT property to java classes. Only classes found that
also support a single-string constructor are used.init in interface Initializableprivate boolean initSql()
public void exit()
exit in interface ExitCleaningpublic long getInterval()
getInterval in interface DataCollectingpublic void processData(Map<String,DataEvent> sensor, boolean weather)
processData in interface DataCollectingsensor - Mapping sensor names to data events.weather - True if current weather is good.private DataEvent getDataEvent(String sensor, Map<String,DataEvent> data)
private Object getSqlEntry(Object sqlfield, String init)
KEY_DATACLASS or, if found in KEY_FORMAT, as an
instance of the appropriate type. The class used to instantiate a new
object must have a single-string constructor. If everything fails a new
string using the second string passed over as a source is returned.sqlfield - The name of the database field.init - The value with which the class is to be instantiated.