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.SchemaSetDAOImpl.java
/** * @see eionet.meta.dao.ISchemaSetDAO#searchSchemaSets(eionet.meta.service.data.SchemaSetFilter) *///from w w w . j av a 2 s . c om @Override public SchemaSetsResult searchSchemaSets(SchemaSetFilter searchFilter) { int nameAttrId = getNameAttributeId(); Map<String, Object> parameters = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); sql.append("SELECT SQL_CALC_FOUND_ROWS ss.*, ATTRIBUTE.VALUE as NAME_ATTR "); sql.append("FROM T_SCHEMA_SET ss "); sql.append("left outer join ATTRIBUTE on "); sql.append("(ss.SCHEMA_SET_ID=ATTRIBUTE.DATAELEM_ID and ATTRIBUTE.PARENT_TYPE=:attrParentType "); sql.append("and ATTRIBUTE.M_ATTRIBUTE_ID=:nameAttrId) "); parameters.put("attrParentType", DElemAttribute.ParentType.SCHEMA_SET.toString()); parameters.put("nameAttrId", nameAttrId); sql.append("where "); String searchingUser = searchFilter.getSearchingUser(); if (StringUtils.isBlank(searchingUser)) { sql.append("(ss.WORKING_COPY=false "); if (StringUtils.isEmpty(searchFilter.getRegStatus()) && CollectionUtils.isEmpty(searchFilter.getRegStatuses())) { sql.append("AND ss.REG_STATUS IN ( :regStatusPublic ) "); parameters.put("regStatusPublic", RegStatus.getPublicStatuses()); } sql.append(") "); } else { sql.append("(ss.WORKING_COPY=false or ss.WORKING_USER=:workingUser) "); parameters.put("workingUser", searchingUser); } // Where clause if (searchFilter.isValued()) { parameters.put("parentType", DElemAttribute.ParentType.SCHEMA_SET.toString()); if (StringUtils.isNotEmpty(searchFilter.getIdentifier())) { sql.append("AND "); sql.append("ss.IDENTIFIER like :identifier "); String identifier = "%" + searchFilter.getIdentifier() + "%"; parameters.put("identifier", identifier); } if (StringUtils.isNotEmpty(searchFilter.getRegStatus())) { sql.append("AND "); sql.append("ss.REG_STATUS = :regStatus "); parameters.put("regStatus", searchFilter.getRegStatus()); } else if (searchFilter.getRegStatuses() != null && searchFilter.getRegStatuses().size() > 0) { sql.append(" AND ss.REG_STATUS IN ( :regStatuses ) "); parameters.put("regStatuses", searchFilter.getRegStatuses()); } /* * if (searchFilter.isAttributesValued()) { for (int i = 0; i < searchFilter.getAttributes().size(); i++) { Attribute a * = searchFilter.getAttributes().get(i); String idKey = "attrId" + i; String valueKey = "attrValue" + i; if * (StringUtils.isNotEmpty(a.getValue())) { sql.append("AND "); sql.append("ss.SCHEMA_SET_ID IN ( "); * sql.append("SELECT a.DATAELEM_ID FROM ATTRIBUTE a WHERE "); sql.append("a.M_ATTRIBUTE_ID = :" + idKey + * " AND a.VALUE like :" + valueKey + " AND a.PARENT_TYPE = :parentType "); sql.append(") "); } parameters.put(idKey, * a.getId()); String value = "%" + a.getValue() + "%"; parameters.put(valueKey, value); } } */ sql.append(getAttributesSqlConstraintAndAppendParams(searchFilter, parameters, "ss.SCHEMA_SET_ID")); sql.append(getComplexAttrsSqlConstraintAndAppendParams(searchFilter, parameters, "ss.SCHEMA_SET_ID")); } // Sorting if (StringUtils.isNotEmpty(searchFilter.getSortProperty())) { sql.append("ORDER BY ").append(searchFilter.getSortProperty()); if (SortOrderEnum.ASCENDING.equals(searchFilter.getSortOrder())) { sql.append(" ASC "); } else { sql.append(" DESC "); } } if (searchFilter.isUsePaging()) { sql.append("LIMIT ").append(searchFilter.getOffset()).append(",").append(searchFilter.getPageSize()); } // LOGGER.debug("SQL: " + sql.toString()); List<SchemaSet> items = getNamedParameterJdbcTemplate().query(sql.toString(), parameters, new RowMapper<SchemaSet>() { @Override public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setNameAttribute(rs.getString("NAME_ATTR")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); String totalSql = "SELECT FOUND_ROWS()"; int totalItems = getJdbcTemplate().queryForInt(totalSql); SchemaSetsResult result = new SchemaSetsResult(items, totalItems, searchFilter); return result; }
From source file:com.flexive.core.search.PropertyEntry.java
/** * Decodes a daterange result value consisting of two date columns. * @param rs the result set/*ww w. j a va2s .c o m*/ * @param pos the position of the first date column * @param secondDateOffset the offset for the second date column * @return the decoded dates. If a column is null, the corresponding entry is also null. * @throws SQLException if the column datatypes don't match */ private Pair<Date, Date> decodeDateRange(ResultSet rs, int pos, int secondDateOffset) throws SQLException { final Timestamp fromTimestamp = rs.getTimestamp(pos); // FDATE1 final Timestamp toTimestamp = rs.getTimestamp(pos + secondDateOffset); // FDATE2 final Date from = fromTimestamp != null ? new Date(fromTimestamp.getTime()) : null; final Date to = toTimestamp != null ? new Date(toTimestamp.getTime()) : null; return new Pair<Date, Date>(from, to); }
From source file:com.mirth.connect.donkey.test.util.TestUtils.java
public static void assertConnectorMessageExists(ConnectorMessage connectorMessage, boolean deepSearch, Connection connection) throws SQLException { long localChannelId = ChannelController.getInstance().getLocalChannelId(connectorMessage.getChannelId()); PreparedStatement statement = null; ResultSet result = null; try {//w w w .j a va2s. co m statement = connection .prepareStatement("SELECT * FROM d_mm" + localChannelId + " WHERE message_id = ? AND id = ?"); statement.setLong(1, connectorMessage.getMessageId()); statement.setLong(2, connectorMessage.getMetaDataId()); result = statement.executeQuery(); if (!result.next()) { throw new AssertionError(); } Calendar receivedDate = Calendar.getInstance(); receivedDate.setTimeInMillis(result.getTimestamp("received_date").getTime()); Status status = Status.fromChar(result.getString("status").charAt(0)); assertDatesEqual(receivedDate, connectorMessage.getReceivedDate()); assertTrue(testEquality(status, connectorMessage.getStatus())); } finally { close(result); close(statement); } if (deepSearch) { for (ContentType contentType : ContentType.getMessageTypes()) { // Even though raw content exists on the destination connector message, it won't be stored in the database if (contentType != ContentType.RAW || connectorMessage.getMetaDataId() == 0) { MessageContent messageContent = connectorMessage.getMessageContent(contentType); if (messageContent != null) { assertMessageContentExists(connection, messageContent); } } } } }
From source file:eionet.meta.dao.mysql.SchemaDAOImpl.java
@Override public Schema getSchema(String schemaSetIdentifier, String schemaFileName, boolean workingCopy) { String sql = "select * from T_SCHEMA as S left join T_SCHEMA_SET as SS on (S.SCHEMA_SET_ID=SS.SCHEMA_SET_ID) " + "where SS.IDENTIFIER = :schemaSetIdentifier and SS.WORKING_COPY = :workingCopy AND S.FILENAME = :schemaFileName"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("schemaSetIdentifier", schemaSetIdentifier); parameters.put("schemaFileName", schemaFileName); parameters.put("workingCopy", workingCopy); Schema result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<Schema>() { @Override//w w w. j a v a2 s . co m public Schema mapRow(ResultSet rs, int rowNum) throws SQLException { Schema schema = new Schema(); schema.setId(rs.getInt("S.SCHEMA_ID")); schema.setFileName(rs.getString("S.FILENAME")); schema.setContinuityId(rs.getString("S.CONTINUITY_ID")); schema.setRegStatus(RegStatus.fromString(rs.getString("S.REG_STATUS"))); schema.setWorkingCopy(rs.getBoolean("S.WORKING_COPY")); schema.setWorkingUser(rs.getString("S.WORKING_USER")); schema.setDateModified(rs.getTimestamp("S.DATE_MODIFIED")); schema.setUserModified(rs.getString("S.USER_MODIFIED")); schema.setComment(rs.getString("S.COMMENT")); schema.setCheckedOutCopyId(rs.getInt("S.CHECKEDOUT_COPY_ID")); schema.setSchemaSetId(rs.getInt("S.SCHEMA_SET_ID")); schema.setOtherDocument(rs.getBoolean("S.OTHER_DOCUMENT")); return schema; } }); return result; }
From source file:eionet.meta.dao.mysql.SchemaDAOImpl.java
@Override public Schema getRootLevelSchema(String schemaFileName, boolean workingCopy) { String sql = "select * from T_SCHEMA as S where S.SCHEMA_SET_ID is NULL AND " + "S.WORKING_COPY = :workingCopy AND S.FILENAME = :schemaFileName"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("schemaFileName", schemaFileName); parameters.put("workingCopy", workingCopy); Schema result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<Schema>() { @Override/*from w w w.j av a2 s.c o m*/ public Schema mapRow(ResultSet rs, int rowNum) throws SQLException { Schema schema = new Schema(); schema.setId(rs.getInt("S.SCHEMA_ID")); schema.setFileName(rs.getString("S.FILENAME")); schema.setContinuityId(rs.getString("S.CONTINUITY_ID")); schema.setRegStatus(RegStatus.fromString(rs.getString("S.REG_STATUS"))); schema.setWorkingCopy(rs.getBoolean("S.WORKING_COPY")); schema.setWorkingUser(rs.getString("S.WORKING_USER")); schema.setDateModified(rs.getTimestamp("S.DATE_MODIFIED")); schema.setUserModified(rs.getString("S.USER_MODIFIED")); schema.setComment(rs.getString("S.COMMENT")); schema.setCheckedOutCopyId(rs.getInt("S.CHECKEDOUT_COPY_ID")); schema.setSchemaSetId(rs.getInt("S.SCHEMA_SET_ID")); schema.setOtherDocument(rs.getBoolean("S.OTHER_DOCUMENT")); return schema; } }); return result; }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.QcliveAbstractBaseIntegrationTest.java
/** * Retrieves a map with archive_info table values *//* w w w. j a v a 2 s . c o m*/ protected List<Map<String, Object>> retrieveArchiveInfoRecords() { logger.info(" retrieveArchiveInfoRecords - IN"); final List<Map<String, Object>> archiveInfoRecordsList = new ArrayList<Map<String, Object>>(); localCommonTemplate.query(getArchiveInfoRecords, new RowCallbackHandler() { public void processRow(final ResultSet resultSet) throws SQLException { final Map<String, Object> elementIdMap = new HashMap<String, Object>(); elementIdMap.put("ARCHIVE_ID", resultSet.getLong("ARCHIVE_ID")); elementIdMap.put("ARCHIVE_NAME", resultSet.getString("ARCHIVE_NAME")); elementIdMap.put("ARCHIVE_TYPE_ID", resultSet.getLong("ARCHIVE_TYPE_ID")); elementIdMap.put("CENTER_ID", resultSet.getLong("CENTER_ID")); elementIdMap.put("DISEASE_ID", resultSet.getLong("DISEASE_ID")); elementIdMap.put("PLATFORM_ID", resultSet.getLong("PLATFORM_ID")); elementIdMap.put("SERIAL_INDEX", resultSet.getLong("SERIAL_INDEX")); elementIdMap.put("REVISION", resultSet.getLong("REVISION")); elementIdMap.put("SERIES", resultSet.getLong("SERIES")); elementIdMap.put("DATE_ADDED", resultSet.getTimestamp("DATE_ADDED")); elementIdMap.put("DEPLOY_STATUS", resultSet.getString("DEPLOY_STATUS")); elementIdMap.put("DEPLOY_LOCATION", resultSet.getString("DEPLOY_LOCATION")); elementIdMap.put("IS_LATEST", resultSet.getLong("IS_LATEST")); elementIdMap.put("IS_LATEST", resultSet.getLong("INITIAL_SIZE_KB")); elementIdMap.put("FINAL_SIZE_KB", resultSet.getLong("FINAL_SIZE_KB")); elementIdMap.put("IS_LATEST_LOADED", resultSet.getLong("IS_LATEST_LOADED")); elementIdMap.put("DATA_LOADED_DATE", resultSet.getDate("DATA_LOADED_DATE")); archiveInfoRecordsList.add(elementIdMap); } }); logger.info(" retrieveArchiveInfoRecords - OUT"); return archiveInfoRecordsList; }
From source file:com.sfs.whichdoctor.dao.ExamDAOImpl.java
/** * Load exam./*from w ww. j a v a2s . c o m*/ * * @param rs the rs * @return the exam bean * @throws SQLException the sQL exception */ private ExamBean loadExam(final ResultSet rs) throws SQLException { ExamBean exam = new ExamBean(); exam.setId(rs.getInt("ExamId")); exam.setGUID(rs.getInt("GUID")); exam.setReferenceGUID(rs.getInt("ReferenceGUID")); exam.setType(rs.getString("Type")); exam.setTrainingOrganisation(rs.getString("TrainingOrganisation")); exam.setTrainingProgram(rs.getString("TrainingProgram")); exam.setStatus(rs.getString("Status")); exam.setStatusLevel(rs.getString("StatusLevel")); try { exam.setDateSat(rs.getDate("DateSat")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } exam.setLocation(rs.getString("Location")); exam.setAwardedMarks(rs.getInt("AwardedMarks")); exam.setTotalMarks(rs.getInt("TotalMarks")); exam.setActive(rs.getBoolean("Active")); try { exam.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } exam.setCreatedBy(rs.getString("CreatedBy")); try { exam.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } exam.setModifiedBy(rs.getString("ModifiedBy")); try { exam.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } exam.setExportedBy(rs.getString("ExportedBy")); return exam; }
From source file:com.alfaariss.oa.util.saml2.storage.artifact.jdbc.JDBCArtifactMapFactory.java
/** * Retrieve the given artifact./*from ww w . j a v a 2s . co m*/ * @see org.opensaml.common.binding.artifact.SAMLArtifactMap#get(java.lang.String) */ public SAMLArtifactMapEntry get(String artifact) { if (artifact == null) throw new IllegalArgumentException("Suplied artifact is empty"); Connection oConnection = null; SAMLArtifactMapEntry artifactEntry = null; PreparedStatement ps = null; ResultSet rs = null; try { oConnection = _oDataSource.getConnection(); ps = oConnection.prepareStatement(_sSearchQuery); ps.setString(1, artifact); rs = ps.executeQuery(); if (rs.next()) { //Get message String sMessage = rs.getString(4); Element eMessage = _pool.parse(new StringReader(sMessage)).getDocumentElement(); Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(eMessage); SAMLObject message = (SAMLObject) unmarshaller.unmarshall(eMessage); //Construct entry artifactEntry = new ArtifactMapEntry(rs.getString(1), rs.getString(2), rs.getString(3), rs.getTimestamp(5).getTime(), message); } } catch (SQLException e) { _logger.error("Could not execute search query: " + _sSearchQuery, e); } catch (ClassCastException e) { _logger.error("Could not unmarshall SAML message, not a valid SAMLObject, artifact: " + artifact, e); } catch (XMLParserException e) { _logger.error("Could not deserialize SAML message, associated with artifact: " + artifact, e); } catch (UnmarshallingException e) { _logger.error("Could not unmarshall SAML message, associated with artifact: " + artifact, e); } finally { try { if (rs != null) rs.close(); } catch (SQLException e) { _logger.debug("Could not close resultset", e); } try { if (ps != null) ps.close(); } catch (SQLException e) { _logger.debug("Could not close statement", e); } try { if (oConnection != null) oConnection.close(); } catch (SQLException e) { _logger.debug("Could not close connection", e); } } return artifactEntry; }
From source file:au.com.ish.derbydump.derbydump.metadata.Column.java
/** * Get a string value for the value in this column in the datarow * /* ww w . j av a 2 s .c o m*/ * @param dataRow The row which we are exporting * @return an SQL statement compliant string version of the value */ public String toString(ResultSet dataRow) throws SQLException { switch (getColumnDataType()) { case Types.BINARY: case Types.VARBINARY: case Types.BLOB: { Blob obj = dataRow.getBlob(columnName); return (obj == null) ? "NULL" : processBinaryData(obj); } case Types.CLOB: { Clob obj = dataRow.getClob(columnName); return (obj == null) ? "NULL" : processClobData(obj); } case Types.CHAR: case Types.LONGNVARCHAR: case Types.VARCHAR: { String obj = dataRow.getString(columnName); return (obj == null) ? "NULL" : processStringData(obj); } case Types.TIME: { Time obj = dataRow.getTime(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.DATE: { Date obj = dataRow.getDate(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.TIMESTAMP: { Timestamp obj = dataRow.getTimestamp(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.SMALLINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.BIGINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.INTEGER: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.NUMERIC: case Types.DECIMAL: { BigDecimal obj = dataRow.getBigDecimal(columnName); return (obj == null) ? "NULL" : String.valueOf(obj); } case Types.REAL: case Types.FLOAT: { Float obj = dataRow.getFloat(columnName); // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } case Types.DOUBLE: { Double obj = dataRow.getDouble(columnName); return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } default: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } } }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackend.java
@Override protected PinLaterJobInfo lookupJobFromShard(final String queueName, final String shardName, final int priority, final long localId, final boolean isIncludeBody) throws Exception { final String mySQLQuery = isIncludeBody ? MySQLQueries.LOOKUP_JOB_WITH_BODY : MySQLQueries.LOOKUP_JOB; String jobsTableName = MySQLBackendUtils.constructJobsTableName(queueName, shardName, priority); Connection conn = null;/*w w w. j a v a2 s . c o m*/ ImmutableMap<String, MySQLDataSources> shardMap = shardMapRef.get(); try { conn = shardMap.get(shardName).getGeneralDataSource().getConnection(); PinLaterJobInfo jobInfo = JdbcUtils.selectOne(conn, String.format(mySQLQuery, jobsTableName), new RowProcessor<PinLaterJobInfo>() { @Override public PinLaterJobInfo process(ResultSet rs) throws IOException, SQLException { PinLaterJobInfo ji = new PinLaterJobInfo(); ji.setJobDescriptor( new PinLaterJobDescriptor(queueName, shardName, priority, rs.getLong(1)) .toString()); ji.setJobState(PinLaterJobState.findByValue(rs.getInt(2))); ji.setAttemptsAllowed(rs.getInt(3)); ji.setAttemptsRemaining(rs.getInt(4)); ji.setCreatedAtTimestampMillis(rs.getTimestamp(5).getTime()); ji.setRunAfterTimestampMillis(rs.getTimestamp(6).getTime()); ji.setUpdatedAtTimestampMillis(rs.getTimestamp(7).getTime()); String claimDescriptor = rs.getString(8); if (claimDescriptor != null) { ji.setClaimDescriptor(claimDescriptor); } ; ji.setCustomStatus(Strings.nullToEmpty(rs.getString(9))); if (isIncludeBody) { ji.setBody(rs.getBytes(10)); } return ji; } }, localId); return jobInfo; } finally { JdbcUtils.closeConnection(conn); } }