use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class PostgreSqlDdlReader method getTriggers.
@Override
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 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;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class AbstractXmlPublisherExtensionPoint method readData.
protected List<String[]> readData(final Table table, String[] args) {
final IDatabasePlatform platform = engine.getDatabasePlatform();
List<String[]> rows = new ArrayList<String[]>();
final String[] columnNames = table.getColumnNames();
if (columnNames != null && columnNames.length > 0) {
StringBuilder builder = new StringBuilder("select ");
for (int i = 0; i < columnNames.length; i++) {
String columnName = columnNames[i];
if (i > 0) {
builder.append(",");
}
builder.append(columnName);
}
builder.append(" from ").append(table.getName()).append(" where ");
for (int i = 0; i < groupByColumnNames.size(); i++) {
String columnName = groupByColumnNames.get(i);
if (i > 0 && i < groupByColumnNames.size()) {
builder.append(" and ");
}
builder.append(columnName).append("=?");
}
ISqlTemplate template = platform.getSqlTemplate();
Object[] argObjs = platform.getObjectValues(engine.getSymmetricDialect().getBinaryEncoding(), args, table.getColumnsWithName(groupByColumnNames.toArray(new String[groupByColumnNames.size()])));
rows = template.query(builder.toString(), new ISqlRowMapper<String[]>() {
@Override
public String[] mapRow(Row row) {
return platform.getStringValues(engine.getSymmetricDialect().getBinaryEncoding(), table.getColumns(), row, false, false);
}
}, argObjs);
}
return rows;
}
use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.
the class ConfigurationService method getNodeChannels.
public List<NodeChannel> getNodeChannels(final String nodeId, boolean refreshExtractMillis) {
boolean loaded = false;
long channelCacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_CHANNEL_IN_MS);
List<NodeChannel> nodeChannels = nodeChannelCache != null ? nodeChannelCache.get(nodeId) : null;
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannels == null) {
synchronized (this) {
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannelCache == null || nodeChannelCache.get(nodeId) == null || nodeChannels == null) {
if (System.currentTimeMillis() - nodeChannelCacheTime >= channelCacheTimeoutInMs || nodeChannelCache == null) {
nodeChannelCache = new HashMap<String, List<NodeChannel>>();
nodeChannelCacheTime = System.currentTimeMillis();
}
if (nodeId != null) {
nodeChannels = sqlTemplate.query(getSql("selectNodeChannelsSql"), new ISqlRowMapper<NodeChannel>() {
public NodeChannel mapRow(Row row) {
NodeChannel nodeChannel = new NodeChannel();
nodeChannel.setChannelId(row.getString("channel_id"));
nodeChannel.setNodeId(nodeId);
nodeChannel.setIgnoreEnabled(row.getBoolean("ignore_enabled"));
nodeChannel.setSuspendEnabled(row.getBoolean("suspend_enabled"));
nodeChannel.setProcessingOrder(row.getInt("processing_order"));
nodeChannel.setMaxBatchSize(row.getInt("max_batch_size"));
nodeChannel.setEnabled(row.getBoolean("enabled"));
nodeChannel.setMaxBatchToSend(row.getInt("max_batch_to_send"));
nodeChannel.setMaxDataToRoute(row.getInt("max_data_to_route"));
nodeChannel.setUseOldDataToRoute(row.getBoolean("use_old_data_to_route"));
nodeChannel.setUseRowDataToRoute(row.getBoolean("use_row_data_to_route"));
nodeChannel.setUsePkDataToRoute(row.getBoolean("use_pk_data_to_route"));
nodeChannel.setContainsBigLob(row.getBoolean("contains_big_lob"));
nodeChannel.setBatchAlgorithm(row.getString("batch_algorithm"));
nodeChannel.setLastExtractTime(row.getDateTime("last_extract_time"));
nodeChannel.setExtractPeriodMillis(row.getLong("extract_period_millis"));
nodeChannel.setDataLoaderType(row.getString("data_loader_type"));
nodeChannel.setCreateTime(row.getDateTime("create_time"));
nodeChannel.setLastUpdateBy(row.getString("last_update_by"));
nodeChannel.setLastUpdateTime(row.getDateTime("last_update_time"));
nodeChannel.setFileSyncFlag(row.getBoolean("file_sync_flag"));
nodeChannel.setReloadFlag(row.getBoolean("reload_flag"));
return nodeChannel;
}
}, nodeId);
nodeChannelCache.put(nodeId, nodeChannels);
loaded = true;
} else {
nodeChannels = new ArrayList<NodeChannel>(0);
}
}
}
}
if (!loaded && refreshExtractMillis) {
/*
* need to read last extracted time from database regardless of
* whether we used the cache or not. locate the nodes in the cache,
* and update it.
*/
final Map<String, NodeChannel> nodeChannelsMap = new HashMap<String, NodeChannel>();
for (NodeChannel nc : nodeChannels) {
nodeChannelsMap.put(nc.getChannelId(), nc);
}
sqlTemplate.query(getSql("selectNodeChannelControlLastExtractTimeSql"), new ISqlRowMapper<Object>() {
public Object mapRow(Row row) {
String channelId = row.getString("channel_id");
Date extractTime = row.getDateTime("last_extract_time");
NodeChannel nodeChannel = nodeChannelsMap.get(channelId);
if (nodeChannel != null) {
nodeChannel.setLastExtractTime(extractTime);
}
return nodeChannelsMap;
}
}, nodeId);
}
return nodeChannels;
}
Aggregations