Search in sources :

Example 31 with Data

use of org.jumpmind.symmetric.model.Data in project symmetric-ds by JumpMind.

the class DataService method insertCreateEvent.

public void insertCreateEvent(ISqlTransaction transaction, Node targetNode, TriggerHistory triggerHistory, String routerId, boolean isLoad, long loadId, String createBy) {
    Trigger trigger = engine.getTriggerRouterService().getTriggerById(triggerHistory.getTriggerId(), false);
    String reloadChannelId = getReloadChannelIdForTrigger(trigger, engine.getConfigurationService().getChannels(false));
    Data data = new Data(triggerHistory.getSourceTableName(), DataEventType.CREATE, null, null, triggerHistory, isLoad ? reloadChannelId : Constants.CHANNEL_CONFIG, null, null);
    data.setNodeList(targetNode.getNodeId());
    try {
        if (isLoad) {
            insertDataAndDataEventAndOutgoingBatch(transaction, data, targetNode.getNodeId(), routerId, isLoad, loadId, createBy, Status.NE);
        } else {
            insertData(transaction, data);
        }
    } catch (UniqueKeyException e) {
        if (e.getRootCause() != null && e.getRootCause() instanceof DataTruncation) {
            log.error("Table data definition XML was too large and failed.  The feature to send table creates during the initial load may be limited on your platform.  You may need to set the initial.load.create.first parameter to false.");
        }
        throw e;
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) DataTruncation(java.sql.DataTruncation)

Example 32 with Data

use of org.jumpmind.symmetric.model.Data in project symmetric-ds by JumpMind.

the class DataService method reloadMissingForeignKeyRows.

public void reloadMissingForeignKeyRows(String nodeId, long dataId) {
    try {
        Data data = findData(dataId);
        log.debug("reloadMissingForeignKeyRows for nodeId '{}' dataId '{}' table '{}'", nodeId, dataId, data.getTableName());
        TriggerHistory hist = data.getTriggerHistory();
        Table table = platform.getTableFromCache(hist.getSourceCatalogName(), hist.getSourceSchemaName(), hist.getSourceTableName(), false);
        Map<String, String> dataMap = data.toColumnNameValuePairs(table.getColumnNames(), CsvData.ROW_DATA);
        List<TableRow> tableRows = new ArrayList<TableRow>();
        Row row = new Row(dataMap.size());
        row.putAll(dataMap);
        tableRows.add(new TableRow(table, row, null, null, null));
        List<TableRow> foreignTableRows;
        try {
            foreignTableRows = getForeignTableRows(tableRows, new HashSet<TableRow>());
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        if (foreignTableRows.isEmpty()) {
            log.info("Could not determine foreign table rows to fix foreign key violation for " + "nodeId '{}' dataId '{}' table '{}'", nodeId, dataId, data.getTableName());
        }
        Collections.reverse(foreignTableRows);
        Set<TableRow> visited = new HashSet<TableRow>();
        for (TableRow foreignTableRow : foreignTableRows) {
            if (visited.add(foreignTableRow)) {
                Table foreignTable = foreignTableRow.getTable();
                String catalog = foreignTable.getCatalog();
                String schema = foreignTable.getSchema();
                if (StringUtils.equals(platform.getDefaultCatalog(), catalog)) {
                    catalog = null;
                }
                if (StringUtils.equals(platform.getDefaultSchema(), schema)) {
                    schema = null;
                }
                log.info("Issuing foreign key correction reload " + "nodeId {} catalog '{}' schema '{}' foreign table name '{}' fk name '{}' where sql '{}' " + "to correct dataId '{}' table '{}' for column '{}'", nodeId, catalog, schema, foreignTable.getName(), foreignTableRow.getFkName(), foreignTableRow.getWhereSql(), dataId, data.getTableName(), foreignTableRow.getReferenceColumnName());
                reloadTable(nodeId, catalog, schema, foreignTable.getName(), foreignTableRow.getWhereSql());
            }
        }
    } catch (Exception e) {
        log.error("Unknown exception while processing foreign key for node id: " + nodeId + " data id " + dataId, e);
    }
}
Also used : Table(org.jumpmind.db.model.Table) ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) NotImplementedException(org.apache.commons.lang.NotImplementedException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Row(org.jumpmind.db.sql.Row) HashSet(java.util.HashSet)

Example 33 with Data

use of org.jumpmind.symmetric.model.Data in project symmetric-ds by JumpMind.

the class DataService method createData.

public Data createData(String catalogName, String schemaName, String tableName, String whereClause) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        Data data = createData(transaction, catalogName, schemaName, tableName, whereClause);
        transaction.commit();
        return data;
    } 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) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 34 with Data

use of org.jumpmind.symmetric.model.Data in project symmetric-ds by JumpMind.

the class DataService method createData.

public Data createData(ISqlTransaction transaction, String catalogName, String schemaName, String tableName, String whereClause) {
    Data data = null;
    Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(catalogName, schemaName, tableName, false);
    if (triggerRouters != null && triggerRouters.size() > 0) {
        data = createData(transaction, triggerRouters.iterator().next().getTrigger(), whereClause);
    }
    return data;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 35 with Data

use of org.jumpmind.symmetric.model.Data in project symmetric-ds by JumpMind.

the class DataService method insertHeartbeatEvent.

/**
     * Because we can't add a trigger on the _node table, we are artificially
     * generating heartbeat events.
     * 
     * @param node
     */
public void insertHeartbeatEvent(Node node, boolean isReload) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        String tableName = TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST);
        List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
        for (NodeGroupLink nodeGroupLink : links) {
            if (nodeGroupLink.getDataEventAction() == NodeGroupLinkAction.P) {
                Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(nodeGroupLink, null, null, tableName, false);
                if (triggerRouters != null && triggerRouters.size() > 0) {
                    Data data = createData(transaction, triggerRouters.iterator().next().getTrigger(), String.format(" t.node_id = '%s'", node.getNodeId()));
                    if (data != null) {
                        insertData(transaction, data);
                    } else {
                        log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
                    }
                } else {
                    log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
                }
            }
        }
        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) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Aggregations

Data (org.jumpmind.symmetric.model.Data)42 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)19 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)18 Test (org.junit.Test)18 CsvData (org.jumpmind.symmetric.io.data.CsvData)16 Table (org.jumpmind.db.model.Table)14 ArrayList (java.util.ArrayList)12 Node (org.jumpmind.symmetric.model.Node)12 HashSet (java.util.HashSet)11 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)10 Router (org.jumpmind.symmetric.model.Router)9 DataGap (org.jumpmind.symmetric.model.DataGap)7 TransformedData (org.jumpmind.symmetric.io.data.transform.TransformedData)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Trigger (org.jumpmind.symmetric.model.Trigger)5 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)5 File (java.io.File)3 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)3 TransformTableNodeGroupLink (org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)3 Row (org.jumpmind.db.sql.Row)2