org.compass.gps.device.jdbc
Class AbstractJdbcGpsDevice

java.lang.Object
  extended by org.compass.gps.device.AbstractGpsDevice
      extended by org.compass.gps.device.jdbc.AbstractJdbcGpsDevice
All Implemented Interfaces:
CompassGpsDevice, JdbcGpsDevice
Direct Known Subclasses:
AbstractJdbcActiveMirrorGpsDevice

public abstract class AbstractJdbcGpsDevice
extends AbstractGpsDevice
implements JdbcGpsDevice

A helper base class for Jdbc Gps Device. Provides supprot for DataSource and JdbcDialect. Also provides template like support for processing database indexing using the IndexExecution object hint, and a set of callback methods: processResultSet(Object, ResultSet, CompassSession), processRow(Object, ResultSet, CompassSession), and processRowValue(Object, ResultSet, CompassSession). One of the callback mehtods should be overriden by the derived class otherwize the class won't index anyhting.

Author:
kimchy

Nested Class Summary
static class AbstractJdbcGpsDevice.IndexExecution
          A hint object which provides the statement query to execute or the actual PreparedStatement.
 
Field Summary
protected  DataSource dataSource
           
protected  JdbcDialect dialect
           
protected  org.apache.commons.logging.Log log
           
 
Fields inherited from class org.compass.gps.device.AbstractGpsDevice
compassGps
 
Constructor Summary
AbstractJdbcGpsDevice()
           
 
Method Summary
protected abstract  AbstractJdbcGpsDevice.IndexExecution[] doGetIndexExecutions(Connection connection)
          Returns an array of the AbstractJdbcGpsDevice.IndexExecution that should be executed it's respective ResultSet should be indexed.
protected  void doIndex(CompassSession session)
          Performs the indexing operation.
protected  void doStart()
          Derived devices can implement it in case of start event notification.
 DataSource getDataSource()
          Returns the Jdbc data source that will be used to connect to the database.
 JdbcDialect getDialect()
          Returns the JdbcDialect that will be used when executing operations that might have different implementations based on the target database.
 int getFetchSize()
          Returns the fetch size that will be used when executing select queries against the database.
protected  void processResultSet(Object description, ResultSet rs, CompassSession session)
          Called for each AbstractJdbcGpsDevice.IndexExecution returned from the doGetIndexExecutions(Connection) with the ResultSet.
protected  void processRow(Object description, ResultSet rs, CompassSession session)
          Called for each row in the ResultSet which maps to an AbstractJdbcGpsDevice.IndexExecution.
protected  Object processRowValue(Object description, ResultSet rs, CompassSession session)
          Called for each row in the ResultSet which maps to an AbstractJdbcGpsDevice.IndexExecution.
 void setDataSource(DataSource dataSource)
          Sets the Jdbc data source that will be used to connect to the database.
 void setDialect(JdbcDialect dialect)
          Sets the JdbcDialect that will be used when executing operations that might have different implementations based on the target database.
 void setFetchSize(int fetchSize)
          Sets the fetch size that will be used when executing select queries against the database.
 
Methods inherited from class org.compass.gps.device.AbstractGpsDevice
buildMessage, doIndex, doStop, getGps, getName, index, injectGps, isFilteredForIndex, isPerformingIndexOperation, isRunning, setFilteredEntitiesForIndex, setName, shouldMirrorDataChanges, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.compass.gps.CompassGpsDevice
getGps, getName, index, injectGps, isPerformingIndexOperation, isRunning, setName, shouldMirrorDataChanges, start, stop
 

Field Detail

log

protected org.apache.commons.logging.Log log

dataSource

protected DataSource dataSource

dialect

protected JdbcDialect dialect
Constructor Detail

AbstractJdbcGpsDevice

public AbstractJdbcGpsDevice()
Method Detail

doStart

protected void doStart()
                throws CompassGpsException
Description copied from class: AbstractGpsDevice
Derived devices can implement it in case of start event notification.

Overrides:
doStart in class AbstractGpsDevice
Throws:
CompassGpsException

doIndex

protected void doIndex(CompassSession session)
                throws CompassGpsException
Performs the indexing operation.

Calls the abstract doGetIndexExecutions(Connection) method with an open connection to get the list of AbstractJdbcGpsDevice.IndexExecution to perform.

For each AbstractJdbcGpsDevice.IndexExecution, executes the select query, and calls the processResultSet(Object, ResultSet, CompassSession) for the returned ResultSet.

Throws:
CompassGpsException

processResultSet

protected void processResultSet(Object description,
                                ResultSet rs,
                                CompassSession session)
                         throws SQLException,
                                CompassException
Called for each AbstractJdbcGpsDevice.IndexExecution returned from the doGetIndexExecutions(Connection) with the ResultSet. Can be override by derived classes, if not override, than iterates threw the ResultSet and calls processRow(Object, ResultSet, CompassSession) for each row.

Throws:
SQLException
CompassException

processRow

protected void processRow(Object description,
                          ResultSet rs,
                          CompassSession session)
                   throws SQLException,
                          CompassException
Called for each row in the ResultSet which maps to an AbstractJdbcGpsDevice.IndexExecution. Can be override by derived classes, if not override, than calls processRowValue(Object, ResultSet, CompassSession) and uses it's return value to save it in the CompassSession. The return value can be an OSEM enables object, a Resource, or an array of one of them.

Throws:
SQLException
CompassException

processRowValue

protected Object processRowValue(Object description,
                                 ResultSet rs,
                                 CompassSession session)
                          throws SQLException,
                                 CompassException
Called for each row in the ResultSet which maps to an AbstractJdbcGpsDevice.IndexExecution. Can be override by derived classes, and should return the actual data to be saved using the CompassSession. The return value can be either an OSEM enables object, a Resource, or an array of one of them.

Throws:
SQLException
CompassException

doGetIndexExecutions

protected abstract AbstractJdbcGpsDevice.IndexExecution[] doGetIndexExecutions(Connection connection)
                                                                        throws SQLException,
                                                                               JdbcGpsDeviceException
Returns an array of the AbstractJdbcGpsDevice.IndexExecution that should be executed it's respective ResultSet should be indexed.

Throws:
SQLException
JdbcGpsDeviceException

getDataSource

public DataSource getDataSource()
Description copied from interface: JdbcGpsDevice
Returns the Jdbc data source that will be used to connect to the database.

Specified by:
getDataSource in interface JdbcGpsDevice
Returns:
The data source used with the device

setDataSource

public void setDataSource(DataSource dataSource)
Description copied from interface: JdbcGpsDevice
Sets the Jdbc data source that will be used to connect to the database. Note that it must be set before calling the start method.

Specified by:
setDataSource in interface JdbcGpsDevice

getFetchSize

public int getFetchSize()
Description copied from interface: JdbcGpsDevice
Returns the fetch size that will be used when executing select queries against the database. See PreparedStatement#setFetchSize.

Specified by:
getFetchSize in interface JdbcGpsDevice
Returns:
The fetch size for indexing and mirroring

setFetchSize

public void setFetchSize(int fetchSize)
Description copied from interface: JdbcGpsDevice
Sets the fetch size that will be used when executing select queries against the database. See PreparedStatement#setFetchSize.

Specified by:
setFetchSize in interface JdbcGpsDevice

getDialect

public JdbcDialect getDialect()
Description copied from interface: JdbcGpsDevice
Returns the JdbcDialect that will be used when executing operations that might have different implementations based on the target database.

Specified by:
getDialect in interface JdbcGpsDevice
Returns:
The dialect used by the device

setDialect

public void setDialect(JdbcDialect dialect)
Description copied from interface: JdbcGpsDevice
Sets the JdbcDialect that will be used when executing operations that might have different implementations based on the target database.

Specified by:
setDialect in interface JdbcGpsDevice


Copyright (c) 2004-2008 The Compass Project.