use of org.jumpmind.symmetric.model.IncomingError in project symmetric-ds by JumpMind.
the class ConflictResolutionTest method testUpdateRowOnServerThenUpdateRowOnClient.
// Tests simultaneous updates to an existing row with resolution based on resolve data and then same scenario again
// with resolution based on resolve_ignore.
protected void testUpdateRowOnServerThenUpdateRowOnClient(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
int count = rootServer.getSqlTemplate().update(String.format("update %s set string_a=? where id=?", testTableA.getName()), "notS3", "2");
assertEquals(1, count);
count = clientServer.getSqlTemplate().update(String.format("update %s set string_a=? where id=?", testTableA.getName()), "S3", "2");
assertEquals(1, count);
assertTrue(push("client"));
assertEquals("notS3", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
IncomingError error = getOnlyIncomingError(rootServer, "client");
String rowData = error.getRowData();
assertTrue(rowData.contains("\"S3\""));
String resolveData = rowData.replace("\"S3\"", "\"S4\"");
rootServer.getSqlTemplate().update("update sym_incoming_error set resolve_data=? where batch_id=?", resolveData, error.getBatchId());
assertTrue(push("client"));
error = getOnlyIncomingError(rootServer, "client");
assertEquals(null, error);
assertEquals("S4", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
// Same test, but we're ignore row this time
count = rootServer.getSqlTemplate().update(String.format("update %s set string_a=? where id=?", testTableA.getName()), "notS5", "2");
assertEquals(1, count);
count = clientServer.getSqlTemplate().update(String.format("update %s set string_a=? where id=?", testTableA.getName()), "S5", "2");
assertEquals(1, count);
assertTrue(push("client"));
assertEquals("notS5", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
error = getOnlyIncomingError(rootServer, "client");
rowData = error.getRowData();
rootServer.getSqlTemplate().update("update sym_incoming_error set resolve_ignore=? where batch_id=?", 1, error.getBatchId());
assertTrue(push("client"));
error = getOnlyIncomingError(rootServer, "client");
assertEquals(null, error);
assertEquals("notS5", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
}
use of org.jumpmind.symmetric.model.IncomingError in project symmetric-ds by JumpMind.
the class DataLoaderService method insertIncomingError.
public void insertIncomingError(IncomingError incomingError) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
insertIncomingError(transaction, incomingError);
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
}
use of org.jumpmind.symmetric.model.IncomingError 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;
}
use of org.jumpmind.symmetric.model.IncomingError in project symmetric-ds by JumpMind.
the class ConflictResolutionTest method testExistingRowInServerInsertOnClient.
protected void testExistingRowInServerInsertOnClient(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
rootServer.getSqlTemplate().update(rootServer.getDatabasePlatform().scrubSql(String.format("insert into %s values (?,?,current_timestamp)", testTableA.getName())), "2", "s1");
assertEquals(2, rootServer.getSqlTemplate().queryForInt("select count(*) from conflict_table_a"));
assertEquals("s1", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
clientServer.getSqlTemplate().update(clientServer.getDatabasePlatform().scrubSql(String.format("insert into %s values (?,?,current_timestamp)", testTableA.getName())), "2", "c1");
assertTrue(push("client"));
assertEquals("s1", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
IncomingError error = getOnlyIncomingError(rootServer, "client");
String rowData = error.getRowData();
assertTrue(rowData.contains("\"c1\""));
String resolveData = rowData.replace("\"c1\"", "\"s2\"");
rootServer.getSqlTemplate().update("update sym_incoming_error set resolve_data=? where batch_id=?", resolveData, error.getBatchId());
assertTrue(push("client"));
assertEquals("s2", rootServer.getSqlTemplate().queryForString("select string_a from conflict_table_a where id='2'"));
}
Aggregations