use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class OracleDdlReader method getTableNames.
public List<String> getTableNames(final String catalog, final String schema, final String[] tableTypes) {
List<String> tableNames = new ArrayList<String>();
JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
StringBuilder sql = new StringBuilder("select TABLE_NAME from ALL_TABLES");
Object[] params = null;
if (isNotBlank(schema)) {
sql.append(" where OWNER=?");
params = new Object[] { schema };
}
tableNames = sqlTemplate.query(sql.toString(), new ISqlRowMapper<String>() {
public String mapRow(Row row) {
return row.getString("TABLE_NAME");
}
}, params);
return tableNames;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class RedshiftDdlReader 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;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class OracleDdlReader 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 ALL_TRIGGERS " + "WHERE TABLE_NAME=? 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(Boolean.valueOf(row.getString("STATUS")));
trigger.setSource("create ");
String triggerType = row.getString("TRIGGERING_EVENT");
if (triggerType.equals("DELETE") || triggerType.equals("INSERT") || triggerType.equals("UPDATE")) {
trigger.setTriggerType(TriggerType.valueOf(triggerType));
}
trigger.setMetaData(row);
return trigger;
}
}, tableName, schema);
for (final Trigger trigger : triggers) {
String name = trigger.getName();
String sourceSql = "select TEXT from all_source " + "where NAME=? order by LINE ";
sqlTemplate.query(sourceSql, new ISqlRowMapper<Trigger>() {
public Trigger mapRow(Row row) {
trigger.setSource(trigger.getSource() + "\n" + row.getString("TEXT"));
;
return trigger;
}
}, name);
}
return triggers;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testTwoNewGapsFull.
@Test
public void testTwoNewGapsFull() throws Exception {
detector.setFullGapAnalysis(true);
when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
List<Long> dataIds = new ArrayList<Long>();
dataIds.add(5L);
dataIds.add(8L);
@SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
String sql = Matchers.anyString();
when(sqlTemplate.query(sql, mapper, Matchers.eq(4L), Matchers.eq(50000004L))).thenReturn(dataIds);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(3, 3));
dataGaps.add(new DataGap(4, 50000004));
runGapDetector(dataGaps, new ArrayList<Long>(), true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(4, 50000004));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(4, 4));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(6, 7));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(9, 50000008));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.db.sql.ISqlRowMapper 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;
}
Aggregations