use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class InformixDdlReader 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 " + "trigname AS trigger_name, " + "owner AS schema_name, " + "tab.tabname AS table_name, " + "event AS trigger_type" + "trigid, " + "tabid, " + "old, " + "new, " + "collation " + "FROM systriggers AS trig " + "INNER JOIN systables AS tab " + "ON tab.tabid = trig.tabid " + "WHERE tab.tabname=? AND tab.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("schema_name"));
trigger.setTableName(row.getString("table_name"));
trigger.setEnabled(true);
trigger.setSource("");
String trigEvent = row.getString("trigger_type");
switch(trigEvent.toUpperCase().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);
trigger.setMetaData(row);
return trigger;
}
}, tableName, schema);
for (final Trigger trigger : triggers) {
String id = trigger.getMetaData().get("trigid").toString();
String sourceSql = "SELECT " + "data " + "FROM systrigbody " + "WHERE trigid=? AND (datakey='A' OR datakey='D') " + "ORDER BY datakey DESC, seqno ASC ;";
sqlTemplate.query(sourceSql, new ISqlRowMapper<Trigger>() {
public Trigger mapRow(Row row) {
trigger.setSource(trigger.getSource() + "\n" + row.getString("data"));
return trigger;
}
}, id);
}
return triggers;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class HsqlDb2DdlReader 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;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class TableExtractDataReaderSource method startNewCursor.
protected void startNewCursor() {
DatabaseInfo dbInfo = platform.getDatabaseInfo();
String sql = String.format("select * from %s %s", table.getQualifiedTableName(dbInfo.getDelimiterToken(), dbInfo.getCatalogSeparator(), dbInfo.getSchemaSeparator()), StringUtils.isNotBlank(whereClause) ? " where " + whereClause : "");
this.cursor = platform.getSqlTemplate().queryForCursor(sql, new ISqlRowMapper<CsvData>() {
public CsvData mapRow(Row row) {
return new CsvData(DataEventType.INSERT, toStringData(row, table.getPrimaryKeyColumns()), toStringData(row, table.getColumns()));
}
});
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class GroupletService method getGrouplets.
public List<Grouplet> getGrouplets(boolean refreshCache) {
long maxCacheTime = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_GROUPLETS_IN_MS);
List<Grouplet> all = cache;
if (all == null || System.currentTimeMillis() - lastCacheTime >= maxCacheTime || lastCacheTime == 0 || refreshCache) {
ISqlTemplate sqlTemplate = platform.getSqlTemplate();
final Map<String, Grouplet> groupletMap = new HashMap<String, Grouplet>();
all = sqlTemplate.query(getSql("selectGroupletSql"), new ISqlRowMapper<Grouplet>() {
public Grouplet mapRow(Row rs) {
Grouplet grouplet = new Grouplet();
grouplet.setGroupletId(rs.getString("grouplet_id"));
grouplet.setDescription(rs.getString("description"));
grouplet.setGroupletLinkPolicy(GroupletLinkPolicy.valueOf(rs.getString("grouplet_link_policy")));
grouplet.setCreateTime(rs.getDateTime("create_time"));
grouplet.setLastUpdateBy(rs.getString("last_update_by"));
grouplet.setLastUpdateTime(rs.getDateTime("last_update_time"));
groupletMap.put(grouplet.getGroupletId(), grouplet);
return grouplet;
}
});
sqlTemplate.query(getSql("selectGroupletLinkSql"), new ISqlRowMapper<GroupletLink>() {
public GroupletLink mapRow(Row rs) {
GroupletLink groupletLink = new GroupletLink();
String groupletId = rs.getString("grouplet_id");
Grouplet grouplet = groupletMap.get(groupletId);
groupletLink.setExternalId(rs.getString("external_id"));
groupletLink.setCreateTime(rs.getDateTime("create_time"));
groupletLink.setLastUpdateBy(rs.getString("last_update_by"));
groupletLink.setLastUpdateTime(rs.getDateTime("last_update_time"));
if (grouplet != null) {
grouplet.getGroupletLinks().add(groupletLink);
}
return groupletLink;
}
});
sqlTemplate.query(getSql("selectTriggerRouterGroupletSql"), new ISqlRowMapper<TriggerRouterGrouplet>() {
public TriggerRouterGrouplet mapRow(Row rs) {
TriggerRouterGrouplet trGrouplet = new TriggerRouterGrouplet();
String groupletId = rs.getString("grouplet_id");
Grouplet grouplet = groupletMap.get(groupletId);
trGrouplet.setAppliesWhen(AppliesWhen.valueOf(rs.getString("applies_when")));
trGrouplet.setRouterId(rs.getString("router_id"));
trGrouplet.setTriggerId(rs.getString("trigger_id"));
trGrouplet.setCreateTime(rs.getDateTime("create_time"));
trGrouplet.setLastUpdateBy(rs.getString("last_update_by"));
trGrouplet.setLastUpdateTime(rs.getDateTime("last_update_time"));
if (grouplet != null) {
grouplet.getTriggerRouterGrouplets().add(trGrouplet);
}
return trGrouplet;
}
});
cache = all;
lastCacheTime = System.currentTimeMillis();
}
return all;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testNewGapFull.
@Test
public void testNewGapFull() throws Exception {
detector.setFullGapAnalysis(true);
when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
List<Long> dataIds = new ArrayList<Long>();
dataIds.add(100L);
@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, 99));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(101, 50000100));
verifyNoMoreInteractions(dataService);
}
Aggregations