com.continuent.tungsten.replicator.filter
Class EnumToStringFilter

java.lang.Object
  extended by com.continuent.tungsten.replicator.filter.EnumToStringFilter
All Implemented Interfaces:
Filter, ReplicatorPlugin
Direct Known Subclasses:
SetToStringFilter

public class EnumToStringFilter
extends java.lang.Object
implements Filter

EnumToStringFilter transforms enum data type values to corresponding string representation as follows:
1. On each event it checks whether targeted table has enum data type column.
2. If it does, corresponding enum column values of the event are mapped from integer into string representations.

The filter is to be used with row replication.

Filter takes an optional parameter for performance tuning. Instead of checking all the tables you may define only a specific comma-delimited list in process_tables_schemas parameter. Eg.:
replicator.filter.enumtostringfilter.process_tables_schemas=myschema.mytable1,myschema.mytable2

Version:
1.0
Author:
Linas Virbalas

Constructor Summary
EnumToStringFilter()
           
 
Method Summary
protected  void checkForListType(OneRowChange orc)
          Checks for ENUM columns in the event.
protected  void checkForListType(OneRowChange orc, java.lang.String type)
          Checks for ENUM/SET type columns in the event.
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent filter(ReplDBMSEvent event)
          Filter the event.
static int largestElement(java.lang.String[] enumValues)
           
static int largestElementLen(java.lang.String enumDefinition)
           
static int largestElementLen(java.lang.String[] enumValues)
          Returns how long is the largest element of enumeration.
static java.lang.String[] parseEnumeration(java.lang.String enumDefinition)
          Parses MySQL enum type definition statement.
static java.lang.String[] parseListDefString(java.lang.String colType, java.lang.String definition)
          Parses strings of the following form:
enum('val1','val2',...)
set('val1','val2',...)
protected  java.lang.String[] parseListType(java.lang.String listTypeDefinition)
           
 void prepare(PluginContext context)
          Prepare plug-in for use.
 void release(PluginContext context)
          Release all resources used by plug-in.
 void setPassword(java.lang.String password)
           
 void setProcessTablesSchemas(java.lang.String processTablesSchemas)
           
 void setUrl(java.lang.String url)
           
 void setUser(java.lang.String user)
           
protected  void transformColumns(java.util.ArrayList<OneRowChange.ColumnSpec> columns, java.util.ArrayList<java.util.ArrayList<OneRowChange.ColumnVal>> columnValues, java.util.HashMap<java.lang.Integer,java.lang.String[]> enumDefinitions, java.lang.String typeCaption)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumToStringFilter

public EnumToStringFilter()
Method Detail

configure

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

Specified by:
configure in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
See Also:
ReplicatorPlugin.configure(com.continuent.tungsten.replicator.plugin.PluginContext)

prepare

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

Specified by:
prepare in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource allocation fails
See Also:
ReplicatorPlugin.prepare(com.continuent.tungsten.replicator.plugin.PluginContext)

release

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

Specified by:
release in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource deallocation fails
See Also:
ReplicatorPlugin.release(com.continuent.tungsten.replicator.plugin.PluginContext)

filter

public ReplDBMSEvent filter(ReplDBMSEvent event)
                     throws ReplicatorException,
                            java.lang.InterruptedException
Filter the event. Filters may transform the event or return null if the event should be discarded. Filters must be prepared to be interrupted, which mechanism is used to cancel processing.

Specified by:
filter in interface Filter
Parameters:
event - An event to be filtered
Returns:
Filtered ReplDBMSEvent or null
Throws:
ReplicatorException - Thrown if there is a processing error
java.lang.InterruptedException - Must be thrown if the filter is interrupted or the replicator may hang
See Also:
Filter.filter(com.continuent.tungsten.replicator.event.ReplDBMSEvent)

parseListType

protected java.lang.String[] parseListType(java.lang.String listTypeDefinition)

parseEnumeration

public static java.lang.String[] parseEnumeration(java.lang.String enumDefinition)
Parses MySQL enum type definition statement. Eg.:
enum('Active','Inactive','Removed')
enum('No','Yes')
etc.

Parameters:
enumDefinition - String of the following form: enum('val1','val2',...)
Returns:
Enumeration elements in an array. Unquoted. Eg.: Active,Inactive,Removed

parseListDefString

public static java.lang.String[] parseListDefString(java.lang.String colType,
                                                    java.lang.String definition)
Parses strings of the following form:
enum('val1','val2',...)
set('val1','val2',...)

Parameters:
colType - "enum" or "string"
definition - String like "enum('val1','val2',...)" or "set('val1','val2',...)".
Returns:
Elements in the definition (val1,val2,...).

largestElementLen

public static int largestElementLen(java.lang.String enumDefinition)
Parameters:
enumDefinition - String of the following form: enum('val1','val2',...)
Returns:
Length of the largest element in given enumeration definition.
See Also:
largestElement(String[])

largestElementLen

public static int largestElementLen(java.lang.String[] enumValues)
Returns how long is the largest element of enumeration.

Parameters:
enumValues - Values of enumeration. Eg.: 'No','Yes'
Returns:
Length of the largest element.

largestElement

public static int largestElement(java.lang.String[] enumValues)
Returns:
Position of the largest element in the array.

checkForListType

protected void checkForListType(OneRowChange orc)
                         throws java.sql.SQLException,
                                ReplicatorException
Checks for ENUM columns in the event. If found, transforms values from integers to corresponding strings.

Parameters:
orc -
Throws:
java.sql.SQLException
ReplicatorException

checkForListType

protected void checkForListType(OneRowChange orc,
                                java.lang.String type)
                         throws java.sql.SQLException,
                                ReplicatorException
Checks for ENUM/SET type columns in the event. If found, transforms values from integers to corresponding strings.

Parameters:
type - "ENUM" or "SET".
Throws:
java.sql.SQLException
ReplicatorException

transformColumns

protected void transformColumns(java.util.ArrayList<OneRowChange.ColumnSpec> columns,
                                java.util.ArrayList<java.util.ArrayList<OneRowChange.ColumnVal>> columnValues,
                                java.util.HashMap<java.lang.Integer,java.lang.String[]> enumDefinitions,
                                java.lang.String typeCaption)
                         throws ReplicatorException
Throws:
ReplicatorException

setUser

public void setUser(java.lang.String user)

setUrl

public void setUrl(java.lang.String url)

setPassword

public void setPassword(java.lang.String password)

setProcessTablesSchemas

public void setProcessTablesSchemas(java.lang.String processTablesSchemas)