use of org.jumpmind.db.model.Trigger 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;
}
Aggregations