com.continuent.tungsten.replicator.database
Class MySQLCommentEditor

java.lang.Object
  extended by com.continuent.tungsten.replicator.database.MySQLCommentEditor
All Implemented Interfaces:
SqlCommentEditor

public class MySQLCommentEditor
extends java.lang.Object
implements SqlCommentEditor

Parses SQL statements to extract the SQL operation and the object, identified by type, name and schema, to which it pertains.

Version:
1.0
Author:
Robert Hodges

Field Summary
protected  boolean commentEditingEnabled
           
protected  java.util.regex.Pattern dropTable
           
protected  java.util.regex.Pattern dropTablePattern
           
protected  java.util.regex.Pattern ifExistsPattern
           
protected  java.util.regex.Pattern sprocPattern
           
protected  java.util.regex.Pattern standardPattern
           
 
Constructor Summary
MySQLCommentEditor()
           
 
Method Summary
 java.lang.String addComment(java.lang.String statement, SqlOperation sqlOp, java.lang.String comment)
          Inserts a comment safely into a SQL statement.
 java.lang.String fetchComment(java.lang.String statement, SqlOperation sqlOp)
          Fetches the first comment string that matches the regex.
 java.lang.String formatAppendableComment(SqlOperation sqlOp, java.lang.String comment)
          Formats an appendable comment if this works.
 void setCommentEditingEnabled(boolean enabled)
          If true, comment editing is enabled.
 void setCommentRegex(java.lang.String regex)
          Set comment regex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commentEditingEnabled

protected boolean commentEditingEnabled

standardPattern

protected java.util.regex.Pattern standardPattern

sprocPattern

protected java.util.regex.Pattern sprocPattern

dropTablePattern

protected java.util.regex.Pattern dropTablePattern

ifExistsPattern

protected java.util.regex.Pattern ifExistsPattern

dropTable

protected java.util.regex.Pattern dropTable
Constructor Detail

MySQLCommentEditor

public MySQLCommentEditor()
Method Detail

setCommentEditingEnabled

public void setCommentEditingEnabled(boolean enabled)
If true, comment editing is enabled. If false, comment editing is ignored and we just return the current statement.

Specified by:
setCommentEditingEnabled in interface SqlCommentEditor
See Also:
SqlCommentEditor.setCommentEditingEnabled(boolean)

addComment

public java.lang.String addComment(java.lang.String statement,
                                   SqlOperation sqlOp,
                                   java.lang.String comment)
Inserts a comment safely into a SQL statement.

Specified by:
addComment in interface SqlCommentEditor
Parameters:
statement - Statement that requires a comment to be inserted.
sqlOp - Metadata from parsing statement, if any
comment - Comment string to be added.
Returns:
Query with comment added
See Also:
SqlCommentEditor.addComment(java.lang.String, com.continuent.tungsten.replicator.database.SqlOperation, java.lang.String)

formatAppendableComment

public java.lang.String formatAppendableComment(SqlOperation sqlOp,
                                                java.lang.String comment)
Formats an appendable comment if this works.

Specified by:
formatAppendableComment in interface SqlCommentEditor
Parameters:
sqlOp - Metadata from parsing statement
comment - Comment string to be added.
Returns:
Appendable comment or null if such comments are not safe for current statement
See Also:
SqlCommentEditor.formatAppendableComment(SqlOperation, String)

fetchComment

public java.lang.String fetchComment(java.lang.String statement,
                                     SqlOperation sqlOp)
Fetches the first comment string that matches the regex.

Specified by:
fetchComment in interface SqlCommentEditor
Parameters:
statement - Statement to search
Returns:
Matching comment string or null if not found.
See Also:
SqlCommentEditor.fetchComment(String, SqlOperation)

setCommentRegex

public void setCommentRegex(java.lang.String regex)
Set comment regex. This is used to fetch out specific parts of the comment and is set once to avoid regex recompilation.

Specified by:
setCommentRegex in interface SqlCommentEditor
See Also:
SqlCommentEditor.setCommentRegex(java.lang.String)