Search in sources :

Example 26 with Row

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;
}
Also used : IParameterFilter(org.jumpmind.symmetric.config.IParameterFilter) Row(org.jumpmind.db.sql.Row) TypedProperties(org.jumpmind.properties.TypedProperties)

Example 27 with Row

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;
}
Also used : ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row)

Example 28 with Row

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;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) TreeMap(java.util.TreeMap) OutgoingLoadSummary(org.jumpmind.symmetric.model.OutgoingLoadSummary) Date(java.util.Date)

Example 29 with Row

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;
}
Also used : HashMap(java.util.HashMap) Node(org.jumpmind.symmetric.model.Node) NetworkedNode(org.jumpmind.symmetric.model.NetworkedNode) Row(org.jumpmind.db.sql.Row) Date(java.util.Date)

Example 30 with Row

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;
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Aggregations

Row (org.jumpmind.db.sql.Row)66 ArrayList (java.util.ArrayList)27 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)23 Trigger (org.jumpmind.db.model.Trigger)19 JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)19 DmlStatement (org.jumpmind.db.sql.DmlStatement)13 Column (org.jumpmind.db.model.Column)11 Table (org.jumpmind.db.model.Table)9 Date (java.util.Date)8 HashMap (java.util.HashMap)7 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)7 Test (org.junit.Test)5 HashSet (java.util.HashSet)3 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)3 SqlException (org.jumpmind.db.sql.SqlException)3 NetworkedNode (org.jumpmind.symmetric.model.NetworkedNode)3 Node (org.jumpmind.symmetric.model.Node)3 Map (java.util.Map)2 NotImplementedException (org.apache.commons.lang.NotImplementedException)2 Database (org.jumpmind.db.model.Database)2