List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:org.apache.wiki.auth.user.JDBCUserDatabase.java
/** * @see org.apache.wiki.auth.user.UserDatabase#save(org.apache.wiki.auth.user.UserProfile) *///w w w .j a v a2 s .co m public void save(UserProfile profile) throws WikiSecurityException { String initialRole = "Authenticated"; // Figure out which prepared statement to use & execute it String loginName = profile.getLoginName(); PreparedStatement ps = null; UserProfile existingProfile = null; try { existingProfile = findByLoginName(loginName); } catch (NoSuchPrincipalException e) { // Existing profile will be null } // Get a clean password from the passed profile. // Blank password is the same as null, which means we re-use the // existing one. String password = profile.getPassword(); String existingPassword = (existingProfile == null) ? null : existingProfile.getPassword(); if (NOTHING.equals(password)) { password = null; } if (password == null) { password = existingPassword; } // If password changed, hash it before we save if (!StringUtils.equals(password, existingPassword)) { password = getHash(password); } Connection conn = null; try { // Open the database connection conn = m_ds.getConnection(); if (m_supportsCommits) { conn.setAutoCommit(false); } Timestamp ts = new Timestamp(System.currentTimeMillis()); Date modDate = new Date(ts.getTime()); java.sql.Date lockExpiry = profile.getLockExpiry() == null ? null : new java.sql.Date(profile.getLockExpiry().getTime()); if (existingProfile == null) { // User is new: insert new user record ps = conn.prepareStatement(m_insertProfile); ps.setString(1, profile.getUid()); ps.setString(2, profile.getEmail()); ps.setString(3, profile.getFullname()); ps.setString(4, password); ps.setString(5, profile.getWikiName()); ps.setTimestamp(6, ts); ps.setString(7, profile.getLoginName()); try { ps.setString(8, Serializer.serializeToBase64(profile.getAttributes())); } catch (IOException e) { throw new WikiSecurityException( "Could not save user profile attribute. Reason: " + e.getMessage(), e); } ps.setTimestamp(9, ts); ps.execute(); ps.close(); // Insert new role record ps = conn.prepareStatement(m_findRoles); ps.setString(1, profile.getLoginName()); ResultSet rs = ps.executeQuery(); int roles = 0; while (rs.next()) { roles++; } ps.close(); if (roles == 0) { ps = conn.prepareStatement(m_insertRole); ps.setString(1, profile.getLoginName()); ps.setString(2, initialRole); ps.execute(); ps.close(); } // Set the profile creation time profile.setCreated(modDate); } else { // User exists: modify existing record ps = conn.prepareStatement(m_updateProfile); ps.setString(1, profile.getUid()); ps.setString(2, profile.getEmail()); ps.setString(3, profile.getFullname()); ps.setString(4, password); ps.setString(5, profile.getWikiName()); ps.setTimestamp(6, ts); ps.setString(7, profile.getLoginName()); try { ps.setString(8, Serializer.serializeToBase64(profile.getAttributes())); } catch (IOException e) { throw new WikiSecurityException( "Could not save user profile attribute. Reason: " + e.getMessage(), e); } ps.setDate(9, lockExpiry); ps.setString(10, profile.getLoginName()); ps.execute(); ps.close(); } // Set the profile mod time profile.setLastModified(modDate); // Commit and close connection if (m_supportsCommits) { conn.commit(); } } catch (SQLException e) { throw new WikiSecurityException(e.getMessage(), e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:com.redhat.rhn.manager.monitoring.MonitoringManager.java
/** * Get the timeseries data for a probe//from ww w .ja v a 2s . co m * @param probeIn probe we want data for * @param metricId probe metric we are going to search for * @param startTime start time to lookup * @param endTime end time to lookup * @return array of TimeSeriesData DTO objects */ public TimeSeriesData[] getProbeData(Probe probeIn, String metricId, Timestamp startTime, Timestamp endTime) { SelectMode tsMode = ModeFactory.getMode("Monitoring_queries", "time_series_for_probe"); // Convert to minutes from millis Long startMinutes = new Long(startTime.getTime() / 1000); Long endMinutes = new Long(endTime.getTime() / 1000); Map<String, Object> params = new HashMap<String, Object>(); //Must concat the values together //to produce the oid: 1-3-pctfree // orgId-probeId-metric StringBuilder oid = new StringBuilder(); oid.append(probeIn.getOrg().getId()); oid.append("-"); oid.append(probeIn.getId()); oid.append("-"); oid.append(metricId); params.put("oid", oid.toString()); params.put("start_time", startMinutes); params.put("end_time", endMinutes); log.debug("Params: " + params); DataResult dr = tsMode.execute(params); log.debug("results: " + dr); if (dr.size() == 0) { return null; } Iterator i = dr.iterator(); List retval = new LinkedList(); while (i.hasNext()) { Map row = (Map) i.next(); // Have to multiply by 1000 since // this table stores the data as seconds since 1970, // not millis. Timestamp entryTime = new Timestamp(((Long) row.get("entry_time")).longValue() * 1000); String sdata = (String) row.get("data"); if (sdata == null) { sdata = "0.0"; } Float data = new Float(sdata); TimeSeriesData tsd = new TimeSeriesData(oid.toString(), data, entryTime, metricId); retval.add(tsd); } return (TimeSeriesData[]) retval.toArray(new TimeSeriesData[0]); }
From source file:org.kuali.coeus.propdev.impl.s2s.schedule.S2SPollingTask.java
/** * This method is the starting point of execution for the thread that is scheduled by the scheduler service * /*from ww w. j a v a 2 s.c o m*/ */ public void execute() { LOG.info("Executing polling schedule for status -" + statusMap.values() + ":" + stopPollInterval); Map<String, SubmissionData> pollingList = populatePollingList(); int appListSize = pollingList.size(); Iterator<SubmissionData> submissions = pollingList.values().iterator(); HashMap<String, Vector<SubmissionData>> htMails = new LinkedHashMap<String, Vector<SubmissionData>>(); Vector<SubmissionData> submList = new Vector<SubmissionData>(); Timestamp[] lastNotiDateArr = new Timestamp[appListSize]; while (submissions.hasNext()) { SubmissionData localSubInfo = submissions.next(); S2sAppSubmission appSubmission = localSubInfo.getS2sAppSubmission(); Timestamp oldLastNotiDate = appSubmission.getLastNotifiedDate(); Timestamp today = new Timestamp(new Date().getTime()); boolean updateFlag = false; boolean sendEmailFlag = false; boolean statusChanged = false; GetApplicationListResponse applicationListResponse = null; try { ProposalDevelopmentDocument pdDoc = getProposalDevelopmentDocument( appSubmission.getProposalNumber()); if (pdDoc != null) { applicationListResponse = s2sSubmissionService.fetchApplicationListResponse(pdDoc); } if (applicationListResponse.getApplicationInfo() == null || applicationListResponse.getApplicationInfo().size() == 0) { statusChanged = s2sSubmissionService.checkForSubmissionStatusChange(pdDoc, appSubmission); if (statusChanged == false && appSubmission.getComments() .equals(S2sAppSubmissionConstants.STATUS_NO_RESPONSE_FROM_GRANTS_GOV)) { localSubInfo.setSortId(SORT_ID_F); sendEmailFlag = true; } } else { ApplicationInfo ggApplication = applicationListResponse.getApplicationInfo().get(0); if (ggApplication != null) { localSubInfo.setAcType('U'); statusChanged = !appSubmission.getStatus() .equalsIgnoreCase(ggApplication.getGrantsGovApplicationStatus().value()); s2sSubmissionService.populateAppSubmission(pdDoc, appSubmission, ggApplication); } } } catch (S2sCommunicationException e) { LOG.error(e.getMessage(), e); appSubmission.setComments(e.getMessage()); localSubInfo.setSortId(SORT_ID_F); sendEmailFlag = true; } String sortId = SORT_ID_Z; Timestamp lastNotifiedDate = appSubmission.getLastNotifiedDate(); Timestamp statusChangedDate = appSubmission.getLastModifiedDate(); Calendar lastNotifiedDateCal = Calendar.getInstance(); if (lastNotifiedDate != null) { lastNotifiedDateCal.setTimeInMillis(lastNotifiedDate.getTime()); } Calendar statusChangedDateCal = Calendar.getInstance(); if (statusChangedDate != null) { statusChangedDateCal.setTimeInMillis(statusChangedDate.getTime()); } Calendar recDateCal = Calendar.getInstance(); recDateCal.setTimeInMillis(appSubmission.getReceivedDate().getTime()); if (statusChanged) { if (appSubmission.getStatus() .indexOf(S2sAppSubmissionConstants.STATUS_GRANTS_GOV_SUBMISSION_ERROR) != -1) { updateFlag = true; sendEmailFlag = true; sortId = SORT_ID_A; } else if (!lstStatus.contains(appSubmission.getStatus().trim().toUpperCase())) { updateFlag = false; sendEmailFlag = true; sortId = SORT_ID_B; } else { updateFlag = true; sendEmailFlag = true; sortId = SORT_ID_E; } } else { long lastModifiedTime = statusChangedDate == null ? appSubmission.getReceivedDate().getTime() : statusChangedDate.getTime(); long lastNotifiedTime = lastNotifiedDate == null ? lastModifiedTime : lastNotifiedDate.getTime(); long mailDelta = today.getTime() - lastNotifiedTime; long delta = today.getTime() - lastModifiedTime; long stopPollDiff = ((Integer.parseInt(getStopPollInterval()) == 0 ? 4320L : Integer.parseInt(getStopPollInterval())) - (delta / (60 * 60 * 1000))); if ((mailDelta / (1000 * 60)) >= (Integer.parseInt(getMailInterval()))) { if (localSubInfo.getSortId() == null) { if (stopPollDiff <= 24) { sortId = SORT_ID_C; } else { sortId = SORT_ID_D; sortMsgKeyMap.put(SORT_ID_D, "Following submissions status has not been changed in " + getMailInterval() + " minutes"); } } updateFlag = true; sendEmailFlag = true; } } if (sendEmailFlag) { Map<String, String> proposalMap = new HashMap<String, String>(); proposalMap.put(KEY_PROPOSAL_NUMBER, appSubmission.getProposalNumber()); DevelopmentProposal developmentProposal = (DevelopmentProposal) businessObjectService .findByPrimaryKey(DevelopmentProposal.class, proposalMap); String dunsNum; if (developmentProposal.getApplicantOrganization().getOrganization().getDunsNumber() != null) { dunsNum = developmentProposal.getApplicantOrganization().getOrganization().getDunsNumber(); } else { dunsNum = developmentProposal.getApplicantOrganization().getOrganizationId(); } Vector<SubmissionData> mailGrpForDunNum = new Vector<SubmissionData>(); mailGrpForDunNum.add(localSubInfo); htMails.put(dunsNum, mailGrpForDunNum); appSubmission.setLastNotifiedDate(today); } if (localSubInfo.getSortId() == null) { localSubInfo.setSortId(sortId); } if (updateFlag) { submList.addElement(localSubInfo); lastNotiDateArr[submList.size() - 1] = oldLastNotiDate; } } try { sendMail(htMails); } catch (InvalidAddressException ex) { LOG.error("Mail sending failed"); LOG.error(ex.getMessage(), ex); int size = submList.size(); for (int i = 0; i < size; i++) { SubmissionData localSubInfo = submList.elementAt(i); localSubInfo.getS2sAppSubmission().setLastNotifiedDate(lastNotiDateArr[i]); } } catch (MessagingException me) { LOG.error("Mail sending failed"); LOG.error(me.getMessage(), me); int size = submList.size(); for (int i = 0; i < size; i++) { SubmissionData localSubInfo = submList.elementAt(i); localSubInfo.getS2sAppSubmission().setLastNotifiedDate(lastNotiDateArr[i]); } } saveSubmissionDetails(submList); }
From source file:net.sf.jasperreports.engine.JRResultSetDataSource.java
protected Object readTimestamp(Integer columnIndex, JRField field) throws SQLException { Calendar calendar = getFieldCalendar(field); java.sql.Timestamp objValue = calendar == null ? resultSet.getTimestamp(columnIndex) : resultSet.getTimestamp(columnIndex, calendar); if (resultSet.wasNull()) { objValue = null;/* ww w . j a v a 2 s . co m*/ } if (log.isDebugEnabled()) { log.debug("timestamp field " + field.getName() + " is " + (objValue == null ? "null" : (objValue + " (" + objValue.getTime() + ")"))); } return objValue; }
From source file:org.kuali.kra.s2s.polling.S2SPollingTask.java
/** * This method is the starting point of execution for the thread that is scheduled by the scheduler service * /* www. java 2 s . com*/ */ public void execute() { LOG.info("Executing polling schedule for status -" + statusMap.values() + ":" + stopPollInterval); Map<String, SubmissionData> pollingList = populatePollingList(); int appListSize = pollingList.size(); Iterator<SubmissionData> submissions = pollingList.values().iterator(); HashMap<String, Vector<SubmissionData>> htMails = new LinkedHashMap<String, Vector<SubmissionData>>(); Vector<SubmissionData> submList = new Vector<SubmissionData>(); Timestamp[] lastNotiDateArr = new Timestamp[appListSize]; while (submissions.hasNext()) { SubmissionData localSubInfo = submissions.next(); S2sAppSubmission appSubmission = localSubInfo.getS2sAppSubmission(); Timestamp oldLastNotiDate = appSubmission.getLastNotifiedDate(); Timestamp today = dateTimeService.getCurrentTimestamp(); boolean updateFlag = false; boolean sendEmailFlag = false; boolean statusChanged = false; GetApplicationListResponse applicationListResponse = null; try { ProposalDevelopmentDocument pdDoc = getProposalDevelopmentDocument( appSubmission.getProposalNumber()); if (pdDoc != null) { applicationListResponse = s2SService.fetchApplicationListResponse(pdDoc); } if (applicationListResponse.getApplicationInformation() == null || applicationListResponse.getApplicationInformation().size() == 0) { statusChanged = s2SService.checkForSubmissionStatusChange(pdDoc, appSubmission); if (statusChanged == false && appSubmission.getComments() .equals(S2SConstants.STATUS_NO_RESPONSE_FROM_GRANTS_GOV)) { localSubInfo.setSortId(SORT_ID_F); sendEmailFlag = true; } } else { ApplicationInformationType ggApplication = applicationListResponse.getApplicationInformation() .get(0); if (ggApplication != null) { localSubInfo.setAcType('U'); statusChanged = !appSubmission.getStatus() .equalsIgnoreCase(ggApplication.getGrantsGovApplicationStatus().value()); s2SService.populateAppSubmission(pdDoc, appSubmission, ggApplication); } } } catch (S2SException e) { LOG.error(e.getMessage(), e); appSubmission.setComments(e.getMessage()); localSubInfo.setSortId(SORT_ID_F); sendEmailFlag = true; } String sortId = SORT_ID_Z; Timestamp lastNotifiedDate = appSubmission.getLastNotifiedDate(); Timestamp statusChangedDate = appSubmission.getLastModifiedDate(); Calendar lastNotifiedDateCal = dateTimeService.getCurrentCalendar(); if (lastNotifiedDate != null) { lastNotifiedDateCal.setTimeInMillis(lastNotifiedDate.getTime()); } Calendar statusChangedDateCal = dateTimeService.getCurrentCalendar(); if (statusChangedDate != null) { statusChangedDateCal.setTimeInMillis(statusChangedDate.getTime()); } Calendar recDateCal = dateTimeService.getCurrentCalendar(); recDateCal.setTimeInMillis(appSubmission.getReceivedDate().getTime()); if (statusChanged) { if (appSubmission.getStatus().indexOf(S2SConstants.STATUS_GRANTS_GOV_SUBMISSION_ERROR) != -1) { updateFlag = true; sendEmailFlag = true; sortId = SORT_ID_A; } else if (!lstStatus.contains(appSubmission.getStatus().trim().toUpperCase())) { updateFlag = false; sendEmailFlag = true; sortId = SORT_ID_B; } else { updateFlag = true; sendEmailFlag = true; sortId = SORT_ID_E; } } else { long lastModifiedTime = statusChangedDate == null ? appSubmission.getReceivedDate().getTime() : statusChangedDate.getTime(); long lastNotifiedTime = lastNotifiedDate == null ? lastModifiedTime : lastNotifiedDate.getTime(); long mailDelta = today.getTime() - lastNotifiedTime; long delta = today.getTime() - lastModifiedTime; long stopPollDiff = ((Integer.parseInt(getStopPollInterval()) == 0 ? 4320L : Integer.parseInt(getStopPollInterval())) - (delta / (60 * 60 * 1000))); if ((mailDelta / (1000 * 60)) >= (Integer.parseInt(getMailInterval()))) { if (localSubInfo.getSortId() == null) { if (stopPollDiff <= 24) { sortId = SORT_ID_C; } else { sortId = SORT_ID_D; sortMsgKeyMap.put(SORT_ID_D, "Following submissions status has not been changed in " + getMailInterval() + " minutes"); } } updateFlag = true; sendEmailFlag = true; } } if (sendEmailFlag) { Map<String, String> proposalMap = new HashMap<String, String>(); proposalMap.put(KEY_PROPOSAL_NUMBER, appSubmission.getProposalNumber()); DevelopmentProposal developmentProposal = (DevelopmentProposal) businessObjectService .findByPrimaryKey(DevelopmentProposal.class, proposalMap); String dunsNum; if (developmentProposal.getApplicantOrganization().getOrganization().getDunsNumber() != null) { dunsNum = developmentProposal.getApplicantOrganization().getOrganization().getDunsNumber(); } else { dunsNum = developmentProposal.getApplicantOrganization().getOrganizationId(); } Vector<SubmissionData> mailGrpForDunNum = new Vector<SubmissionData>(); mailGrpForDunNum.add(localSubInfo); htMails.put(dunsNum, mailGrpForDunNum); appSubmission.setLastNotifiedDate(today); } if (localSubInfo.getSortId() == null) { localSubInfo.setSortId(sortId); } if (updateFlag) { submList.addElement(localSubInfo); lastNotiDateArr[submList.size() - 1] = oldLastNotiDate; } } try { sendMail(htMails); } catch (InvalidAddressException ex) { LOG.error("Mail sending failed"); LOG.error(ex.getMessage(), ex); int size = submList.size(); for (int i = 0; i < size; i++) { SubmissionData localSubInfo = submList.elementAt(i); localSubInfo.getS2sAppSubmission().setLastNotifiedDate(lastNotiDateArr[i]); } } saveSubmissionDetails(submList); }
From source file:de.blizzy.backup.restore.RestoreDialog.java
private Entry toEntry(Record record, boolean fullPaths) { int id = record.getValue(Tables.ENTRIES.ID).intValue(); Integer parentIdInt = record.getValue(Tables.ENTRIES.PARENT_ID); int parentId = (parentIdInt != null) ? parentIdInt.intValue() : -1; String name = record.getValue(Tables.ENTRIES.NAME); EntryType type = EntryType.fromValue(record.getValue(Tables.ENTRIES.TYPE).intValue()); Timestamp createTime = record.getValue(Tables.ENTRIES.CREATION_TIME); Date creationTime = (createTime != null) ? new Date(createTime.getTime()) : null; Timestamp modTime = record.getValue(Tables.ENTRIES.MODIFICATION_TIME); Date modificationTime = (modTime != null) ? new Date(modTime.getTime()) : null; boolean hidden = record.getValue(Tables.ENTRIES.HIDDEN).booleanValue(); Long lengthLong = record.getValue(Tables.FILES.LENGTH); long length = (lengthLong != null) ? lengthLong.longValue() : -1; String backupPath = record.getValue(Tables.FILES.BACKUP_PATH); Byte compressionByte = record.getValue(Tables.FILES.COMPRESSION); Compression compression = (compressionByte != null) ? Compression.fromValue(compressionByte.intValue()) : null;//from ww w . j a va 2s . co m Entry entry = new Entry(id, parentId, name, type, creationTime, modificationTime, hidden, length, backupPath, compression); if (fullPaths) { entry.fullPath = getFolderPath(parentId); } return entry; }
From source file:com.redhat.rhn.manager.monitoring.MonitoringManager.java
/** * Get the List of com.redhat.rhn.frontend.dto.monitoring.StateChangeData associated * with this probe between the two Timestamps * @param probeIn probe we want to lookup * @param startTime starting time/*w w w. j a va2s. c o m*/ * @param endTime ending time * @return List of StateChangeData DTO objects */ public DataResult getProbeStateChangeData(Probe probeIn, Timestamp startTime, Timestamp endTime) { SelectMode scMode = ModeFactory.getMode("Monitoring_queries", "state_change_for_probe"); Map<String, Object> params = new HashMap<String, Object>(); // Convert to millis to minutes Long startMinutes = new Long(startTime.getTime() / 1000); Long endMinutes = new Long(endTime.getTime() / 1000); params.put("oid", probeIn.getId().toString()); params.put("start_time", startMinutes); params.put("end_time", endMinutes); return makeDataResultNoPagination(params, new HashMap(), scMode); }
From source file:org.geowebcache.storage.jdbc.metastore.JDBCMBWrapper.java
protected boolean getTile(TileObject stObj) throws SQLException { String query;/*w w w.j a va 2s. com*/ if (stObj.getParametersId() == -1L) { query = "SELECT TILE_ID,BLOB_SIZE,CREATED,LOCK,NOW() FROM TILES WHERE " + " LAYER_ID = ? AND X = ? AND Y = ? AND Z = ? AND GRIDSET_ID = ? " + " AND FORMAT_ID = ? AND PARAMETERS_ID IS NULL LIMIT 1 "; } else { query = "SELECT TILE_ID,BLOB_SIZE,CREATED,LOCK,NOW() FROM TILES WHERE " + " LAYER_ID = ? AND X = ? AND Y = ? AND Z = ? AND GRIDSET_ID = ? " + " AND FORMAT_ID = ? AND PARAMETERS_ID = ? LIMIT 1 "; } long[] xyz = stObj.getXYZ(); final Connection conn = getConnection(); PreparedStatement prep = null; try { prep = conn.prepareStatement(query); prep.setLong(1, stObj.getLayerId()); prep.setLong(2, xyz[0]); prep.setLong(3, xyz[1]); prep.setLong(4, xyz[2]); prep.setLong(5, stObj.getGridSetIdId()); prep.setLong(6, stObj.getFormatId()); if (stObj.getParametersId() != -1L) { prep.setLong(7, stObj.getParametersId()); } ResultSet rs = prep.executeQuery(); try { if (rs.first()) { Timestamp lock = rs.getTimestamp(4); // This tile is locked if (lock != null) { Timestamp now = rs.getTimestamp(5); long diff = now.getTime() - lock.getTime(); // System.out.println(now.getTime() + " " + System.currentTimeMillis()); if (diff > lockTimeout) { log.warn("Database lock exceeded (" + diff + "ms , " + lock.toString() + ") for " + stObj.toString() + ", clearing tile."); deleteTile(conn, stObj); stObj.setStatus(StorageObject.Status.EXPIRED_LOCK); } else { stObj.setStatus(StorageObject.Status.LOCK); } // This puts the request back in the queue return false; } stObj.setId(rs.getLong(1)); stObj.setBlobSize(rs.getInt(2)); stObj.setCreated(rs.getLong(3)); stObj.setStatus(StorageObject.Status.HIT); return true; } else { stObj.setStatus(StorageObject.Status.MISS); return false; } } finally { close(rs); } } finally { close(prep); close(conn); } }
From source file:com.etcc.csc.dao.OraclePaymentDAO.java
private Calendar timestampToCalendar(Timestamp timestamp) { if (timestamp == null) { return null; }//from www . ja v a2s . c o m Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(timestamp.getTime())); return calendar; }