com.continuent.tungsten.replicator.loader
Class CSVLoader

java.lang.Object
  extended by com.continuent.tungsten.replicator.loader.Loader
      extended by com.continuent.tungsten.replicator.loader.CSVLoader
All Implemented Interfaces:
RawExtractor, ReplicatorPlugin

public class CSVLoader
extends Loader

Load THL events from a series of CSV files

Version:
1.0
Author:
Jeff Mace

Field Summary
 
Fields inherited from class com.continuent.tungsten.replicator.loader.Loader
chunkSize, lockTables, params, uri
 
Constructor Summary
CSVLoader()
           
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 DBMSEvent extract()
          Extract the next available DBMSEvent from the CSV file
 DBMSEvent extract(java.lang.String eventId)
          Extract starting after the event ID provided as an argument.
 java.lang.String getCurrentResourceEventId()
          Returns the last event ID committed in the database from which we are extracting.
protected  java.lang.String getDefaultSchema()
          Return the schema to use in the THL events
protected  java.lang.String getSourceID()
          Return the source ID to use in the THL events
protected  void nextTable()
          Update variables to point to the next table to load values for
 void prepare(PluginContext context)
          Prepare plug-in for use.
protected  void prepareCurrentTable()
          Open the CSV file containing the values for the current table
protected  void prepareTableDefinition(java.io.File f)
          Parse the table columns and data types from the table definition file
protected  java.lang.String[] readNext(java.io.LineNumberReader reader)
          Load the next set of CSV values from the file
 void release(PluginContext context)
          Release all resources used by plug-in.
 void setLastEventId(java.lang.String eventId)
          Set the value of the last event ID we have processed.
 
Methods inherited from class com.continuent.tungsten.replicator.loader.Loader
getChunkSize, getFinishLoadEvent, getLockTables, parseStringValue, setChunkSize, setLockTables, setUri
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVLoader

public CSVLoader()
Method Detail

configure

public void configure(PluginContext context)
               throws ReplicatorException,
                      java.lang.InterruptedException
Complete plug-in configuration. This is called after setters are invoked at the time that the replicator goes through configuration.

Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
java.lang.InterruptedException

prepare

public void prepare(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Prepare plug-in for use. This method is assumed to allocate all required resources. It is called before the plug-in performs any operations.

Throws:
ReplicatorException - Thrown if resource allocation fails
java.lang.InterruptedException

prepareTableDefinition

protected void prepareTableDefinition(java.io.File f)
                               throws ReplicatorException
Parse the table columns and data types from the table definition file

Parameters:
f -
Throws:
ReplicatorException

release

public void release(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Release all resources used by plug-in. This is called before the plug-in is deallocated.

Throws:
ReplicatorException - Thrown if resource deallocation fails
java.lang.InterruptedException

setLastEventId

public void setLastEventId(java.lang.String eventId)
                    throws ReplicatorException
Set the value of the last event ID we have processed. The extractor is responsible for returning the next event ID in sequence after this one the next time extract() is called.

Parameters:
eventId - Event ID at which to begin extracting
Throws:
ReplicatorException

nextTable

protected void nextTable()
                  throws ReplicatorException
Update variables to point to the next table to load values for

Throws:
ReplicatorException

prepareCurrentTable

protected void prepareCurrentTable()
                            throws ReplicatorException
Open the CSV file containing the values for the current table

Throws:
ReplicatorException

extract

public DBMSEvent extract()
                  throws ReplicatorException,
                         java.lang.InterruptedException
Extract the next available DBMSEvent from the CSV file

Returns:
next DBMSEvent found in the logs
Throws:
java.io.IOException
ReplicatorException
java.lang.InterruptedException

readNext

protected java.lang.String[] readNext(java.io.LineNumberReader reader)
                               throws java.io.IOException
Load the next set of CSV values from the file

Parameters:
reader -
Returns:
An array of strings representing the next row
Throws:
java.io.IOException

extract

public DBMSEvent extract(java.lang.String eventId)
                  throws ReplicatorException,
                         java.lang.InterruptedException
Extract starting after the event ID provided as an argument. This is equivalent to invoking setLastEventId() followed by extract().

Parameters:
eventId - Event ID at which to begin extracting
Returns:
DBMSEvent corresponding to the id
Throws:
ReplicatorException - Thrown if extractor processing fails
java.lang.InterruptedException - Thrown if the applier is interrupted

getCurrentResourceEventId

public java.lang.String getCurrentResourceEventId()
                                           throws ReplicatorException,
                                                  java.lang.InterruptedException
Returns the last event ID committed in the database from which we are extracting. It is used to help synchronize state between the database and the transaction history log. Values returned from this call must correspond with the last extracted DBMSEvent.eventId as follows:
  1. If the returned value is greater than DBMSEvent.eventId, the database has more recent updates
  2. If the returned value is equal to DBMSEvent.eventId, all events have been extracted
It should not be possible to receive a value that is less than the last extracted DBMSEvent.eventId as this implies that the extractor is somehow ahead of the state of the database, which would be inconsistent.

Returns:
A current event ID that can be compared with event IDs in DBMSEvent
Throws:
ReplicatorException
java.lang.InterruptedException

getSourceID

protected java.lang.String getSourceID()
                                throws java.lang.Exception
Return the source ID to use in the THL events

Throws:
java.lang.Exception

getDefaultSchema

protected java.lang.String getDefaultSchema()
                                     throws ReplicatorException
Return the schema to use in the THL events

Throws:
ReplicatorException