com.ail.core.configure
Class JDBCConfigurationLoader

java.lang.Object
  extended by com.ail.core.configure.AbstractConfigurationLoader
      extended by com.ail.core.configure.JDBCConfigurationLoader
Direct Known Subclasses:
ConnectionPoolConfigurationLoader

public class JDBCConfigurationLoader
extends AbstractConfigurationLoader

This class handles the loading and saving of property (configuration) information held in a JDBC datastore.

This loader expects the loader.property file to define the following (as a minimum):

  1. driver - the JDBC driver class to use.
  2. url - The database connection url.
  3. databaseName - The name of the database in which table can be found.
  4. table - The name of the database table holding configuration information.
  5. user - The db user to use when accessing the database.
  6. password - The db user's password.
The database table defined (table above) is expected to match the description below. Assuming that the user has the necessary privilages, this table will be created automatically:
 +---------------+---------------+------+-----+---------+-------+
 | Field         | Type          | Null | Key | Default | Extra |
 +---------------+---------------+------+-----+---------+-------+
 | namespace     | varchar(255)  |      |     |         |       |
 | manager       | varchar(255)  |      |     |         |       |
 | configuration | longblob      |      |     |         |       |
 | validfrom     | bigint(20)    |      |     | 0       |       |
 | validto       | bigint(20)    | YES  |     | NULL    |       |
 | who           | varchar(32)   |      |     |         |       |
 | version       | varchar(32)   |      |     |         |       |
 +---------------+---------------+------+-----+---------+-------+

Version:
$Revision: 1.6 $

Constructor Summary
JDBCConfigurationLoader()
           
 
Method Summary
 void deleteConfigurationRepository()
          Delete the repository holding configuration information.
 java.util.Collection<java.lang.String> getNamespaces()
          Return a list of all the namespaces in the database which have a validTo date of 0.
 java.util.Collection<ConfigurationSummary> getNamespacesHistorySummary(java.lang.String namespace)
          Return details of a namespaces versions.
 java.util.Collection<ConfigurationSummary> getNamespacesSummary()
          Return a list of details of all the namespaces in the database which have a validTo date of 0.
 Configuration loadConfiguration(java.lang.String namespace, VersionEffectiveDate date)
          Load a namespace's configuration.
 java.sql.Connection openConnection()
          Open a connection to the configuration database.
 void purgeAllConfigurations()
          Delete ALL configuration information.
 void reset()
          When the configuration handler is asked to "reset", it passes that request onto the loader currently in user.
 void saveConfiguration(java.lang.String namespace, Configuration config)
          Save a configuration into the database.
 
Methods inherited from class com.ail.core.configure.AbstractConfigurationLoader
getLoaderParams, loadLoader
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCConfigurationLoader

public JDBCConfigurationLoader()
Method Detail

openConnection

public java.sql.Connection openConnection()
Open a connection to the configuration database. Note: This is public for testing purposes only. Directly using the configuration table of a live system is strongly discouraged!

Returns:
connection to read data from.

loadConfiguration

public Configuration loadConfiguration(java.lang.String namespace,
                                       VersionEffectiveDate date)
Load a namespace's configuration. Namespaces are date relative, and the table will contain more than one copy of the same namespace's configuration as it was valid on different dates. Each row in the database has a validFrom and validTo timestamp. The latest version of the configuration will have the validTo set to zero.

NOTE: If either the database or table specified in loader.properties do not exist when the system starts, this method handles this like a missing namespace. But if the system is live, and the table disappears, that is recognised as an error.

Specified by:
loadConfiguration in class AbstractConfigurationLoader
Parameters:
namespace - The namespace to load.
date - The date to load the namespace for.
Returns:
The configuration.
Throws:
UnknownNamespaceError - if the namespace does not exist, or is not valid for the date specificed.

saveConfiguration

public void saveConfiguration(java.lang.String namespace,
                              Configuration config)
Save a configuration into the database. All namespace records have a validfrom and a validto date stamp. A record with validto set to zero indicates the latest config. This method will update the current latest record, setting its validto to now. It will then insert a new record with validFrom set to now+1ms, and validTo set to zero.

If either the database or table specified in loader.properties does not exist on the first attempt to save a configuration, this method will attempt to create both. For this to work the db user specified in loader.properties must have the necessary 'GRANTS' for table and database creation.

Specified by:
saveConfiguration in class AbstractConfigurationLoader
Parameters:
namespace - The namespace the configuration is associated with.
config - The configuration to be saved.
Throws:
BootstrapConfigurationError - if the configuration cannot be serialized, or the database access fails.

getNamespaces

public java.util.Collection<java.lang.String> getNamespaces()
Return a list of all the namespaces in the database which have a validTo date of 0.

Specified by:
getNamespaces in class AbstractConfigurationLoader
Returns:
A list of currently defined namespaces as Strings

getNamespacesSummary

public java.util.Collection<ConfigurationSummary> getNamespacesSummary()
Return a list of details of all the namespaces in the database which have a validTo date of 0.

Specified by:
getNamespacesSummary in class AbstractConfigurationLoader
Returns:
A list of currently defined namespaces as Strings

getNamespacesHistorySummary

public java.util.Collection<ConfigurationSummary> getNamespacesHistorySummary(java.lang.String namespace)
Return details of a namespaces versions.

Specified by:
getNamespacesHistorySummary in class AbstractConfigurationLoader
Parameters:
namespace - The namespace to fetch the history for.
Returns:
A collection of instances of ConfigurationSummary representing the history of the specified namespace.

reset

public void reset()
When the configuration handler is asked to "reset", it passes that request onto the loader currently in user. The loader should reset any internal state in this method.

Specified by:
reset in class AbstractConfigurationLoader

deleteConfigurationRepository

public void deleteConfigurationRepository()
Delete the repository holding configuration information. This not only removes all configuration information purgeAllConfigurations() but also removes the repository itself.

NOTE: ALL CONFIGURATION INFORMATION WILL BE LOST!

In the context of the JDBCConfigurationLoader this simply means droping the config table.

Specified by:
deleteConfigurationRepository in class AbstractConfigurationLoader

purgeAllConfigurations

public void purgeAllConfigurations()
Delete ALL configuration information. This will include all historical configuration information.

NOTE: ALL CONFIGURATION INFORMATION WILL BE LOST! In the context of the JDBCConfigurationLoader this means delete all the records from the configuration table.

Specified by:
purgeAllConfigurations in class AbstractConfigurationLoader