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

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

Introduction

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

Prototype

void beforeFirst() throws InvalidResultSetAccessException;

Source Link

Document

Move the cursor to the front of this row set, just before the first row.

Usage

From source file:transaction.script.ProjectTrScript.java

/**
 * @param template/* w w w .  ja va 2s .c  o m*/
 * @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:com.krawler.crm.reportBuilder.bizservice.ReportBuilderServiceImpl.java

public List getIdsList(SqlRowSet rs) {
    List<Object> ll = new ArrayList<Object>();
    List<String> idList = new ArrayList<String>();
    Boolean productColFlag = false;
    try {//from  ww w  . ja v a2  s .c o m
        SqlRowSetMetaData rsmd = rs.getMetaData();
        while (rs.next()) {
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                String columnLabel = rsmd.getColumnLabel(i);
                if (columnLabel.equals(Constants.Crm_leadid) || columnLabel.equals(Constants.Crm_productid)
                        || columnLabel.equals(Constants.Crm_accountid)
                        || columnLabel.equals(Constants.Crm_contactid)
                        || columnLabel.equals(Constants.Crm_caseid)
                        || columnLabel.equals(Constants.Crm_opportunityid)) {
                    if (rs.getObject(i) != null) {
                        idList.add(rs.getObject(i).toString());
                    }
                } else if (columnLabel.equals(Constants.Crm_lead_product_key)
                        || columnLabel.equals(Constants.Crm_opportunity_product_key)
                        || columnLabel.equals(Constants.Crm_account_product_key)
                        || columnLabel.equals(Constants.Crm_case_product_key)) {
                    productColFlag = true;
                }
            }
        }
        rs.beforeFirst();
        ll.add(idList);
        ll.add(productColFlag);
    } catch (Exception ex) {
        LOGGER.warn(ex.getMessage(), ex);
    }
    return ll;
}