Search in sources :

Example 1 with IDatabaseWriterFilter

use of org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter in project symmetric-ds by JumpMind.

the class DbImportCommand method executeWithOptions.

@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
    DbImport dbImport = new DbImport(getDatabasePlatform(true));
    if (line.hasOption(OPTION_FORMAT)) {
        dbImport.setFormat(Format.valueOf(line.getOptionValue(OPTION_FORMAT).toUpperCase()));
    }
    if (line.hasOption(OPTION_CATALOG)) {
        dbImport.setCatalog(line.getOptionValue(OPTION_CATALOG));
    }
    if (line.hasOption(OPTION_SCHEMA)) {
        dbImport.setSchema(line.getOptionValue(OPTION_SCHEMA));
    }
    if (line.hasOption(OPTION_USE_VARIABLE_DATES)) {
        dbImport.setUseVariableForDates(true);
    }
    if (line.hasOption(OPTION_COMMIT)) {
        dbImport.setCommitRate(Long.parseLong(line.getOptionValue(OPTION_COMMIT)));
    }
    if (line.hasOption(OPTION_INTERVAL)) {
        dbImport.setInterval((Integer.parseInt(line.getOptionValue(OPTION_INTERVAL))));
    }
    if (line.hasOption(OPTION_ALTER_CASE)) {
        dbImport.setAlterCaseToMatchDatabaseDefaultCase(true);
    }
    if (line.hasOption(OPTION_DROP_IF_EXISTS)) {
        dbImport.setDropIfExists(true);
    }
    if (line.hasOption(OPTION_ALTER)) {
        dbImport.setAlterTables(true);
    }
    if (line.hasOption(OPTION_FILTER_CLASSES)) {
        String filters = line.getOptionValue(OPTION_FILTER_CLASSES);
        if (StringUtils.isNotBlank(filters)) {
            String[] clazzes = filters.split(",");
            for (String clazz : clazzes) {
                if (StringUtils.isNotBlank(clazz)) {
                    IDatabaseWriterFilter databaseWriterFilter = (IDatabaseWriterFilter) Class.forName(clazz.trim()).newInstance();
                    dbImport.addDatabaseWriterFilter(databaseWriterFilter);
                }
            }
        }
    }
    if (line.hasOption(OPTION_FORCE)) {
        dbImport.setForceImport(true);
    }
    if (line.hasOption(OPTION_REPLACE)) {
        dbImport.setReplaceRows(true);
    }
    if (line.hasOption(OPTION_IGNORE)) {
        dbImport.setIgnoreCollisions(true);
    }
    String[] args = line.getArgs();
    if (args.length == 0) {
        dbImport.importTables(System.in, line.getOptionValue(OPTION_TABLE));
    } else {
        for (String fileName : args) {
            if (!new File(fileName).exists()) {
                throw new RuntimeException("Cannot find file " + fileName);
            }
        }
        for (String fileName : args) {
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileName));
            dbImport.importTables(in, line.getOptionValue(OPTION_TABLE));
            in.close();
        }
    }
    return true;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DbImport(org.jumpmind.symmetric.io.data.DbImport) IDatabaseWriterFilter(org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with IDatabaseWriterFilter

use of org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter 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

IDatabaseWriterFilter (org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DbImport (org.jumpmind.symmetric.io.data.DbImport)1 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)1 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)1 IDatabaseWriterErrorHandler (org.jumpmind.symmetric.io.data.writer.IDatabaseWriterErrorHandler)1 ResolvedData (org.jumpmind.symmetric.io.data.writer.ResolvedData)1 TransformWriter (org.jumpmind.symmetric.io.data.writer.TransformWriter)1 DynamicDatabaseWriterFilter (org.jumpmind.symmetric.load.DynamicDatabaseWriterFilter)1 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)1 IncomingError (org.jumpmind.symmetric.model.IncomingError)1 LoadFilter (org.jumpmind.symmetric.model.LoadFilter)1 LoadFilterType (org.jumpmind.symmetric.model.LoadFilter.LoadFilterType)1 Node (org.jumpmind.symmetric.model.Node)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1