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;
}
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;
}
Aggregations