List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:pdfjsannotator.controller.AnnotationController.java
@RequestMapping(value = "/api/annotations/{id}", method = RequestMethod.PUT) public Annotation update(@PathVariable String id, @RequestBody Annotation annotation) { LOGGER.info("Requested update of annotation with id " + id); Annotation oldAnnotation = annotationRepository.findOne(id); oldAnnotation.setText(annotation.getText()); oldAnnotation.setQuote(annotation.getQuote()); oldAnnotation.setUpdated(new Timestamp(Calendar.getInstance().getTimeInMillis())); return annotationRepository.save(oldAnnotation); }
From source file:corner.hadoop.services.impl.LocalFileAccessorProxy.java
@Override public FileDesc getFileDesc(String filePath) throws IOException { File file = new File(addRootPath(filePath)); if (file.exists()) { return new FileDesc(file.getAbsolutePath(), file.isDirectory(), new Timestamp(file.lastModified()), file.length());/*from w w w. j av a2 s . c om*/ } else { return null; } }
From source file:edu.uoc.json.controller.MeetingController.java
@RequestMapping(method = RequestMethod.POST) public @ResponseBody JSONResponse stopRecord(HttpSession session) { JSONResponse response = new JSONResponse(); try {//from w w w. j a v a 2 s . c om Room room = (Room) session.getAttribute(Constants.ROOM_SESSION); MeetingRoom meeting = (MeetingRoom) session.getAttribute(Constants.MEETING_SESSION); User user = (User) session.getAttribute(Constants.USER_SESSION); if (user != null && meeting != null) { meeting = meetingDao.findById(meeting.getId()); room = this.roomDao.findByRoomCode(room.getId()); room.setIs_blocked(false); room.setReason_blocked(null); this.roomDao.save(room); meeting.setRecorded((byte) 1); meeting.setEnd_record(new Timestamp(new Date().getTime())); meeting.setFinished((byte) 0); this.meetingDao.save(meeting); response.setOk(true); } } catch (Exception e) { logger.error("Error stoping record ", e); } return response; }
From source file:eionet.gdem.dcm.business.BackupManager.java
/** * Remove backup files and refereces in database * * @param nofDays//from ww w . jav a 2s . c om * - number of days to keep * @return * @throws DCMException */ public int purgeBackup(int nofDays) throws DCMException { int result = 0; Calendar purgeDate = Calendar.getInstance(); purgeDate.add(Calendar.DATE, -nofDays); SimpleDateFormat sf = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); LOGGER.info("Purge backup files created before: " + sf.format(new Date(purgeDate.getTimeInMillis()))); long purgeDateInMillis = purgeDate.getTimeInMillis(); Timestamp ts = new Timestamp(purgeDateInMillis); File backupFolder = new File(Properties.queriesFolder, Constants.BACKUP_FOLDER_NAME); if (backupFolder.exists() && backupFolder.isDirectory()) { File[] files = backupFolder.listFiles(); for (int i = 0; i < files.length; i++) { String fileName = files[i].getName(); // check if it is backup file if (!files[i].isFile() || !fileName.startsWith(Constants.BACKUP_FILE_PREFIX)) { continue; } int start = fileName.indexOf("_", Constants.BACKUP_FILE_PREFIX.length()); int end = fileName.lastIndexOf("."); String fileTimestamp = fileName.substring(start + 1, end); long lFileTimestamp = 0; try { lFileTimestamp = Long.parseLong(fileTimestamp); } catch (ClassCastException e) { continue; } if (lFileTimestamp < purgeDateInMillis) { try { files[i].delete(); result++; } catch (Exception ioe) { LOGGER.error("Unable to delete backup file: " + files[i].getPath(), ioe); } } } } LOGGER.info("Number of back files deleted: " + result); // remove database rows try { backupDao.removeBackupsOlderThan(ts); } catch (Exception e) { // e.printStackTrace(); LOGGER.error("Error removing backups.", e); throw new DCMException(BusinessConstants.EXCEPTION_GENERAL); } return result; }
From source file:fitmon.DietAPI.java
public ArrayList<ArrayList<Food>> searchFood(String foodName) throws InvalidKeyException, NoSuchAlgorithmException, ParserConfigurationException, SAXException, IOException { xmlParser xParser = new xmlParser(); ArrayList<ArrayList<Food>> listOfFoodList = new ArrayList<ArrayList<Food>>(); ArrayList<String> list; String base = URLEncoder.encode("GET") + "&"; base += "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&"; String params;//from w w w. j av a 2s .co m //params = "format=json&"; params = "method=foods.search&"; params += "oauth_consumer_key=5f2d9f7c250c4d75b9807a4f969363a7&"; // ur consumer key params += "oauth_nonce=123&"; params += "oauth_signature_method=HMAC-SHA1&"; Date date = new java.util.Date(); Timestamp ts = new Timestamp(date.getTime()); params += "oauth_timestamp=" + ts.getTime() + "&"; params += "oauth_version=1.0&"; params += "search_expression=" + foodName; String params2 = URLEncoder.encode(params); base += params2; System.out.println(base); String line = ""; String secret = "76172de2330a4e55b90cbd2eb44f8c63&"; Mac sha256_HMAC = Mac.getInstance("HMACSHA1"); SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HMACSHA1"); sha256_HMAC.init(secret_key); String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(base.getBytes())); //$url = "http://platform.fatsecret.com/rest/server.api?".$params."&oauth_signature=".rawurlencode($sig); String url = "http://platform.fatsecret.com/rest/server.api?" + params + "&oauth_signature=" + URLEncoder.encode(hash); System.out.println(url); list = xParser.foodSearchParser(url); for (int i = 0; i < list.size(); i++) { listOfFoodList.add(getFood(list.get(i))); } return listOfFoodList; }
From source file:org.gridobservatory.greencomputing.dao.TimeseriesDao.java
protected void insertTimeSeriesAcquisitions(final BigInteger timeSeriesId, final List<TimeseriesAcquisitionType> acquisitions) { executor.submit(new Runnable() { @Override/*from w w w .j av a 2s . com*/ public void run() { if (acquisitions != null) { getJdbcTemplate().batchUpdate( "insert into time_series_acquisition (time_series_id, ts, value) values (?,?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, timeSeriesId.longValue()); long dateInMilis = acquisitions.get(i).getTs() .multiply(BigInteger.valueOf(1000l)).longValue(); ps.setTimestamp(2, new Timestamp(dateInMilis)); ps.setBigDecimal(3, new BigDecimal(acquisitions.get(i).getV())); } @Override public int getBatchSize() { return acquisitions.size(); } }); } } }); }
From source file:com.nortal.petit.converter.util.ResultSetHelper.java
public static Timestamp getTimestamp(ResultSet rs, ColumnPosition column) throws SQLException { Long milliseconds = getMilliseconds(rs, column); return milliseconds == null ? null : new Timestamp(milliseconds); }
From source file:com.ibm.iot.android.iotstarter.utils.MessageConductor.java
/** * Steer incoming MQTT messages to the proper activities based on their content. * * @param payload The log of the MQTT message. * @param topic The topic the MQTT message was received on. * @throws JSONException If the message contains invalid JSON. *//*w ww .j a v a 2s . c om*/ public void steerMessage(String payload, String topic) throws JSONException { Log.d(TAG, ".steerMessage() entered"); JSONObject top = new JSONObject(payload); JSONObject d = top.getJSONObject("d"); if (topic.contains(Constants.COLOR_EVENT)) { Log.d(TAG, "Color Event"); int r = d.getInt("r"); int g = d.getInt("g"); int b = d.getInt("b"); // alpha value received is 0.0 < a < 1.0 but Color.argb expects 0 < a < 255 int alpha = (int) (d.getDouble("alpha") * 255.0); if ((r > 255 || r < 0) || (g > 255 || g < 0) || (b > 255 || b < 0) || (alpha > 255 || alpha < 0)) { return; } app.setColor(Color.argb(alpha, r, g, b)); Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT); actionIntent.putExtra(Constants.INTENT_DATA, Constants.COLOR_EVENT); context.sendBroadcast(actionIntent); } else if (topic.contains(Constants.FRE_EVENT)) { JSONObject topp = new JSONObject(payload); JSONObject dd = topp.getJSONObject("d"); int frequency = dd.getInt("f"); Log.d("MMM", "" + frequency); app.setFfe(frequency); } else if (topic.contains(Constants.LIGHT_EVENT)) { app.handleLightMessage(); } else if (topic.contains(Constants.TEXT_EVENT)) { int unreadCount = app.getUnreadCount(); String messageText = d.getString("text"); app.setUnreadCount(++unreadCount); // Log message with the following format: // [yyyy-mm-dd hh:mm:ss.S] Received text: // <message text> Date date = new Date(); String logMessage = "[" + new Timestamp(date.getTime()) + "] Received Text:\n"; app.getMessageLog().add(logMessage + messageText); // Send intent to LOG fragment to mark list data invalidated String runningActivity = app.getCurrentRunningActivity(); //if (runningActivity != null && runningActivity.equals(LogPagerFragment.class.getName())) { Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG); actionIntent.putExtra(Constants.INTENT_DATA, Constants.TEXT_EVENT); context.sendBroadcast(actionIntent); //} // Send intent to current active fragment / activity to update Unread message count // Skip sending intent if active tab is LOG // TODO: 'current activity' code needs fixing. Intent unreadIntent; if (runningActivity.equals(LogPagerFragment.class.getName())) { unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG); } else if (runningActivity.equals(LoginPagerFragment.class.getName())) { unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOGIN); } else if (runningActivity.equals(IoTPagerFragment.class.getName())) { unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT); } else if (runningActivity.equals(ProfilesActivity.class.getName())) { unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_PROFILES); } else { return; } if (messageText != null) { unreadIntent.putExtra(Constants.INTENT_DATA, Constants.UNREAD_EVENT); context.sendBroadcast(unreadIntent); } } else if (topic.contains(Constants.ALERT_EVENT)) { // save payload in an arrayList int unreadCount = app.getUnreadCount(); String messageText = d.getString("text"); app.setUnreadCount(++unreadCount); // Log message with the following format: // [yyyy-mm-dd hh:mm:ss.S] Received alert: // <message text> Date date = new Date(); String logMessage = "[" + new Timestamp(date.getTime()) + "] Received Alert:\n"; app.getMessageLog().add(logMessage + messageText); String runningActivity = app.getCurrentRunningActivity(); if (runningActivity != null) { //if (runningActivity.equals(LogPagerFragment.class.getName())) { Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG); actionIntent.putExtra(Constants.INTENT_DATA, Constants.TEXT_EVENT); context.sendBroadcast(actionIntent); //} // Send alert intent with message payload to current active activity / fragment. // TODO: update for current activity changes. Intent alertIntent; if (runningActivity.equals(LogPagerFragment.class.getName())) { alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG); } else if (runningActivity.equals(LoginPagerFragment.class.getName())) { alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOGIN); } else if (runningActivity.equals(IoTPagerFragment.class.getName())) { alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT); } else if (runningActivity.equals(ProfilesActivity.class.getName())) { alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_PROFILES); } else { return; } if (messageText != null) { alertIntent.putExtra(Constants.INTENT_DATA, Constants.ALERT_EVENT); alertIntent.putExtra(Constants.INTENT_DATA_MESSAGE, d.getString("text")); context.sendBroadcast(alertIntent); } } } }
From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java
public Timestamp getInstance(Class<?> clazz) { return new Timestamp(Integer.MAX_VALUE); }