Skip to content

Commit

Permalink
0002898: DBCompare should consult sym_router when determining target
Browse files Browse the repository at this point in the history
catalog and schema
  • Loading branch information
mmichalek committed Nov 16, 2016
1 parent 941e90b commit 474d0b5
Showing 1 changed file with 28 additions and 1 deletion.
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
Expand All @@ -43,6 +44,7 @@
import org.jumpmind.symmetric.common.TableConstants;
import org.jumpmind.symmetric.io.DbCompareReport.TableReport;
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.model.TriggerRouter;
import org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -393,6 +395,10 @@ protected boolean mapPrimaryKey(DbCompareTables tables) {

protected Table loadTargetTable(DbCompareTables tables) {
Table targetTable = null;

String catalog = targetEngine.getDatabasePlatform().getDefaultCatalog();
String schema = targetEngine.getDatabasePlatform().getDefaultSchema();

if (config.isUseSymmetricConfig()) {
TransformTableNodeGroupLink transform = getTransformFor(tables.getSourceTable());
if (transform != null) {
Expand All @@ -401,15 +407,36 @@ protected Table loadTargetTable(DbCompareTables tables) {
tables.setTransform(transform);
return targetTable;
}

TriggerRouter triggerRouter = getTriggerRouterFor(tables.getSourceTable());
if (triggerRouter != null) {
catalog = triggerRouter.getTargetCatalog(catalog);
schema = triggerRouter.getTargetSchema(schema);
}
}

targetTable = targetEngine.getDatabasePlatform().
getTableFromCache(tables.getSourceTable().getName(), true);
getTableFromCache(catalog, schema, tables.getSourceTable().getName(), true);
tables.setTargetTable(targetTable);

return targetTable;
}

protected TriggerRouter getTriggerRouterFor(Table sourceTable) {
// TODO get routers.
Set<TriggerRouter> triggerRouters = sourceEngine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(
sourceTable.getCatalog(), sourceTable.getSchema(), sourceTable.getName(), false);

for (TriggerRouter triggerRouter : triggerRouters) {
String routerTargetNodeGroupId = triggerRouter.getRouter().getNodeGroupLink().getTargetNodeGroupId();
String compareTargetNodeGroupId = targetEngine.getNodeService().getCachedIdentity().getNodeGroupId();
if (StringUtils.equals(compareTargetNodeGroupId, routerTargetNodeGroupId)) {
return triggerRouter;
}
}
return null;
}

protected TransformTableNodeGroupLink getTransformFor(Table sourceTable) {
String sourceNodeGroupId = sourceEngine.getNodeService().findIdentity().getNodeGroupId();
String targetNodeGroupId = targetEngine.getNodeService().findIdentity().getNodeGroupId();
Expand Down

0 comments on commit 474d0b5

Please sign in to comment.