List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:fr.paris.lutece.plugins.mylutece.modules.database.authentication.web.MyLuteceDatabaseApp.java
/** * Reactivate an account if necessary/*w w w.j a v a 2 s .c o m*/ * @param request The request * @throws SiteMessageException A SiteMessageException is ALWAYS thrown */ public void reactivateAccount(HttpServletRequest request) throws SiteMessageException { String strUserId = request.getParameter(MARK_USER_ID); String strRef = request.getParameter(MARK_REF); int nUserId = -1; if ((strUserId != null) && StringUtils.isNotBlank(strUserId)) { try { nUserId = Integer.parseInt(strUserId); } catch (NumberFormatException e) { nUserId = -1; } } if ((nUserId < 0) || StringUtils.isEmpty(strRef)) { SiteMessageService.setMessage(request, PROPERTY_NO_USER_SELECTED, null, PROPERTY_MESSAGE_LABEL_ERROR, AppPropertiesService.getProperty(PROPERTY_MYLUTECE_DEFAULT_REDIRECT_URL), null, SiteMessage.TYPE_ERROR); } else { DatabaseUser user = DatabaseUserHome.findByPrimaryKey(nUserId, _plugin); if ((user == null) || (user.getAccountMaxValidDate() == null) || !StringUtils .equals(CryptoService.encrypt(Long.toString(user.getAccountMaxValidDate().getTime()), AppPropertiesService.getProperty(PROPERTY_ACCOUNT_REF_ENCRYPT_ALGO)), strRef)) { SiteMessageService.setMessage(request, PROPERTY_NO_USER_SELECTED, null, PROPERTY_MESSAGE_LABEL_ERROR, AppPropertiesService.getProperty(PROPERTY_MYLUTECE_DEFAULT_REDIRECT_URL), null, SiteMessage.TYPE_ERROR); } int nbDaysBeforeFirstAlert = SecurityUtils.getIntegerSecurityParameter(_userParamService, _plugin, PARAMETER_TIME_BEFORE_ALERT_ACCOUNT); Timestamp firstAlertMaxDate = new Timestamp( new java.util.Date().getTime() + DateUtil.convertDaysInMiliseconds(nbDaysBeforeFirstAlert)); // If the account is close to expire but has not expired yet if (user.getAccountMaxValidDate() != null) { if ((user.getAccountMaxValidDate().getTime() < firstAlertMaxDate.getTime()) && (user.getStatus() < DatabaseUser.STATUS_EXPIRED)) { _databaseService.updateUserExpirationDate(nUserId, _plugin); } SiteMessageService.setMessage(request, PROPERTY_ACCOUNT_REACTIVATED, null, PROPERTY_ACCOUNT_REACTIVATED_TITLE, AppPropertiesService.getProperty(PROPERTY_MYLUTECE_DEFAULT_REDIRECT_URL), null, SiteMessage.TYPE_INFO); } } SiteMessageService.setMessage(request, PROPERTY_ERROR_NO_ACCOUNT_TO_REACTIVATE, null, PROPERTY_MESSAGE_LABEL_ERROR, AppPropertiesService.getProperty(PROPERTY_MYLUTECE_DEFAULT_REDIRECT_URL), null, SiteMessage.TYPE_ERROR); }
From source file:kx.c.java
void w(Timestamp p) { long j = p.getTime(); if (vt < 1) throw new RuntimeException("Timestamp not valid pre kdb+2.6"); w(j == nj ? j : 1000000 * (lg(j) - k) + p.getNanos() % 1000000); }
From source file:com.xpn.xwiki.xmlrpc.XWikiXmlRpcApiImpl.java
/** * Returns a list of XWikiPageHistorySummary containing all the pages that have been modified since a given date in * all their versions./*from w w w . j a v a2 s.c o m*/ * * @param token * @param date The starting date * @param numberOfResults The number of results to be returned * @param start The start offset in the result set * @param fromLatest True if the result set will list recent changed pages before. * @return A list of maps representing XWikiPageHistorySummary * @throws Exception An invalid token is provided. */ public List getModifiedPagesHistory(String token, Date date, int numberOfResults, int start, boolean fromLatest) throws Exception { XWikiXmlRpcUser user = XWikiUtils.checkToken(token, this.xwikiContext); LOGGER.debug(String.format("User %s has called getModifiedPagesHistory()", user.getName())); List result = new ArrayList(); String order = fromLatest ? "desc" : "asc"; String query = String.format( "select doc.fullName, rcs.id, rcs.date, rcs.author from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId=doc.id and rcs.date > :date order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order); QueryManager queryManager = Utils.getComponent(QueryManager.class); List<Object> queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("date", date) .setLimit(numberOfResults).setOffset(start).execute(); for (Object o : queryResult) { Object[] fields = (Object[]) o; String pageId = (String) fields[0]; XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[1]; Timestamp timestamp = (Timestamp) fields[2]; String author = (String) fields[3]; XWikiPageHistorySummary pageHistory = new XWikiPageHistorySummary(); pageHistory.setId(pageId); pageHistory.setVersion(nodeId.getVersion().at(0)); pageHistory.setMinorVersion(nodeId.getVersion().at(1)); pageHistory.setModified(new Date(timestamp.getTime())); pageHistory.setModifier(author); result.add(pageHistory.toRawMap()); } return result; }
From source file:com.google.gerrit.acceptance.server.notedb.ChangeRebuilderIT.java
@Test public void rebuilderRespectsReadOnlyInNoteDbChangeState() throws Exception { TestTimeUtil.resetWithClockStep(1, SECONDS); PushOneCommit.Result r = createChange(); PatchSet.Id psId1 = r.getPatchSetId(); Change.Id id = psId1.getParentKey(); checker.rebuildAndCheckChanges(id);//from ww w. j a v a 2 s.c om setNotesMigration(true, true); ReviewDb db = getUnwrappedDb(); Change c = db.changes().get(id); NoteDbChangeState state = NoteDbChangeState.parse(c); Timestamp until = new Timestamp(TimeUtil.nowMs() + MILLISECONDS.convert(1, DAYS)); state = state.withReadOnlyUntil(until); c.setNoteDbState(state.toString()); db.changes().update(Collections.singleton(c)); try { rebuilderWrapper.rebuild(db, id); assert_().fail("expected rebuild to fail"); } catch (OrmRuntimeException e) { assertThat(e.getMessage()).contains("read-only until"); } TestTimeUtil.setClock(new Timestamp(until.getTime() + MILLISECONDS.convert(1, SECONDS))); rebuilderWrapper.rebuild(db, id); }
From source file:com.collabnet.ccf.core.AbstractReader.java
public String getArtifactLastModifiedTime(Document syncInfo) { Node node = syncInfo.selectSingleNode(ARTIFACT_LAST_MODIFIED_DATE); if (node == null) return null; String dbTime = node.getText(); if (!StringUtils.isEmpty(dbTime)) { java.sql.Timestamp ts = java.sql.Timestamp.valueOf(dbTime); long time = ts.getTime(); Date date = new Date(time); return DateUtil.format(date); }//w ww . j a v a2 s .c om return null; }
From source file:com.collabnet.ccf.core.AbstractReader.java
/** * Extracts and returns the last modified time of the artifact that was * sync-ed last./*from www . j av a2 s . c om*/ * * @param syncInfo * @return */ public String getLastSourceArtifactModificationDate(Document syncInfo) { // LAST_SOURCE_ARTIFACT_MODIFICATION_DATE Node node = syncInfo.selectSingleNode(LAST_SOURCE_ARTIFACT_MODIFICATION_DATE); if (node == null) return null; String dbTime = node.getText(); if (!StringUtils.isEmpty(dbTime)) { java.sql.Timestamp ts = java.sql.Timestamp.valueOf(dbTime); long time = ts.getTime(); Date date = new Date(time); return DateUtil.format(date); } return null; }
From source file:cz.incad.kramerius.processes.impl.DatabaseProcessManager.java
private LRProcess processFromResultSet(ResultSet rs) throws SQLException { // CREATE TABLE PROCESSES(DEFID VARCHAR, UUID VARCHAR ,PID // VARCHAR,STARTED timestamp, STATUS int String definitionId = rs.getString("DEFID"); String pid = rs.getString("PID"); String uuid = rs.getString("UUID"); int status = rs.getInt("STATUS"); Timestamp planned = rs.getTimestamp("PLANNED"); Timestamp started = rs.getTimestamp("STARTED"); Timestamp finished = rs.getTimestamp("FINISHED"); String name = rs.getString("PNAME"); String params = rs.getString("PARAMS"); String token = rs.getString("TOKEN"); String authToken = rs.getString("AUTH_TOKEN"); int startedBy = rs.getInt("STARTEDBY"); String loginname = rs.getString("LOGINNAME"); String firstname = rs.getString("FIRSTNAME"); String surname = rs.getString("SURNAME"); String userKey = rs.getString("USER_KEY"); String paramsMapping = rs.getString("params_mapping"); int batchStatus = rs.getInt("BATCH_STATUS"); String ipAddr = rs.getString("IP_ADDR"); LRProcessDefinition definition = this.lrpdm.getLongRunningProcessDefinition(definitionId); if (definition == null) { throw new RuntimeException("cannot find definition '" + definitionId + "'"); }/*from w ww . ja v a 2 s. co m*/ LRProcess process = definition.loadProcess(uuid, pid, planned != null ? planned.getTime() : 0, States.load(status), BatchStates.load(batchStatus), name); process.setGroupToken(token); process.setAuthToken(authToken); if (started != null) process.setStartTime(started.getTime()); if (params != null) { String[] paramsArray = params.split(","); process.setParameters(Arrays.asList(paramsArray)); } process.setFirstname(firstname); process.setSurname(surname); process.setLoginname(loginname); process.setLoggedUserKey(userKey); if (paramsMapping != null) { Properties props = PropertiesStoreUtils.loadProperties(paramsMapping); process.setParametersMapping(props); } if (finished != null) { process.setFinishedTime(finished.getTime()); } if (ipAddr != null) { process.setPlannedIPAddress(ipAddr); } return process; }
From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java
public void addItem(NoteWrapper nw) throws DAOException { if (log.isTraceEnabled()) { log.trace("PIMNoteDAO addItem begin"); }/*w w w . j a va2 s . c o m*/ Connection con = null; PreparedStatement ps = null; long id = 0; String sId = null; Timestamp lastUpdate = nw.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); // calculate table row id sId = nw.getId(); if (sId == null) { // ...as it should be sId = getNextID(); nw.setId(sId); } id = Long.parseLong(sId); ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_NOTE); int k = 1; // // GENERAL // if (log.isTraceEnabled()) { log.trace("Preparing statement with ID " + id); } ps.setLong(k++, id); if (log.isTraceEnabled()) { log.trace("Preparing statement with user ID " + userId); } ps.setString(k++, userId); ps.setLong(k++, lastUpdate.getTime()); ps.setString(k++, String.valueOf(Def.PIM_STATE_NEW)); Note note = nw.getNote(); ps.setString(k++, StringUtils.left(note.getSubject().getPropertyValueAsString(), SQL_SUBJECT_DIM)); String textDescription = note.getTextDescription().getPropertyValueAsString(); if (textDescription != null) { textDescription = textDescription.replace('\0', ' '); } String truncatedTextDescription = StringUtils.left(textDescription, SQL_TEXTDESCRIPTION_DIM); ps.setString(k++, truncatedTextDescription); ps.setString(k++, truncateCategoriesField(note.getCategories().getPropertyValueAsString(), SQL_CATEGORIES_DIM)); ps.setString(k++, truncateFolderField(note.getFolder().getPropertyValueAsString(), SQL_FOLDER_DIM)); Property color = note.getColor(); Property height = note.getHeight(); Property width = note.getWidth(); Property top = note.getTop(); Property left = note.getLeft(); if (Property.isEmptyProperty(color)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(color.getPropertyValueAsString())); } if (Property.isEmptyProperty(height)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(height.getPropertyValueAsString())); } if (Property.isEmptyProperty(width)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(width.getPropertyValueAsString())); } if (Property.isEmptyProperty(top)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(top.getPropertyValueAsString())); } if (Property.isEmptyProperty(left)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(left.getPropertyValueAsString())); } Long crc = calculateCrc(truncatedTextDescription); if (crc == null) { ps.setNull(k++, Types.BIGINT); } else { ps.setLong(k++, crc); } ps.executeUpdate(); } catch (Exception e) { throw new DAOException("Error adding note.", e); } finally { DBTools.close(con, ps, null); } if (log.isTraceEnabled()) { log.trace("Added item with ID " + id); log.trace("PIMNoteDAO addItem end"); } }
From source file:com.github.nmorel.gwtjackson.shared.annotations.JsonFormatTester.java
public void testFormatDate(ObjectMapperTester<FormatDateBean> mapper) { long millis = getUTCTime(2013, 12, 25, 0, 0, 0, 0); Date date = new Date(millis); Timestamp timestamp = new Timestamp(millis); FormatDateBean bean = new FormatDateBean(new Date(millis)); bean.dateString = date;/*from ww w .ja v a2 s . co m*/ bean.dateNumber = date; bean.dateParis = date; bean.dateLosAngeles = date; bean.date = date; bean.timestampString = timestamp; bean.timestampNumber = timestamp; bean.timestampParis = timestamp; bean.timestampLosAngeles = timestamp; bean.timestamp = timestamp; String expected = "{" + "\"dateInParameter\":\"P2013/12/25\"," + "\"dateString\":\"/2013/12/25/\"," + "\"dateNumber\":" + millis + "," + "\"dateParis\":\"2013-12-25T01:00:00.000+0100\"," + "\"dateLosAngeles\":\"2013-12-24 16:00:00.000 -0800\"," + "\"date\":\"2013-12-25T00:00:00.000+0000\"," + "\"timestampString\":\"/2013/12/25/\"," + "\"timestampNumber\":" + millis + "," + "\"timestampParis\":\"2013-12-25T01:00:00.000+0100\"," + "\"timestampLosAngeles\":\"2013-12-24 16:00:00.000 -0800\"," + "\"timestamp\":\"2013-12-25T00:00:00.000+0000\"" + "}"; String result = mapper.write(bean); assertEquals(expected, result); FormatDateBean actual = mapper.read(expected); assertEquals(date, actual.dateString); assertEquals(date, actual.dateNumber); assertEquals(date.getTime(), actual.dateParis.getTime()); assertEquals(date.getTime(), actual.dateLosAngeles.getTime()); assertEquals(date, actual.date); assertEquals(date, actual.dateInParameter); assertEquals(timestamp, actual.timestampString); assertEquals(timestamp, actual.timestampNumber); assertEquals(timestamp.getTime(), actual.timestampParis.getTime()); assertEquals(timestamp.getTime(), actual.timestampLosAngeles.getTime()); assertEquals(timestamp, actual.timestamp); }
From source file:fedora.server.access.dissemination.DisseminationService.java
/** * <p>/* w w w. ja v a 2s. com*/ * Datastream locations are considered privileged information by the Fedora * repository. To prevent disclosing physical datastream locations to * external mechanism services, a proxy is used to disguise the datastream * locations. This method generates a temporary ID that maps to the physical * datastream location and registers this information in a memory resident * hashtable for subsequent resolution of the physical datastream location. * The servlet <code>DatastreamResolverServlet</code> provides the proxy * resolution service for datastreams. * </p> * <p> * </p> * <p> * The format of the tempID is derived from <code>java.sql.Timestamp</code> * with an arbitrary counter appended to the end to insure uniqueness. The * syntax is of the form: * <ul> * <p> * YYYY-MM-DD HH:mm:ss.mmm:dddddd where * </p> * <ul> * <li>YYYY - year (1900-8099)</li> * <li>MM - month (01-12)</li> * <li>DD - day (01-31)</li> * <li>hh - hours (0-23)</li> * <li>mm - minutes (0-59)</li> * <li>ss - seconds (0-59)</li> * <li>mmm - milliseconds (0-999)</li> * <li>dddddd - incremental counter (0-999999)</li> * </ul> * </ul> * * @param dsLocation * The physical location of the datastream. * @param dsControlGroupType * The type of the datastream. * @return A temporary ID used to reference the physical location of the * specified datastream * @throws ServerException * If an error occurs in registering a datastream location. */ public String registerDatastreamLocation(String dsLocation, String dsControlGroupType, String beServiceCallbackRole, String methodName) throws ServerException { String tempID = null; Timestamp timeStamp = null; if (counter > 999999) { counter = 0; } long currentTime = new Timestamp(new Date().getTime()).getTime(); long expireLimit = currentTime - (long) datastreamExpirationLimit * 1000; String dsMediatedServletPath = null; String dsMediatedCallbackHost = null; try { // Remove any datastream registrations that have expired. // The expiration limit can be adjusted using the Fedora config parameter // named "datastreamExpirationLimit" which is in seconds. for (Enumeration e = dsRegistry.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); timeStamp = Timestamp.valueOf(extractTimestamp(key)); if (expireLimit > timeStamp.getTime()) { dsRegistry.remove(key); LOG.debug("DatastreamMediationKey removed from Hash: " + key); } } // Register datastream. if (tempID == null) { timeStamp = new Timestamp(new Date().getTime()); tempID = timeStamp.toString() + ":" + counter++; DatastreamMediation dm = new DatastreamMediation(); dm.mediatedDatastreamID = tempID; dm.dsLocation = dsLocation; dm.dsControlGroupType = dsControlGroupType; dm.methodName = methodName; // See if datastream reference is to fedora server itself or an external location. // M and X type datastreams always reference fedora server. With E type datastreams // we must examine URL to see if this is referencing a remote datastream or is // simply a callback to the fedora server. If the reference is remote, then use // the role of the backend service that will make a callback for this datastream. // If the referenc s to the fedora server, use the special role of "fedoraInternalCall-1" to // denote that the callback will come from the fedora server itself. String beServiceRole = null; if (ServerUtility.isURLFedoraServer(dsLocation) || dsControlGroupType.equals("M") || dsControlGroupType.equals("X")) { beServiceRole = BackendPolicies.FEDORA_INTERNAL_CALL; } else { beServiceRole = beServiceCallbackRole; } // Store beSecurity info in hash Hashtable beHash = m_beSS.getSecuritySpec(beServiceRole, methodName); boolean beServiceCallbackBasicAuth = new Boolean((String) beHash.get("callbackBasicAuth")) .booleanValue(); boolean beServiceCallBasicAuth = new Boolean((String) beHash.get("callBasicAuth")).booleanValue(); boolean beServiceCallbackSSL = new Boolean((String) beHash.get("callbackSSL")).booleanValue(); boolean beServiceCallSSL = new Boolean((String) beHash.get("callSSL")).booleanValue(); String beServiceCallUsername = (String) beHash.get("callUsername"); String beServiceCallPassword = (String) beHash.get("callPassword"); if (LOG.isDebugEnabled()) { LOG.debug("******************Registering datastream dsLocation: " + dsLocation); LOG.debug("******************Registering datastream dsControlGroupType: " + dsControlGroupType); LOG.debug("******************Registering datastream beServiceRole: " + beServiceRole); LOG.debug("******************Registering datastream beServiceCallbackBasicAuth: " + beServiceCallbackBasicAuth); LOG.debug("******************Registering datastream beServiceCallBasicAuth: " + beServiceCallBasicAuth); LOG.debug("******************Registering datastream beServiceCallbackSSL: " + beServiceCallbackSSL); LOG.debug("******************Registering datastream beServiceCallSSL: " + beServiceCallSSL); LOG.debug("******************Registering datastream beServiceCallUsername: " + beServiceCallUsername); LOG.debug("******************Registering datastream beServiceCallPassword: " + beServiceCallPassword); } dm.callbackRole = beServiceRole; dm.callUsername = beServiceCallUsername; dm.callPassword = beServiceCallPassword; dm.callbackBasicAuth = beServiceCallbackBasicAuth; dm.callBasicAuth = beServiceCallBasicAuth; dm.callbackSSL = beServiceCallbackSSL; dm.callSSL = beServiceCallSSL; dsRegistry.put(tempID, dm); LOG.debug("DatastreammediationKey added to Hash: " + tempID); } } catch (Throwable th) { throw new DisseminationException("[DisseminationService] register" + "DatastreamLocation: " + "returned an error. The underlying error was a " + th.getClass().getName() + " The message " + "was \"" + th.getMessage() + "\" ."); } // Replace the blank between date and time with the character "T". return tempID.replaceAll(" ", "T"); }