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

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

Introduction

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

Prototype

boolean next() throws InvalidResultSetAccessException;

Source Link

Document

Move the cursor to the next row.

Usage

From source file:edu.uca.aca2016.impulse.repository.InteractionsDAO.java

/**
 *getInteractionsCount method and SQL Query
 * @return// ww  w . j ava  2s  .c om
 */
public int getInteractionCount() {
    String sql = "SELECT COUNT(InteractionID) AS rowcount FROM interactions";
    SqlRowSet rs = template.queryForRowSet(sql);

    if (rs.next()) {
        return rs.getInt("rowcount");
    }

    return 1;
}

From source file:edu.uca.aca2016.impulse.repository.InteractionsDAO.java

/**
 *getClientsMap method and SQL Query/*from www. j  a  v a2s . co  m*/
 * @return
 */
public Map<Integer, String> getClientsMap() {
    Map<Integer, String> clients = new LinkedHashMap<>();
    String sql = "SELECT ClientID, FirstName, LastName FROM Client ORDER BY FirstName";

    SqlRowSet rs = template.queryForRowSet(sql);

    while (rs.next()) {
        clients.put(rs.getInt(1), rs.getString(2) + " " + rs.getString(3));
    }

    return clients;
}

From source file:com.zousu.mongopresser.Presser.java

public void press() {
    //get a list of all the tables and columns
    logger.info("Starting MySQL to Mongo Conversion...");
    logger.info("Preparing Tables...");
    mySQLHandler.initialiseDatabase();//from   w ww  . j a v a2 s.  c  o m
    List<Table> tables = mySQLHandler.getTableList();
    for (int i = 0; i < tables.size(); i++) {
        Table table = tables.get(i);
        List<Column> columns = table.getColumns();
        List<DBObject> dboList = new ArrayList<DBObject>();
        SqlRowSet rs = mySQLHandler.selectAllFromTable(table.getTableName());
        logger.info("Creating objects for " + table.getTableName() + "...");
        while (rs.next()) {
            BasicDBObject dbo = new BasicDBObject();
            for (int j = 0; j < columns.size(); j++) {
                Column col = columns.get(j);
                String colName = col.getColumnName();
                switch (col.getType()) {
                case Types.INTEGER:
                case Types.BIGINT:
                    dbo.append(colName, rs.getInt(colName));
                    break;
                case Types.DOUBLE:
                    dbo.append(colName, rs.getDouble(colName));
                    break;
                case Types.DATE:
                    dbo.append(colName, rs.getDate(colName));
                    break;
                default:
                    dbo.append(colName, rs.getString(colName));
                    break;
                }

            }
            dboList.add(dbo);
        }

        //now insert it
        logger.info("Inserting " + dboList.size() + " mongo rows into " + table.getTableName() + "...");
        table.setNumOfRows(dboList.size());
        try {
            mongoHandler.createCollection(table.getTableName(), true);
            mongoHandler.batchInsert(dboList, table.getTableName());
            assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == dboList.size());
            logger.info(table.getTableName() + " DONE!");
        } catch (CollectionExistException e) {
            e.printStackTrace();
        }
    }
    logger.info(tables.size() + " collections added!");

    //now check go get it from mongo and check if the data there is correct
    logger.info("Checking mongo consistency...");
    for (int i = 0; i < tables.size(); i++) {
        Table table = tables.get(i);
        assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == table.getNumOfRows());
        logger.info(table.getTableName() + " consistent!");
    }
    logger.info("MySQL to Mongo Conversion Completed!!!!");
}

From source file:dk.nsi.sdm4.dosering.parser.DoseringParserIntegrationTest.java

@Test
public void Should_import_dosage_units_correctly() throws Exception {
    runImporter();// w w w .  j a v  a 2s.  c o m

    SqlRowSet rs = jdbcTemplate.queryForRowSet("select * from DosageUnit");
    rs.next();

    assertThat(rs.getLong("releaseNumber"), equalTo(125L));
    assertThat(rs.getInt("code"), equalTo(8));
    assertThat(rs.getString("textSingular"), equalTo("brusetablet"));
    assertThat(rs.getString("textPlural"), equalTo("brusetabletter"));

    // expect only one row
    assertFalse(rs.next());

}

From source file:dk.nsi.sdm4.dosering.parser.DoseringParserIntegrationTest.java

@Test
public void importTheVersionFileCorrectly() throws Exception {
    runImporter();/*from  w w  w.  j  a  v  a2 s . c  o m*/

    SqlRowSet rs = jdbcTemplate.queryForRowSet("select * from DosageVersion");
    rs.next();

    assertThat(rs.getLong("releaseNumber"), equalTo(125L));
    assertThat(rs.getDate("releaseDate"), equalTo(date("2011-02-15")));
    assertThat(rs.getDate("lmsDate"), equalTo(date("2011-02-02")));
    assertThat(rs.getDate("daDate"), equalTo(date("2011-01-24")));

    // expect only one row
    assertFalse(rs.next());
}

From source file:dk.nsi.sdm4.dosering.parser.DoseringParserIntegrationTest.java

@Test
public void importTheStructuresCorrectly() throws Exception {
    runImporter();/*  ww w  . j  a va  2  s  . co  m*/

    SqlRowSet rs = jdbcTemplate.queryForRowSet("select * from DosageStructure");
    rs.next();

    assertThat(rs.getLong("releaseNumber"), equalTo(125L));
    assertThat(rs.getString("code"), equalTo("3"));
    assertThat(rs.getString("type"), equalTo("M+M+A+N"));
    assertThat(rs.getString("simpleString"), equalTo("0.5"));
    assertThat(rs.getString("shortTranslation"), equalTo("1/2 tablet morgen"));
    assertThat(rs.getString("xml"), equalTo(
            "<b:DosageStructure\n   xsi:schemaLocation=\"http://www.dkma.dk/medicinecard/xml.schema/2009/01/01 DKMA_DosageStructure.xsd\"\n   xmlns:a=\"http://www.dkma.dk/medicinecard/xml.schema/2008/06/01\"\n   xmlns:b=\"http://www.dkma.dk/medicinecard/xml.schema/2009/01/01\"\n   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n   <b:DosageTimesStructure>\n      <a:DosageTimesIterationIntervalQuantity>1</a:DosageTimesIterationIntervalQuantity>\n      <a:DosageTimesStartDate>2000-01-01</a:DosageTimesStartDate>\n      <b:DosageQuantityUnitText>tablet</b:DosageQuantityUnitText>\n      <b:DosageDayElementStructure>\n         <a:DosageDayIdentifier>1</a:DosageDayIdentifier>\n         <b:MorningDosageTimeElementStructure>\n            <a:DosageQuantityValue>0.5</a:DosageQuantityValue>\n         </b:MorningDosageTimeElementStructure>\n      </b:DosageDayElementStructure>\n   </b:DosageTimesStructure>\n</b:DosageStructure>"));
    assertThat(rs.getString("longTranslation"), equalTo("Daglig 1/2 tablet morgen"));
    assertThat(rs.getString("supplementaryText"), nullValue());

    // expect only one row
    assertFalse(rs.next());
}

From source file:org.restsql.core.impl.postgresql.PostgreSqlSqlResourceMetaData.java

/**
 * Retrieves database-specific table name used in SQL statements. Used to
 * build join table meta data.//from ww w .ja  va 2 s .com
 */
@Override
protected String getQualifiedTableName(String databaseName, String tableName) {

    SqlRowSet resultSet = null;

    String schemaName = "unknown";

    resultSet = this.jdbcTemplate.queryForRowSet(SQL_TABLE_SCHEMA_QUERY, databaseName, tableName);
    if (resultSet.next()) {
        schemaName = resultSet.getString(1);
    }
    return databaseName + "." + schemaName + "." + tableName;

}

From source file:db.postgres.V2_0_1__InitializeIdentityZones.java

private void removeDuplicateRows(final JdbcTemplate jdbcTemplate, final Long zone) {
    final List<SubjectEntity> subjects = jdbcTemplate
            .query("SELECT DISTINCT subject_identifier, attributes FROM subject", new SubjectRowMapper());
    jdbcTemplate.update("DELETE FROM subject *");
    for (SubjectEntity s : subjects) {
        jdbcTemplate.update(/*from  w  ww.  j  a  va  2 s. c om*/
                "INSERT INTO subject (subject_identifier, attributes, "
                        + " authorization_zone_id) VALUES (?,?,?)",
                s.getSubjectIdentifier(), s.getAttributesAsJson(), zone);
    }
    final List<ResourceEntity> resources = jdbcTemplate
            .query("SELECT DISTINCT resource_identifier, attributes FROM resource", new ResourceRowMapper());
    jdbcTemplate.update("DELETE FROM resource *");
    for (ResourceEntity r : resources) {
        jdbcTemplate.update(
                "INSERT INTO resource (resource_identifier, attributes, "
                        + " authorization_zone_id) VALUES (?,?,?)",
                r.getResourceIdentifier(), r.getAttributesAsJson(), zone);
    }

    final List<PolicySetEntity> policysets = jdbcTemplate
            .query("SELECT DISTINCT policy_set_id, policy_set_json FROM policy_set", new PolicySetRowMapper());
    jdbcTemplate.update("DELETE FROM policy_set *");
    for (PolicySetEntity ps : policysets) {
        SqlRowSet row = jdbcTemplate.queryForRowSet("SELECT * FROM policy_set WHERE policy_set_id =?",
                ps.getPolicySetID());
        if (row.next()) {
            jdbcTemplate.update("UPDATE policy_set SET policy_set_json = ? WHERE policy_set_id = ?",
                    ps.getPolicySetJson(), ps.getPolicySetID());
        } else {
            jdbcTemplate.update(
                    "INSERT INTO policy_set (policy_set_id, policy_set_json, "
                            + " authorization_zone_id) VALUES (?,?,?)",
                    ps.getPolicySetID(), ps.getPolicySetJson(), zone);
        }
    }
}

From source file:pl.edu.icm.comac.vis.server.service.DbGraphIdService.java

@Override
public List<String> getNodes(String graphId) throws UnknownGraphException {
    log.debug("Retrieving graph " + graphId);
    SqlRowSet set = jdbcTemplate.queryForRowSet(
            "select element  from graph g join graph_entry ge on graph_id=id where id = ?", graphId);
    List<String> res = new ArrayList<>();

    while (set.next()) {
        res.add(set.getString(1));//from   w ww  .j a  v  a2 s  . com
    }
    log.debug("Retrieved for graph " + graphId + " found " + res.size() + " nodes.");
    if (res.size() == 0) {
        throw new UnknownGraphException("Graph with id " + graphId + " not found.");
    }
    return res;
}

From source file:com.emergya.openfleetservices.importer.ddbb.JDBCConnector.java

/**
 * Given a tablename and the column where the address lies, for each row, it
 * geocodes the address and saves the geometry on the geocolumn
 * //  w w w.jav  a2 s  .  c  om
 * @param dsd
 * @return
 */
public int geocode(DataSetDescriptor dsd, String address) {
    NominatimConnector nm = new NominatimConnector("http://nominatim.openstreetmap.org/search.php");
    nm.setFormat("json");
    boolean containColumn = address.contains("{");
    int rowCont = 0;
    if (!containColumn) {
        // In order to not contain a column name into the search, the geometry field is the same for all
        nm.setQuery(address);
        String geoColumnAddress = nm.getAddress();
        System.out.println(geoColumnAddress);
        // Update all fields with geoColumnAddress and geoColumnName
        this.updateGeometryColumn(dsd, geoColumnAddress);
    } else {
        // Get the columns from address
        List<String> col = new LinkedList<String>();
        nm.getColumnsToGeom(col, address);
        SqlRowSet columnsMap = this.getColumnsByList(dsd, col);
        while (columnsMap.next()) {
            for (String c : col) {
                String dir = address;
                String param = columnsMap.getString(c);
                int pk = columnsMap.getInt(dsd.getNamePK());
                dir = dir.replace("{" + c + "}", param);
                nm.setQuery(dir);
                String geoAddress = nm.getAddress();
                if (geoAddress != null) {
                    String[] splitGeom = geoAddress.split(",");
                    Double lon = Double.valueOf(splitGeom[0]);
                    Double lat = Double.valueOf(splitGeom[1]);
                    String updateSQL = "UPDATE " + dsd.getTablename() + " SET " + dsd.getGeoColumnName()
                            + " = ST_GeomFromEWKT(:geom)" + " WHERE " + dsd.getNamePK() + "=:pk";
                    Map<String, Object> paramMap = new HashMap<String, Object>();
                    paramMap.put("pk", pk);
                    paramMap.put("geom", "SRID=4326;POINT(" + lon + " " + lat + ")");
                    this.namedJdbcTemplate.update(updateSQL, paramMap);
                } else {
                    rowCont++;
                }
            }
        }
    }
    return rowCont;
}