org.gbif.datatester
Class JdbcRecordSet

java.lang.Object
  extended by org.gbif.datatester.JdbcRecordSet
All Implemented Interfaces:
GenericRecordSet

public class JdbcRecordSet
extends java.lang.Object
implements GenericRecordSet

This class implements a JDBC GenericRecordSet. In this case records come from a table or view inside a relational database.

Version:
$Revision: 1.6 $
Author:
Renato De Giovanni ( renato at cria . org . br )

Constructor Summary
JdbcRecordSet(java.sql.Connection connection, java.lang.String tableName, java.util.Map conceptMapping, java.util.List idDefinition)
          Constructs a JDBCRecordSet based on a JDBC connection, a table or view name, a concept mapping (Concepts pointing to fields), and a List of Concepts used to identify the records.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compare two record sets for equality based on database name, table name, concept mapping and id definition.
protected  void executeQuery()
          Executes the query.
 java.util.Set getAvailableConcepts()
          Returns a Set of Concept objects for which each record has an associated value.
protected  java.util.Set getConceptsBeingUsed()
          Returns the Concepts being used by the record set.
 int hashCode()
          Returns a hash code based on database name, table name, concept mapping and id definition.
 void limitConceptsTo(java.util.Set concepts)
          Method used to indicate which Concepts will be used, so that this implementation can optimize performance by restricting the scope of search and storage of values.
 GenericRecord nextRecord()
          Moves the cursor to the next record and returns a reference to it (or null if there's no next record).
 void resetCursor()
          Resets the cursor so that when nextRecord is called it will return the first one.
 void setRecordFilter(RecordFilter recordFilter)
          Sets a RecordFilter that can indicate which records should be skipped during validation.
 void setWhereClause(java.lang.String whereClause)
          Specific method that can be used to set an optional SQL "where" clause to be used when retrieving records.
 int size()
          Returns the number of records.
 void sortBy(java.util.LinkedHashMap concepts)
          Sorts the record set by the specified Concepts.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcRecordSet

public JdbcRecordSet(java.sql.Connection connection,
                     java.lang.String tableName,
                     java.util.Map conceptMapping,
                     java.util.List idDefinition)

Constructs a JDBCRecordSet based on a JDBC connection, a table or view name, a concept mapping (Concepts pointing to fields), and a List of Concepts used to identify the records.

Parameters:
connection - JDBC Connection to the database.
tableName - Table or view name containing the records.
conceptMapping - Mapping between Concepts and field names.
idDefinition - Concepts used to identify records.
Throws:
java.lang.IllegalArgumentException
Method Detail

getAvailableConcepts

public java.util.Set getAvailableConcepts()

Returns a Set of Concept objects for which each record has an associated value.

Specified by:
getAvailableConcepts in interface GenericRecordSet
Returns:
Set of available Concepts.

limitConceptsTo

public void limitConceptsTo(java.util.Set concepts)
                     throws RecordSetException

Method used to indicate which Concepts will be used, so that this implementation can optimize performance by restricting the scope of search and storage of values.

Specified by:
limitConceptsTo in interface GenericRecordSet
Parameters:
concepts - Set of Concepts that will be used. When not specified, then use all Concepts.
Throws:
java.lang.IllegalArgumentException
RecordSetException

nextRecord

public GenericRecord nextRecord()
                         throws RecordSetException

Moves the cursor to the next record and returns a reference to it (or null if there's no next record).

Specified by:
nextRecord in interface GenericRecordSet
Returns:
Reference to the next GenericRecord
Throws:
RecordSetException

sortBy

public void sortBy(java.util.LinkedHashMap concepts)

Sorts the record set by the specified Concepts.

Specified by:
sortBy in interface GenericRecordSet
Parameters:
concepts - LiknedHashMap where key is Concept object and value is a Boolean indicating if the order is ascending.

resetCursor

public void resetCursor()
                 throws RecordSetException

Resets the cursor so that when nextRecord is called it will return the first one.

Specified by:
resetCursor in interface GenericRecordSet
Throws:
RecordSetException

size

public int size()
         throws RecordSetException

Returns the number of records.

Specified by:
size in interface GenericRecordSet
Returns:
Number of records.
Throws:
RecordSetException

setRecordFilter

public void setRecordFilter(RecordFilter recordFilter)

Sets a RecordFilter that can indicate which records should be skipped during validation.

Specified by:
setRecordFilter in interface GenericRecordSet
Parameters:
recordFilter - A RecordFilter object that can indicate if a specific record should be skipped during the test or not.

getConceptsBeingUsed

protected java.util.Set getConceptsBeingUsed()

Returns the Concepts being used by the record set.

Returns:
Set of Concepts being used.

executeQuery

protected void executeQuery()
                     throws java.sql.SQLException

Executes the query.

Throws:
java.sql.SQLException

setWhereClause

public void setWhereClause(java.lang.String whereClause)

Specific method that can be used to set an optional SQL "where" clause to be used when retrieving records. Only available on the JdbcRecordSet implementation.

Parameters:
whereClause - SQL where clause to be included in the SQL statement.

hashCode

public int hashCode()

Returns a hash code based on database name, table name, concept mapping and id definition. Note: This implementation cannot distinguish between databases installed in different machines if they have the same name, the same table and the same mapping!

Overrides:
hashCode in class java.lang.Object
Returns:
hash code.

equals

public boolean equals(java.lang.Object obj)

Compare two record sets for equality based on database name, table name, concept mapping and id definition. Note: This implementation cannot distinguish between databases installed in different machines if they have the same name, the same table and the same mapping!.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Object to be compared.
Returns:
true if the record sets are equal, false otherwise.