Example usage for org.springframework.jdbc.support.rowset SqlRowSet first

List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet first

Introduction

In this page you can find the example usage for org.springframework.jdbc.support.rowset SqlRowSet first.

Prototype

boolean first() throws InvalidResultSetAccessException;

Source Link

Document

Move the cursor to the first row of this row set.

Usage

From source file:transaction.script.ProjectTrScript.java

/**
 * @param template//w ww.j  a  v a2  s  .c om
 * @param query
 * @param conditionsMapList
 * @return
 * @throws SQLException
 */
public static boolean query(JdbcTemplate template, String query, List<Map<String, Object>> conditionsMapList)
        throws SQLException {
    logger.info("Query to execute is: " + query);

    SqlRowSet set = template.queryForRowSet(query);
    boolean result = true;

    SqlRowSetMetaData mdata = set.getMetaData();
    int columnAmount = mdata.getColumnCount();
    logger.info("Columns: " + columnAmount);
    logger.info("Map size: " + conditionsMapList.size());

    //TODO
    if (set.first()) {
        set.last();
        int rowNum = set.getRow();
        result = (rowNum == conditionsMapList.size());
        set.beforeFirst();
    } else {
        if (!conditionsMapList.get(0).isEmpty()) {
            result = false;
        }
    }

    logger.info("Two maps comparison result is " + result);

    if (result) {
        while (set.next()) {
            int rowNum = set.getRow();

            Map<String, Object> map = conditionsMapList.get(rowNum - 1);

            for (int i = 1; i <= columnAmount; i++) {
                result &= map.containsKey(mdata.getColumnName(i))
                        && map.get(mdata.getColumnName(i)).toString().equals(set.getObject(i).toString());
            }
        }
    }
    return result;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGeneratorSlowTest.java

/**
 * Tests the {@link QCLiveTestDataGenerator#generateTestData(String)} method with a valid archive name
 * and check assertions to verify that CNTL test data was loaded.
 *//*w  ww . jav a  2 s .c  o m*/
@Test
public void testLoadCNTLTestDataForNonCNTLArchive() throws IOException, SQLException, ParseException {

    // Retrieve the QCLiveTestDataGenerator from the Spring context and invoke it using a valid archive name
    ((QCLiveTestDataGenerator) testAppCtx.getBean("qcLiveTestDataGenerator"))
            .generateTestData("nationwidechildrens.org_BRCA.bio.Level_1.85.21.0");

    final JdbcTemplate diseaseLocalJdbcTemplate = (JdbcTemplate) testAppCtx.getBean("diseaseLocalJdbcTemplate");
    final SqlRowSet rowSet = diseaseLocalJdbcTemplate.queryForRowSet("select * from data_level");

    assertNotNull(rowSet);
    assertTrue(rowSet.first());
    assertEquals(1, rowSet.getInt("level_number"));
    assertEquals("cAsESeNsItIvE", rowSet.getString("level_definition"));
    assertTrue(rowSet.isLast());
}

From source file:org.geoserver.jdbcconfig.internal.DbMappings.java

private BiMap<Integer, Class<?>> loadTypes(NamedParameterJdbcOperations template) {
    String sql = "select oid, typename from type";
    SqlRowSet rowSet = template.queryForRowSet(sql, params("", ""));
    BiMap<Integer, Class<?>> types = HashBiMap.create();
    if (rowSet.first()) {
        do {// w ww.  ja v a 2  s  .  c o m
            Number oid = (Number) rowSet.getObject(1);
            String typeName = rowSet.getString(2);
            Class<?> clazz;
            try {
                clazz = Class.forName(typeName);
            } catch (ClassNotFoundException e) {
                throw Throwables.propagate(e);
            }
            types.put(oid.intValue(), clazz);
        } while (rowSet.next());
    }
    return types;
}

From source file:org.sipfoundry.sipxconfig.feature.FeatureManagerImpl.java

@Override
public boolean isFeatureEnabled(LocationFeature feature, Location location) {
    SqlRowSet queryForRowSet = m_jdbcTemplate.queryForRowSet(
            "select 1 from feature_local where feature_id = ? and location_id = ?", feature.getId(),
            location.getId());/*from w  w w.j a  v a2s  . c  om*/
    return queryForRowSet.first();
}

From source file:org.sipfoundry.sipxconfig.feature.FeatureManagerImpl.java

@Override
public boolean isFeatureEnabled(GlobalFeature feature) {
    SqlRowSet queryForRowSet = m_jdbcTemplate
            .queryForRowSet("select 1 from feature_global where feature_id = ?", feature.getId());
    return queryForRowSet.first();
}

From source file:org.sipfoundry.sipxconfig.feature.FeatureManagerImpl.java

@Override
public boolean isFeatureEnabled(LocationFeature feature) {
    SqlRowSet queryForRowSet = m_jdbcTemplate.queryForRowSet("select 1 from feature_local where feature_id = ?",
            feature.getId());/*ww w .  ja va2  s .  co  m*/
    return queryForRowSet.first();
}