org.openstreetmap.osmosis.core.apidb.common
Class BaseTableReader<T>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.apidb.common.BaseTableReader<T>
Type Parameters:
T - The type of entity to retrieved.
All Implemented Interfaces:
java.util.Iterator<T>, Releasable, ReleasableIterator<T>

public abstract class BaseTableReader<T>
extends java.lang.Object
implements ReleasableIterator<T>

Provides the base implementation of all database table readers.

Author:
Brett Henderson

Nested Class Summary
protected static class BaseTableReader.ReadResult<T>
          Represents the result of an entity read from the result set at the current position.
 
Constructor Summary
BaseTableReader(DatabaseLoginCredentials loginCredentials)
          Creates a new instance.
 
Method Summary
protected  BaseTableReader.ReadResult<T> createLastValue()
          If the implementation requires multiple rows to build an entity object, this method allows the implementation to return an entity based on the fact that no more rows are available.
protected abstract  BaseTableReader.ReadResult<T> createNextValue(java.sql.ResultSet activeResultSet)
          Builds an entity object from the current recordset row.
protected abstract  java.sql.ResultSet createResultSet(DatabaseContext queryDbCtx)
          Builds the result set that the reader will iterate over.
 boolean hasNext()
          
 T next()
          
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 void remove()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseTableReader

public BaseTableReader(DatabaseLoginCredentials loginCredentials)
Creates a new instance.

Parameters:
loginCredentials - Contains all information required to connect to the database.
Method Detail

createResultSet

protected abstract java.sql.ResultSet createResultSet(DatabaseContext queryDbCtx)
Builds the result set that the reader will iterate over.

Parameters:
queryDbCtx - The database context to query against.
Returns:
A result set positioned before the first record.

createNextValue

protected abstract BaseTableReader.ReadResult<T> createNextValue(java.sql.ResultSet activeResultSet)
Builds an entity object from the current recordset row.

Parameters:
activeResultSet - The record set to retrieve the data from.
Returns:
The result of the read.

createLastValue

protected BaseTableReader.ReadResult<T> createLastValue()
If the implementation requires multiple rows to build an entity object, this method allows the implementation to return an entity based on the fact that no more rows are available. This default implementation returns a blank result.

Returns:
The last result record.

hasNext

public boolean hasNext()

Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()

Specified by:
next in interface java.util.Iterator<T>

release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable

remove

public void remove()

Specified by:
remove in interface java.util.Iterator<T>