Search in sources :

Example 16 with TriggerHistory

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

the class TriggerRouterService method findTriggerHistories.

public List<TriggerHistory> findTriggerHistories(String catalogName, String schemaName, String tableName) {
    List<TriggerHistory> listToReturn = new ArrayList<TriggerHistory>();
    List<TriggerHistory> triggerHistories = getActiveTriggerHistories();
    if (triggerHistories != null && triggerHistories.size() > 0) {
        for (TriggerHistory triggerHistory : triggerHistories) {
            boolean matches = true;
            if (StringUtils.isNotBlank(catalogName)) {
                matches = catalogName.equals(triggerHistory.getSourceCatalogName());
            }
            if (matches && StringUtils.isNotBlank(schemaName)) {
                matches = schemaName.equals(triggerHistory.getSourceSchemaName());
            }
            if (matches && StringUtils.isNotBlank(tableName)) {
                boolean ignoreCase = parameterService.is(ParameterConstants.DB_METADATA_IGNORE_CASE) && !FormatUtils.isMixedCase(tableName);
                matches = ignoreCase ? triggerHistory.getSourceTableName().equalsIgnoreCase(tableName) : triggerHistory.getSourceTableName().equals(tableName);
            }
            if (matches) {
                listToReturn.add(triggerHistory);
            }
        }
    }
    return listToReturn;
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) ArrayList(java.util.ArrayList)

Example 17 with TriggerHistory

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

the class SymmetricAdmin method sendSchema.

private void sendSchema(CommandLine line, List<String> args) {
    String catalog = line.getOptionValue(OPTION_CATALOG);
    String schema = line.getOptionValue(OPTION_SCHEMA);
    Collection<Node> nodes = getNodes(line);
    if (args.size() == 0) {
        for (TriggerHistory hist : engine.getTriggerRouterService().getActiveTriggerHistories()) {
            for (Node node : nodes) {
                if ((catalog == null || catalog.equals(hist.getSourceCatalogName())) && (schema == null || schema.equals(hist.getSourceSchemaName()))) {
                    getSymmetricEngine().getDataService().sendSchema(node.getNodeId(), hist.getSourceCatalogName(), hist.getSourceSchemaName(), hist.getSourceTableName(), false);
                }
            }
        }
    } else {
        for (String tableName : args) {
            for (Node node : nodes) {
                getSymmetricEngine().getDataService().sendSchema(node.getNodeId(), catalog, schema, tableName, false);
            }
        }
    }
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node)

Example 18 with TriggerHistory

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

the class AbstractFileParsingRouter method getTriggerHistory.

protected TriggerHistory getTriggerHistory(String tableName, String columnNames) {
    List<TriggerHistory> triggerHistories = getEngine().getTriggerRouterService().getActiveTriggerHistories(tableName);
    for (TriggerHistory history : triggerHistories) {
        if (history.getTriggerId().equals(TRIGGER_ID_FILE_PARSER)) {
            return history;
        }
    }
    TriggerHistory newTriggerHist = new TriggerHistory(tableName, "", columnNames);
    newTriggerHist.setTriggerId(TRIGGER_ID_FILE_PARSER);
    newTriggerHist.setTableHash(0);
    newTriggerHist.setTriggerRowHash(0);
    newTriggerHist.setTriggerTemplateHash(0);
    newTriggerHist.setLastTriggerBuildReason(TriggerReBuildReason.NEW_TRIGGERS);
    newTriggerHist.setColumnNames(columnNames);
    getEngine().getTriggerRouterService().insert(newTriggerHist);
    return newTriggerHist;
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory)

Example 19 with TriggerHistory

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

the class ColumnMatchDataRouterTest method testExpressionExternalData.

@Test
public void testExpressionExternalData() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setExternalData("100");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("EXTERNAL_DATA = :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(1, result.size());
    assertEquals(true, result.contains("100"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 20 with TriggerHistory

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

the class ColumnMatchDataRouterTest method testExpressionNotEqualsNull.

@Test
public void testExpressionNotEqualsNull() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("COLUMN2 != NULL");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(0, result.size());
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Aggregations

TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)50 Table (org.jumpmind.db.model.Table)19 Data (org.jumpmind.symmetric.model.Data)19 Node (org.jumpmind.symmetric.model.Node)17 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)14 Trigger (org.jumpmind.symmetric.model.Trigger)14 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Router (org.jumpmind.symmetric.model.Router)10 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)9 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)8 List (java.util.List)6 CsvData (org.jumpmind.symmetric.io.data.CsvData)6 SymmetricException (org.jumpmind.symmetric.SymmetricException)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 Date (java.util.Date)4 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)4 HashMap (java.util.HashMap)3