Search in sources :

Example 1 with IncomingError

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'"));
}
Also used : IncomingError(org.jumpmind.symmetric.model.IncomingError)

Example 2 with IncomingError

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);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IncomingError(org.jumpmind.symmetric.model.IncomingError)

Example 3 with IncomingError

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

Example 4 with IncomingError

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'"));
}
Also used : IncomingError(org.jumpmind.symmetric.model.IncomingError)

Aggregations

IncomingError (org.jumpmind.symmetric.model.IncomingError)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)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 IDatabaseWriterFilter (org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter)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 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 ProcessInfoDataWriter (org.jumpmind.symmetric.model.ProcessInfoDataWriter)1 TransformTableNodeGroupLink (org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)1