List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:cn.mypandora.service.TestDeptService.java
@Test public void updateDept() { BaseDept dept = service.findDeptById(5L); dept.setName(""); dept.setLft(99999999);//from ww w . ja v a 2s .c o m dept.setUpdateTime(new Timestamp(System.currentTimeMillis())); service.updateDept(dept); }
From source file:ru.org.linux.user.LostPasswordController.java
@RequestMapping(method = RequestMethod.POST) public ModelAndView sendPassword(@RequestParam("email") String email, HttpServletRequest request) throws Exception { Template tmpl = Template.getTemplate(request); if (Strings.isNullOrEmpty(email)) { throw new BadInputException("email "); }// w w w .j ava2s . c o m User user = userDao.getByEmail(email, true); if (user == null) { throw new BadInputException(" email ?!"); } user.checkBlocked(); user.checkAnonymous(); if (user.isModerator() && !tmpl.isModeratorSession()) { throw new AccessViolationException( "? ?? "); } if (!tmpl.isModeratorSession() && !userDao.canResetPassword(user)) { throw new BadInputException( "?? !"); } Timestamp now = new Timestamp(System.currentTimeMillis()); try { sendEmail(user, email, now); userDao.updateResetDate(user, now); return new ModelAndView("action-done", "message", "?? ?? ? email"); } catch (AddressException ex) { throw new UserErrorException("Incorrect email address"); } }
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;/* w ww .j a va 2s . c om*/ 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:com.pinterest.pinlater.backends.mysql.MySQLQueueMonitor.java
@Override protected void jobMonitorImpl(long runStartMillis, Map.Entry<String, MySQLDataSources> shard, int numAutoRetries) { Connection conn = null;/*from w w w .ja va 2s. c om*/ ResultSet dbNameRs = null; Timestamp succeededGCTimestamp = new Timestamp(runStartMillis - getJobSucceededGCTimeoutMillis()); Timestamp failedGCTimestamp = new Timestamp(runStartMillis - getJobFailedGCTimeoutMillis()); Timestamp timeoutTimestamp = new Timestamp(runStartMillis - getJobClaimedTimeoutMillis()); try { conn = shard.getValue().getMonitorDataSource().getConnection(); Set<String> queueNames = MySQLBackendUtils.getQueueNames(conn, shard.getKey()); for (String queueName : queueNames) { for (int priority = 1; priority <= numPriorityLevels; priority++) { String jobsTableName = MySQLBackendUtils.constructJobsTableName(queueName, shard.getKey(), priority); // Handle timed out jobs with attempts exhausted. numTimeoutDone += JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.MONITOR_TIMEOUT_DONE_UPDATE, jobsTableName), PinLaterJobState.FAILED.getValue(), PinLaterJobState.IN_PROGRESS.getValue(), timeoutTimestamp, getUpdateMaxSize()); // Handle timed out jobs with attempts remaining. numTimeoutRetry += JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.MONITOR_TIMEOUT_RETRY_UPDATE, jobsTableName), PinLaterJobState.PENDING.getValue(), PinLaterJobState.IN_PROGRESS.getValue(), timeoutTimestamp, getUpdateMaxSize()); // Succeeded job GC. numSucceededGC += JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.MONITOR_GC_DONE_JOBS, jobsTableName), PinLaterJobState.SUCCEEDED.getValue(), succeededGCTimestamp, getUpdateMaxSize()); // Failed job GC. numFailedGC += JdbcUtils.executeUpdate(conn, String.format(MySQLQueries.MONITOR_GC_DONE_JOBS, jobsTableName), PinLaterJobState.FAILED.getValue(), failedGCTimestamp, getUpdateMaxSize()); logCount++; if (logCount % getLogInterval() == 0) { LOG.info(String.format( "JobQueueMonitor: " + "Shard: %s Queue: %s Priority: %d Timeout Done: %d Timeout Retry: %d " + "Succeeded GC: %d Failed GC: %d", shard.getKey(), queueName, priority, numTimeoutDone, numTimeoutRetry, numSucceededGC, numFailedGC)); Stats.incr(queueName + "_timeout_done", numTimeoutDone); Stats.incr(queueName + "_timeout_retry", numTimeoutRetry); Stats.incr(queueName + "_succeeded_gc", numSucceededGC); Stats.incr(queueName + "_failed_gc", numFailedGC); logCount = 0; numTimeoutDone = 0; numTimeoutRetry = 0; numSucceededGC = 0; numFailedGC = 0; } } } } catch (Exception e) { // Deadlocks are occasionally expected for our high-contention queries. We // retry a few times so as not to abort an entire monitor cycle. if (MySQLBackendUtils.isDeadlockException(e) && numAutoRetries > 0) { Stats.incr("mysql-deadlock-monitor"); jobMonitorImpl(runStartMillis, shard, numAutoRetries - 1); } else { LOG.error("Exception in JobQueueMonitor task", e); } } finally { JdbcUtils.closeResultSet(dbNameRs); JdbcUtils.closeConnection(conn); } }
From source file:dsd.dao.ParsedInputFilesDAO.java
public static String FetchStoredPath(eFileType fileType, Calendar date) { String storedPath = null;/*ww w .j av a2s . co m*/ try { Connection con = DAOProvider.getDataSource().getConnection(); try { Object[] parameters = new Object[3]; parameters[0] = new Integer(fileType.getCode()); parameters[1] = new Integer(fileType.getCode()); parameters[2] = new Timestamp(date.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, " stored_path ", " type = ? and timestamp = (select max(timestamp) from parsed_input_files where type = ? and timestamp <= ?) ", "", con, parameters); while (results.next()) { storedPath = results.getString(1); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); } catch (Exception exc) { exc.printStackTrace(); } return storedPath; }
From source file:com.gisgraphy.util.DateConverter.java
/** * Convert a String to a Date with the specified pattern. * /* w w w . j a v a 2 s . c om*/ * @param type * String * @param value * value of String * @param pattern * date pattern to parse with * @return Converted value for property population */ @SuppressWarnings("unchecked") protected Object convertToDate(Class type, Object value, String pattern) { DateFormat df = new SimpleDateFormat(pattern); if (value instanceof String) { try { if (StringUtils.isEmpty(value.toString())) { return null; } Date date = df.parse((String) value); if (type.equals(Timestamp.class)) { return new Timestamp(date.getTime()); } return date; } catch (Exception pe) { throw new ConversionException("Error converting String to Date"); } } throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName()); }
From source file:controllers.LoginController.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww. j av a 2s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); //User user = (User) request.getAttribute("user"); //if (user != null) { // User has been already registered //response.sendRedirect(request.getContextPath() + "/home"); //} else { // Login in user String email = request.getParameter("email"), password = request.getParameter("pass"); JSONObject object = null; object = (JSONObject) ISConnector.validateLogin(email, password); if (object.containsKey("token")) { Cookie cookie = new Cookie("token", (String) object.get("token")); cookie.setPath("/"); long expiredDate = -1; if (object.containsKey("expiry_date")) { expiredDate = (long) object.get("expiry_date") - new Timestamp(new Date().getTime()).getTime(); expiredDate /= 1000; cookie.setMaxAge((int) expiredDate); } response.addCookie(cookie); response.sendRedirect(request.getContextPath() + "/home"); } else if (object.containsKey("error")) { request.setAttribute("error", (String) object.get("error")); String error = (String) object.get("error"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet coba2</title>"); out.println("</head>"); out.println("<body>"); out.println(error); out.println("</body>"); out.println("</html>"); } //doGet(request, response); } else { try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet coba2</title>"); out.println("</head>"); out.println("<body>"); out.println(object); out.println("</body>"); out.println("</html>"); } } //} }
From source file:com.adanac.module.blog.dao.RecordDao.java
public Integer save(String username, String title, String record, String content) { return execute(new TransactionalOperation<Integer>() { @Override// w w w . j a v a 2s . c om public Integer doInConnection(Connection connection) { String sql = "insert into records (username,title,record,content,create_date) values (?,?,?,?,?)"; try { PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); statement.setString(1, username); statement.setString(2, title); statement.setString(3, record); statement.setString(4, content); statement.setTimestamp(5, new Timestamp(System.currentTimeMillis())); int result = statement.executeUpdate(); if (result > 0) { ResultSet keyResultSet = statement.getGeneratedKeys(); if (keyResultSet.next()) { return keyResultSet.getInt(1); } } } catch (SQLException e) { throw new RuntimeException(e); } return null; } }); }
From source file:se.crisp.codekvast.warehouse.file_import.ImportDAOImpl.java
@Override public void recordFileAsImported(ExportFileMetaInfo metaInfo, ImportStatistics importStatistics) { if (isFileImported(metaInfo)) { log.warn("Rejecting import of {}", metaInfo); } else {/*w w w . ja v a 2 s . c om*/ jdbcTemplate.update( "INSERT INTO import_file_info(uuid, fileSchemaVersion, fileName, fileLengthBytes, importedAt, " + "importTimeMillis, " + "daemonHostname, daemonVersion, daemonVcsId, environment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", metaInfo.getUuid(), metaInfo.getSchemaVersion(), importStatistics.getImportFile().getPath(), importStatistics.getImportFile().length(), new Timestamp(System.currentTimeMillis()), importStatistics.getProcessingTime().toMillis(), metaInfo.getDaemonHostname(), metaInfo.getDaemonVersion(), metaInfo.getDaemonVcsId(), metaInfo.getEnvironment()); log.info("Imported {} {}", metaInfo, importStatistics); } }
From source file:de.tuttas.restful.VertretungsManager.java
/** * Absenz Meldung abgeben/*from w ww. j av a2 s. co m*/ * @param vo Vetretungsobjekt * @return Vertertungsobjekt mit ID oder NULL bei Fehlern */ @POST public VertretungsObject addVertretung(VertretungsObject vo) { Log.d("POST Vertretungsmanager"); Vertretung v = new Vertretung(vo.getEingereichtVon(), null, vo.getAbsenzLehrer(), new Timestamp(vo.getAbsenzAm().getTime()), ""); v.setKommentar(vo.getKommentar()); v.setEingereichtAm(new Timestamp(System.currentTimeMillis())); Log.d("setVertertung " + v.toString()); JSONArray ja = new JSONArray(); if (vo.getEintraege() != null) { String vorschlag = ""; klassenlehrerStorage.clear(); vertertungslehrerStorage.clear(); String content = loadTemplate(); Lehrer absender = em.find(Lehrer.class, vo.getEingereichtVon()); if (absender == null) { vo.setSuccess(false); vo.setMsg("Kann Absender Lehrer mit Krzel " + vo.getEingereichtVon() + " nicht finden!"); return vo; } if (absender.getEMAIL() == null) { vo.setSuccess(false); vo.setMsg("Absender keine EMail Adresse hinterlegt!"); return vo; } MailObject mo; try { mo = new MailObject(absender.getEMAIL(), null, null); } catch (MailFormatException ex) { vo.setSuccess(false); vo.setMsg(ex.getMessage()); return vo; } Lehrer absentLehrer = em.find(Lehrer.class, vo.getAbsenzLehrer()); if (absentLehrer == null) { vo.setSuccess(false); vo.setMsg("Kann Lehrer mit Krzel " + vo.getAbsenzLehrer() + " nicht finden!"); return vo; } if (absentLehrer.getEMAIL() == null) { vo.setWarning(true); vo.getWarningMsg().add("Fr absenten Lehrer mit ID " + absentLehrer.getId() + " ist keine EMail Adresse hinterlegt!"); } else { try { mo.addCC(absentLehrer.getEMAIL()); } catch (AddressException ex) { vo.setWarning(true); vo.getWarningMsg().add(ex.getMessage()); } catch (MailFormatException ex) { vo.setWarning(true); vo.getWarningMsg().add(ex.getMessage()); } } String subject = "Vertretungsvorschlag fr " + absentLehrer.getVNAME() + " " + absentLehrer.getNNAME() + "(" + absentLehrer.getId() + ") am " + vo.getAbsenzAm().toString(); mo.setSubject(subject); content = content.replace("[[ABSENZ]]", absentLehrer.getVNAME() + " " + absentLehrer.getNNAME()); content = content.replace("[[DATUM]]", vo.getAbsenzAm().toString()); content = content.replace("[[ABS]]", absender.getVNAME() + " " + absender.getNNAME()); if (vo.getKommentar() != null) { content = content.replace("[[KOMMENTAR]]", vo.getKommentar()); } else { content = content.replace("[[KOMMENTAR]]", ""); } for (Vetretungseintrag e : vo.getEintraege()) { ja.add(e.toJson()); Klasse klasse = em.find(Klasse.class, e.getIdKlasse()); if (klasse == null) { vo.setWarning(true); vo.getWarningMsg().add("Kann Klasse mit ID " + e.getIdKlasse() + " nicht finden!"); } else { String bem = "Vetretungsregelung fr " + vo.getAbsenzLehrer() + ":"; String von = ""; if (e.getAktion().equals("entfllt")) { bem += e.getAktion() + " " + e.getKommentar(); von = vo.getEingereichtVon(); } else { bem += e.getAktion() + " durch " + e.getVertreter() + " " + e.getKommentar(); von = e.getVertreter(); } String std = ""; if (e.getStunde() <= 9) { std += "0" + e.getStunde(); } else { std += "" + e.getStunde(); } Verlauf ver = new Verlauf(e.getIdKlasse(), new Timestamp(vo.getAbsenzAm().getTime()), std, von, "LF19", "N.N", bem, ""); em.merge(ver); em.flush(); if (klasse.getID_LEHRER() == null) { vo.setWarning(true); vo.getWarningMsg() .add("Der Klasse " + e.getKlasse() + " ist kein Klassenlehrer zugeordnet!"); } else { Lehrer klassenlehrer = em.find(Lehrer.class, klasse.getID_LEHRER()); if (klassenlehrer == null) { vo.setWarning(true); vo.getWarningMsg().add("Kann Klassenlehrer der Klasse " + klasse.getKNAME() + " mit Krzel " + klasse.getID_LEHRER() + " nicht finden!"); } else { if (klassenlehrer.getEMAIL() == null) { vo.setWarning(true); vo.getWarningMsg().add("Dem Klassenlehrer der Klasse " + klasse.getKNAME() + " mit Krzel " + klasse.getID_LEHRER() + " ist keine EMail zugeordnet!"); } else { if (!klassenlehrerStorage.containsKey(klassenlehrer.getId())) { klassenlehrerStorage.put(klassenlehrer.getId(), klassenlehrer.getEMAIL()); try { mo.addCC(klassenlehrer.getEMAIL()); } catch (AddressException ex) { vo.setSuccess(false); vo.setMsg(ex.getMessage()); return vo; } catch (MailFormatException ex) { vo.setWarning(true); vo.getWarningMsg().add(ex.getMessage()); } } } } } } if (e.getVertreter() != null && !e.getVertreter().equals("")) { Lehrer vertreter = em.find(Lehrer.class, e.getVertreter()); if (vertreter == null) { vo.setWarning(true); vo.getWarningMsg() .add("Kann Vertretungslehrer mit Krzel " + e.getVertreter() + " nicht finden!"); } else { vorschlag += " Stunde:" + e.getStunde() + " Klasse:" + e.getKlasse() + " (" + klasse.getID_LEHRER() + ") [" + e.getAktion() + "] " + vertreter.getVNAME() + " " + vertreter.getNNAME() + " (" + vertreter.getId() + ") " + e.getKommentar() + "\n"; if (vertreter.getEMAIL() == null) { vo.setWarning(true); vo.getWarningMsg().add("Dem Vertretungslehrer mit Krzel " + vertreter.getId() + " ist keine EMail zugeordnet!"); } else { if (!vertertungslehrerStorage.containsKey(vertreter.getEMAIL())) { vertertungslehrerStorage.put(vertreter.getId(), vertreter.getEMAIL()); } try { mo.addCC(vertreter.getEMAIL()); } catch (AddressException ex) { Logger.getLogger(VertretungsManager.class.getName()).log(Level.SEVERE, null, ex); } catch (MailFormatException ex) { vo.setWarning(true); vo.getWarningMsg().add(ex.getMessage()); } } } } else { vorschlag += " Stunde:" + e.getStunde() + " Klasse:" + e.getKlasse() + " (" + klasse.getID_LEHRER() + ") [" + e.getAktion() + "] " + e.getKommentar() + "\n"; } } content = content.replace("[[VOSCHLAEGE]]", vorschlag); mo.setContent(content); v.setJsonString(ja.toJSONString()); em.merge(v); em.flush(); try { mo.addRecipient("stundenplan@mmbbs.de"); } catch (AddressException ex) { Logger.getLogger(VertretungsManager.class.getName()).log(Level.SEVERE, null, ex); } catch (MailFormatException ex) { Logger.getLogger(VertretungsManager.class.getName()).log(Level.SEVERE, null, ex); } MailSender.getInstance().sendMail(mo); vo.setSuccess(true); vo.setMsg( "Vertretung eingereicht! EMail vesrendet an stundenplan@mmbbs.de und Kollegen und Kolleginnen benachtichtig!"); } else { vo.setSuccess(false); vo.setMsg("Keine Vertretungseintrge"); } return vo; }