Search in sources :

Example 1 with Trigger

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

the class AbstractJdbcDdlReader method getTriggerFor.

public Trigger getTriggerFor(Table table, String triggerName) {
    Trigger trigger = null;
    List<Trigger> triggers = getTriggers(table.getCatalog(), table.getSchema(), table.getName());
    for (Trigger t : triggers) {
        if (t.getName().equals(triggerName)) {
            trigger = t;
            break;
        }
    }
    return trigger;
}
Also used : Trigger(org.jumpmind.db.model.Trigger)

Example 2 with Trigger

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

the class SqliteDdlReader method getTriggerFor.

public Trigger getTriggerFor(Table table, String triggerName) {
    Trigger trigger = null;
    List<Trigger> triggers = getTriggers(table.getCatalog(), table.getSchema(), table.getName());
    for (Trigger t : triggers) {
        if (t.getName().equals(triggerName)) {
            trigger = t;
            break;
        }
    }
    return trigger;
}
Also used : Trigger(org.jumpmind.db.model.Trigger)

Example 3 with Trigger

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

the class AseDdlReader method getTriggers.

@Override
public List<Trigger> getTriggers(final String catalog, final String schema, final String tableName) throws SqlException {
    List<Trigger> triggers = new ArrayList<Trigger>();
    log.debug("Reading triggers for: " + tableName);
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    String sql = "SELECT " + "trig.name AS trigger_name, " + "trig.id AS trigger_id, " + "tab.name AS table_name, " + "tab.id AS table_id, " + "db.name AS catalog, " + "trig.crdate AS created_on, " + "tab.deltrig AS table_delete_trigger_id, " + "tab.instrig AS table_insert_trigger_id, " + "tab.updtrig AS table_update_trigger_id " + "FROM sysobjects AS trig " + "INNER JOIN sysobjects AS tab " + "ON trig.id = tab.deltrig " + "OR trig.id = tab.instrig " + "OR trig.id = tab.updtrig " + "INNER JOIN master.dbo.sysdatabases AS db " + "ON db.dbid = db_id() " + "WHERE tab.name = ? AND db.name = ? ";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("trigger_name"));
            trigger.setTableName(row.getString("table_name"));
            trigger.setCatalogName(row.getString("catalog"));
            trigger.setEnabled(true);
            trigger.setSource("");
            if (row.getString("table_insert_trigger_id").equals(row.getString("trigger_id"))) {
                trigger.setTriggerType(TriggerType.INSERT);
                row.put("trigger_type", "insert");
            } else if (row.getString("table_delete_trigger_id").equals(row.getString("trigger_id"))) {
                trigger.setTriggerType(TriggerType.DELETE);
                row.put("trigger_type", "delete");
            } else if (row.getString("table_update_trigger_id").equals(row.getString("trigger_id"))) {
                trigger.setTriggerType(TriggerType.UPDATE);
                row.put("trigger_type", "update");
            }
            row.remove("table_insert_trigger_id");
            row.remove("table_delete_trigger_id");
            row.remove("table_update_trigger_id");
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName, catalog);
    for (final Trigger trigger : triggers) {
        int id = (Integer) trigger.getMetaData().get("trigger_id");
        String sourceSql = "SELECT text " + "FROM syscomments " + "WHERE id = ? " + "ORDER BY colid ";
        sqlTemplate.query(sourceSql, new ISqlRowMapper<Trigger>() {

            public Trigger mapRow(Row row) {
                trigger.setSource(trigger.getSource() + "\n" + row.getString("text"));
                return trigger;
            }
        }, id);
    }
    return triggers;
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Example 4 with Trigger

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

the class H2DdlReader method getTriggers.

@Override
public List<Trigger> getTriggers(final String catalog, final String schema, final String tableName) throws SqlException {
    List<Trigger> triggers = new ArrayList<Trigger>();
    log.debug("Reading triggers for: " + tableName);
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    String sql = "SELECT * FROM INFORMATION_SCHEMA.TRIGGERS " + "WHERE TABLE_NAME=? and TRIGGER_SCHEMA=? and TRIGGER_CATALOG=? ;";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("TRIGGER_NAME"));
            trigger.setCatalogName(row.getString("TRIGGER_CATALOG"));
            trigger.setSchemaName(row.getString("TRIGGER_SCHEMA"));
            trigger.setTableName(row.getString("TABLE_NAME"));
            trigger.setEnabled(true);
            trigger.setSource(row.getString("SQL"));
            row.remove("SQL");
            String triggerType = row.getString("TRIGGER_TYPE");
            if (triggerType.equals("DELETE") || triggerType.equals("INSERT") || triggerType.equals("UPDATE")) {
                trigger.setTriggerType(TriggerType.valueOf(triggerType));
            }
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName, schema, catalog);
    return triggers;
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Example 5 with Trigger

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

the class GreenplumDdlReader method getTriggers.

public List<Trigger> getTriggers(final String catalog, final String schema, final String tableName) {
    List<Trigger> triggers = new ArrayList<Trigger>();
    log.debug("Reading triggers for: " + tableName);
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    String sql = "SELECT " + "trigger_name, " + "trigger_schema, " + "trigger_catalog, " + "event_manipulation AS trigger_type, " + "event_object_table AS table_name," + "trig.*, " + "pgproc.prosrc " + "FROM INFORMATION_SCHEMA.TRIGGERS AS trig " + "INNER JOIN pg_catalog.pg_trigger AS pgtrig " + "ON pgtrig.tgname=trig.trigger_name " + "INNER JOIN pg_catalog.pg_proc AS pgproc " + "ON pgproc.oid=pgtrig.tgfoid " + "WHERE event_object_table=? AND event_object_schema=?;";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("trigger_name"));
            trigger.setCatalogName(row.getString("trigger_catalog"));
            trigger.setSchemaName(row.getString("trigger_schema"));
            trigger.setTableName(row.getString("table_name"));
            trigger.setEnabled(true);
            trigger.setSource(row.getString("prosrc"));
            row.remove("prosrc");
            String triggerType = row.getString("trigger_type");
            if (triggerType.equals("DELETE") || triggerType.equals("INSERT") || triggerType.equals("UPDATE")) {
                trigger.setTriggerType(TriggerType.valueOf(triggerType));
            }
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName, schema);
    return triggers;
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Aggregations

Trigger (org.jumpmind.db.model.Trigger)21 Row (org.jumpmind.db.sql.Row)19 ArrayList (java.util.ArrayList)18 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)18 JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)18