Example usage for org.springframework.jdbc.core RowCallbackHandler RowCallbackHandler

List of usage examples for org.springframework.jdbc.core RowCallbackHandler RowCallbackHandler

Introduction

In this page you can find the example usage for org.springframework.jdbc.core RowCallbackHandler RowCallbackHandler.

Prototype

RowCallbackHandler

Source Link

Usage

From source file:org.geowebcache.storage.MetastoreRemover.java

private void migrateTileDates(JdbcTemplate template, final FilePathGenerator generator) {
    String query = "select layers.value as layer, gridsets.value as gridset, "
            + "tiles.parameters_id, tiles.z, tiles.x, tiles.y, created, formats.value as format \n"
            + "from tiles join layers on layers.id = tiles.layer_id \n"
            + "join gridsets on gridsets.id = tiles.gridset_id \n"
            + "join formats on formats.id = tiles.format_id \n"
            + "order by layer_id, parameters_id, gridset, z, x, y";

    final long total = template.queryForLong("select count(*) from (" + query + ")");
    log.info("Migrating " + total + " tile creation dates from the metastore to the file system");

    template.query(query, new RowCallbackHandler() {

        int count = 0;

        public void processRow(ResultSet rs) throws SQLException {
            // read the result set
            String layer = rs.getString(1);
            String gridset = rs.getString(2);
            String paramsId = rs.getString(3);
            long z = rs.getLong(4);
            long x = rs.getLong(5);
            long y = rs.getLong(6);
            long created = rs.getLong(7);
            String format = rs.getString(8);

            // create the tile and thus the tile path
            TileObject tile = TileObject.createCompleteTileObject(layer, new long[] { x, y, z }, gridset,
                    format, null, null);
            tile.setParametersId(paramsId);
            try {
                File file = generator.tilePath(tile, MimeType.createFromFormat(format));

                // update the last modified according to the date
                if (file.exists()) {
                    file.setLastModified(created);
                }/*w  w w  . ja  va  2  s.c om*/
            } catch (MimeException e) {
                log.error("Failed to locate mime type for format '" + format + "', this should never happen!");
            }

            count++;
            if (count % 10000 == 0 || count >= total) {
                log.info("Migrated " + count + "/" + total
                        + " tile creation dates from the metastore to the file system");
            }
        }
    });
}

From source file:gov.nih.nci.cabig.ctms.tools.configuration.DatabaseBackedConfigurationTest.java

private <V> void assertStoredValue(final String expected, String expectedTable,
        ConfigurationProperty<V> property) {
    final int[] count = new int[1];
    jdbc.query(String.format("SELECT value FROM %s WHERE key=?", expectedTable),
            new Object[] { property.getKey() }, new RowCallbackHandler() {
                public void processRow(ResultSet rs) throws SQLException {
                    assertEquals(expected, rs.getString("value"));
                    count[0]++;//www.  jav a 2s. c o  m
                }
            });
    assertEquals("Wrong number of values found", 1, count[0]);
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.ExtractorConfDaoImpl.java

private void genTaskParameters(String taskInstanceId) {
    String sql = super.getSql("QUERY_TASK_PARAMETERS");
    final Properties parameters = new Properties();
    final Set<String> mapperConfs = new HashSet<String>(2);
    super.getJdbcTemplate().query(sql, new Object[] { taskInstanceId }, new RowCallbackHandler() {

        public void processRow(ResultSet rs) throws SQLException {
            String key = rs.getString("PARAM_NAME");
            if ("mapper-spring".equals(key)) {
                if (null != rs.getString("PARAM_VALUE") && !rs.getString("PARAM_VALUE").equals("")) {
                    mapperConfs.add(new StringBuilder(Constants.SPRING_DIRECTORY)
                            .append(rs.getString("PARAM_VALUE")).toString());
                    //???
                    AdapterExtractorContext.getInstance().setFileUpload(false);
                }// w ww.  j a  v  a 2s  .  c om
            } else if ("adapter-spring".equals(key)) {
                if (null != rs.getString("PARAM_VALUE") && !rs.getString("PARAM_VALUE").equals("")) {
                    mapperConfs.add(new StringBuilder(Constants.SPRING_DIRECTORY)
                            .append(rs.getString("PARAM_VALUE")).toString());
                    //???
                    AdapterExtractorContext.getInstance().setFileUpload(false);
                }
            } else if ("filePath".equals(key)) {
                // filePath,,,??
                AdapterExtractorContext.getInstance().setNeedMultiExtract(true);
                AdapterExtractorContext.getInstance().setDsDirectory(rs.getString("PARAM_VALUE"));

                parameters.setProperty(key, rs.getString("PARAM_VALUE"));
                //???
                AdapterExtractorContext.getInstance().setFileUpload(true);
            } else if ("dsMdId".equals(key)) {
                // Excel??:ID
                // ?
                AppendMetadata aMetadata = genAMetadata(rs.getString("PARAM_VALUE"));
                AdapterExtractorContext.getInstance().setAMetadata(aMetadata);
            } else {
                String value = rs.getString("PARAM_VALUE");
                if (value == null) {
                    value = "";
                }
                parameters.setProperty(key, value);
            }
        }

    });

    String[] confs = new String[mapperConfs.size()];
    AdapterExtractorContext.getInstance().setMapperConfs(mapperConfs.toArray(confs));
    boolean isMapperCGB = false;
    boolean isAdapterCGB = false;
    for (String str : mapperConfs) {
        if (!"".equals(str) && str.endsWith("adapter-db-cgb.xml")) {
            isAdapterCGB = true;
        } else if (!"".equals(str) && str.endsWith("mapper-db-cgb.xml")) {
            isMapperCGB = true;
        }
    }
    if (isAdapterCGB && isMapperCGB) {
        AdapterExtractorContext.getInstance().setIsDBExtract(true);
    } else {
        AdapterExtractorContext.getInstance().setIsDBExtract(false);
    }
    AdapterExtractorContext.getInstance().setParameters(parameters);

}

From source file:com.oracle2hsqldb.dialect.Oracle9Dialect.java

/**
 * Superclass's implementation does not work. Seems that the Oracle driver does not support DatabaseMetaData.getIndexInfo() well.
 *//*from  w  w w.  j av a2 s  . co m*/
public Iterator getUniqueKeys(DataSource dataSource, String schemaName) {
    final List specs = new LinkedList();
    new JdbcTemplate(dataSource).query("SELECT ucc.column_name, ucc.constraint_name, ucc.table_name "
            + "FROM user_constraints uc INNER JOIN user_cons_columns ucc ON ucc.constraint_name=uc.constraint_name "
            + "WHERE uc.constraint_type='U'", new RowCallbackHandler() {
                public void processRow(ResultSet columns) throws SQLException {
                    String columnName = columns.getString("COLUMN_NAME");
                    String tableName = columns.getString("TABLE_NAME");
                    String constraintName = columns.getString("CONSTRAINT_NAME");
                    if (log.isDebugEnabled())
                        log.debug("Reading unique constraint:column " + constraintName + ":" + columnName);
                    specs.add(new UniqueConstraint.Spec(tableName, columnName, constraintName));
                }
            });
    return specs.iterator();
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.DAMQueriesCGCCLevelTwoAndThree.java

private Map<String, Integer> queryBarcodesForArchive(final List<DataSetLevelTwoThree> datasets) {
    final Map<String, Integer> loadedBarcodes = new HashMap<String, Integer>();
    getJdbcTemplate().query(/*from ww  w  .  j ava  2s.  c om*/
            GET_DATASETS_QUERY, new Object[] { datasets.get(0).getDepositBaseName(),
                    datasets.get(0).getDepositBatch(), datasets.get(0).getDataRevision(), getDataLevel() },
            new RowCallbackHandler() {
                public void processRow(final ResultSet resultSet) throws SQLException {
                    loadedBarcodes.put(resultSet.getString(2), resultSet.getInt(1));
                }
            });
    return loadedBarcodes;
}

From source file:com.px100systems.data.plugin.persistence.jdbc.Storage.java

protected void load(List<String> unitNames, final LoadCallback callback) {
    final LoadData currentRecord = new LoadData();

    StringBuilder where = new StringBuilder();
    if (unitNames != null)
        for (String like : unitNames) {
            if (where.length() > 0)
                where.append(" OR ");
            where.append("(unit_name LIKE '");
            where.append(like);/*  w w w.  j  a v a 2s .c  o  m*/
            where.append("%')");
        }

    connection.getJdbc().setFetchSize(50);
    connection.getJdbc()
            .query("SELECT unit_name, generator_name, class_name, id, data_size, data FROM " + table
                    + (where.length() > 0 ? (" WHERE " + where) : "")
                    + " ORDER BY unit_name ASC, id ASC, block_number ASC", new RowCallbackHandler() {
                        @Override
                        public void processRow(ResultSet rs) throws SQLException {
                            String unitName = rs.getString("unit_name");
                            String generatorName = rs.getString("generator_name");
                            String className = rs.getString("class_name");
                            Long id = rs.getLong("id");
                            int dataSize = rs.getInt("data_size");
                            byte[] data = rs.getBytes("data");

                            if (currentRecord.id != null && (!currentRecord.id.equals(id)
                                    || !currentRecord.unitName.equals(unitName)))
                                currentRecord.insert(callback);

                            currentRecord.grow(unitName, generatorName, className, id, data, dataSize);
                        }
                    });

    currentRecord.insert(callback);
}

From source file:com.oracle2hsqldb.dialect.Oracle9Dialect.java

/**
 * Superclass returns nothing.//from w w w.j a va  2  s .  c  o  m
 */
public Iterator getSequences(DataSource dataSource, String schemaName) throws SQLException {
    final List seq = new LinkedList();
    new JdbcTemplate(dataSource).query("SELECT sequence_name, last_number FROM user_sequences",
            new RowCallbackHandler() {
                public void processRow(ResultSet rs) throws SQLException {
                    String seqName = rs.getString("SEQUENCE_NAME");
                    long seqValue = rs.getLong("LAST_NUMBER");
                    if (log.isDebugEnabled())
                        log.debug("Reading sequence " + seqName + "; currval=" + seqValue);
                    seq.add(new Sequence(seqName, new Long(seqValue)));
                }
            });
    return seq.iterator();
}

From source file:ru.org.linux.poll.PollDao.java

/**
 *  ? ?  ?//  w  w w .ja v  a2 s  . c  om
 *
 * @param poll   ??
 * @param order ? ?  Poll.ORDER_ID  Poll.ORDER_VOTES
 * @param user ?  ?  
 * @return ? ??  ?
 */
public ImmutableList<PollVariantResult> getPollVariants(Poll poll, int order, final User user) {
    final List<PollVariantResult> variants = new ArrayList<>();

    String query;

    switch (order) {
    case Poll.ORDER_ID:
        query = queryPollVariantsOrderById;
        break;
    case Poll.ORDER_VOTES:
        query = queryPollVariantsOrderByVotes;
        break;
    default:
        throw new RuntimeException("Oops!? order=" + order);
    }

    jdbcTemplate.query(query, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            int id = resultSet.getInt("id");
            String label = resultSet.getString("label");
            int votes = resultSet.getInt("votes");
            boolean voted = false;
            if (user != null
                    && jdbcTemplate.queryForInt(queryPollUserVote, user.getId(), resultSet.getInt("id")) != 0) {
                voted = true;
            }
            variants.add(new PollVariantResult(id, label, votes, voted));
        }
    }, poll.getId());

    return ImmutableList.copyOf(variants);
}

From source file:ru.org.linux.user.UserDao.java

/**
 *  ?? ?/*from w  w  w  .  j  a  v a 2 s. c om*/
 * @param user 
 * @param exact ?  ? ??
 * @return ??
 */
public UserStatistics getUserStatisticsClass(User user, boolean exact) {
    int ignoreCount = ignoreListDao.getIgnoreStat(user);

    int commentCount = 0;
    boolean exactCommentCount = false;

    if (!exact) {
        List<Integer> res = jdbcTemplate.queryForList("SELECT cnt FROM user_comment_counts WHERE userid=?",
                Integer.class, user.getId());

        if (res.size() > 0) {
            commentCount = (int) Math.round(res.get(0) / 1000.0) * 1000;
        }
    }

    if (commentCount == 0) {
        try {
            commentCount = jdbcTemplate.queryForInt(queryCommentStat, user.getId());
        } catch (EmptyResultDataAccessException exception) {
        }

        exactCommentCount = true;
    }

    List<Timestamp> commentStat;

    try {
        commentStat = jdbcTemplate.queryForObject(queryCommentDates, new RowMapper<List<Timestamp>>() {
            @Override
            public List<Timestamp> mapRow(ResultSet resultSet, int i) throws SQLException {
                return Lists.newArrayList(resultSet.getTimestamp("first"), resultSet.getTimestamp("last"));
            }
        }, user.getId());
    } catch (EmptyResultDataAccessException exception) {
        commentStat = null;
    }

    List<Timestamp> topicStat;

    try {
        topicStat = jdbcTemplate.queryForObject(queryTopicDates, new RowMapper<List<Timestamp>>() {
            @Override
            public List<Timestamp> mapRow(ResultSet resultSet, int i) throws SQLException {
                return Lists.newArrayList(resultSet.getTimestamp("first"), resultSet.getTimestamp("last"));
            }
        }, user.getId());
    } catch (EmptyResultDataAccessException exception) {
        topicStat = null;
    }

    final ImmutableList.Builder<UsersSectionStatEntry> builder = ImmutableList.builder();
    jdbcTemplate.query(queryTopicsBySectionStat, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            builder.add(new UsersSectionStatEntry(resultSet.getInt("section"), resultSet.getInt("c")));
        }
    }, user.getId());

    return new UserStatistics(ignoreCount, commentCount, exactCommentCount, commentStat.get(0),
            commentStat.get(1), topicStat.get(0), topicStat.get(1), builder.build());
}