Search in sources :

Example 21 with JdbcSqlTemplate

use of org.jumpmind.db.sql.JdbcSqlTemplate in project symmetric-ds by JumpMind.

the class SqlAnywhereDdlReader 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 " + "trigname AS trigger_name, " + "owner, " + "tname AS table_name, " + "event AS trigger_type, " + "trigtime AS trigger_time, " + "trigdefn " + "FROM SYS.SYSTRIGGERS " + "WHERE tname=? and owner=? ;";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("trigger_name"));
            trigger.setSchemaName(row.getString("owner"));
            trigger.setTableName(row.getString("table_name"));
            trigger.setEnabled(true);
            trigger.setSource(row.getString("trigdefn"));
            row.remove("trigdefn");
            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)

Example 22 with JdbcSqlTemplate

use of org.jumpmind.db.sql.JdbcSqlTemplate in project symmetric-ds by JumpMind.

the class PostgreSqlDdlReader method getTriggers.

@Override
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)

Example 23 with JdbcSqlTemplate

use of org.jumpmind.db.sql.JdbcSqlTemplate in project symmetric-ds by JumpMind.

the class MySqlDdlReader 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, " + "EVENT_OBJECT_SCHEMA AS TABLE_SCHEMA, " + "EVENT_OBJECT_CATALOG AS TABLE_CATALOG, " + "TRIG.* " + "FROM INFORMATION_SCHEMA.TRIGGERS AS TRIG " + "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);
            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, catalog);
    for (final Trigger trigger : triggers) {
        String name = trigger.getName();
        String sourceSql = "SHOW CREATE TRIGGER " + name;
        sqlTemplate.query(sourceSql, new ISqlRowMapper<Trigger>() {

            public Trigger mapRow(Row row) {
                trigger.setSource(row.getString("SQL Original Statement"));
                return trigger;
            }
        });
    }
    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

JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)23 ArrayList (java.util.ArrayList)19 Row (org.jumpmind.db.sql.Row)19 Trigger (org.jumpmind.db.model.Trigger)18 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)18 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)2 IConnectionCallback (org.jumpmind.db.sql.IConnectionCallback)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Database (org.jumpmind.db.model.Database)1 SqlException (org.jumpmind.db.sql.SqlException)1