QJCC homepage

biz.chitec.quarterback.util
Class PropertiesStorer

java.lang.Object
  extended bybiz.chitec.quarterback.util.PropertiesStorer

public final class PropertiesStorer
extends java.lang.Object

Static helper class to store a Properties object into a database. For this to work, a table has to be defined:

 create table propertiestable (
   name varchar(40) not null default '',
   thekey varchar(255) not null default '',
   thevalue mediumtext not null default '',
   unique (name,thekey)
 );
 
Property tables' names have to be defines uniquely, of course. Storing is done in a way that the least possible information is lost in case of an intermediate crash.

Version:
$Id: aab46855022cadb795457d1199df1372a3f15d29 $
Author:
cantamen/Dirk Hillbrecht 2005

Constructor Summary
private PropertiesStorer()
          This is a fully static class
 
Method Summary
static void dropProperties(java.sql.Statement dbstmt, java.lang.String propertiesname)
          Drops a properties object finally from the database.
static java.lang.String getProperty(java.sql.Statement dbstmt, java.lang.String propertiesname, java.lang.String key, java.lang.String defaultvalue)
          Get a single property from the database.
static java.util.Properties loadProperties(java.sql.Statement dbstmt, java.lang.String propertiesname, java.util.Properties defaults)
          Loads a properties object from the database.
static void storeProperties(java.sql.Statement dbstmt, java.lang.String propertiesname, java.util.Set allowedkeys, java.util.Properties props)
          Stores a properties object into the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesStorer

private PropertiesStorer()
This is a fully static class

Method Detail

storeProperties

public static void storeProperties(java.sql.Statement dbstmt,
                                   java.lang.String propertiesname,
                                   java.util.Set allowedkeys,
                                   java.util.Properties props)
                            throws java.sql.SQLException
Stores a properties object into the database. The properties object is handled as a complete replacement for all entries in the database. I.e. if an entry is in the database but not in the properties object, it is removed from the database. It is possible to define the given properties object to be only a replacement for parts of the data stored in the database. In this case, "allowedkeys" must be different from null and containing all the keys which should be covered by the contents of the given properties.

The method locks the entries for this properties object as long as it stores them. For this, it uses the RowLock mechanism.

Parameters:
dbstmt - Statement to work on
propertiesname - Name of the properties object
allowedkeys - Complete set of keys which are changeable, null if irrelevant
props - The properties to store
Throws:
java.sql.SQLException - If something goes wrong in the database

loadProperties

public static java.util.Properties loadProperties(java.sql.Statement dbstmt,
                                                  java.lang.String propertiesname,
                                                  java.util.Properties defaults)
                                           throws java.sql.SQLException
Loads a properties object from the database. The method locks the entries for this properties object as long as it loads them.

Parameters:
dbstmt - Statement to work on
propertiesname - Name of the properties table to load
defaults - Default (or "parent") properties for the properties to build, null if none exist
Returns:
Filled properties object
Throws:
java.sql.SQLException

getProperty

public static java.lang.String getProperty(java.sql.Statement dbstmt,
                                           java.lang.String propertiesname,
                                           java.lang.String key,
                                           java.lang.String defaultvalue)
                                    throws java.sql.SQLException
Get a single property from the database. This method should only be used if only one certain value is needed from the properties element. If you need multiple elements, you should always read the complete Properties bundle via loadProperties(Statement, String, Properties).

Parameters:
dbstmt - Statement to work on the database with
propertiesname - Name of the bundle
key - The needed value's key.
defaultvalue - The default value to return if nothing is stored in the database
Returns:
The value stored in the database or the given default value if nothing is stored.
Throws:
java.sql.SQLException - If something goes wrong with the database

dropProperties

public static void dropProperties(java.sql.Statement dbstmt,
                                  java.lang.String propertiesname)
                           throws java.sql.SQLException
Drops a properties object finally from the database. After calling this method, the properties are completely and unrecoverably deleted from the database.

Parameters:
dbstmt - Statement to work on
propertiesname - Name of the properties table to drop
Throws:
java.sql.SQLException

QJCC homepage