List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}//from ww w. jav a 2s . com */ @Override public List<VocabularyFolder> getVocabularyFolders(int folderId, String userName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("folderId", folderId); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where "); if (StringUtils.isBlank(userName)) { sql.append("v.WORKING_COPY=FALSE "); } else { sql.append("(v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } sql.append("and v.FOLDER_ID=:folderId "); sql.append("order by f.IDENTIFIER, v.IDENTIFIER "); List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:eionet.meta.dao.mysql.VocabularyFolderDAOImpl.java
/** * {@inheritDoc}/*ww w. j a va 2s. com*/ */ @Override public List<VocabularyFolder> getVocabularyFolderVersions(String continuityId, int vocabularyFolderId, String userName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("continuityId", continuityId); params.put("vocabularyFolderId", vocabularyFolderId); StringBuilder sql = new StringBuilder(); sql.append( "select v.VOCABULARY_ID, v.IDENTIFIER, v.LABEL, v.REG_STATUS, v.WORKING_COPY, v.BASE_URI, v.VOCABULARY_TYPE, "); sql.append("v.WORKING_USER, v.DATE_MODIFIED, v.USER_MODIFIED, v.CHECKEDOUT_COPY_ID, v.CONTINUITY_ID, "); sql.append("v.CONCEPT_IDENTIFIER_NUMERIC, "); sql.append("f.ID, f.IDENTIFIER, f.LABEL, v.NOTATIONS_EQUAL_IDENTIFIERS "); sql.append("from VOCABULARY v "); sql.append("left join VOCABULARY_SET f on f.ID=v.FOLDER_ID "); sql.append("where v.CONTINUITY_ID = :continuityId and v.VOCABULARY_ID != :vocabularyFolderId "); if (StringUtils.isBlank(userName)) { sql.append("and v.WORKING_COPY=FALSE "); } else { sql.append("and (v.WORKING_COPY=FALSE or v.WORKING_USER=:workingUser) "); params.put("workingUser", userName); } List<VocabularyFolder> items = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyFolder>() { @Override public VocabularyFolder mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyFolder vf = new VocabularyFolder(); vf.setId(rs.getInt("v.VOCABULARY_ID")); vf.setIdentifier(rs.getString("v.IDENTIFIER")); vf.setLabel(rs.getString("v.LABEL")); vf.setRegStatus(RegStatus.fromString(rs.getString("v.REG_STATUS"))); vf.setType(VocabularyType.valueOf(rs.getString("v.VOCABULARY_TYPE"))); vf.setWorkingCopy(rs.getBoolean("v.WORKING_COPY")); vf.setWorkingUser(rs.getString("v.WORKING_USER")); vf.setDateModified(rs.getTimestamp("v.DATE_MODIFIED")); vf.setUserModified(rs.getString("v.USER_MODIFIED")); vf.setCheckedOutCopyId(rs.getInt("v.CHECKEDOUT_COPY_ID")); vf.setContinuityId(rs.getString("v.CONTINUITY_ID")); vf.setNumericConceptIdentifiers(rs.getBoolean("v.CONCEPT_IDENTIFIER_NUMERIC")); vf.setNotationsEqualIdentifiers(rs.getBoolean("NOTATIONS_EQUAL_IDENTIFIERS")); vf.setBaseUri(rs.getString("v.BASE_URI")); vf.setFolderId(rs.getShort("f.ID")); vf.setFolderName(rs.getString("f.IDENTIFIER")); vf.setFolderLabel(rs.getString("f.LABEL")); return vf; } }); return items; }
From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java
public static RowMapperFactory getScalarRowMapperFactory(final Type itemType, final String name, boolean req) { if (itemType == String.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getString(name); }/*from ww w . ja va 2 s . c o m*/ }; } if (itemType == Integer.class || itemType == Integer.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getInt(name); } }; } if (itemType == URL.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getURL(name); } }; } if (itemType == BigInteger.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { final BigDecimal res = rs.getBigDecimal(name); return res == null ? null : res.toBigInteger(); } }; } if (itemType == BigDecimal.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBigDecimal(name); } }; } if (itemType == InputStream.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBinaryStream(name); } }; } if (itemType == Boolean.class || itemType == Boolean.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBoolean(name); } }; } if (itemType == Blob.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBlob(name); } }; } if (itemType == java.sql.Date.class || itemType == java.util.Date.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getTimestamp(name); } }; } if (itemType instanceof Class) { final Class itemClass = (Class) itemType; final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass); if (columnMapper != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return columnMapper.map(rs, name); } }; } final Converter converter = ConvertUtils.lookup(itemClass); if (converter != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } return converter.convert(itemClass, s); } }; } if (Enum.class.isAssignableFrom((Class<?>) itemType)) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } //noinspection unchecked return Enum.valueOf((Class<Enum>) itemType, s); } }; } } if (req) { throw new IllegalArgumentException("no mapping defined for " + itemType); } return null; }
From source file:com.globalsight.ling.tm3.core.TuStorage.java
/** * Load data from "tm3_tuv_shared_xx" and "tm3_tuv_ext_shared_xx" tables. *//*www . j a v a 2s . co m*/ private void loadTuvs(Connection conn, List<Long> tuIds, List<TuData<T>> tuDatas, boolean locking) throws SQLException { StatementBuilder sb = new StatementBuilder("SELECT ").append( "tuId, id, localeId, fingerprint, content, firstEventId, lastEventId, creationUser, creationDate, modifyUser, modifyDate") .append(" FROM ").append(getStorage().getTuvTableName()).append(" WHERE tuId IN") .append(SQLUtil.longGroup(tuIds)).append("ORDER BY tuId"); try { PreparedStatement ps = sb.toPreparedStatement(conn); ResultSet rs = SQLUtil.execQuery(ps); // In order to avoid a hidden ResultSet in the data factory // invalidating our current one, we must defer looking up // the locales until after we've read all of the data. List<TuvData<T>> rawTuvs = new ArrayList<TuvData<T>>(); while (rs.next()) { rawTuvs.add(new TuvData<T>(rs.getLong(1), rs.getLong(2), rs.getLong(3), rs.getLong(4), rs.getString(5), rs.getLong(6), rs.getLong(7), rs.getString(8), rs.getTimestamp(9), rs.getString(10), rs.getTimestamp(11))); } ps.close(); // Load TUV extension data into TUV objects. HashMap<Long, TuvData<T>> rawTuvsMap = new HashMap<Long, TuvData<T>>(); for (TuvData<T> tuvData : rawTuvs) { rawTuvsMap.put(tuvData.id, tuvData); } sb = new StatementBuilder("SELECT ") .append("tuvId, tuId, tmId, lastUsageDate, jobId, jobName, previousHash, nextHash, sid ") .append("FROM ").append(getStorage().getTuvExtTableName()).append(" WHERE tuId IN") .append(SQLUtil.longGroup(tuIds)); ps = sb.toPreparedStatement(conn); rs = SQLUtil.execQuery(ps); TuvData<T> tuvData = null; while (rs.next()) { tuvData = rawTuvsMap.get(rs.getLong("tuvId")); if (tuvData != null) { tuvData.setLastUsageDate(rs.getTimestamp("lastUsageDate")); tuvData.setJobId(rs.getLong("jobId")); tuvData.setJobName(rs.getString("jobName")); tuvData.setPreviousHash(rs.getLong("previousHash")); tuvData.setNextHash(rs.getLong("nextHash")); tuvData.setSid(rs.getString("sid")); } } ps.close(); TM3Attribute sidAttr = null; for (TM3Attribute att : getStorage().getInlineAttributes()) { if (att != null && att.getName().equals(".sid")) { sidAttr = att; break; } } Iterator<TuData<T>> tus = tuDatas.iterator(); TuData<T> current = null; for (TuvData<T> rawTuv : rawTuvs) { current = advanceToTu(current, tus, rawTuv.tuId); if (current == null) { throw new IllegalStateException("Couldn't find tuId for " + rawTuv.tuId); } // "tuId, id, localeId, fingerprint, content"; TM3Tuv<T> tuv = createTuv(rawTuv); tuv.setStorage(getTuStorage(current.tmId)); if (tuv.getLocale().getId() == current.srcLocaleId) { current.srcTuv = tuv; } else { current.tgtTuvs.add(tuv); } // Put srcTuv SID to in-line SID attribute. if (sidAttr != null && StringUtils.isNotEmpty(tuv.getSid())) { current.attrs.put(sidAttr, tuv.getSid()); } } } catch (Exception e) { throw new SQLException(e); } }
From source file:biblivre3.acquisition.supplier.SupplierDAO.java
private final SupplierDTO populateDto(ResultSet rs) throws Exception { final SupplierDTO dto = new SupplierDTO(); dto.setSerial(Integer.valueOf(rs.getInt("serial_supplier"))); dto.setTrademarkName(rs.getString("trade_mark_name")); dto.setCompanyName(rs.getString("company_name")); dto.setCompanyNumber(rs.getString("company_number")); dto.setVatRegistrationNumber(rs.getString("vat_registration_number")); dto.setAddress(rs.getString("address")); dto.setAddressNumber(rs.getString("number_address")); dto.setComplement(rs.getString("complement")); dto.setArea(rs.getString("area")); dto.setCity(rs.getString("city")); dto.setState(rs.getString("state")); dto.setCountry(rs.getString("country")); dto.setZipCode(rs.getString("zip_code")); dto.setTelephone1(rs.getString("telephone_1")); dto.setTelephone2(rs.getString("telephone_2")); dto.setTelephone3(rs.getString("telephone_3")); dto.setTelephone4(rs.getString("telephone_4")); dto.setContact1(rs.getString("contact_1")); dto.setContact2(rs.getString("contact_2")); dto.setContact3(rs.getString("contact_3")); dto.setContact4(rs.getString("contact_4")); dto.setObs(rs.getString("obs")); dto.setCreated(rs.getTimestamp("created")); dto.setModified(rs.getTimestamp("modified")); dto.setUrl(rs.getString("url")); dto.setEmail(rs.getString("email")); return dto;//from ww w . ja v a2 s . com }
From source file:org.meerkat.services.WebApp.java
/** * getCustomEventsList/* w w w .j a v a 2s.co m*/ * @param appName * @param rows * @param rowBegin * @param rowEnd * @param orderBy * @param asdDSC * @return customEvents */ public final ArrayList<WebAppEvent> getCustomEventsList(String rowBegin, String rowEnd, String orderBy, String asdDSC) { ArrayList<WebAppEvent> customEvents = new ArrayList<WebAppEvent>(); Connection conn = embDB.getConnForQueries(); String orderByStr = ""; // Prevent null values if called direct link (outside Datatables) if (rowBegin == null || rowEnd == null) { rowBegin = "0"; rowEnd = "10"; } // Process order if (orderBy == null) { orderBy = "0"; } if (orderBy.equals("0")) { orderByStr = "ID"; } else if (orderBy.equals("1")) { orderByStr = "DATEEV"; } else if (orderBy.equals("2")) { orderByStr = "ONLINE"; } else if (orderBy.equals("3")) { orderByStr = "AVAILABILITY"; } else if (orderBy.equals("4")) { orderByStr = "LOADTIME"; } else if (orderBy.equals("5")) { orderByStr = "LATENCY"; } else if (orderBy.equals("6")) { orderByStr = "HTTPSTATUSCODE"; } else if (orderBy.equals("7")) { orderByStr = "DESCRIPTION"; } int nRows = Integer.valueOf(rowEnd) - Integer.valueOf(rowBegin); String fields = "SELECT ID, CRITICAL, DATEEV, ONLINE, AVAILABILITY, \n" + "LOADTIME, LATENCY, HTTPSTATUSCODE, DESCRIPTION \n"; log.debug(" "); log.debug("||-- APP: " + this.name); log.debug("||-- Results: " + rowBegin + " to: " + rowBegin + nRows); log.debug("||-- Order by: " + orderByStr + " " + asdDSC); String eventsQuery = fields + "FROM MEERKAT.EVENTS \n" + "WHERE APPNAME LIKE '" + this.name + "' \n" + "ORDER BY " + orderByStr + " " + asdDSC + " \n" + "OFFSET " + rowBegin + " ROWS FETCH NEXT " + nRows + " ROWS ONLY "; int id; boolean critical; String date; boolean online; String availability; String loadTime; String latency; int httStatusCode = 0; String description; PreparedStatement ps; ResultSet rs = null; try { ps = conn.prepareStatement(eventsQuery); rs = ps.executeQuery(); while (rs.next()) { id = rs.getInt(1); critical = rs.getBoolean(2); date = rs.getTimestamp(3).toString(); online = rs.getBoolean(4); availability = String.valueOf(rs.getDouble(5)); loadTime = String.valueOf(rs.getDouble(6)); latency = String.valueOf(rs.getDouble(7)); httStatusCode = rs.getInt(8); description = rs.getString(9); WebAppEvent currEv = new WebAppEvent(critical, date, online, availability, httStatusCode, description); currEv.setID(id); currEv.setPageLoadTime(loadTime); currEv.setLatency(latency); customEvents.add(currEv); } rs.close(); ps.close(); } catch (SQLException e) { log.error("Failed query events from application " + this.getName()); log.error("", e); log.error("QUERY IS: " + eventsQuery); } return customEvents; }
From source file:br.bookmark.db.util.ResultSetUtils.java
/** * Map JDBC objects to Java equivalents. * Used by getBean() and getBeans()./*from www. j a v a2 s . c om*/ * <p> * Some types not supported. * Many not work with all drivers. * <p> * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT. * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY, * VARBINARY. * <p> * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman. * Others not guaranteed. * @param classeDestino * @throws NoSuchFieldException * @throws SecurityException */ private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i, Class classeDestino) throws Exception { /* In a perfect universe, this would be enough properties.put( metaData.getColumnName(i), resultSet.getObject(i)); But only String, Timestamp, and Integer seem to get through that way. */ String columnName = metaData.getColumnName(i); // Testa se uma FK /*Field[] fields = classeDestino.getDeclaredFields(); for (int j = 0; j < fields.length; j++) { if (fields[j].getAnnotation(DBFK.class) != null) { properties.put(columnName, resultSet.getString(i)); } }*/ //System.out.println(i+"-"+metaData.getColumnType(i)); switch (metaData.getColumnType(i)) { // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html case Types.BIGINT: properties.put(columnName, new Long(resultSet.getLong(i))); break; case Types.DATE: properties.put(columnName, resultSet.getDate(i)); break; case Types.DECIMAL: case Types.DOUBLE: properties.put(columnName, new Double(resultSet.getDouble(i))); break; case Types.FLOAT: properties.put(columnName, new Float(resultSet.getFloat(i))); break; case Types.INTEGER: int valor = 0; try { // Se o campo esta vazio d erro valor = resultSet.getInt(i); } catch (SQLException e) { } properties.put(columnName, new Integer(valor)); break; case Types.REAL: properties.put(columnName, new Double(resultSet.getString(i))); break; case Types.SMALLINT: properties.put(columnName, new Short(resultSet.getShort(i))); break; case Types.TIME: properties.put(columnName, resultSet.getTime(i)); break; case Types.TIMESTAMP: properties.put(columnName, resultSet.getTimestamp(i)); break; // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer // :FIXME: with Poolman and MySQL unless use getString. case Types.TINYINT: properties.put(columnName, new Byte(resultSet.getString(i))); break; case Types.CHAR: case Types.CLOB: case Types.VARCHAR: case Types.LONGVARCHAR: // :FIXME: Handle binaries differently? case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: properties.put(columnName, resultSet.getString(i)); break; /* :FIXME: Add handlers for ARRAY BINARY BIT DISTINCT JAVA_OBJECT NULL NUMERIC OTHER REF STRUCT */ // Otherwise, pass as *String property to be converted default: properties.put(columnName + "String", resultSet.getString(i)); break; } // end switch }
From source file:mysql5.MySQL5PlayerDAO.java
@Override public PlayerCommonData loadPlayerCommonData(final int playerObjId) { PlayerCommonData cached = playerCommonData.get(playerObjId); if (cached != null) { log.debug("[DAO: MySQL5PlayerDAO] PlayerCommonData for id: " + playerObjId + " obtained from cache"); return cached; }//from w ww . java 2s . c o m final PlayerCommonData cd = new PlayerCommonData(playerObjId); boolean success = false; Connection con = null; try { con = DatabaseFactory.getConnection(); PreparedStatement stmt = con.prepareStatement("SELECT * FROM players WHERE id = ?"); stmt.setInt(1, playerObjId); ResultSet resultSet = stmt.executeQuery(); log.debug("[DAO: MySQL5PlayerDAO] loading from db " + playerObjId); if (resultSet.next()) { success = true; cd.setName(resultSet.getString("name")); // set player class before exp cd.setPlayerClass(PlayerClass.valueOf(resultSet.getString("player_class"))); cd.setExp(resultSet.getLong("exp")); cd.setRecoverableExp(resultSet.getLong("recoverexp")); cd.setRace(Race.valueOf(resultSet.getString("race"))); cd.setGender(Gender.valueOf(resultSet.getString("gender"))); cd.setLastOnline(resultSet.getTimestamp("last_online")); cd.setNote(resultSet.getString("note")); cd.setQuestExpands(resultSet.getInt("quest_expands")); cd.setNpcExpands(resultSet.getInt("npc_expands")); cd.setAdvancedStigmaSlotSize(resultSet.getInt("advanced_stigma_slot_size")); cd.setTitleId(resultSet.getInt("title_id")); cd.setBonusTitleId(resultSet.getInt("bonus_title_id")); cd.setWarehouseSize(resultSet.getInt("warehouse_size")); cd.setOnline(resultSet.getBoolean("online")); cd.setMailboxLetters(resultSet.getInt("mailbox_letters")); cd.setDp(resultSet.getInt("dp")); cd.setDeathCount(resultSet.getInt("soul_sickness")); cd.setCurrentReposteEnergy(resultSet.getLong("reposte_energy")); cd.setCurrentEventExp(resultSet.getLong("event_exp")); cd.setBattleGroundPoints(resultSet.getInt("bg_points")); float x = resultSet.getFloat("x"); float y = resultSet.getFloat("y"); float z = resultSet.getFloat("z"); byte heading = resultSet.getByte("heading"); int worldId = resultSet.getInt("world_id"); PlayerInitialData playerInitialData = DataManager.PLAYER_INITIAL_DATA; boolean checkThis = World.getInstance().getWorldMap(worldId).isInstanceType(); // this helps to pretend an player loading error // if you have a better idea do it :) if (checkThis) { mr = null; } else { mr = World.getInstance().getWorldMap(worldId).getMainWorldMapInstance().getRegion(x, y, z); } if (mr == null && playerInitialData != null) { // unstuck unlucky characters :) LocationData ld = playerInitialData.getSpawnLocation(cd.getRace()); x = ld.getX(); y = ld.getY(); z = ld.getZ(); heading = ld.getHeading(); worldId = ld.getMapId(); } WorldPosition position = World.getInstance().createPosition(worldId, x, y, z, heading, 0); cd.setPosition(position); cd.setWorldOwnerId(resultSet.getInt("world_owner")); cd.setMentorFlagTime(resultSet.getInt("mentor_flag_time")); cd.setInitialGameStats(resultSet.getInt("initial_gamestats")); cd.setLastTransferTime(resultSet.getLong("last_transfer_time")); cd.setFatigue(resultSet.getInt("fatigue")); cd.setFatigueRecover(resultSet.getInt("fatigueRecover")); cd.setFatigueReset(resultSet.getInt("fatigueReset")); cd.setPassportStamps(resultSet.getInt("stamps")); cd.setPassportReward(resultSet.getInt("rewarded_pass")); cd.setLastStamp(resultSet.getTimestamp("last_stamp")); cd.setJoinRequestLegionId(resultSet.getInt("joinRequestLegionId")); cd.setJoinRequestState(LegionJoinRequestState.valueOf(resultSet.getString("joinRequestState"))); } else { log.info("Missing PlayerCommonData from db " + playerObjId); } resultSet.close(); stmt.close(); } catch (Exception e) { log.error("Could not restore PlayerCommonData data for player: " + playerObjId + " from DB: " + e.getMessage(), e); } finally { DatabaseFactory.close(con); } if (success) { if (CacheConfig.CACHE_COMMONDATA) { playerCommonData.put(playerObjId, cd); playerCommonDataByName.put(cd.getName().toLowerCase(), cd); } return cd; } return null; }
From source file:dk.nsi.haiba.minipasconverter.dao.impl.MinipasDAOImpl.java
@Override public Collection<MinipasTADM> getMinipasTADM(String year, long fromKRecnum, int batchSize) { Monitor mon = MonitorFactory.start("MinipasDAOImpl.getMinipasTADM"); String tableName = "T_ADM" + year; // maybe this works - needs to find out if order by executes on resultset or before (before is the intend) List<MinipasTADM> query = jdbc.query("SELECT * FROM " + minipasPrefix + tableName + " WHERE K_RECNUM > ? ORDER BY K_RECNUM FETCH FIRST " + batchSize + " ROWS ONLY", new RowMapper<MinipasTADM>() { @Override/*w w w. j a v a 2s. c o m*/ public MinipasTADM mapRow(ResultSet rs, int rowNum) throws SQLException { MinipasTADM returnValue = new MinipasTADM(); returnValue.setC_adiag(rs.getString("C_ADIAG")); returnValue.setC_afd(rs.getString("C_AFD")); returnValue.setC_bopamt(rs.getString("C_BOPAMT")); returnValue.setC_hafd(rs.getString("C_HAFD")); returnValue.setC_henm(rs.getString("C_HENM")); returnValue.setC_hsgh(rs.getString("C_HSGH")); returnValue.setC_indm(rs.getString("C_INDM")); returnValue.setC_kom(rs.getString("C_KOM")); returnValue.setC_kontaars(rs.getString("C_KONTAARS")); returnValue.setC_pattype(rs.getString("C_PATTYPE")); returnValue.setC_sex(rs.getString("C_SEX")); returnValue.setC_sgh(rs.getString("C_SGH")); returnValue.setC_sghamt(rs.getString("C_SGHAMT")); returnValue.setC_spec(rs.getString("C_SPEC")); returnValue.setC_udm(rs.getString("C_UDM")); returnValue.setD_hendto(rs.getTimestamp("D_HENDTO")); returnValue.setD_inddto(rs.getTimestamp("D_INDDTO")); returnValue.setD_uddto(rs.getTimestamp("D_UDDTO")); returnValue.setIdnummer(rs.getString("IDNUMMER")); returnValue.setK_recnum(rs.getInt("K_RECNUM")); returnValue.setSkemaopdat(rs.getTimestamp("SKEMAOPDAT")); returnValue.setSkemaopret(rs.getTimestamp("SKEMAOPRET")); returnValue.setV_alder(rs.getInt("V_ALDER")); returnValue.setV_behdage(rs.getInt("V_BEHDAGE")); returnValue.setV_cpr(rs.getString("V_CPR")); returnValue.setV_sengdage(rs.getInt("V_SENGDAGE")); return returnValue; } }, fromKRecnum); mon.stop(); return query; }
From source file:org.ohmage.query.impl.AuditQueries.java
@Override public List<Audit> readAuditInformation(final List<Long> auditIds) throws DataAccessException { if (auditIds == null) { return new LinkedList<Audit>(); }/*from www.ja v a2s .c o m*/ final List<Audit> result = new ArrayList<Audit>(auditIds.size()); for (Long auditId : auditIds) { try { final Audit auditInformation = getJdbcTemplate().queryForObject(SQL_GET_AUDIT_INFORMATION_FROM_ID, new Object[] { auditId.longValue() }, new RowMapper<Audit>() { @Override public Audit mapRow(final ResultSet rs, final int rowNum) throws SQLException { RequestType requestType; try { requestType = RequestType.valueOf(rs.getString("request_type").toUpperCase()); } catch (IllegalArgumentException e) { requestType = RequestType.UNKNOWN; } JSONObject response; try { response = new JSONObject(rs.getString("response")); } catch (JSONException e) { response = new JSONObject(); } return new Audit(requestType, rs.getString("uri"), rs.getString("client"), rs.getString("device_id"), response, rs.getLong("received_millis"), rs.getLong("respond_millis"), rs.getTimestamp("db_timestamp")); } }); // Micro inner class to deal with getting key-value pairs from // the database. class KeyValuePair { private String key; private String value; public KeyValuePair(String key, String value) { this.key = key; this.value = value; } } // Add all of the parameters. try { final List<KeyValuePair> parameters = getJdbcTemplate().query(SQL_GET_AUDIT_PARAMETERS, new Object[] { auditId }, new RowMapper<KeyValuePair>() { @Override public KeyValuePair mapRow(final ResultSet rs, final int rowNum) throws SQLException { return new KeyValuePair(rs.getString("param_key"), rs.getString("param_value")); } }); for (KeyValuePair parameter : parameters) { try { auditInformation.addParameter(parameter.key, parameter.value); } catch (DomainException e) { throw new DataAccessException("The audit parameters table has a corrupt record.", e); } } } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException( "Error executing SQL '" + SQL_GET_AUDIT_PARAMETERS + "' with parameter: " + auditId, e); } // Add all of the extras. try { final List<KeyValuePair> extras = getJdbcTemplate().query(SQL_GET_AUDIT_EXTRAS, new Object[] { auditId }, new RowMapper<KeyValuePair>() { @Override public KeyValuePair mapRow(final ResultSet rs, final int rowNum) throws SQLException { return new KeyValuePair(rs.getString("extra_key"), rs.getString("extra_value")); } }); for (KeyValuePair extra : extras) { try { auditInformation.addExtra(extra.key, extra.value); } catch (DomainException e) { throw new DataAccessException("The audit extras table has a corrupt record.", e); } } } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException( "Error executing SQL '" + SQL_GET_AUDIT_EXTRAS + "' with parameter: " + auditId, e); } // Add the audit information to the result. result.add(auditInformation); } catch (org.springframework.dao.IncorrectResultSizeDataAccessException e) { throw new DataAccessException("The audit ID does not exist: " + auditId, e); } catch (org.springframework.dao.DataAccessException e) { throw new DataAccessException("Error executing SQL '" + SQL_GET_AUDIT_INFORMATION_FROM_ID + "' with parameter: " + auditId, e); } } return result; }