use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class ParameterService method readParametersFromDatabase.
protected TypedProperties readParametersFromDatabase(String sqlKey, Object... values) {
final TypedProperties properties = new TypedProperties();
final IParameterFilter filter = extensionService != null ? extensionService.getExtensionPoint(IParameterFilter.class) : null;
sqlTemplate.query(sql.getSql(sqlKey), new ISqlRowMapper<Object>() {
public Object mapRow(Row row) {
String key = row.getString("param_key");
String value = row.getString("param_value");
if (filter != null) {
value = filter.filterParameter(key, value);
}
if (value != null) {
properties.setProperty(key, value);
}
return row;
}
}, values);
return properties;
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class PurgeService method selectIdsAndDelete.
protected int selectIdsAndDelete(String selectSql, String fieldName, String deleteSql) {
List<Row> results = sqlTemplate.query(selectSql);
int rowCount = 0;
if (!results.isEmpty()) {
List<Integer> ids = new ArrayList<Integer>(results.size());
for (Row row : results) {
ids.add(row.getInt(fieldName));
}
results = null;
StringBuilder placeHolders = new StringBuilder(ids.size() * 2);
for (int i = 0; i < ids.size(); i++) {
placeHolders.append("?,");
}
placeHolders.setLength(placeHolders.length() - 1);
String deleteStatement = deleteSql.replace("?", placeHolders);
rowCount = sqlTemplate.update(deleteStatement, ids.toArray());
}
return rowCount;
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class OutgoingBatchService method getLoadSummaries.
public List<OutgoingLoadSummary> getLoadSummaries(boolean activeOnly) {
final Map<String, OutgoingLoadSummary> loadSummaries = new TreeMap<String, OutgoingLoadSummary>();
sqlTemplateDirty.query(getSql("getLoadSummariesSql"), new ISqlRowMapper<OutgoingLoadSummary>() {
public OutgoingLoadSummary mapRow(Row rs) {
long loadId = rs.getLong("load_id");
String nodeId = rs.getString("node_id");
String loadNodeId = String.format("%010d-%s", loadId, nodeId);
OutgoingLoadSummary summary = loadSummaries.get(loadNodeId);
if (summary == null) {
summary = new OutgoingLoadSummary();
summary.setLoadId(loadId);
summary.setNodeId(nodeId);
summary.setChannelId(rs.getString("channel_id"));
summary.setCreateBy(rs.getString("create_by"));
loadSummaries.put(loadNodeId, summary);
}
Status status = Status.valueOf(rs.getString("status"));
int count = rs.getInt("cnt");
Date lastUpdateTime = rs.getDateTime("last_update_time");
if (summary.getLastUpdateTime() == null || summary.getLastUpdateTime().before(lastUpdateTime)) {
summary.setLastUpdateTime(lastUpdateTime);
}
Date createTime = rs.getDateTime("create_time");
if (summary.getCreateTime() == null || summary.getCreateTime().after(createTime)) {
summary.setCreateTime(createTime);
}
summary.setReloadBatchCount(summary.getReloadBatchCount() + count);
if (status == Status.OK || status == Status.IG) {
summary.setFinishedBatchCount(summary.getFinishedBatchCount() + count);
} else {
summary.setPendingBatchCount(summary.getPendingBatchCount() + count);
boolean inError = rs.getBoolean("error_flag");
summary.setInError(inError || summary.isInError());
if (status != Status.NE && count == 1) {
summary.setCurrentBatchId(rs.getLong("current_batch_id"));
summary.setCurrentDataEventCount(rs.getLong("current_data_event_count"));
}
}
return null;
}
});
List<OutgoingLoadSummary> loads = new ArrayList<OutgoingLoadSummary>(loadSummaries.values());
Iterator<OutgoingLoadSummary> it = loads.iterator();
while (it.hasNext()) {
OutgoingLoadSummary loadSummary = it.next();
if (activeOnly && !loadSummary.isActive()) {
it.remove();
}
}
return loads;
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class NodeService method findLastHeartbeats.
public Map<String, Date> findLastHeartbeats() {
Map<String, Date> dates = new HashMap<String, Date>();
Node myNode = findIdentity();
if (myNode != null) {
List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"));
for (Row node : list) {
String nodeId = node.getString("node_id");
Date time = node.getDateTime("heartbeat_time");
dates.put(nodeId, time);
}
}
return dates;
}
use of org.jumpmind.db.sql.Row in project symmetric-ds by JumpMind.
the class H2DdlReader 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;
}
Aggregations