List of usage examples for java.sql ResultSet getObject
Object getObject(String columnLabel) throws SQLException;
Gets the value of the designated column in the current row of this ResultSet
object as an Object
in the Java programming language.
From source file:org.mayocat.cms.home.store.jdbi.mapper.HomePageMapper.java
@Override public HomePage map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { HomePage homePage = new HomePage(); homePage.setId((UUID) resultSet.getObject("id")); if (!Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try {//from w w w . j ava2 s . c om Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } homePage.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } return homePage; }
From source file:com.azaptree.services.security.dao.SessionDAO.java
@Override public UUID[] getSessionIdsBySubject(final UUID subjectId) { final String sql = "select entity_id from t_session where subject_id = ?"; final Object[] args = { subjectId }; final List<UUID> sessionIds = new LinkedList<>(); jdbc.query(sql, args, new RowCallbackHandler() { @Override/* ww w . j ava 2s .co m*/ public void processRow(final ResultSet rs) throws SQLException { sessionIds.add((UUID) rs.getObject(1)); } }); return sessionIds.toArray(new UUID[sessionIds.size()]); }
From source file:org.mayocat.shop.catalog.store.jdbi.mapper.FeatureMapper.java
@Override public Feature map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { Feature feature = new Feature(); feature.setId((UUID) resultSet.getObject("id")); feature.setParentId((UUID) resultSet.getObject("parent_id")); feature.setSlug(resultSet.getString("slug")); feature.setTitle(resultSet.getString("title")); feature.setFeature(resultSet.getString("feature")); feature.setFeatureSlug(resultSet.getString("feature_slug")); if (MapperUtils.hasColumn("localization_data", resultSet) && !Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try {/*from w w w .j a va 2 s. c o m*/ Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { localizedVersions.put(Locale.forLanguageTag((String) map.get("locale")), (Map) map.get("entity")); } feature.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } return feature; }
From source file:com.viettel.ws.client.JDBCUtil.java
/** * Create document using DOM api//from w w w. j av a 2 s . c o m * * @param rs a result set * @param doc a input document for append content * @param rsName name of the appended element * @return a document after append content * @throws ParserConfigurationException If error when parse XML string * @throws SQLException If error when read data from database */ public static Document add2Document1(ResultSet rs1, ResultSet rs2, Document doc, String rsName) throws ParserConfigurationException, SQLException { if (rs1 == null && rs2 == null) { return doc; } //Get root element Element root = doc.getDocumentElement(); Element rsElement = doc.createElement(rsName); root.appendChild(rsElement); if (rs1 != null) { ResultSetMetaData rsmd = rs1.getMetaData(); int colCount = rsmd.getColumnCount(); while (rs1.next()) { Element row = doc.createElement("Row"); rsElement.appendChild(row); try { for (int i = 1; i <= colCount; i++) { String columnName = rsmd.getColumnName(i); Object value = rs1.getObject(i); if (value == null) { value = ""; } Element node = doc.createElement(columnName); node.appendChild(doc.createTextNode(value.toString())); row.appendChild(node); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // logger.error(e, e); } } } if (rs2 != null) { ResultSetMetaData rsmd = rs2.getMetaData(); int colCount = rsmd.getColumnCount(); while (rs2.next()) { Element row = doc.createElement("Row"); rsElement.appendChild(row); try { for (int i = 1; i <= colCount; i++) { String columnName = rsmd.getColumnName(i); Object value = rs2.getObject(i); if (value == null) { value = ""; } Element node = doc.createElement(columnName); node.appendChild(doc.createTextNode(value.toString())); row.appendChild(node); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // logger.error(e, e); } } } return doc; }
From source file:org.mayocat.shop.payment.store.jdbi.mapper.PaymentOperationMapper.java
@Override public PaymentOperation map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { PaymentOperation operation = new PaymentOperation(); operation.setId((UUID) resultSet.getObject("operation_id")); operation.setOrderId((UUID) resultSet.getObject("order_id")); operation.setExternalId(resultSet.getString("external_id")); operation.setGatewayId(resultSet.getString("gateway_id")); operation.setResult(PaymentOperation.Result.valueOf(resultSet.getString("result"))); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); if (resultSet.getString("memo") != null) { try {/*from www. j ava 2 s .co m*/ Map<String, Object> data = mapper.readValue(resultSet.getString("memo"), new TypeReference<Map<String, Object>>() { }); operation.setMemo(data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(PaymentOperationMapper.class); logger.error("Failed to de-serialize payment operation memo", e); } } return operation; }
From source file:org.mayocat.shop.shipping.store.jdbi.mapper.CarrierMapper.java
@Override public Carrier map(int index, ResultSet r, StatementContext ctx) throws SQLException { Carrier carrier = null;/* w ww . j av a 2s.c o m*/ UUID thisRowId = (UUID) r.getObject("id"); if (ctx.getAttribute("__accumulator") != null) { carrier = (Carrier) ctx.getAttribute("__accumulator"); if (!carrier.getId().equals(thisRowId)) { carrier = new Carrier(); } } if (carrier == null) { carrier = new Carrier(); } carrier.setId(thisRowId); carrier.setTitle(r.getString("title")); carrier.setDescription(r.getString("description")); carrier.setId((UUID) r.getObject("id")); carrier.setTenantId((UUID) r.getObject("tenant_id")); carrier.setMinimumDays(r.getInt("minimum_days")); carrier.setMaximumDays(r.getInt("maximum_days")); carrier.setStrategy(Strategy.fromJson(r.getString("strategy"))); carrier.setPerShipping(r.getBigDecimal("per_shipping")); carrier.setPerItem(r.getBigDecimal("per_item")); carrier.setPerAdditionalUnit(r.getBigDecimal("per_additional_unit")); ObjectMapper objectMapper = new ObjectMapper(); try { carrier.setDestinations(objectMapper.<List<String>>readValue(r.getString("destinations"), new TypeReference<List<String>>() { })); } catch (IOException e) { throw new SQLException("Failed to de-serialize carrier destinations", e); } if (r.getBigDecimal("price") != null) { CarrierRule rule = new CarrierRule(); rule.setUpToValue(r.getBigDecimal("up_to_value")); rule.setPrice(r.getBigDecimal("price")); carrier.addRule(rule); } if (r.getBigDecimal("vat_rate") != null) { carrier.setVatRate(r.getBigDecimal("vat_rate")); } ctx.setAttribute("__accumulator", carrier); return carrier; }
From source file:com.baidu.qa.service.test.util.JdbcUtil.java
protected static List<Map<String, Object>> excuteQuerySql(String sqlStr, String dbname) throws Exception { List<Map<String, Object>> rltList = new ArrayList<Map<String, Object>>(); // ???//from ww w.ja v a 2 s .c o m Connection con = null; Statement sm = null; ResultSet rs = null; try { //? con = MysqlDatabaseManager.getCon(dbname); Assert.assertNotNull("connect to db error:" + dbname, con); //?? sm = con.createStatement(); rs = sm.executeQuery(sqlStr); log.info("[sql:]" + sqlStr); ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); int count = 0; String key; Object value; // ???? while (rs.next()) { Map<String, Object> expectData = new HashMap<String, Object>(); count = 0; while (count++ < numberOfColumns) { key = rsmd.getColumnLabel(count); value = rs.getObject(key); expectData.put(key, value); } rltList.add(expectData); } return rltList; } catch (Exception e) { throw e; } finally { if (con != null) { con.close(); } if (sm != null) { sm.close(); } if (rs != null) { rs.close(); } } }
From source file:com.qnoid.java.t0mR.TemplateResultSetHandler.java
/** * This method will iterate through all the columns * (as specified in the constructor) in the result set and provide a single * callback to the {@link #newType(Row)} with a Row object holding all the * column values.//from www.j a v a2s.co m * * @param rs a ResultSet pointing to the row holding the next instance of {@code T} * @return an object of type T as returned by the {@link #newType(Row)} * @see ResultSet#next() */ @Override public final T handle(ResultSet rs) throws SQLException { Row row = new Row(); for (Column<?> column : this.columns) { row.put(column, rs.getObject(column.name())); } return this.newType(row); }
From source file:org.mayocat.addons.mapper.AddonGroupMapper.java
@Override public AddonGroup map(int index, ResultSet result, StatementContext context) throws SQLException { AddonGroup addonGroup = new AddonGroup(); addonGroup.setEntityId((UUID) result.getObject("entity_id")); addonGroup.setGroup(result.getString("addon_group")); addonGroup.setSource(AddonSource.fromJson(result.getString("source"))); ObjectMapper mapper = new ObjectMapper(); try {/*from w w w . j a v a 2 s .c om*/ Map<String, Object> value = mapper.readValue(result.getString("value"), new TypeReference<Map<String, Object>>() { }); addonGroup.setValue(value); } catch (IOException e) { // Failed as a map ? it must be a sequenced addon try { List<Map<String, Object>> value = mapper.readValue(result.getString("value"), new TypeReference<List<Map<String, Object>>>() { }); addonGroup.setValue(value); } catch (IOException e1) { throw new SQLException("Failed to de-serialize value", e); } } try { Map<String, Map<String, Object>> model = mapper.readValue(result.getString("model"), new TypeReference<Map<String, Object>>() { }); addonGroup.setModel(model); } catch (IOException e) { throw new SQLException("Failed to de-serialize model", e); } return addonGroup; }
From source file:com.azaptree.services.domain.entity.dao.EntityRowMapperSupport.java
@Override public T mapRow(final ResultSet rs, final int rowNum) throws SQLException { final T entity = createEntity(rs, rowNum); final DomainEntity domainEntity = (DomainEntity) entity; domainEntity.setEntityId((UUID) rs.getObject("entity_id")); return mapRow(entity, rs, rowNum); }