List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:com.appeligo.search.actions.ProgramAlertAction.java
public String setScheduledAlert() throws Exception { User user = getUser();/*from w w w . j a v a 2 s. c o m*/ boolean on = onOff.trim().toLowerCase().equals("on"); Timestamp startTime = new Timestamp(getProgramStartTime()); List<PendingAlert> pendingAlerts = PendingAlert.getManualAlertsForUser(user); for (PendingAlert pendingAlert : pendingAlerts) { if (pendingAlert.isManual() && pendingAlert.getProgramId().equals(programId) && pendingAlert.getCallSign().equals(callSign) && pendingAlert.getProgramStartTime().getTime() == getProgramStartTime()) { if (!on) { pendingAlert.setDeleted(true); pendingAlert.save(); return SUCCESS; } else { log.warn("Tried to turn on an existing scheduled alert!"); return INPUT; } } } if (!on) { log.warn("Tried to turn off a non-existent scheduled alert!"); return INPUT; } PendingAlert pendingAlert = new PendingAlert(); pendingAlert.setManual(true); pendingAlert.setUserId(user.getUserId()); pendingAlert.setProgramId(getProgramId()); pendingAlert.setCallSign(getCallSign()); pendingAlert.setProgramStartTime(startTime); Timestamp alertTime = new Timestamp(startTime.getTime() - (user.getAlertMinutesDefault() * 60000)); pendingAlert.setAlertTime(alertTime); pendingAlert.save(); setReturnUrl("/empty.vm"); return SUCCESS; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Updates file data object metadata. <code>content</code> is not used. * @param fdow// w w w . j av a 2s . c om * @throws com.funambol.foundation.exception.DAOException */ public void updateItem(FileDataObjectWrapper fdow) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { FileDataObject fdo = fdow.getFileDataObject(); Long fdoId = Long.valueOf(fdow.getId()); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); StringBuilder updateQuery = new StringBuilder(); updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_BEGIN); updateQuery.append(SQL_FIELD_LAST_UPDATE).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_UPLOAD_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA); String localName = fdow.getLocalName(); if (localName != null) { updateQuery.append(SQL_FIELD_LOCAL_NAME).append(SQL_EQUALS_QUESTIONMARK_COMMA); } else { // if the item was deleted and readded again with a sync // considering only the metadata, the local name must be set to // null, since the previous file was already deleted and the new // file would be uploaded later. updateQuery.append(SQL_FIELD_LOCAL_NAME).append(SQL_EQUALS_NULL_COMMA); } Long crc = Long.valueOf(fdow.getFileDataObject().getCrc()); updateQuery.append(SQL_FIELD_CRC).append(SQL_EQUALS_QUESTIONMARK_COMMA); String trueName = fdo.getName(); if (trueName != null) { updateQuery.append(SQL_FIELD_TRUE_NAME).append(SQL_EQUALS_QUESTIONMARK_COMMA); } MediaUtils.setFDODates(fdo, fdo.getCreated(), fdo.getModified()); Timestamp created = timestamp(fdo.getCreated()); if (created == null) { created = currentTime; } Timestamp modified = timestamp(fdo.getModified()); if (modified == null) { modified = currentTime; } updateQuery.append(SQL_FIELD_CREATED).append(SQL_EQUALS_QUESTIONMARK_COMMA); updateQuery.append(SQL_FIELD_MODIFIED).append(SQL_EQUALS_QUESTIONMARK_COMMA); Timestamp accessed = timestamp(fdo.getAccessed()); if (accessed != null) { updateQuery.append(SQL_FIELD_ACCESSED).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean hidden = fdo.getHidden(); if (hidden != null) { updateQuery.append(SQL_FIELD_H).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean system = fdo.getSystem(); if (system != null) { updateQuery.append(SQL_FIELD_S).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean archived = fdo.getArchived(); if (archived != null) { updateQuery.append(SQL_FIELD_A).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean deleted = fdo.getDeleted(); if (deleted != null) { updateQuery.append(SQL_FIELD_D).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean writable = fdo.getWritable(); if (writable != null) { updateQuery.append(SQL_FIELD_W).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean readable = fdo.getReadable(); if (readable != null) { updateQuery.append(SQL_FIELD_R).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Boolean executable = fdo.getExecutable(); if (executable != null) { updateQuery.append(SQL_FIELD_X).append(SQL_EQUALS_QUESTIONMARK_COMMA); } String contentType = fdo.getContentType(); if (contentType != null) { updateQuery.append(SQL_FIELD_CTTYPE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Long size = fdo.getSize(); if (size != null) { updateQuery.append(SQL_FIELD_SIZE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } Long sizeOnStorage = fdow.getSizeOnStorage(); if (sizeOnStorage != null) { updateQuery.append(SQL_FIELD_SIZE_ON_STORAGE).append(SQL_EQUALS_QUESTIONMARK_COMMA); } if (updateQuery.charAt(updateQuery.length() - 2) == ',') { updateQuery.deleteCharAt(updateQuery.length() - 2); } updateQuery.append(SQL_UPDATE_FNBL_FILE_DATA_OBJECT_END); // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); ps = con.prepareStatement(updateQuery.toString()); int k = 1; Timestamp lastUpdate = (fdow.getLastUpdate() == null) ? currentTime : fdow.getLastUpdate(); ps.setLong(k++, lastUpdate.getTime()); ps.setString(k++, String.valueOf(Def.PIM_STATE_UPDATED)); ps.setString(k++, String.valueOf(fdo.getUploadStatus())); if (localName != null) { ps.setString(k++, StringUtils.left(localName, SQL_LOCAL_NAME_DIM)); } ps.setLong(k++, crc); if (trueName != null) { ps.setString(k++, StringUtils.left(trueName, SQL_TRUE_NAME_DIM)); } // cannot be null ps.setTimestamp(k++, created); ps.setTimestamp(k++, modified); if (accessed != null) { ps.setTimestamp(k++, accessed); } if (hidden != null) { ps.setString(k++, hidden ? ONE : NIL); } if (system != null) { ps.setString(k++, system ? ONE : NIL); } if (archived != null) { ps.setString(k++, archived ? ONE : NIL); } if (deleted != null) { ps.setString(k++, deleted ? ONE : NIL); } if (writable != null) { ps.setString(k++, writable ? ONE : NIL); } if (readable != null) { ps.setString(k++, readable ? ONE : NIL); } if (executable != null) { ps.setString(k++, executable ? ONE : NIL); } if (contentType != null) { ps.setString(k++, StringUtils.left(contentType, SQL_CTTYPE_DIM)); } if (size != null) { ps.setLong(k++, size); } if (sizeOnStorage != null) { ps.setLong(k++, sizeOnStorage); } ps.setLong(k++, fdoId); ps.setString(k++, userId); ps.setString(k++, sourceURI); ps.executeUpdate(); // delete and add the properties associated to the new FDO removeAllProperties(fdow.getId()); addProperties(fdow); } catch (Exception e) { throw new DAOException("Error updating file data object.", e); } finally { DBTools.close(con, ps, rs); } }
From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java
private ItemStatus addItemToProperQueue(ItemInfo itemInfo, Timestamp baseTime) { // Always check whether we even want it for this client // The loader's profile and the cache profile will always have a negative client_id, // which means that we always want to keep it if (this.client_id != -1) { if (this.userIdGenerator == null) this.initializeUserIdGenerator(this.client_id); if (this.userIdGenerator.checkClient(itemInfo.getSellerId()) == false) { return (null); }//from ww w .j ava 2 s. c o m } long remaining = itemInfo.endDate.getTime() - baseTime.getTime(); ItemStatus new_status = (itemInfo.status != null ? itemInfo.status : ItemStatus.OPEN); // Already ended if (remaining <= AuctionMarkConstants.ITEM_ALREADY_ENDED) { if (itemInfo.numBids > 0 && itemInfo.status != ItemStatus.CLOSED) { new_status = ItemStatus.WAITING_FOR_PURCHASE; } else { new_status = ItemStatus.CLOSED; } } // About to end soon else if (remaining < AuctionMarkConstants.ITEM_ENDING_SOON) { new_status = ItemStatus.ENDING_SOON; } if (new_status != itemInfo.status) { if (itemInfo.status != null) assert (new_status.ordinal() > itemInfo.status.ordinal()) : "Trying to improperly move " + itemInfo + " from " + itemInfo.status + " to " + new_status; switch (new_status) { case OPEN: this.addItem(this.items_available, itemInfo); break; case ENDING_SOON: this.items_available.remove(itemInfo); this.addItem(this.items_endingSoon, itemInfo); break; case WAITING_FOR_PURCHASE: (itemInfo.status == ItemStatus.OPEN ? this.items_available : this.items_endingSoon) .remove(itemInfo); this.addItem(this.items_waitingForPurchase, itemInfo); break; case CLOSED: if (itemInfo.status == ItemStatus.OPEN) this.items_available.remove(itemInfo); else if (itemInfo.status == ItemStatus.ENDING_SOON) this.items_endingSoon.remove(itemInfo); else this.items_waitingForPurchase.remove(itemInfo); this.addItem(this.items_completed, itemInfo); break; default: } // SWITCH itemInfo.status = new_status; } if (LOG.isTraceEnabled()) LOG.trace(String.format("%s - #%d [%s]", new_status, itemInfo.itemId.encode(), itemInfo.getEndDate())); return (new_status); }
From source file:org.projectforge.web.teamcal.event.TeamEventEditPage.java
/** * @param parameters/* www . ja va 2 s . co m*/ */ public TeamEventEditPage(final PageParameters parameters, final TeamEvent event, final Timestamp newStartDate, final Timestamp newEndDate, final RecurrencyChangeType recurrencyChangeType) { super(parameters, "plugins.teamcal.event"); Validate.notNull(event); Validate.notNull(recurrencyChangeType); // event contains the new start and/or stop date if modified. if (log.isDebugEnabled() == true) { log.debug("TeamEvent is: newStartDate=" + newStartDate + ", newEndDate=" + newEndDate + ", event=[" + event + "], recurrencyChangeType=[" + recurrencyChangeType + "]"); } this.eventOfCaller = event; this.recurrencyChangeType = recurrencyChangeType; Integer id; if (event instanceof TeamEventDO) { id = ((TeamEventDO) event).getId(); } else { id = ((TeamRecurrenceEvent) event).getMaster().getId(); } final TeamEventDO teamEventDO = teamEventDao.getById(id); if (recurrencyChangeType == RecurrencyChangeType.ALL) { // The user wants to edit all events, so check if the user changes start and/or end date. If so, move the date of the original event. if (newStartDate != null) { final long startDateMove = newStartDate.getTime() - event.getStartDate().getTime(); teamEventDO.setStartDate(new Timestamp(teamEventDO.getStartDate().getTime() + startDateMove)); } if (newEndDate != null) { final long endDateMove = newEndDate.getTime() - event.getEndDate().getTime(); teamEventDO.setEndDate(new Timestamp(teamEventDO.getEndDate().getTime() + endDateMove)); } } else { if (newStartDate != null) { teamEventDO.setStartDate(newStartDate); } else { teamEventDO.setStartDate(new Timestamp(event.getStartDate().getTime())); } if (newEndDate != null) { teamEventDO.setEndDate(newEndDate); } else { teamEventDO.setEndDate(new Timestamp(event.getEndDate().getTime())); } } if (recurrencyChangeType == RecurrencyChangeType.ONLY_CURRENT) { // The user wants to change only the current event, so remove all recurrency fields. teamEventDO.clearAllRecurrenceFields(); } init(teamEventDO); }
From source file:org.openbravo.erpCommon.utility.Utility.java
/** * Gets the date format for the organization country. * /*from ww w . j av a2 s.c o m*/ * @param timeStamp * TimeStamp to apply the format. * @param orgid * ID of the organization. * * @return date with the country format string applied. In case is not defined, a default format * is applied */ public static String applyCountryDateFormat(Timestamp timeStamp, String orgid) { return applyCountryDateFormat(new Date(timeStamp.getTime()), orgid); }
From source file:org.bytesoft.openjtcc.supports.logger.DbTransactionLoggerImpl.java
private Map<XidImpl, TransactionArchive> loadTransactionSet(Connection connection) { Map<XidImpl, TransactionArchive> metaMap = new HashMap<XidImpl, TransactionArchive>(); PreparedStatement stmt = null; ResultSet rs = null;//from w w w . ja v a 2 s . c o m try { StringBuilder ber = new StringBuilder(); ber.append("select global_tx_id, status, status_trace"); ber.append(", coordinator, created_time "); ber.append("from tcc_transaction "); ber.append("where application = ? and endpoint = ? and deleted = ?"); stmt = connection.prepareStatement(ber.toString()); stmt.setString(1, this.instanceKey.getApplication()); stmt.setString(2, this.instanceKey.getEndpoint()); stmt.setBoolean(3, false); rs = stmt.executeQuery(); while (rs.next()) { String globalTransactionId = rs.getString("global_tx_id"); int state = rs.getInt("status"); int trace = rs.getInt("status_trace"); boolean coordinator = rs.getBoolean("coordinator"); Timestamp createdTime = rs.getTimestamp("created_time"); TransactionContext context = new TransactionContext(); TerminalKey terminalKey = new TerminalKey(); terminalKey.setApplication(this.instanceKey.getApplication()); terminalKey.setEndpoint(this.instanceKey.getEndpoint()); context.setTerminalKey(terminalKey); context.setRecovery(true); context.setCompensable(true); context.setCoordinator(coordinator); byte[] globalBytes = ByteUtils.stringToByteArray(globalTransactionId); XidImpl globalXid = this.xidFactory.createGlobalXid(globalBytes); // context.setGlobalXid(globalXid); context.setCreationXid(globalXid); context.setCurrentXid(globalXid); context.setCreatedTime(createdTime.getTime()); TransactionStatus status = new TransactionStatus(state, trace); TransactionArchive meta = new TransactionArchive(); meta.setTransactionStatus(status); meta.setTransactionContext(context); metaMap.put(globalXid, meta); } } catch (Exception ex) { ex.printStackTrace(); } finally { closeResultSet(rs); closeStatement(stmt); } return metaMap; }
From source file:de.tuttas.servlets.DokuServlet.java
private String toReadableFromat(Timestamp absenzAm) { Calendar gc = GregorianCalendar.getInstance(); gc.setTime(new Date(absenzAm.getTime())); return toReadableDate(gc); }
From source file:org.sakaiproject.search.component.service.impl.SearchIndexBuilderWorkerImpl.java
public boolean getHardLock(long nodeLifetime, boolean forceLock) { String nodeID = getNodeID();/*from ww w . j a va 2s. com*/ Connection connection = null; boolean locked = false; boolean autoCommit = false; PreparedStatement selectLock = null; PreparedStatement updateLock = null; PreparedStatement insertLock = null; PreparedStatement countWork = null; ResultSet resultSet = null; Timestamp now = new Timestamp(System.currentTimeMillis()); Timestamp expiryDate = new Timestamp(now.getTime() + (10L * 60L * 1000L)); try { // I need to go direct to JDBC since its just too awful to // try and do this in Hibernate. updateNodeLock(nodeLifetime); connection = dataSource.getConnection(); autoCommit = connection.getAutoCommit(); if (autoCommit) { connection.setAutoCommit(false); } selectLock = connection.prepareStatement(SELECT_LOCK_SQL); updateLock = connection.prepareStatement(UPDATE_LOCK_SQL); insertLock = connection.prepareStatement(INSERT_LOCK_SQL); countWork = connection.prepareStatement(COUNT_WORK_SQL); SearchWriterLock swl = null; selectLock.clearParameters(); selectLock.setString(1, LOCKKEY); resultSet = selectLock.executeQuery(); if (resultSet.next()) { swl = new SearchWriterLockImpl(); swl.setId(resultSet.getString(1)); swl.setNodename(resultSet.getString(2)); swl.setLockkey(resultSet.getString(3)); swl.setExpires(resultSet.getTimestamp(4)); log.debug("GOT Lock Record " + swl.getId() + "::" + swl.getNodename() + "::" + swl.getExpires()); } resultSet.close(); resultSet = null; boolean takelock = false; if (swl == null) { log.debug("_-------------NO Lock Record"); takelock = true; } else if ("none".equals(swl.getNodename())) { takelock = true; log.debug(nodeID + "_-------------no lock"); } else if (nodeID.equals(swl.getNodename())) { takelock = true; log.debug(nodeID + "_------------matched threadid "); } else if (swl.getExpires() == null || swl.getExpires().before(now)) { takelock = true; log.debug(nodeID + "_------------thread dead "); } if (takelock) { // any work ? int nitems = 0; if (!forceLock) { countWork.clearParameters(); countWork.setInt(1, SearchBuilderItem.STATE_PENDING.intValue()); resultSet = countWork.executeQuery(); if (resultSet.next()) { nitems = resultSet.getInt(1); } resultSet.close(); resultSet = null; } if (nitems > 0 || forceLock) { try { if (swl == null) { insertLock.clearParameters(); insertLock.setString(1, nodeID); insertLock.setString(2, nodeID); insertLock.setString(3, LOCKKEY); insertLock.setTimestamp(4, expiryDate); if (insertLock.executeUpdate() == 1) { log.debug("INSERT Lock Record " + nodeID + "::" + nodeID + "::" + expiryDate); locked = true; } } else { updateLock.clearParameters(); updateLock.setString(1, nodeID); updateLock.setTimestamp(2, expiryDate); updateLock.setString(3, swl.getId()); updateLock.setString(4, swl.getNodename()); updateLock.setString(5, swl.getLockkey()); if (updateLock.executeUpdate() == 1) { log.debug("UPDATED Lock Record " + swl.getId() + "::" + nodeID + "::" + expiryDate); locked = true; } } } catch (SQLException sqlex) { locked = false; log.debug("Failed to get lock, but this is Ok ", sqlex); } } } connection.commit(); } catch (Exception ex) { if (connection != null) { try { connection.rollback(); } catch (SQLException e) { log.debug(e); } } log.error("Failed to get lock " + ex.getMessage()); locked = false; } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.debug(e); } } if (selectLock != null) { try { selectLock.close(); } catch (SQLException e) { log.debug(e); } } if (updateLock != null) { try { updateLock.close(); } catch (SQLException e) { log.debug(e); } } if (insertLock != null) { try { insertLock.close(); } catch (SQLException e) { log.debug(e); } } if (countWork != null) { try { countWork.close(); } catch (SQLException e) { log.debug(e); } } if (connection != null) { try { connection.setAutoCommit(autoCommit); } catch (SQLException e) { } try { connection.close(); log.debug("Connection Closed "); } catch (SQLException e) { log.error("Error Closing Connection ", e); } connection = null; } } return locked; }
From source file:org.apache.nifi.mongodb.MongoDBLookupServiceIT.java
@Test public void testLookupRecord() throws Exception { runner.disableControllerService(service); runner.setProperty(service, MongoDBLookupService.LOOKUP_VALUE_FIELD, ""); runner.setProperty(service, MongoDBLookupService.PROJECTION, "{ \"_id\": 0 }"); runner.enableControllerService(service); Date d = new Date(); Timestamp ts = new Timestamp(new Date().getTime()); List list = Arrays.asList("a", "b", "c", "d", "e"); col.insertOne(new Document().append("uuid", "x-y-z").append("dateField", d).append("longField", 10000L) .append("stringField", "Hello, world").append("timestampField", ts) .append("decimalField", Double.MAX_VALUE / 2.0) .append("subrecordField", new Document().append("nestedString", "test").append("nestedLong", new Long(1000))) .append("arrayField", list)); Map<String, Object> criteria = new HashMap<>(); criteria.put("uuid", "x-y-z"); Optional result = service.lookup(criteria); Assert.assertNotNull("The value was null.", result.get()); Assert.assertTrue("The value was wrong.", result.get() instanceof MapRecord); MapRecord record = (MapRecord) result.get(); RecordSchema subSchema = ((RecordDataType) record.getSchema().getField("subrecordField").get() .getDataType()).getChildSchema(); Assert.assertEquals("The value was wrong.", "Hello, world", record.getValue("stringField")); Assert.assertEquals("The value was wrong.", "x-y-z", record.getValue("uuid")); Assert.assertEquals(new Long(10000), record.getValue("longField")); Assert.assertEquals((Double.MAX_VALUE / 2.0), record.getValue("decimalField")); Assert.assertEquals(d, record.getValue("dateField")); Assert.assertEquals(ts.getTime(), ((Date) record.getValue("timestampField")).getTime()); Record subRecord = record.getAsRecord("subrecordField", subSchema); Assert.assertNotNull(subRecord);/* w w w . j ava2 s.c om*/ Assert.assertEquals("test", subRecord.getValue("nestedString")); Assert.assertEquals(new Long(1000), subRecord.getValue("nestedLong")); Assert.assertEquals(list, record.getValue("arrayField")); Map<String, Object> clean = new HashMap<>(); clean.putAll(criteria); col.deleteOne(new Document(clean)); try { result = service.lookup(criteria); } catch (LookupFailureException ex) { Assert.fail(); } Assert.assertTrue(!result.isPresent()); }
From source file:beproject.MainGUI.java
void getTimeLineData(TimeSeriesCollection t) throws SQLException { Statement stmt = Initializer.inConn2.createStatement(); ResultSet rs1 = stmt.executeQuery("select max(ts) from tweets"); rs1.first();/*from w ww . j av a 2s . co m*/ Timestamp ts1 = rs1.getTimestamp(1); for (String tmp : ScheduledMoviesList.getMovieNames()) { TimeSeries t1 = new TimeSeries(tmp, Hour.class); Timestamp ts = (Timestamp) ts1.clone(); for (int i = 0; i < 6; i++) { Date d1 = new java.util.Date(ts.getTime()); Date d2 = new java.util.Date(ts.getTime() + 3600000); ResultSet rs = stmt .executeQuery("select count(*) from tweets where moviename='" + tmp + "' and ts between '" + Regression.sdf.format(d1) + "' and '" + Regression.sdf.format(d2) + "'"); rs.first(); //if(!rs.first()) // t1.addOrUpdate(new Hour(d1), 0); //else t1.addOrUpdate(new Hour(d1), rs.getInt(1)); ts.setTime(ts.getTime() - 3600000); } t.addSeries(t1); } }