net.smartlab.config
Class SQLConfiguration

java.lang.Object
  extended by net.smartlab.config.Element
      extended by net.smartlab.config.Node
          extended by net.smartlab.config.Configuration
              extended by net.smartlab.config.SQLConfiguration

public final class SQLConfiguration
extends Configuration

Represents a configuration expressed through a database table.

Author:
rlogiacco

Field Summary
protected static java.lang.String LAST_UPDATE
          Name used to identify the last update time on the database.
 
Fields inherited from class net.smartlab.config.Configuration
listeners, monitor
 
Fields inherited from class net.smartlab.config.Node
attributes, children, content, resolved
 
Fields inherited from class net.smartlab.config.Element
name, parent
 
Constructor Summary
SQLConfiguration(java.sql.Connection connection)
          Constructs a configuration structure from a JDBC connection.
SQLConfiguration(javax.sql.DataSource pool)
          Constructs a configuration structure from a JDBC data source.
 
Method Summary
 long getLastUpdate(boolean set)
          Extracts the last modification timestamp from the underling database.
 boolean isChanged()
          This method checks if the source from the configuration structure was modified since it was last read.
 void setLastUpdate(long timestamp)
          Sets the last modification timestamp into the underling database.
 void update()
          Ensures the in memory representation of the configuration matches with the underlying representation.
 
Methods inherited from class net.smartlab.config.Configuration
addListener, check, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getListeners, getResolve, init, removeListener, resolve, setResolve
 
Methods inherited from class net.smartlab.config.Node
getAttribute, getAttributeNames, getAttributes, getContent, getElement, getElements, getElements, getId, resolve, setContent
 
Methods inherited from class net.smartlab.config.Element
getAttributeValues, getElement, getElement, getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LAST_UPDATE

protected static final java.lang.String LAST_UPDATE
Name used to identify the last update time on the database.

See Also:
Constant Field Values
Constructor Detail

SQLConfiguration

public SQLConfiguration(java.sql.Connection connection)
                 throws ConfigurationException
Constructs a configuration structure from a JDBC connection. The providen connection must be active and open and should not be closed from outside otherwise any subsequent update check will fail.

Parameters:
connection - the connection to use to retrieve informations from the database.
Throws:
ConfigurationException

SQLConfiguration

public SQLConfiguration(javax.sql.DataSource pool)
                 throws ConfigurationException
Constructs a configuration structure from a JDBC data source.

Parameters:
pool - the data source providing database connections.
Throws:
ConfigurationException
Method Detail

isChanged

public boolean isChanged()
                  throws ConfigurationException
Description copied from class: Configuration
This method checks if the source from the configuration structure was modified since it was last read.

Specified by:
isChanged in class Configuration
Returns:
true if the underlying representation of the structure was modified since last read.
Throws:
ConfigurationException - if something wrong occurred while checking the underlaying structure like the file is no more readable or the stream no more available.
See Also:
Configuration.isChanged()

update

public void update()
            throws ConfigurationException
Description copied from class: Configuration
Ensures the in memory representation of the configuration matches with the underlying representation.

Specified by:
update in class Configuration
Throws:
ConfigurationException - if the underlying representation of the structure is no more accessible or the decoding process fails due to an unappropriately initialized Cipher.
See Also:
Configuration.update()

getLastUpdate

public long getLastUpdate(boolean set)
                   throws ConfigurationException
Extracts the last modification timestamp from the underling database.

Parameters:
set - specifies if the last modification time must be set if not found
Returns:
the last modification timestamp.
Throws:
ConfigurationException - if something unexpected happens trying to retrieve the last modification timestamp or if the corresponding parameter has not been defined.

setLastUpdate

public void setLastUpdate(long timestamp)
                   throws ConfigurationException
Sets the last modification timestamp into the underling database.

Parameters:
timestamp - the last modification timestamp to set.
Throws:
ConfigurationException - f something unexpected happens trying to set the last modification timestamp.


Copyright © 2002-2008 SmartLab s.r.l.. All Rights Reserved.