Search in sources :

Example 16 with JdbcSqlTemplate

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

the class Db2DdlReader method getTriggers.

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 " + "NAME as TRIGGER_NAME, " + "SCHEMA, " + "DEFINER, " + "TBNAME as TABLE_NAME, " + "TBCREATOR as TABLE_CREATOR, " + "TRIGEVENT as TRIGGER_TYPE, " + "TRIGTIME as TRIGGER_TIME, " + "GRANULARITY, " + "VALID, " + "TEXT, " + "ENABLED, " + "CREATE_TIME, " + "FUNC_PATH as FUNCTION_PATH, " + "ALTER_TIME as LAST_ALTERED " + "FROM SYSIBM.SYSTRIGGERS " + "WHERE TBNAME=? and SCHEMA=?";
    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("SCHEMA"));
            trigger.setTableName(row.getString("TABLE_NAME"));
            trigger.setEnabled(row.getString("ENABLED").equals("Y"));
            trigger.setSource(row.getString("TEXT"));
            row.remove("TEXT");
            String trigEvent = row.getString("TRIGGER_TYPE");
            switch(trigEvent.charAt(0)) {
                case ('I'):
                    trigEvent = "INSERT";
                    break;
                case ('U'):
                    trigEvent = "UPDATE";
                    break;
                case ('D'):
                    trigEvent = "DELETE";
            }
            trigger.setTriggerType(TriggerType.valueOf(trigEvent));
            row.put("TRIGGER_TYPE", trigEvent);
            switch(row.getString("TRIGGER_TIME").charAt(0)) {
                case ('A'):
                    row.put("TRIGGER_TIME", "AFTER");
                    break;
                case ('B'):
                    row.put("TRIGGER_TIME", "BEFORE");
                    break;
                case ('I'):
                    row.put("TRIGGER_TIME", "INSTEAD OF");
            }
            if (row.getString("GRANULARITY").equals("S"))
                row.put("GRANULARITY", "ONCE PER STATEMENT");
            else if (row.getString("GRANULARITY").equals("R"))
                row.put("GRANULARITY", "ONCE PER ROW");
            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 17 with JdbcSqlTemplate

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

the class Db2zOsDdlReader method getTriggers.

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 SYSCAT.TRIGGERS " + "WHERE TABNAME=? and TABSCHEMA=?";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("TRIGNAME"));
            trigger.setSchemaName(row.getString("TRIGSCHEMA"));
            trigger.setTableName(row.getString("TABNAME"));
            trigger.setEnabled(true);
            trigger.setSource(row.getString("TEXT"));
            row.remove("TEXT");
            switch(row.getString("TRIGEVENT").charAt(0)) {
                case ('I'):
                    row.put("TRIGEVENT", "INSERT");
                    break;
                case ('U'):
                    row.put("TRIGEVENT", "UPDATE");
                    break;
                case ('D'):
                    row.put("TRIGEVENT", "DELETE");
            }
            trigger.setTriggerType(TriggerType.valueOf(row.getString("TRIGEVENT")));
            switch(row.getString("TRIGTIME").charAt(0)) {
                case ('A'):
                    row.put("TRIGTIME", "AFTER");
                    break;
                case ('B'):
                    row.put("TRIGTIME", "BEFORE");
                    break;
                case ('I'):
                    row.put("TRIGTIME", "INSTEAD OF");
            }
            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 18 with JdbcSqlTemplate

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

the class Db2As400DdlReader method getTriggers.

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 " + "TRIGGER_NAME, " + "TRIGGER_SCHEMA, " + "EVENT_OBJECT_TABLE as TABLE_NAME, " + "ACTION_TIMING as TRIGGER_TIME, " + "EVENT_MANIPULATION as TRIGGER_TYPE, " + "CREATED, " + "ENABLED " + "FROM QSYS2.SYSTRIGGERS " + "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.setSchemaName(row.getString("TRIGGER_SCHEMA"));
            trigger.setTableName(row.getString("TABLE_NAME"));
            trigger.setEnabled(row.getString("ENABLED").equals("Y"));
            trigger.setTriggerType(TriggerType.valueOf(row.getString("TRIGGER_TYPE")));
            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 19 with JdbcSqlTemplate

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

the class HsqlDbDdlReader 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 20 with JdbcSqlTemplate

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

the class InterbaseDdlReader 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.RDB$TRIGGER_NAME as TRIGGER_NAME, " + "TRIG.RDB$RELATION_NAME as TABLE_NAME, " + "TYPES1.RDB$TYPE_NAME as TRIGGER_TYPE, " + "TRIG.RDB$TRIGGER_SEQUENCE as TRIGGER_SEQUENCE, " + "TRIG.RDB$TRIGGER_BLR as TRIGGER_BLR, " + "TRIG.RDB$DESCRIPTION as DESCRIPTION, " + "TRIG.RDB$TRIGGER_INACTIVE as TRIGGER_INACTIVE, " + "TYPES2.RDB$TYPE_NAME as SYSTEM_FLAG, " + "TRIG.RDB$FLAGS as FLAGS, " + "TRIG.RDB$VALID_BLR as VALID_BLR, " + "TRIG.RDB$DEBUG_INFO as DEBUG_INFO," + "TRIG.RDB$TRIGGER_SOURCE as TRIGGER_SOURCE " + "from RDB$TRIGGERS as TRIG " + "inner join RDB$TYPES as TYPES1 " + "on TYPES1.RDB$FIELD_NAME = 'RDB$TRIGGER_TYPE' " + "and TYPES1.RDB$TYPE = TRIG.RDB$TRIGGER_TYPE " + "inner join RDB$TYPES as TYPES2 " + "on TYPES2.RDB$FIELD_NAME = 'RDB$SYSTEM_FLAG' " + "and TYPES2.RDB$TYPE = TRIG.RDB$SYSTEM_FLAG " + "where RDB$RELATION_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.setEnabled(true);
            trigger.setSource(row.getString("TRIGGER_SOURCE"));
            row.remove("TRIGGER_SOURCE");
            String triggerType = row.getString("TRIGGER_TYPE");
            if (triggerType.contains("STORE"))
                trigger.setTriggerType(TriggerType.INSERT);
            else if (triggerType.contains("ERASE"))
                trigger.setTriggerType(TriggerType.DELETE);
            else if (triggerType.contains("MODIFY"))
                trigger.setTriggerType(TriggerType.UPDATE);
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName);
    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