com.netflix.config.sources
Class JDBCConfigurationSource

java.lang.Object
  extended by com.netflix.config.sources.JDBCConfigurationSource
All Implemented Interfaces:
PolledConfigurationSource

public class JDBCConfigurationSource
extends java.lang.Object
implements PolledConfigurationSource

Simple JDBC source of config properties. Assuming you have a table with a column that stores the keys and a column to store values, this class can be used as your source of polled configuration.


Constructor Summary
JDBCConfigurationSource(javax.sql.DataSource datasource, java.lang.String query, java.lang.String keyColumnName, java.lang.String valueColumnName)
          Constructor
 
Method Summary
protected  java.sql.Connection getConnection()
          Returns a Connection object.
 javax.sql.DataSource getDatasource()
          Returns the used DataSource object.
 PollResult poll(boolean initial, java.lang.Object checkPoint)
          Poll the configuration source to get the latest content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCConfigurationSource

public JDBCConfigurationSource(javax.sql.DataSource datasource,
                               java.lang.String query,
                               java.lang.String keyColumnName,
                               java.lang.String valueColumnName)
Constructor

Parameters:
datasource - The DataSource object for the JDBC; e.g. new OracleDataSource(databaseName, schema);
query - The query statement to fetch the properties; e.g. "Select distinct property_key, property_value from SITE_PROPERTIES"
keyColumnName - The column name which stores the property keys; e.g. property_key
valueColumnName - The column name which stores the property values; e.g. property_value
Method Detail

poll

public PollResult poll(boolean initial,
                       java.lang.Object checkPoint)
                throws java.lang.Exception
Description copied from interface: PolledConfigurationSource
Poll the configuration source to get the latest content.

Specified by:
poll in interface PolledConfigurationSource
Parameters:
initial - true if this operation is the first poll.
checkPoint - Object that is used to determine the starting point if the result returned is incremental. Null if there is no check point or the caller wishes to get the full content.
Returns:
The content of the configuration which may be full or incremental.
Throws:
java.lang.Exception - If any exception occurs when fetching the configurations.

getDatasource

public javax.sql.DataSource getDatasource()
Returns the used DataSource object.

Returns:
the data source
Since:
1.4

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Returns a Connection object. This method is called when ever the database is to be accessed. This implementation returns a connection from the current DataSource.

Returns:
the Connection object to be used
Throws:
java.sql.SQLException - if an error occurs
Since:
1.4