|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.PropertyContainer
util.PropertyResources
util.PropertyBundles
mysql.SensorSql
public class SensorSql
A class that provides data base access to weather sensor data. It allows
inserting and retrieval of a DataEvents from a postgresql
database.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class util.PropertyResources |
|---|
PropertyResources.URLResource |
| Field Summary | |
|---|---|
private Connection |
db
The connection to the database. |
private static String |
DEFBRIDGE
The default JDBC-postgres bridge class. |
private static String |
DEFCONNECT
The default driver-specific connection string. |
private static SimpleDateFormat |
DEFDATEFORMAT
The default date format . |
private static String |
DEFPASSWORD
The default password used for identifying the user. |
private static String |
DEFTABLE
The default name of the table to use in database queries. |
private static String |
DEFUSER
The default user name to identify the class on the database. |
private Statement |
execute
The executional statement. |
static String |
KEY_BRIDGE
The class name of the JDBC-postgres bridge. |
static String |
KEY_CONNECT
The driver-specific connection string. |
static String |
KEY_DATEFORMAT
The date formatter to use. |
static String |
KEY_PASSWORD
The password used for identifying the user. |
static String |
KEY_TABLE
The name of the table to use in database queries. |
static String |
KEY_USER
The user name to identify the class on the database. |
private static boolean |
LOADED
True, if driver class has been loaded to avoid overhead. |
| Fields inherited from class util.PropertyBundles |
|---|
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES |
| Fields inherited from class util.PropertyResources |
|---|
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset |
| Fields inherited from class util.PropertyContainer |
|---|
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR |
| Fields inherited from interface util.ResourceSupplying |
|---|
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME |
| Fields inherited from interface util.PropertySupplying |
|---|
CONFIG, KEY_CLASS |
| Constructor Summary | |
|---|---|
SensorSql(Map prop)
Constructs a new sql-db access object. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the sensor database. |
private void |
closeDatabase()
Closes the connection. |
private void |
closeStatement()
Closes the statement. |
private void |
createStatement()
Creates the executable statement. |
private String |
getDatabaseEntry(Object val)
Formats the argument to allow it to be entered into a normal database. |
void |
init()
Initializes the sensor-data to SQL-DB access. |
void |
insert(Map data)
Inserts new data into the database. |
void |
open()
Opens the sensor database. |
private void |
openDatabase()
Opens the connection to the database. |
void |
replace(Map data,
String where)
Replaces data in the database. |
ResultSet |
retrieve(List fields,
String where)
Returns the result of a database query. |
| Methods inherited from class util.PropertyBundles |
|---|
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource |
| Methods inherited from class util.PropertyResources |
|---|
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet |
| Methods inherited from class util.PropertyContainer |
|---|
augment, augment, augment, 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, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface util.ResourceSupplying |
|---|
getResource, getResourceAsStream, getResources |
| Methods inherited from interface util.PropertySupplying |
|---|
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties |
| Field Detail |
|---|
public static final String KEY_BRIDGE
public static final String KEY_CONNECT
public static final String KEY_USER
public static final String KEY_PASSWORD
public static final String KEY_TABLE
public static final String KEY_DATEFORMAT
private static final String DEFBRIDGE
private static final String DEFCONNECT
private static final String DEFUSER
private static final String DEFPASSWORD
private static final String DEFTABLE
private static final SimpleDateFormat DEFDATEFORMAT
private static boolean LOADED
private Connection db
private Statement execute
| Constructor Detail |
|---|
public SensorSql(Map prop)
init() method occurs.
| Method Detail |
|---|
public void init()
KEY_BRIDGE, is loaded.
init in interface Initializableinit in class PropertyResources
public void open()
throws SQLException
SQLException
public void close()
throws SQLException
SQLException
public void insert(Map data)
throws SQLException
INSERT INTO {table} ({field1}, {field2},...) VALUES({num1}, '{string2}',...)
The user supplied lists are the field list and the values list. The
values should consist of object of types String, Numbers, or Dates.
String are converted to be embraced with single quotes ('), Date objects
are converted into strings using the KEY_DATEFORMAT format.
Numbers are simply converted into strings. Note that it is the users
responsibility to ensure proper ordering in the list, as no further
type checks are done, only the run-time types of the values are used.
fields - A list of strings giving the field names in the databasevalues - A list of objects that are the correspondend values to the
fields in the parameter above.
SQLException
public void replace(Map data,
String where)
throws SQLException
UPDATE {table} SET {field1}={num1}, {field2}='{string2}',...
The user supplied lists are the field list and the values list. The
values should consist of object of types String, Numbers, or Dates.
String are converted to be embraced with single quotes ('), Date objects
are converted into strings using the KEY_DATEFORMAT format.
Numbers are simply converted into strings. Note that it is the users
responsibility to ensure proper ordering in the list, as no further
type checks are done, only the run-time types of the values are used.
fields - A list of strings giving the field names in the databasevalues - A list of objects that are the correspondend values to the
fields in the parameter above.where - The identification which sets should be affected, without
the leading WHERE.
SQLException
public ResultSet retrieve(List fields,
String where)
throws SQLException
fields - A list of fields to retrieve or null, if all fields are
needed.where - The WHERE clause without the leading WHERE
SQLExceptionprivate String getDatabaseEntry(Object val)
KEY_DATEFORMAT to
convert the date into a string, returns this within single quotes.
private void openDatabase()
throws SQLException
SQLException
private void createStatement()
throws SQLException
SQLException
private void closeStatement()
throws SQLException
SQLException
private void closeDatabase()
throws SQLException
SQLException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||