List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:org.zenoss.zep.dao.impl.compat.DatabaseCompatibilityPostgreSQL.java
@Override public TypeConverter<Long> getTimestampConverter() { return new TypeConverter<Long>() { @Override/* ww w.java2s . co m*/ public Long fromDatabaseType(ResultSet rs, String columnName) throws SQLException { Timestamp ts = rs.getTimestamp(columnName); return (ts != null) ? ts.getTime() : null; } @Override public Object toDatabaseType(Long timestampInMillis) { if (timestampInMillis == null) { return null; } return new Timestamp(timestampInMillis); } }; }
From source file:com.egt.core.jsf.component.Calendario.java
private Date obj2Date(Object arg0) { if (arg0 instanceof Timestamp) { return (Timestamp) arg0; } else if (arg0 instanceof Date) { Date date = (Date) arg0; java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(date);/*from ww w . j a v a 2 s . co m*/ return new Timestamp(calendar.getTimeInMillis()); } else { return null; } }
From source file:gov.nih.nci.cabig.caaers.service.migrator.EvaluateAndInitiateReportConverter.java
public ExpeditedAdverseEventReport convert(EvaluateAndInitiateInputMessage evaluateInputMessage, AdverseEventReportingPeriod repPeriod, SaveAndEvaluateAEsOutputMessage response) { Timestamp now = new Timestamp(System.currentTimeMillis()); ExpeditedAdverseEventReport aeSrcReport = new ExpeditedAdverseEventReport(); for (AdverseEvent adverseEvent : repPeriod.getAdverseEvents()) { if (isTrue(adverseEvent.getRequiresReporting()) || (!isTrue(adverseEvent.isRetired()) && isTrue(adverseEvent.getReported()))) { aeSrcReport.addAdverseEventUnidirectional(adverseEvent); }/*w ww. java2 s . c o m*/ } aeSrcReport.setExternalId(evaluateInputMessage.getReportId()); aeSrcReport.setReporter(utility.convertReporter(evaluateInputMessage.getReporter())); aeSrcReport.setPhysician(utility.convertPhysician(evaluateInputMessage.getPhysician())); aeSrcReport.setCreatedAt(now); aeSrcReport.setReportingPeriod(repPeriod); List<Report> reports = new ArrayList<Report>(); aeSrcReport.setReports(reports); if (CollectionUtils.isNotEmpty(response.getRecommendedActions())) { for (RecommendedActions action : response.getRecommendedActions()) { Report report = new Report(); report.setReportDefinition(reportDefinitionDao.getByName(action.getReport())); if (BooleanUtils.isTrue(evaluateInputMessage.isWithdrawReport()) || StringUtils.equalsIgnoreCase("Withdraw", action.getAction())) { report.setWithdrawnOn(now); } report.setCaseNumber(evaluateInputMessage.getReportId()); reports.add(report); } } return aeSrcReport; }
From source file:name.richardson.james.bukkit.alias.persistence.PlayerNameRecordManager.java
public PlayerNameRecord create(String playerName) { PlayerNameRecord record = find(playerName); if (record == null) { logger.log(Level.FINER, "Creating new PlayerNameRecord for {0}.", playerName); record = new PlayerNameRecord(); record.setPlayerName(playerName); record.setLastSeen(new Timestamp(System.currentTimeMillis())); save(record);//from ww w . j a v a2s.c o m record = find(playerName); } return record; }
From source file:net.mindengine.oculus.frontend.service.report.filter.JdbcFilterDAO.java
@Override public long createFilter(Filter filter) throws Exception { String sql = "insert into filters (name, description, user_id, date, filter) values (?,?,?,?,?)"; PreparedStatement ps = getConnection().prepareStatement(sql); ps.setString(1, filter.getName());// w w w . j ava 2 s . c o m ps.setString(2, filter.getDescription()); ps.setLong(3, filter.getUserId()); ps.setTimestamp(4, new Timestamp(filter.getDate().getTime())); ps.setString(5, filter.getFilter()); logger.info(ps); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getLong(1); } return 0; }
From source file:com.bitranger.parknshop.seller.controller.SellerApplyShopCtrl.java
@RequestMapping(value = "/seller/applyShop", method = RequestMethod.GET) public void applyShop(HttpServletRequest request, HttpServletResponse response) throws IOException { PsSeller psSeller = (PsSeller) request.getSession().getAttribute("currentSeller"); String message = request.getParameter("msg"); PsShopApply psShopApply = new PsShopApply(); psShopApply.setIdSeller(psSeller.getId()); psShopApply.setMessage(message);/*from w ww . j ava 2 s . c o m*/ psShopApply.setTimeCreated(new Timestamp(System.currentTimeMillis())); psShopApplyDAO.save(psShopApply); PrintWriter out = response.getWriter(); out.write("success"); out.flush(); out.close(); }
From source file:com.josue.lottery.eap.persistence.entity.rest.Resource.java
public void setDateCreated(Date dateCreated) { this.dateCreated = new Timestamp(dateCreated.getTime()); }
From source file:iddb.web.security.dao.SessionDAO.java
public void insert(Session session) { String sql;// w w w . j a va2 s.co m sql = "insert into user_session (id, userid, ip, created) values (?,?,?,?)"; Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, session.getKey()); st.setLong(2, session.getUserId()); st.setString(3, session.getIp()); st.setTimestamp(4, new Timestamp(new Date().getTime())); st.executeUpdate(); } catch (SQLException e) { log.error("insert", e); } catch (IOException e) { log.error("insert", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:com.daon.identityx.entity.Account.java
public Account(CreateAccount createUser) { this.firstName = createUser.getFirstName(); this.lastName = createUser.getLastName(); this.email = createUser.getEmail(); this.createdDTM = new Timestamp(System.currentTimeMillis()); }
From source file:com.chaosinmotion.securechat.server.commands.ForgotPassword.java
/** * Process a forgot password request. This generates a token that the * client is expected to return with the change password request. * @param requestParams/* w ww .jav a 2 s . co m*/ * @throws SQLException * @throws IOException * @throws ClassNotFoundException * @throws JSONException * @throws NoSuchAlgorithmException */ public static void processRequest(JSONObject requestParams) throws SQLException, ClassNotFoundException, IOException, NoSuchAlgorithmException, JSONException { String username = requestParams.optString("username"); /* * Step 1: Convert username to the userid for this */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; int userID = 0; String retryID = UUID.randomUUID().toString(); try { c = Database.get(); ps = c.prepareStatement("SELECT userid " + "FROM Users " + "WHERE username = ?"); ps.setString(1, username); rs = ps.executeQuery(); if (rs.next()) { userID = rs.getInt(1); } if (userID == 0) return; ps.close(); rs.close(); /* * Step 2: Generate the retry token and insert into the forgot * database with an expiration date 1 hour from now. */ Timestamp ts = new Timestamp(System.currentTimeMillis() + 3600000); ps = c.prepareStatement("INSERT INTO ForgotPassword " + " ( userid, token, expires ) " + "VALUES " + " ( ?, ?, ?)"); ps.setInt(1, userID); ps.setString(2, retryID); ps.setTimestamp(3, ts); ps.execute(); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } /* * Step 3: formulate a JSON string with the retry and send * to the user. The format of the command we send is: * * { "cmd": "forgotpassword", "token": token } */ JSONObject obj = new JSONObject(); obj.put("cmd", "forgotpassword"); obj.put("token", retryID); MessageQueue.getInstance().enqueueAdmin(userID, obj.toString(4)); }