com.continuent.tungsten.replicator.loader
Class JdbcLoader

java.lang.Object
  extended by com.continuent.tungsten.replicator.loader.Loader
      extended by com.continuent.tungsten.replicator.loader.JdbcLoader
All Implemented Interfaces:
RawExtractor, ReplicatorPlugin
Direct Known Subclasses:
MySQLLoader

public abstract class JdbcLoader
extends Loader


Field Summary
protected  java.util.ArrayList<OneRowChange.ColumnSpec> columnDefinitions
           
protected  Database conn
           
protected  java.lang.String driver
           
protected  java.sql.ResultSet importTables
           
protected  java.util.List<java.lang.String> includeSchemas
           
protected  boolean includeStructure
           
protected  java.sql.DatabaseMetaData metadata
           
protected  java.lang.String password
           
protected  java.sql.Statement statement
           
protected  java.lang.String tungstenServiceSchema
           
protected  java.lang.String tungstenServiceSchemaPosition
           
protected  java.lang.String url
           
protected  java.lang.String user
           
 
Fields inherited from class com.continuent.tungsten.replicator.loader.Loader
chunkSize, lockTables, params, uri
 
Constructor Summary
JdbcLoader()
           
 
Method Summary
protected  java.lang.String buildCreateSchemaStatement()
          Return a statement that will create the schema, null if no create schema can be given
protected  java.lang.String buildCreateTableStatement()
          Return a statement that will create the table structure, null if no create table can be given
 void configure(PluginContext context)
          Complete plug-in configuration.
 DBMSEvent extract()
          Extract a THL event up to getChunkSize() rows Extract the next available DBMSEvent from the database log.
 DBMSEvent extract(java.lang.String eventId)
          Extract starting after the event ID provided as an argument.
protected  int extractColumnType(java.sql.ResultSet columnList)
          Determine the java.sql.Types type of a column based on the column metadata
protected  RowChangeData extractRowChangeData()
          Extract the actual rows from the database and build the change set
protected  java.io.Serializable extractRowValue(int type, java.sql.ResultSet rowValues, java.lang.String columnName)
          Take a raw value and return the proper Java data type for the java.sql.Types type given
 java.lang.String getCurrentResourceEventId()
          Parse the value of tungstenServiceSchemaPosition for the current eventId
 java.lang.String getTungstenSchema()
           
 java.lang.String getTungstenServiceSchema()
           
protected  boolean includeImportTable()
          Should the current table be imported
 void lockTables()
          A placeholder function for loaders that can lock tables
protected  void nextTable()
          Prepare the next table for extraction by resetting the position and parsing column definitions
 void prepare(PluginContext context)
          Prepare plug-in for use.
protected  void prepareImportTable()
          Parse column definitions for the current table
 void release(PluginContext context)
          Release all resources used by plug-in.
 void setIncludeSchemas(java.lang.String includeSchemas)
          Set the list of schemas to include when extracting events.
 void setIncludeStructure(boolean includeStructure)
           
 void setLastEventId(java.lang.String eventId)
          Prepare to start extraction from the first table found Set the value of the last event ID we have processed.
 void setPassword(java.lang.String password)
          Set the MySQL password to connect with
 void setTungstenServiceSchema(java.lang.String schemaName)
           
 void setUser(java.lang.String user)
          Set the MySQL user to connect with
 
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
 

Field Detail

driver

protected java.lang.String driver

url

protected java.lang.String url

user

protected java.lang.String user

password

protected java.lang.String password

conn

protected Database conn

statement

protected java.sql.Statement statement

metadata

protected java.sql.DatabaseMetaData metadata

importTables

protected java.sql.ResultSet importTables

includeSchemas

protected java.util.List<java.lang.String> includeSchemas

columnDefinitions

protected java.util.ArrayList<OneRowChange.ColumnSpec> columnDefinitions

tungstenServiceSchema

protected java.lang.String tungstenServiceSchema

tungstenServiceSchemaPosition

protected java.lang.String tungstenServiceSchemaPosition

includeStructure

protected boolean includeStructure
Constructor Detail

JdbcLoader

public JdbcLoader()
Method Detail

setUser

public void setUser(java.lang.String user)
Set the MySQL user to connect with

Parameters:
user -

setPassword

public void setPassword(java.lang.String password)
Set the MySQL password to connect with

Parameters:
password -

setTungstenServiceSchema

public void setTungstenServiceSchema(java.lang.String schemaName)

getTungstenServiceSchema

public java.lang.String getTungstenServiceSchema()

setIncludeSchemas

public void setIncludeSchemas(java.lang.String includeSchemas)
Set the list of schemas to include when extracting events. A comma-separated list should be provided.

Parameters:
includeSchemas -

setIncludeStructure

public void setIncludeStructure(boolean includeStructure)

getTungstenSchema

public java.lang.String getTungstenSchema()

setLastEventId

public void setLastEventId(java.lang.String eventId)
                    throws ReplicatorException
Prepare to start extraction from the first table found 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
See Also:
RawExtractor.setLastEventId(java.lang.String)

nextTable

protected void nextTable()
                  throws ReplicatorException,
                         java.sql.SQLException
Prepare the next table for extraction by resetting the position and parsing column definitions

Throws:
ReplicatorException
java.sql.SQLException

includeImportTable

protected boolean includeImportTable()
                              throws java.sql.SQLException
Should the current table be imported

Throws:
java.sql.SQLException

prepareImportTable

protected void prepareImportTable()
                           throws java.sql.SQLException
Parse column definitions for the current table

Throws:
java.sql.SQLException

extractColumnType

protected int extractColumnType(java.sql.ResultSet columnList)
                         throws java.sql.SQLException
Determine the java.sql.Types type of a column based on the column metadata

Parameters:
columnList -
Returns:
The java.sql.Types value for the column
Throws:
java.sql.SQLException

extractRowValue

protected java.io.Serializable extractRowValue(int type,
                                               java.sql.ResultSet rowValues,
                                               java.lang.String columnName)
                                        throws java.lang.Exception
Take a raw value and return the proper Java data type for the java.sql.Types type given

Throws:
java.lang.Exception

extract

public DBMSEvent extract()
                  throws ReplicatorException,
                         java.lang.InterruptedException
Extract a THL event up to getChunkSize() rows Extract the next available DBMSEvent from the database log.

Returns:
next DBMSEvent found in the logs
Throws:
ReplicatorException
java.lang.InterruptedException
See Also:
RawExtractor.extract()

buildCreateSchemaStatement

protected java.lang.String buildCreateSchemaStatement()
                                               throws ReplicatorException
Return a statement that will create the schema, null if no create schema can be given

Throws:
ReplicatorException

buildCreateTableStatement

protected java.lang.String buildCreateTableStatement()
                                              throws ReplicatorException
Return a statement that will create the table structure, null if no create table can be given

Throws:
ReplicatorException

extractRowChangeData

protected RowChangeData extractRowChangeData()
                                      throws java.sql.SQLException
Extract the actual rows from the database and build the change set

Throws:
java.sql.SQLException

extract

public DBMSEvent extract(java.lang.String eventId)
                  throws ReplicatorException,
                         java.lang.InterruptedException
Description copied from interface: RawExtractor
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

configure

public void configure(PluginContext context)
               throws ReplicatorException,
                      java.lang.InterruptedException
Description copied from interface: ReplicatorPlugin
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
Description copied from interface: ReplicatorPlugin
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

release

public void release(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Description copied from interface: ReplicatorPlugin
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

getCurrentResourceEventId

public java.lang.String getCurrentResourceEventId()
                                           throws ReplicatorException,
                                                  java.lang.InterruptedException
Parse the value of tungstenServiceSchemaPosition for the current eventId

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

lockTables

public void lockTables()
                throws java.sql.SQLException
A placeholder function for loaders that can lock tables

Throws:
java.sql.SQLException