List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getObject
Object getObject(String columnLabel) throws InvalidResultSetAccessException;
From source file:com.univocity.app.data.Data.java
public void reloadData() { data.clear();// w ww.j a va2s . c o m SqlRowSet queryResult = database.getJdbcTemplate().queryForRowSet(selectScript); SqlRowSetMetaData metaData = queryResult.getMetaData(); columnNames = metaData.getColumnNames(); for (int i = 0; i < columnNames.length; i++) { String label = metaData.getColumnLabel(i + 1); if (label != null) { columnNames[i] = label; } } while (queryResult.next()) { Object[] row = new Object[columnNames.length]; for (int i = 0; i < row.length; i++) { row[i] = queryResult.getObject(i + 1); } data.add(row); } }
From source file:com.ineunet.knife.persist.dao.support.JdbcDaoSupport.java
@Override public Object[] queryForArray(String sql, int cols, Object... args) { SqlRowSet sqlSet = getJdbcTemplate().queryForRowSet(sql, args); Object[] array = null;/* w w w .j a v a 2 s. c o m*/ //sqlSet.getRow(): 0 //sqlSet.isBeforeFirst(): true //sqlSet.isFirst(): false if (sqlSet.next()) { array = new Object[cols]; for (int i = 0; i < cols; i++) { array[i] = sqlSet.getObject(i + 1); } } if (sqlSet.next()) { throw new IncorrectResultSizeDataAccessException(1); } //sqlSet.isFirst(): true //sqlSet.isLast(): true //sqlSet.isAfterLast(): false return array; }
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 w w w .j a v a2s. 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; }
From source file:com.krawler.crm.reportBuilder.bizservice.ReportBuilderServiceImpl.java
public JSONObject getReportJSON(int moduleId, SqlRowSet rs, HashMap<String, DefaultMasterItem> defaultMasterMap, HashMap<String, FieldComboData> customComboMap, Map<String, List<CrmProduct>> productsMap, Map ownersMap, HashMap<String, String> dataIndexReftableMap, boolean detailFlag, Boolean productColFlag) { JSONObject jb = new JSONObject(); try {/* w w w. j a v a 2s .c o m*/ SqlRowSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { String primaryKeyVal = ""; JSONObject jobj = new JSONObject(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String columnLabel = rsmd.getColumnLabel(i); // boolean linkFlag = !detailFlag && customReportObj.isGroupflag() && columnLabel.equals(customReportObj.getGroupfield()); if (rs.getObject(i) != null) { if (columnLabel.equals(Constants.Crm_leadid) || columnLabel.equals(Constants.Crm_contactid) || columnLabel.equals(Constants.Crm_accountid) || columnLabel.equals(Constants.Crm_caseid) || columnLabel.equals(Constants.Crm_opportunityid) || columnLabel.equals(Constants.Crm_productid)) { primaryKeyVal = rs.getObject(i).toString(); } if (dataIndexReftableMap.containsKey(columnLabel) && dataIndexReftableMap.get(columnLabel).equals("defaultmasteritem")) { if (defaultMasterMap.containsKey(rs.getObject(i))) { jobj.put(columnLabel, defaultMasterMap.get(rs.getObject(i)).getValue()); jobj.put(columnLabel + "_id", rs.getObject(i)); } else { jobj.put(columnLabel, ""); } } else if (dataIndexReftableMap.containsKey(columnLabel) && dataIndexReftableMap.get(columnLabel).equals("users")) { User userObj = (User) kwlCommonTablesDAOObj .getClassObject("com.krawler.common.admin.User", rs.getObject(i).toString()); if (userObj != null) { jobj.put(columnLabel, userObj.getFullname()); jobj.put(columnLabel + "_id", rs.getObject(i)); } else { jobj.put(columnLabel, "(Blank)"); } } else if (dataIndexReftableMap.containsKey(columnLabel) && dataIndexReftableMap.get(columnLabel).equals(Constants.Crm_account)) { CrmAccount accObj = (CrmAccount) kwlCommonTablesDAOObj .getClassObject(Constants.Crm_account_classpath, rs.getObject(i).toString()); if (accObj != null) { jobj.put(columnLabel, accObj.getAccountname()); jobj.put(columnLabel + "_id", rs.getObject(i)); } else { jobj.put(columnLabel, rs.getObject(i)); } } else if (dataIndexReftableMap.containsKey(columnLabel) && dataIndexReftableMap.get(columnLabel).equals("fieldcombodata")) { String[] comboIds = rs.getObject(i).toString().split(","); String comboValue = " "; String comboValueId = ""; for (int cnt = 0; cnt < comboIds.length; cnt++) { String comboid = comboIds[cnt]; if (customComboMap.containsKey(comboid)) { comboValue += customComboMap.get(comboid).getValue() + ","; comboValueId += customComboMap.get(comboid).getId() + ","; } } jobj.put(columnLabel, comboValue.substring(0, comboValue.length() - 1)); jobj.put(columnLabel + "_id", (comboValueId.length() > 0 ? comboValueId.substring(0, comboValueId.length() - 1) : comboValueId)); } else { jobj.put(columnLabel, rs.getObject(i)); } } else { jobj.put(columnLabel, ""); } } if (productColFlag && productsMap.containsKey(primaryKeyVal)) { List<CrmProduct> crmProducts = productsMap.get(primaryKeyVal); String productNames = ""; for (CrmProduct product : crmProducts) { productNames += product.getProductname() + ", "; } String key = ""; productNames = productNames.substring(0, productNames.lastIndexOf(",")); switch (moduleId) { case 1: key = Constants.Crm_account_product_key; break; case 2: key = Constants.Crm_lead_product_key; break; case 3: key = Constants.Crm_case_product_key; break; case 5: key = Constants.Crm_opportunity_product_key; break; } jobj.put(key, productNames); } jb.append("data", jobj); } } catch (Exception ex) { LOGGER.warn(ex.getMessage(), ex); } return jb; }
From source file:ome.testing.OMEData.java
/** * returns a list of results from the sql statement. if there is more than * one column in the result set, a map from column name to Object is * returned, else the Object itself.// w w w .j ava 2s.c o m * * @param sql * @return */ List runSql(String sql) { JdbcTemplate jt = new JdbcTemplate(ds); SqlRowSet rows = jt.queryForRowSet(sql); List result = new ArrayList(); while (rows.next()) { SqlRowSetMetaData meta = rows.getMetaData(); int count = meta.getColumnCount(); if (count > 1) { Map cols = new HashMap(); String[] names = meta.getColumnNames(); for (int i = 0; i < names.length; i++) { cols.put(names[i], rows.getObject(names[i])); } result.add(cols); } else { result.add(rows.getObject(1)); } } log.debug("SQL:" + sql + "\n\nResult:" + result); return result; }
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 {//from w w w . ja v a2 s. co 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; }