List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:com.passiveMonitorBackend.connectMonitor.model.ChangeOffSet.java
@PreUpdate void updateDate() { long time = new Date().getTime(); this.updateDate = new Timestamp(time); }
From source file:monasca.persister.repository.cassandra.CassandraAlarmRepo.java
public void addToBatch(AlarmStateTransitionedEvent message, String id) { String metricsString = getSerializedString(message.metrics, id); // Validate metricsString does not exceed a sufficient maximum upper bound if (metricsString.length() * MAX_BYTES_PER_CHAR >= MAX_LENGTH_VARCHAR) { metricsString = "[]"; logger.warn("length of metricsString for alarm ID {} exceeds max length of {}", message.alarmId, MAX_LENGTH_VARCHAR);/* w w w .ja va2 s . co m*/ } String subAlarmsString = getSerializedString(message.subAlarms, id); if (subAlarmsString.length() * MAX_BYTES_PER_CHAR >= MAX_LENGTH_VARCHAR) { subAlarmsString = "[]"; logger.warn("length of subAlarmsString for alarm ID {} exceeds max length of {}", message.alarmId, MAX_LENGTH_VARCHAR); } queue.offerLast(cluster.getAlarmHistoryInsertStmt().bind(retention, metricsString, message.oldState.name(), message.newState.name(), subAlarmsString, message.stateChangeReason, EMPTY_REASON_DATA, message.tenantId, message.alarmId, new Timestamp(message.timestamp))); }
From source file:net.pms.database.TableThumbnails.java
/** * Attempts to find a thumbnail in this table by MD5 hash. If not found, * it writes the new thumbnail to this table. * Finally, it writes the ID from this table as the THUMBID in the FILES * table./*w w w . j a va2 s.c o m*/ * * @param thumbnail * @param fullPathToFile */ public static void setThumbnail(final DLNAThumbnail thumbnail, final String fullPathToFile) { String query; String md5Hash = DigestUtils.md5Hex(thumbnail.getBytes(false)); try (Connection connection = database.getConnection()) { query = "SELECT * FROM " + TABLE_NAME + " WHERE MD5 = " + sqlQuote(md5Hash) + " LIMIT 1"; LOGGER.trace("Searching for thumbnail in {} with \"{}\" before update", TABLE_NAME, query); TABLE_LOCK.writeLock().lock(); try (PreparedStatement statement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, Statement.RETURN_GENERATED_KEYS)) { connection.setAutoCommit(false); try (ResultSet result = statement.executeQuery()) { if (result.next()) { LOGGER.trace( "Found existing file entry with ID {} in {}, setting the THUMBID in the FILES table", result.getInt("ID"), TABLE_NAME); // Write the existing thumbnail ID to the FILES table PMS.get().getDatabase().updateThumbnailId(fullPathToFile, result.getInt("ID")); } else { LOGGER.trace("File entry \"{}\" not found in {}", md5Hash, TABLE_NAME); result.moveToInsertRow(); result.updateString("MD5", md5Hash); result.updateObject("THUMBNAIL", thumbnail); result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis())); result.insertRow(); try (ResultSet generatedKeys = statement.getGeneratedKeys()) { if (generatedKeys.next()) { // Write the new thumbnail ID to the FILES table LOGGER.trace( "Inserting new thumbnail with ID {}, setting the THUMBID in the FILES table", generatedKeys.getInt(1)); PMS.get().getDatabase().updateThumbnailId(fullPathToFile, generatedKeys.getInt(1)); } } } } finally { connection.commit(); } } finally { TABLE_LOCK.writeLock().unlock(); } } catch (SQLException e) { LOGGER.error("Database error while writing \"{}\" to {}: {}", md5Hash, TABLE_NAME, e.getMessage()); LOGGER.trace("", e); } }
From source file:at.alladin.rmbt.controlServer.ResultUpdateResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();//from ww w . jav a 2s.c om JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); final String ip = getIP(); System.out.println(MessageFormat.format(labels.getString("NEW_RESULT_UPDATE"), ip)); if (entity != null && !entity.isEmpty()) { try { request = new JSONObject(entity); final UUID clientUUID = UUID.fromString(request.getString("uuid")); final UUID testUUID = UUID.fromString(request.getString("test_uuid")); final int zipCode = request.optInt("zip_code", 0); final double geoLat = request.optDouble("geo_lat", Double.NaN); final double geoLong = request.optDouble("geo_long", Double.NaN); final float geoAccuracy = (float) request.optDouble("accuracy", 0); final String provider = request.optString("provider").toLowerCase(); final Client client = new Client(conn); final long clientId = client.getClientByUuid(clientUUID); if (clientId < 0) throw new IllegalArgumentException("error while loading client"); final Test test = new Test(conn); if (test.getTestByUuid(testUUID) < 0) throw new IllegalArgumentException("error while loading test"); if (test.getField("client_id").longValue() != clientId) throw new IllegalArgumentException("client UUID does not match test"); if (zipCode > 0) { ((IntField) test.getField("zip_code")).setValue(zipCode); } if (!Double.isNaN(geoLat) && !Double.isNaN(geoLong) && (provider.equals(GEO_PROVIDER_GEOCODER) || provider.equals(GEO_PROVIDER_MANUAL))) { final GeoLocation geoloc = new GeoLocation(conn); geoloc.setTest_id(test.getUid()); final Timestamp tstamp = java.sql.Timestamp .valueOf(new Timestamp((new Date().getTime())).toString()); geoloc.setTime(tstamp, TimeZone.getDefault().toString()); geoloc.setAccuracy(geoAccuracy); geoloc.setGeo_lat(geoLat); geoloc.setGeo_long(geoLong); geoloc.setProvider(provider); geoloc.storeLocation(); ((DoubleField) test.getField("geo_lat")).setValue(geoLat); ((DoubleField) test.getField("geo_long")).setValue(geoLong); ((DoubleField) test.getField("geo_accuracy")).setValue(geoAccuracy); test.getField("geo_provider").setString(provider); } test.storeTestResults(true); if (test.hasError()) errorList.addError(test.getError()); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSDON Data " + e.toString()); } catch (final IllegalArgumentException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSDON Data " + e.toString()); } } return answer.toString(); }
From source file:org.kuali.mobility.push.service.send.AndroidSendServiceTest.java
/** * Initialise some data for the unit tests *//*from www .ja va 2 s .c om*/ @Before public void setup() { // Setup some test devices for (int i = 0; i < 4; i++) { Device d = new Device(); d.setRegId(REGISTRATIONS[i]); d.setUsername("Test user"); d.setPostedTimestamp(new Timestamp(new Date().getTime())); d.setType(Device.TYPE_ANDROID); deviceService.saveDevice(d); registrationIds.add(REGISTRATIONS[i]); } // Create test push message push = new Push(); push.setPushId(new Long(5)); push.setPostedTimestamp(new Timestamp(new Date().getTime())); push.setEmergency(false); push.setTitle("Test message"); push.setSender("TesterXX"); push.setMessage("This is a test message"); }
From source file:org.cloudfoundry.identity.uaa.scim.endpoints.PasswordResetEndpoints.java
@RequestMapping(value = "/password_resets", method = RequestMethod.POST) public ResponseEntity<String> resetPassword(@RequestBody String email) { List<ScimUser> results = scimUserProvisioning.query("email eq '" + email + "'"); if (results.isEmpty()) { return new ResponseEntity<String>(BAD_REQUEST); }/*from w w w. j a va 2 s. com*/ ScimUser scimUser = results.get(0); String code = expiringCodeStore .generateCode(scimUser.getId(), new Timestamp(System.currentTimeMillis() + PASSWORD_RESET_LIFETIME)) .getCode(); publish(new ResetPasswordRequestEvent(email, code, SecurityContextHolder.getContext().getAuthentication())); return new ResponseEntity<String>(code, CREATED); }
From source file:monitoring.tools.ITunesApple.java
protected void apiCall() throws IOException, MalformedURLException { String timeStamp = new Timestamp((new Date()).getTime()).toString(); JSONObject data = urlConnection();/*from w w w. ja v a 2s. c o m*/ JSONArray reviews = data.getJSONObject("feed").getJSONArray("entry"); List<MonitoringData> dataList = new ArrayList<>(); for (int i = 1; i < reviews.length(); ++i) { JSONObject obj = reviews.getJSONObject(i); String id = obj.getJSONObject("id").getString("label"); if (!reported.contains(id)) { Iterator<?> keys = obj.keys(); MonitoringData review = new MonitoringData(); review.setReviewID(id); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equals("author")) review.setAuthorName(obj.getJSONObject("author").getJSONObject("name").getString("label")); else if (key.equals("title")) review.setReviewTitle(obj.getJSONObject("title").getString("label")); else if (key.equals("content")) review.setReviewText(obj.getJSONObject("content").getString("label")); else if (key.equals("im:rating")) review.setStarRating(obj.getJSONObject("im:rating").getString("label")); else if (key.equals("im:version")) review.setAppVersion(obj.getJSONObject("im:version").getString("label")); else if (key.equals("link")) review.setLink(obj.getJSONObject("link").getJSONObject("attributes").getString("href")); } dataList.add(review); reported.add(id); } } //kafka.generateResponseKafka(dataList, timeStamp, id, confId, params.getKafkaTopic()); kafka.generateResponseIF(dataList, timeStamp, id, confId, params.getKafkaTopic()); logger.debug("Data sent to kafka endpoint"); ++id; }
From source file:com.globalsight.everest.projecthandler.MachineTranslateAdapter.java
public void setMTCommonOptions(HttpServletRequest p_request, MachineTranslationProfile mtProfile, String engine) {/* w ww .java 2 s.co m*/ makeBaseMT(p_request, mtProfile, engine); Date date = new Date(); mtProfile.setTimestamp(new Timestamp(date.getTime())); EngineEnum ee = EngineEnum.getEngine(engine); switch (ee) { case ProMT: setPromtParams(p_request, mtProfile); setExtendInfo(p_request, mtProfile); break; case Asia_Online: setAOParams(p_request, mtProfile); setExtendInfo(p_request, mtProfile); break; case Safaba: setSafabaParams(p_request, mtProfile); break; case MS_Translator: setMsMtParams(p_request, mtProfile); break; case IPTranslator: setIPMtParams(p_request, mtProfile); break; case DoMT: setDoMtParams(p_request, mtProfile); break; case Google_Translate: setGoogleParams(p_request, mtProfile); break; } }
From source file:com.azaptree.services.security.dao.SubjectDAO.java
@Override public Subject create(final Subject entity) { Assert.notNull(entity, "entity is required"); final SubjectImpl subject = new SubjectImpl(entity); subject.created();// w ww .j a va 2 s .c o m final String sql = "insert into t_subject (entity_id,entity_version,entity_created_on,entity_created_by,entity_updated_on,entity_updated_by,max_sessions,status,status_timestamp,consec_auth_failed_count,last_auth_failed_ts) values (?,?,?,?,?,?,?,?,?,?,?)"; final Optional<UUID> createdBy = entity.getCreatedByEntityId(); final UUID createdByUUID = createdBy.isPresent() ? createdBy.get() : null; jdbc.update(sql, subject.getEntityId(), subject.getEntityVersion(), new Timestamp(subject.getEntityCreatedOn()), createdByUUID, new Timestamp(subject.getEntityUpdatedOn()), createdByUUID, subject.getMaxSessions(), subject.getStatus().code, new Timestamp(subject.getStatusTimestamp()), subject.getConsecutiveAuthenticationFailedCount(), subject.getLastTimeAuthenticationFailed() > 0 ? new Timestamp(subject.getLastTimeAuthenticationFailed()) : null); return subject; }
From source file:edu.utah.further.mdr.data.common.domain.asset.ActivationInfoEntity.java
/** * @param other/*from w w w .ja v a 2s . c o m*/ * @return * @see edu.utah.further.mdr.api.domain.asset.ActivationInfo#copyFrom(edu.utah.further.mdr.api.domain.asset.ActivationInfo) */ @Override public ActivationInfoEntity copyFrom(final ActivationInfo other) { if (other == null) { return this; } // Identifier is not copied // Deep-copy fields final Timestamp otherActivationDate = other.getActivationDate(); if (otherActivationDate != null) { this.activationDate = new Timestamp(otherActivationDate.getTime()); } final Timestamp otherDeactivationDate = other.getDeactivationDate(); if (otherDeactivationDate != null) { this.deactivationDate = new Timestamp(otherDeactivationDate.getTime()); } // Deep-copy collection references but soft-copy their elements return this; }