List of usage examples for java.sql ResultSet getShort
short getShort(String columnLabel) throws SQLException;
ResultSet
object as a short
in the Java programming language. From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.dao.MySQLConfigurationDAO.java
@Override public List<Resource> getMediaAllocations() throws TReqSException { LOGGER.trace("> getMediaAllocations"); final List<Resource> mediaTypeList = new ArrayList<Resource>(); final Object[] objects = MySQLBroker.getInstance().executeSelect(MySQLStatements.SQL_MEDIATYPES_SELECT); // store result final ResultSet result = (ResultSet) objects[1]; try {/*from w w w .j av a 2 s. com*/ while (result.next()) { int index = 1; final byte id = result.getByte(index++); final String name = result.getString(index++); final short qty = result.getShort(index++); final String regExpId = result.getString(index++); final MediaType media = MediaTypesController.getInstance().add(name, id, regExpId); final Resource res = new Resource(media, qty); mediaTypeList.add(res); } } catch (final SQLException exception) { throw new MySQLExecuteException(exception); } finally { MySQLBroker.getInstance().terminateExecution(objects); } if (mediaTypeList.size() == 0) { // No entry in table, something wrong with configuration. LOGGER.warn("No drives (media type) found. Please define them " + "in the database."); } LOGGER.trace("< getMediaAllocations"); return mediaTypeList; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgClient.CFAsteriskXMsgClientSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {/*from w w w .j a va2s.c o m*/ short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskXMsgClientSchema.class, "getNullableInt64", e); } }
From source file:com.srotya.tau.wraith.silo.sql.SQLRulesStore.java
@Override public Map<String, Map<Short, Rule>> listGroupedRules() throws IOException { Map<String, Map<Short, Rule>> rules = new HashMap<>(); try {/*from w ww . ja v a2 s . co m*/ PreparedStatement st = null; if (this.tenants == null) { st = conn.prepareStatement("select * from " + dbName + "." + rulesTable + ""); } else { st = conn.prepareStatement("select * from " + dbName + "." + rulesTable + " where " + COLUMN_RULE_GROUP_ID + " in (?)"); st.setString(1, StringUtils.join(tenants)); } ResultSet resultSet = st.executeQuery(); int counter = 0; while (resultSet.next()) { try { SimpleRule rule = RuleSerializer .deserializeJSONStringToRule(resultSet.getString(COLUMN_RULE_CONTENT)); short ruleId = resultSet.getShort(COLUMN_RULE_ID); String tenantId = resultSet.getString(COLUMN_RULE_GROUP_ID); if (tenantId == null) { // rules with tenantIds are not allowed continue; } if (rule != null && ruleId == rule.getRuleId()) { try { RuleValidator.getInstance().validate(rule); } catch (ValidationException e) { logger.error("Dropping rule:" + rule.getRuleId() + " reason:" + e.getMessage()); continue; } if (!rules.containsKey(tenantId)) { rules.put(tenantId, new LinkedHashMap<>()); } rules.get(tenantId).put(ruleId, rule); counter++; logger.debug("Adding rule:" + rule.getRuleId() + "/" + rule.getName()); } else { logger.error("Dropping rule, RuleId(PK) mismatch with Rule content RuleId"); } } catch (Exception e) { logger.error("Dropping rule, json parse exception:" + e.getMessage()); } } logger.info("Loaded " + counter + " rules from the database"); resultSet.close(); st.close(); } catch (SQLException e) { throw new IOException(e); } return rules; }
From source file:com.srotya.tau.wraith.silo.sql.SQLRulesStore.java
@Override public Map<Short, AlertTemplate> getAllTemplates() throws IOException { Map<Short, AlertTemplate> templateMap = new HashMap<>(); AlertTemplateValidator validator = new AlertTemplateValidator(); try {/*w ww .j a v a2 s.com*/ PreparedStatement st = null; if (this.tenants == null) { st = conn.prepareStatement("select * from " + dbName + "." + templateTable + ""); } else { st = conn.prepareStatement( "select * from " + dbName + "." + templateTable + " where rule_group_id in (?)"); st.setString(1, StringUtils.join(tenants)); } ResultSet resultSet = st.executeQuery(); int counter = 0; while (resultSet.next()) { try { AlertTemplate template = AlertTemplateSerializer .deserialize(resultSet.getString(COLUMN_TEMPLATE_CONTENT)); short templateId = resultSet.getShort(COLUMN_TEMPLATE_ID); if (template != null && templateId == template.getTemplateId()) { try { validator.validate(template); } catch (ValidationException e) { logger.error( "Dropping template:" + template.getTemplateId() + " reason:" + e.getMessage()); continue; } templateMap.put(templateId, template); counter++; logger.debug( "Adding template:" + template.getTemplateId() + "/" + template.getTemplateName()); } else { logger.error("Dropping template, TemplateId(PK) mismatch with Template content templateId"); } } catch (Exception e) { logger.error("Dropping template, json parse exception:" + e.getMessage()); } } logger.info("Loaded " + counter + " templates from the database"); resultSet.close(); st.close(); } catch (SQLException e) { throw new IOException(e); } return templateMap; }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProgramSymbolSqlAdapter.java
private final ProgramSymbol getProgramSymbol(ResultSet resultSet) throws SQLException { int id = resultSet.getInt(Index.ID.index()); int programID = resultSet.getInt(Index.PROGID.index()); String module = resultSet.getString(Index.MODULE.index()); String symbol = resultSet.getString(Index.SYMBOL.index()); int address = resultSet.getInt(Index.ADDRESS.index()); short size = resultSet.getShort(Index.SIZE.index()); Date timestamp = resultSet.getDate(Index.TIMESTAMP.index()); return new ProgramSymbol(id, programID, module, symbol, address, size, timestamp); }
From source file:io.symcpe.wraith.silo.sql.SQLRulesStore.java
@Override public Map<Short, Rule> listRules() throws IOException { Map<Short, Rule> rules = new HashMap<>(); try {//from www.j a v a2 s .c om PreparedStatement st = null; if (this.tenants == null) { st = conn.prepareStatement("select * from " + dbName + "." + rulesTable + ""); } else { st = conn .prepareStatement("select * from " + dbName + "." + rulesTable + " where tenant_id in (?)"); st.setString(1, StringUtils.join(tenants)); } ResultSet resultSet = st.executeQuery(); int counter = 0; while (resultSet.next()) { try { SimpleRule rule = RuleSerializer .deserializeJSONStringToRule(resultSet.getString(COLUMN_RULE_CONTENT)); short ruleId = resultSet.getShort(COLUMN_RULE_ID); if (rule != null && ruleId == rule.getRuleId()) { try { RuleValidator.getInstance().validate(rule); } catch (ValidationException e) { logger.error("Dropping rule:" + rule.getRuleId() + " reason:" + e.getMessage()); continue; } rules.put(ruleId, rule); counter++; logger.debug("Adding rule:" + rule.getRuleId() + "/" + rule.getName()); } else { logger.error("Dropping rule, RuleId(PK) mismatch with Rule content RuleId"); } } catch (Exception e) { logger.error("Dropping rule, json parse exception:" + e.getMessage()); } } logger.info("Loaded " + counter + " rules from the database"); resultSet.close(); st.close(); } catch (SQLException e) { throw new IOException(e); } return rules; }
From source file:io.symcpe.wraith.silo.sql.SQLRulesStore.java
@Override public Map<String, Map<Short, Rule>> listGroupedRules() throws IOException { Map<String, Map<Short, Rule>> rules = new HashMap<>(); try {//from w ww . ja v a2s.c om PreparedStatement st = null; if (this.tenants == null) { st = conn.prepareStatement("select * from " + dbName + "." + rulesTable + ""); } else { st = conn .prepareStatement("select * from " + dbName + "." + rulesTable + " where tenant_id in (?)"); st.setString(1, StringUtils.join(tenants)); } ResultSet resultSet = st.executeQuery(); int counter = 0; while (resultSet.next()) { try { SimpleRule rule = RuleSerializer .deserializeJSONStringToRule(resultSet.getString(COLUMN_RULE_CONTENT)); short ruleId = resultSet.getShort(COLUMN_RULE_ID); String tenantId = resultSet.getString(COLUMN_TENANT_ID); if (tenantId == null) { // rules with tenantIds are not allowed continue; } if (rule != null && ruleId == rule.getRuleId()) { try { RuleValidator.getInstance().validate(rule); } catch (ValidationException e) { logger.error("Dropping rule:" + rule.getRuleId() + " reason:" + e.getMessage()); continue; } if (!rules.containsKey(tenantId)) { rules.put(tenantId, new LinkedHashMap<>()); } rules.get(tenantId).put(ruleId, rule); counter++; logger.debug("Adding rule:" + rule.getRuleId() + "/" + rule.getName()); } else { logger.error("Dropping rule, RuleId(PK) mismatch with Rule content RuleId"); } } catch (Exception e) { logger.error("Dropping rule, json parse exception:" + e.getMessage()); } } logger.info("Loaded " + counter + " rules from the database"); resultSet.close(); st.close(); } catch (SQLException e) { throw new IOException(e); } return rules; }
From source file:io.symcpe.wraith.silo.sql.SQLRulesStore.java
@Override public Map<Short, AlertTemplate> getAllTemplates() throws IOException { Map<Short, AlertTemplate> templateMap = new HashMap<>(); AlertTemplateValidator validator = new AlertTemplateValidator(); try {/*from w w w. ja v a 2 s .c o m*/ PreparedStatement st = null; if (this.tenants == null) { st = conn.prepareStatement("select * from " + dbName + "." + templateTable + ""); } else { st = conn.prepareStatement( "select * from " + dbName + "." + templateTable + " where tenant_id in (?)"); st.setString(1, StringUtils.join(tenants)); } ResultSet resultSet = st.executeQuery(); int counter = 0; while (resultSet.next()) { try { AlertTemplate template = AlertTemplateSerializer .deserialize(resultSet.getString(COLUMN_TEMPLATE_CONTENT)); short templateId = resultSet.getShort(COLUMN_TEMPLATE_ID); if (template != null && templateId == template.getTemplateId()) { try { validator.validate(template); } catch (ValidationException e) { logger.error( "Dropping template:" + template.getTemplateId() + " reason:" + e.getMessage()); continue; } templateMap.put(templateId, template); counter++; logger.debug( "Adding template:" + template.getTemplateId() + "/" + template.getTemplateName()); } else { logger.error("Dropping template, TemplateId(PK) mismatch with Template content templateId"); } } catch (Exception e) { logger.error("Dropping template, json parse exception:" + e.getMessage()); } } logger.info("Loaded " + counter + " templates from the database"); resultSet.close(); st.close(); } catch (SQLException e) { throw new IOException(e); } return templateMap; }
From source file:net.algem.security.UserDaoImpl.java
private User getFromRS(ResultSet rs) throws SQLException { User u = new User(); u.setId(rs.getInt(1));//from w w w. ja v a2 s. co m u.setLogin(getLoginFromStringResult(rs.getString(2))); u.setProfile(getProfileFromId(rs.getShort(3))); u.setName(rs.getString(4)); u.setFirstName(rs.getString(5)); return u; }
From source file:net.algem.security.UserDaoImpl.java
@Override public List<Email> getEmailsFromContact(final int id) { String query = "SELECT email,archive,idx FROM email WHERE idper = ?"; return jdbcTemplate.query(query, new RowMapper<Email>() { @Override//from w w w . j a v a 2s. c om public Email mapRow(ResultSet rs, int i) throws SQLException { Email e = new Email(); e.setIdper(id); e.setEmail(rs.getString(1)); e.setArchive(rs.getBoolean(2)); e.setIndex(rs.getShort(3)); return e; } }, id); }