com.continuent.tungsten.replicator.filter
Class OptimizeUpdatesFilter

java.lang.Object
  extended by com.continuent.tungsten.replicator.filter.OptimizeUpdatesFilter
All Implemented Interfaces:
Filter, ReplicatorPlugin

public class OptimizeUpdatesFilter
extends java.lang.Object
implements Filter

Removes "SET key1=value1" parts of an UPDATE if the values updated are the same as current values in the key part. Eg.:

Original statement: - SQL(0) = - ACTION = UPDATE - TABLE = c - ROW# = 0 - COL(1: null) = 1 - COL(2: null) = 100 - COL(3: null) = Ten - KEY(1: null) = 1 - KEY(2: null) = 10 - KEY(3: null) = Ten
Transformed statement: - SQL(0) = - ACTION = UPDATE - TABLE = c - ROW# = 0 - COL(2: null) = 100 - KEY(1: null) = 1 - KEY(2: null) = 10 - KEY(3: null) = Ten

NOTE: if all columns are static (Issue 355), all are left intact (not removed). In this corner case, we can't remove the event completely, because if there are triggers (eg. which count UPDATEs), they would not fire. Hence, instead, we leave the event unchanged and unoptimized.

Version:
1.0
Author:
Linas Virbalas

Constructor Summary
OptimizeUpdatesFilter()
           
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent filter(ReplDBMSEvent event)
          Filter the event.
 void prepare(PluginContext context)
          Prepare plug-in for use.
 void release(PluginContext context)
          Release all resources used by plug-in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptimizeUpdatesFilter

public OptimizeUpdatesFilter()
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)