Search in sources :

Example 1 with TransformTableNodeGroupLink

use of org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink in project symmetric-ds by JumpMind.

the class DbCompare method getTransformFor.

protected TransformTableNodeGroupLink getTransformFor(Table sourceTable) {
    String sourceNodeGroupId = sourceEngine.getNodeService().findIdentity().getNodeGroupId();
    String targetNodeGroupId = targetEngine.getNodeService().findIdentity().getNodeGroupId();
    List<TransformTableNodeGroupLink> transforms = sourceEngine.getTransformService().findTransformsFor(sourceNodeGroupId, targetNodeGroupId, sourceTable.getName());
    if (!CollectionUtils.isEmpty(transforms)) {
        // Only can operate on a single table transform for now.
        TransformTableNodeGroupLink transform = transforms.get(0);
        if (!StringUtils.isEmpty(transform.getFullyQualifiedTargetTableName())) {
            return transform;
        }
    }
    return null;
}
Also used : TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)

Example 2 with TransformTableNodeGroupLink

use of org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink in project symmetric-ds by JumpMind.

the class DbCompare method loadTargetTable.

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) {
            targetTable = loadTargetTableUsingTransform(transform);
            tables.setTargetTable(targetTable);
            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(catalog, schema, tables.getSourceTable().getName(), true);
    tables.setTargetTable(targetTable);
    return targetTable;
}
Also used : Table(org.jumpmind.db.model.Table) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)

Example 3 with TransformTableNodeGroupLink

use of org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink in project symmetric-ds by JumpMind.

the class AbstractSymmetricDialect method createPurgeSqlFor.

@Override
public String createPurgeSqlFor(Node node, TriggerRouter triggerRouter, TriggerHistory triggerHistory, List<TransformTableNodeGroupLink> transforms, String deleteSql) {
    String sql = null;
    if (StringUtils.isEmpty(triggerRouter.getInitialLoadDeleteStmt())) {
        List<String> tableNames = new ArrayList<String>();
        if (transforms != null) {
            for (TransformTableNodeGroupLink transform : transforms) {
                tableNames.add(transform.getFullyQualifiedTargetTableName());
            }
        } else {
            tableNames.add(triggerRouter.qualifiedTargetTableName(triggerHistory));
        }
        StringBuilder statements = new StringBuilder(128);
        for (String tableName : tableNames) {
            if (deleteSql == null) {
                if (tableName.startsWith(parameterService.getTablePrefix())) {
                    deleteSql = "delete from %s";
                } else {
                    deleteSql = parameterService.getString(ParameterConstants.INITIAL_LOAD_DELETE_FIRST_SQL);
                }
            }
            statements.append(String.format(deleteSql, tableName)).append(";");
        }
        // Lose the last ;
        statements.setLength(statements.length() - 1);
        sql = statements.toString();
    } else {
        sql = triggerRouter.getInitialLoadDeleteStmt();
    }
    return sql;
}
Also used : ArrayList(java.util.ArrayList) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)

Example 4 with TransformTableNodeGroupLink

use of org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink in project symmetric-ds by JumpMind.

the class AbstractSymmetricEngine method uninstall.

public synchronized void uninstall() {
    log.warn("Attempting an uninstall of all SymmetricDS database objects from the database");
    stop();
    log.info("Just cleaned {} files in the staging area during the uninstall.", getStagingManager().clean(0));
    try {
        Table table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_TRIGGER_ROUTER));
        if (table != null) {
            List<Grouplet> grouplets = groupletService.getGrouplets(true);
            for (Grouplet grouplet : grouplets) {
                groupletService.deleteGrouplet(grouplet);
            }
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(false, true);
            for (TriggerRouter triggerRouter : triggerRouters) {
                triggerRouterService.deleteTriggerRouter(triggerRouter);
            }
            List<FileTriggerRouter> fileTriggerRouters = fileSyncService.getFileTriggerRouters();
            for (FileTriggerRouter fileTriggerRouter : fileTriggerRouters) {
                fileSyncService.deleteFileTriggerRouter(fileTriggerRouter);
            }
            List<Router> routers = triggerRouterService.getRouters(true);
            for (Router router : routers) {
                triggerRouterService.deleteRouter(router);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_CONFLICT));
        if (table != null) {
            // need to remove all conflicts before we can remove the node
            // group links
            List<ConflictNodeGroupLink> conflicts = dataLoaderService.getConflictSettingsNodeGroupLinks();
            for (ConflictNodeGroupLink conflict : conflicts) {
                dataLoaderService.delete(conflict);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_TRANSFORM_TABLE));
        if (table != null) {
            // need to remove all transforms before we can remove the node
            // group links
            List<TransformTableNodeGroupLink> transforms = transformService.getTransformTables(false);
            for (TransformTableNodeGroupLink transformTable : transforms) {
                transformService.deleteTransformTable(transformTable.getTransformId());
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_ROUTER));
        if (table != null) {
            List<Router> objects = triggerRouterService.getRouters(true);
            for (Router router : objects) {
                triggerRouterService.deleteRouter(router);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_CONFLICT));
        if (table != null) {
            List<ConflictNodeGroupLink> objects = dataLoaderService.getConflictSettingsNodeGroupLinks();
            for (ConflictNodeGroupLink obj : objects) {
                dataLoaderService.delete(obj);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_NODE_GROUP_LINK));
        if (table != null) {
            // remove the links so the symmetric table trigger will be
            // removed
            List<NodeGroupLink> links = configurationService.getNodeGroupLinks(false);
            for (NodeGroupLink nodeGroupLink : links) {
                configurationService.deleteNodeGroupLink(nodeGroupLink);
            }
        }
        if (table != null) {
            // this should remove all triggers because we have removed all the
            // trigger configuration
            triggerRouterService.syncTriggers();
        }
    } catch (SqlException ex) {
        log.warn("Error while trying remove triggers on tables", ex);
    }
    // remove any additional triggers that may remain because they were not in trigger history
    symmetricDialect.cleanupTriggers();
    symmetricDialect.dropTablesAndDatabaseObjects();
    // force cache to be cleared
    nodeService.deleteIdentity();
    parameterService.setDatabaseHasBeenInitialized(false);
    log.warn("Finished uninstalling SymmetricDS database objects from the database");
}
Also used : Table(org.jumpmind.db.model.Table) ConflictNodeGroupLink(org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink) SqlException(org.jumpmind.db.sql.SqlException) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) Grouplet(org.jumpmind.symmetric.model.Grouplet) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) ConflictNodeGroupLink(org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)

Example 5 with TransformTableNodeGroupLink

use of org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink in project symmetric-ds by JumpMind.

the class DataLoaderService method buildDataWriter.

protected IDataWriter buildDataWriter(ProcessInfo processInfo, String sourceNodeId, String channelId, long batchId, boolean isRetry) {
    TransformTable[] transforms = null;
    NodeGroupLink link = null;
    List<ResolvedData> resolvedDatas = new ArrayList<ResolvedData>();
    List<IDatabaseWriterFilter> filters = extensionService.getExtensionPointList(IDatabaseWriterFilter.class);
    List<IDatabaseWriterFilter> dynamicFilters = filters;
    List<IDatabaseWriterErrorHandler> errorHandlers = extensionService.getExtensionPointList(IDatabaseWriterErrorHandler.class);
    List<IDatabaseWriterErrorHandler> dynamicErrorHandlers = errorHandlers;
    if (sourceNodeId != null) {
        Node sourceNode = nodeService.findNode(sourceNodeId, true);
        if (sourceNode != null) {
            link = new NodeGroupLink(sourceNode.getNodeGroupId(), parameterService.getNodeGroupId());
        }
        Map<LoadFilterType, Map<String, List<LoadFilter>>> loadFilters = loadFilterService.findLoadFiltersFor(link, true);
        List<DynamicDatabaseWriterFilter> databaseWriterFilters = DynamicDatabaseWriterFilter.getDatabaseWriterFilters(engine, loadFilters);
        if (loadFilters != null && loadFilters.size() > 0) {
            dynamicFilters = new ArrayList<IDatabaseWriterFilter>(filters.size() + 1);
            dynamicFilters.addAll(filters);
            dynamicFilters.addAll(databaseWriterFilters);
            dynamicErrorHandlers = new ArrayList<IDatabaseWriterErrorHandler>(errorHandlers.size() + 1);
            dynamicErrorHandlers.addAll(errorHandlers);
            dynamicErrorHandlers.addAll(databaseWriterFilters);
        }
        List<TransformTableNodeGroupLink> transformsList = transformService.findTransformsFor(link, TransformPoint.LOAD);
        transforms = transformsList != null ? transformsList.toArray(new TransformTable[transformsList.size()]) : null;
        if (isRetry) {
            List<IncomingError> incomingErrors = getIncomingErrors(batchId, sourceNodeId);
            for (IncomingError incomingError : incomingErrors) {
                if (incomingError.isResolveIgnore() || StringUtils.isNotBlank(incomingError.getResolveData())) {
                    resolvedDatas.add(new ResolvedData(incomingError.getFailedRowNumber(), incomingError.getResolveData(), incomingError.isResolveIgnore()));
                }
            }
        }
    }
    TransformWriter transformWriter = new TransformWriter(platform, TransformPoint.LOAD, null, transformService.getColumnTransforms(), transforms);
    IDataWriter targetWriter = getFactory(channelId).getDataWriter(sourceNodeId, symmetricDialect, transformWriter, dynamicFilters, dynamicErrorHandlers, getConflictSettingsNodeGroupLinks(link, false), resolvedDatas);
    transformWriter.setNestedWriter(new ProcessInfoDataWriter(targetWriter, processInfo));
    return transformWriter;
}
Also used : ResolvedData(org.jumpmind.symmetric.io.data.writer.ResolvedData) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) TransformTable(org.jumpmind.symmetric.io.data.transform.TransformTable) DynamicDatabaseWriterFilter(org.jumpmind.symmetric.load.DynamicDatabaseWriterFilter) IncomingError(org.jumpmind.symmetric.model.IncomingError) IDatabaseWriterErrorHandler(org.jumpmind.symmetric.io.data.writer.IDatabaseWriterErrorHandler) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) IDatabaseWriterFilter(org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter) ProcessInfoDataWriter(org.jumpmind.symmetric.model.ProcessInfoDataWriter) LoadFilterType(org.jumpmind.symmetric.model.LoadFilter.LoadFilterType) LoadFilter(org.jumpmind.symmetric.model.LoadFilter) TransformWriter(org.jumpmind.symmetric.io.data.writer.TransformWriter) ChannelMap(org.jumpmind.symmetric.model.ChannelMap) Map(java.util.Map) HashMap(java.util.HashMap) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) IDataWriter(org.jumpmind.symmetric.io.data.IDataWriter)

Aggregations

TransformTableNodeGroupLink (org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)7 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)4 ArrayList (java.util.ArrayList)3 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)3 TransformWriter (org.jumpmind.symmetric.io.data.writer.TransformWriter)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Table (org.jumpmind.db.model.Table)2 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)2 IDatabaseWriterErrorHandler (org.jumpmind.symmetric.io.data.writer.IDatabaseWriterErrorHandler)2 IDatabaseWriterFilter (org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter)2 ResolvedData (org.jumpmind.symmetric.io.data.writer.ResolvedData)2 DynamicDatabaseWriterFilter (org.jumpmind.symmetric.load.DynamicDatabaseWriterFilter)2 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)2 IncomingError (org.jumpmind.symmetric.model.IncomingError)2 LoadFilter (org.jumpmind.symmetric.model.LoadFilter)2 LoadFilterType (org.jumpmind.symmetric.model.LoadFilter.LoadFilterType)2 Node (org.jumpmind.symmetric.model.Node)2 ProcessInfoDataWriter (org.jumpmind.symmetric.model.ProcessInfoDataWriter)2 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)2