Skip to main content
Common Reference

dbrename.js Filter

The dbrename JavaScript filter renames database (schemas) using two parameters from the properties file, the dbsource and dbtarget. Each event is then processed, and the statement or row based schema information is updated to dbtarget when the dbsource schema is identified.

Pre-configured filter namedbrename
JavaScript Filter Filetungsten-replicator/support/filters-javascript/dbrename.js
Property prefixreplicator.filter.dbrename
Stage compatibilitybinlog-to-q
tpm Option compatibilitysvc-extractor-filters
Data compatibilityAny event

Parameters

ParameterTypeDefaultDescription
dbsourcestring(none)Source table name (database to be renamed)
dbtargetstring(none)New database name

To configure the filter you would add the following to your properties:

replicator.filter.dbrename=com.continuent.tungsten.replicator.filter.JavaScriptFilter
replicator.filter.dbrename.script=${replicator.home.dir}/samples/extensions/javascript/dbrename.js
replicator.filter.dbrename.dbsource=SOURCE
replicator.filter.dbrename.dbtarget=TEST

The operation of the filter is straightforward, because the schema name is exposed and settable within the statement and row change objects:

function filter(event)
{
sourceName = filterProperties.getString("dbsource");
targetName = filterProperties.getString("dbtarget");

data = event.getData();

for(i=0;i<data.size();i++)
{
d = data.get(i);

if(d instanceof
com.continuent.tungsten.replicator.dbms.StatementData)
{
if(d.getDefaultSchema() != null &&
d.getDefaultSchema().compareTo(sourceName)==0)
{
d.setDefaultSchema(targetName);
}
}
else if(d instanceof
com.continuent.tungsten.replicator.dbms.RowChangeData)
{
rowChanges = data.get(i).getRowChanges();

for(j=0;j<rowChanges.size();j++)
{
oneRowChange = rowChanges.get(j);

if(oneRowChange.getSchemaName().compareTo(sourceName)==0)
{
oneRowChange.setSchemaName(targetName);
}
}
}
}
}