org.vivoweb.harvester.util.repo
Class RecordHandler

java.lang.Object
  extended by org.vivoweb.harvester.util.repo.RecordHandler
All Implemented Interfaces:
java.lang.Iterable<Record>
Direct Known Subclasses:
JDBCRecordHandler, JenaRecordHandler, MapRecordHandler, TextFileRecordHandler

public abstract class RecordHandler
extends java.lang.Object
implements java.lang.Iterable<Record>

Record Handler Interface

Author:
Christopher Haines (hainesc@ctrip.ufl.edu)

Constructor Summary
RecordHandler()
           
 
Method Summary
protected  void addMetaData(Record rec, java.lang.Class<?> operator, RecordMetaData.RecordMetaDataType type)
          Adds a metadata record for the given record
protected abstract  void addMetaData(Record rec, RecordMetaData rmd)
          Adds a metadata record
 boolean addRecord(Record rec, java.lang.Class<?> creator)
          Adds a record to the RecordHandler If overwriteDefault is set to true, will automatically overwrite existing records
abstract  boolean addRecord(Record rec, java.lang.Class<?> creator, boolean overwrite)
          Adds a record to the RecordHandler
 boolean addRecord(java.lang.String recID, java.lang.String recData, java.lang.Class<?> creator)
          Adds a record to the RecordHandler If overwriteDefault is set to true, will automatically overwrite existing records
 boolean addRecord(java.lang.String recID, java.lang.String recData, java.lang.Class<?> creator, boolean overwrite)
          Adds a record to the RecordHandler
abstract  void close()
          Closes the recordhandler
protected abstract  void delMetaData(java.lang.String recID)
          Deletes all metadata for a record
abstract  void delRecord(java.lang.String recID)
          Delete the specified Record
abstract  java.util.Set<java.lang.String> find(java.lang.String idText)
          Find records with idText in their id
protected  RecordMetaData getLastMetaData(java.lang.String recID, RecordMetaData.RecordMetaDataType type, java.lang.Class<?> operator)
          Get the last RecordMetaData of a given type by a given operator for a given record
protected  java.lang.String getParam(java.util.Map<java.lang.String,java.lang.String> params, java.lang.String paramName, boolean required)
          Get a specified parameter
 Record getRecord(java.lang.String recID)
          Get a record
abstract  java.lang.String getRecordData(java.lang.String recID)
          Retrieve the data for a given record
protected abstract  java.util.SortedSet<RecordMetaData> getRecordMetaData(java.lang.String recID)
          Retrieves all metadata for a given record
 boolean isOverwriteDefault()
          Getter for overwriteDefault
 boolean needsProcessed(java.lang.String id, java.lang.Class<?> operator)
          Has the given record been written since last processed by operator?
protected  boolean needsUpdated(Record rec)
          Does the given record contain updated information compared to existing record data
static RecordHandler parseConfig(java.io.File configFile)
          Config File Based Factory
static RecordHandler parseConfig(java.io.File configFile, java.util.Map<java.lang.String,java.lang.String> overrideParams)
          Config File Based Factory
static RecordHandler parseConfig(org.apache.commons.vfs.FileObject configFile)
          Config File Based Factory
static RecordHandler parseConfig(org.apache.commons.vfs.FileObject configFile, java.util.Map<java.lang.String,java.lang.String> overrideParams)
          Config File Based Factory that overrides parameters
static RecordHandler parseConfig(java.io.InputStream configStream, java.util.Map<java.lang.String,java.lang.String> overrideParams)
          Config Stream Based Factory that overrides parameters
static RecordHandler parseConfig(java.lang.String configFileName)
          Config File Based Factory
static RecordHandler parseConfig(java.lang.String configFileName, java.util.Map<java.lang.String,java.lang.String> overrideParams)
          Config File Based Factory
 void setOverwriteDefault(boolean overwrite)
          Setter for overwriteDefault
abstract  void setParams(java.util.Map<java.lang.String,java.lang.String> params)
          Sets parameters from param list
protected  void setProcessed(Record rec, java.lang.Class<?> operator)
          Add a metadata record to indicate that the given operator has processed the given record
protected  void setWritten(Record rec, java.lang.Class<?> operator)
          Add a metadata record to indicate that the given operator has written the given record
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

RecordHandler

public RecordHandler()
Method Detail

setParams

public abstract void setParams(java.util.Map<java.lang.String,java.lang.String> params)
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException
Sets parameters from param list

Parameters:
params - map of parameters
Throws:
java.lang.IllegalArgumentException - invalid parameters
java.io.IOException - error

addRecord

public abstract boolean addRecord(Record rec,
                                  java.lang.Class<?> creator,
                                  boolean overwrite)
                           throws java.io.IOException
Adds a record to the RecordHandler

Parameters:
rec - record to add
creator - the creator
overwrite - when set to true, will automatically overwrite existing records
Returns:
true if added, false if not needed (aka record already existed and was the same)
Throws:
java.io.IOException - error adding

addRecord

public boolean addRecord(java.lang.String recID,
                         java.lang.String recData,
                         java.lang.Class<?> creator,
                         boolean overwrite)
                  throws java.io.IOException
Adds a record to the RecordHandler

Parameters:
recID - record id to add
recData - record data to add
creator - the creator
overwrite - when set to true, will automatically overwrite existing records
Returns:
true if added, false if not needed (aka record already existed and was the same)
Throws:
java.io.IOException - error adding

addRecord

public boolean addRecord(Record rec,
                         java.lang.Class<?> creator)
                  throws java.io.IOException
Adds a record to the RecordHandler If overwriteDefault is set to true, will automatically overwrite existing records

Parameters:
rec - record to add
creator - the creator
Returns:
true if added, false if not needed (aka record already existed and was the same)
Throws:
java.io.IOException - error adding

addRecord

public boolean addRecord(java.lang.String recID,
                         java.lang.String recData,
                         java.lang.Class<?> creator)
                  throws java.io.IOException
Adds a record to the RecordHandler If overwriteDefault is set to true, will automatically overwrite existing records

Parameters:
recID - record id to add
recData - record data to add
creator - the creator
Returns:
true if added, false if not needed (aka record already existed and was the same)
Throws:
java.io.IOException - error adding

getRecord

public Record getRecord(java.lang.String recID)
                 throws java.lang.IllegalArgumentException,
                        java.io.IOException
Get a record

Parameters:
recID - record id to get
Returns:
record
Throws:
java.lang.IllegalArgumentException - record not found
java.io.IOException - error reading

getRecordData

public abstract java.lang.String getRecordData(java.lang.String recID)
                                        throws java.lang.IllegalArgumentException,
                                               java.io.IOException
Retrieve the data for a given record

Parameters:
recID - id of record to retrieve
Returns:
data from record
Throws:
java.lang.IllegalArgumentException - id not found
java.io.IOException - error reading

getRecordMetaData

protected abstract java.util.SortedSet<RecordMetaData> getRecordMetaData(java.lang.String recID)
                                                                  throws java.io.IOException
Retrieves all metadata for a given record

Parameters:
recID - id of record to retrieve metadata for
Returns:
the metadata map
Throws:
java.io.IOException - error retrieving record metadata

getLastMetaData

protected RecordMetaData getLastMetaData(java.lang.String recID,
                                         RecordMetaData.RecordMetaDataType type,
                                         java.lang.Class<?> operator)
                                  throws java.io.IOException
Get the last RecordMetaData of a given type by a given operator for a given record

Parameters:
recID - id of record to retrieve metadata for
type - the type of metadata, null for any type
operator - the operator to get for, null for any type
Returns:
the last metadata of the specified type
Throws:
java.io.IOException - error retrieving record metadata

setProcessed

protected void setProcessed(Record rec,
                            java.lang.Class<?> operator)
                     throws java.io.IOException
Add a metadata record to indicate that the given operator has processed the given record

Parameters:
rec - record to set processed
operator - the class performing the processing
Throws:
java.io.IOException - error setting processed

setWritten

protected void setWritten(Record rec,
                          java.lang.Class<?> operator)
                   throws java.io.IOException
Add a metadata record to indicate that the given operator has written the given record

Parameters:
rec - record to set written
operator - the class performing the writing
Throws:
java.io.IOException - error setting written

addMetaData

protected void addMetaData(Record rec,
                           java.lang.Class<?> operator,
                           RecordMetaData.RecordMetaDataType type)
                    throws java.io.IOException
Adds a metadata record for the given record

Parameters:
rec - record to add metadata for
operator - the class operating on the record
type - the operation type
Throws:
java.io.IOException - error adding meta data

addMetaData

protected abstract void addMetaData(Record rec,
                                    RecordMetaData rmd)
                             throws java.io.IOException
Adds a metadata record

Parameters:
rec - record to add metadata for
rmd - the metadata record
Throws:
java.io.IOException - error adding meta data

delMetaData

protected abstract void delMetaData(java.lang.String recID)
                             throws java.io.IOException
Deletes all metadata for a record

Parameters:
recID - record id to delete metadata for
Throws:
java.io.IOException - error deleting metadata

delRecord

public abstract void delRecord(java.lang.String recID)
                        throws java.io.IOException
Delete the specified Record

Parameters:
recID - id of record to delete
Throws:
java.io.IOException - i/o error

getParam

protected java.lang.String getParam(java.util.Map<java.lang.String,java.lang.String> params,
                                    java.lang.String paramName,
                                    boolean required)
                             throws java.lang.IllegalArgumentException
Get a specified parameter

Parameters:
params - the param list to retrieve from
paramName - the parameter to retrieve
required - is this parameter required?
Returns:
the value for the parameter
Throws:
java.lang.IllegalArgumentException - parameter is required and does not exist

parseConfig

public static RecordHandler parseConfig(java.io.InputStream configStream,
                                        java.util.Map<java.lang.String,java.lang.String> overrideParams)
                                 throws java.io.IOException
Config Stream Based Factory that overrides parameters

Parameters:
configStream - the config input stream
overrideParams - the parameters to override the file with
Returns:
RecordHandler instance
Throws:
java.io.IOException - error configuring

parseConfig

public static RecordHandler parseConfig(org.apache.commons.vfs.FileObject configFile)
                                 throws java.io.IOException
Config File Based Factory

Parameters:
configFile - the vfs config file descriptor
Returns:
RecordHandler instance
Throws:
java.io.IOException - error configuring

parseConfig

public static RecordHandler parseConfig(org.apache.commons.vfs.FileObject configFile,
                                        java.util.Map<java.lang.String,java.lang.String> overrideParams)
                                 throws java.io.IOException
Config File Based Factory that overrides parameters

Parameters:
configFile - the vfs config file descriptor
overrideParams - the parameters to override the file with
Returns:
RecordHandler instance
Throws:
java.io.IOException - error configuring

parseConfig

public static RecordHandler parseConfig(java.io.File configFile)
                                 throws java.io.IOException
Config File Based Factory

Parameters:
configFile - the config file descriptor
Returns:
RecordHandler instance
Throws:
java.io.IOException - error configuring

parseConfig

public static RecordHandler parseConfig(java.io.File configFile,
                                        java.util.Map<java.lang.String,java.lang.String> overrideParams)
                                 throws java.io.IOException
Config File Based Factory

Parameters:
configFile - the config file descriptor
overrideParams - the parameters to override the file with
Returns:
RecordHandler instance
Throws:
java.io.IOException - error configuring

parseConfig

public static RecordHandler parseConfig(java.lang.String configFileName)
                                 throws java.io.IOException
Config File Based Factory

Parameters:
configFileName - the config file path
Returns:
RecordHandler instance
Throws:
java.io.IOException - xml parse error

parseConfig

public static RecordHandler parseConfig(java.lang.String configFileName,
                                        java.util.Map<java.lang.String,java.lang.String> overrideParams)
                                 throws java.io.IOException
Config File Based Factory

Parameters:
configFileName - the config file path
overrideParams - the parameters to override the file with
Returns:
RecordHandler instance
Throws:
java.io.IOException - xml parse error

setOverwriteDefault

public void setOverwriteDefault(boolean overwrite)
Setter for overwriteDefault

Parameters:
overwrite - the new value for overwriteDefault

isOverwriteDefault

public boolean isOverwriteDefault()
Getter for overwriteDefault

Returns:
the overwriteDefault

close

public abstract void close()
                    throws java.io.IOException
Closes the recordhandler

Throws:
java.io.IOException - error closing

needsProcessed

public boolean needsProcessed(java.lang.String id,
                              java.lang.Class<?> operator)
Has the given record been written since last processed by operator?

Parameters:
id - the record to check fo
operator - the class to check for
Returns:
true if written since last processed by operator or if never been processed by operator

needsUpdated

protected boolean needsUpdated(Record rec)
Does the given record contain updated information compared to existing record data

Parameters:
rec - the record
Returns:
true if need updated or record is new

find

public abstract java.util.Set<java.lang.String> find(java.lang.String idText)
                                              throws java.io.IOException
Find records with idText in their id

Parameters:
idText - the text to find
Returns:
list of ids that match
Throws:
java.io.IOException - error searching