List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:ke.co.tawi.babblesms.server.persistence.logs.OutgoingGroupLogDAO.java
/** * @see ke.co.tawi.babblesms.server.persistence.logs.BabbleOutgoingGroupLogDAO#putOutgoingGrouplog(ke.co.tawi.babblesms.server.beans.log.OutgoingGrouplog) *///from w ww . j a v a 2s . c om @Override public boolean put(OutgoingGrouplog log) { boolean success = true; try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn .prepareStatement("INSERT INTO OutgoinggroupLog (Uuid, origin, networkuuid," + "destination, message, sender, messagestatusuuid, logTime) " + "VALUES (?,?,?,?,?,?,?,?);");) { pstmt.setString(1, log.getUuid()); pstmt.setString(2, log.getOrigin()); pstmt.setString(3, log.getNetworkUuid()); pstmt.setString(4, log.getDestination()); pstmt.setString(5, log.getMessage()); pstmt.setString(6, log.getSender()); pstmt.setString(7, log.getMessagestatusuuid()); pstmt.setTimestamp(8, new Timestamp(log.getLogTime().getTime())); pstmt.execute(); } catch (SQLException e) { logger.error("SQL Exception when trying to put: " + log); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } return success; }
From source file:org.pentaho.metaverse.impl.model.ModelSerializationIT.java
@Test public void testSerializeDeserialize() throws Exception { String server = "localhost"; String dbName = "test"; int port = 9999; String user = "testUser"; String password = "password"; JdbcResourceInfo jdbcResource = new JdbcResourceInfo(server, dbName, port, user, password); jdbcResource.setInput(true);/*from w w w. j ava2s . co m*/ String json = mapper.writeValueAsString(jdbcResource); // System.out.println( json ); JdbcResourceInfo rehydrated = mapper.readValue(json, JdbcResourceInfo.class); assertEquals(jdbcResource.getServer(), rehydrated.getServer()); assertEquals(jdbcResource.getDatabaseName(), rehydrated.getDatabaseName()); assertEquals(jdbcResource.getUsername(), rehydrated.getUsername()); assertEquals(jdbcResource.getPassword(), rehydrated.getPassword()); assertEquals(jdbcResource.getPort(), rehydrated.getPort()); assertEquals(jdbcResource.isInput(), rehydrated.isInput()); ExecutionProfile executionProfile = new ExecutionProfile("run1", "some/path/to/a.ktl", "tranformation", "A test profile"); long currentMillis = System.currentTimeMillis(); long futureMillis = currentMillis + 10000; Timestamp startTime = new Timestamp(currentMillis); Timestamp endTime = new Timestamp(futureMillis); executionProfile.getExecutionData().setStartTime(startTime); executionProfile.getExecutionData().setEndTime(endTime); executionProfile.getExecutionData().setClientExecutor("client.executer"); executionProfile.getExecutionData().setExecutorServer("www.pentaho.com"); executionProfile.getExecutionData().setExecutorUser("wseyler"); executionProfile.getExecutionData().setLoggingChannelId("kettle.debug"); executionProfile.getExecutionData() .addParameter(new ParamInfo("testParam1", "Larry", "Fine", "A Test Parameter")); executionProfile.getExecutionData() .addParameter(new ParamInfo("testParam2", "Howard", "Moe", "Another Parameter")); executionProfile.getExecutionData() .addParameter(new ParamInfo("testParam3", "Fine", "Curly", "A Third Parameter")); String externalResourceName = "prices.csv"; String externalResourceDescription = "A test csv file"; String externalResourceType = "csv"; String attributeName = "hair"; String attributeValue = "red"; BaseResourceInfo externalResourceInfo = new BaseResourceInfo(); externalResourceInfo.setName(externalResourceName); externalResourceInfo.setDescription(externalResourceDescription); externalResourceInfo.setInput(true); externalResourceInfo.setType(externalResourceType); externalResourceInfo.putAttribute(attributeName, attributeValue); executionProfile.getExecutionData().addExternalResource("testStep", externalResourceInfo); String variable1Name = "area"; String variable1Value = "West"; String variable2Name = "dept"; String variable2Value = "Sales"; executionProfile.getExecutionData().addVariable(variable1Name, variable1Value); executionProfile.getExecutionData().addVariable(variable2Name, variable2Value); String arg1 = "You're stupid"; String arg2 = "You're ugly"; String arg3 = "You're lazy"; executionProfile.getExecutionData().putArgument(0, arg1); executionProfile.getExecutionData().putArgument(1, arg2); executionProfile.getExecutionData().putArgument(2, arg3); json = mapper.writeValueAsString(executionProfile); // System.out.println( json ); ExecutionProfile rehydratedProfile = mapper.readValue(json, ExecutionProfile.class); assertEquals(executionProfile.getName(), rehydratedProfile.getName()); assertEquals(executionProfile.getPath(), rehydratedProfile.getPath()); assertEquals(executionProfile.getType(), rehydratedProfile.getType()); assertEquals(executionProfile.getDescription(), rehydratedProfile.getDescription()); assertEquals(executionProfile.getExecutionData().getStartTime() .compareTo(rehydratedProfile.getExecutionData().getStartTime()), 0); assertEquals(executionProfile.getExecutionData().getEndTime() .compareTo(rehydratedProfile.getExecutionData().getEndTime()), 0); assertEquals(executionProfile.getExecutionData().getFailureCount(), 0); assertEquals(executionProfile.getExecutionData().getClientExecutor(), rehydratedProfile.getExecutionData().getClientExecutor()); assertEquals(executionProfile.getExecutionData().getExecutorServer(), rehydratedProfile.getExecutionData().getExecutorServer()); assertEquals(executionProfile.getExecutionData().getExecutorUser(), rehydratedProfile.getExecutionData().getExecutorUser()); assertEquals(executionProfile.getExecutionData().getLoggingChannelId(), rehydratedProfile.getExecutionData().getLoggingChannelId()); assertEquals(rehydratedProfile.getExecutionData().getParameters().size(), 3); assertEquals(rehydratedProfile.getExecutionData().getExternalResources().size(), 1); Map<Object, Object> attributes = rehydratedProfile.getExecutionData().getExternalResources().get("testStep") .get(0).getAttributes(); assertEquals(attributes.get(attributeName), attributeValue); assertEquals(executionProfile.getExecutionData().getVariables().size(), 2); assertTrue(executionProfile.getExecutionData().getVariables().containsKey(variable1Name)); assertTrue(executionProfile.getExecutionData().getVariables().containsKey(variable2Name)); assertTrue(executionProfile.getExecutionData().getVariables().containsValue(variable1Value)); assertTrue(executionProfile.getExecutionData().getVariables().containsValue(variable2Value)); assertEquals(executionProfile.getExecutionData().getArguments().get(0), arg1); assertEquals(executionProfile.getExecutionData().getArguments().get(1), arg2); assertEquals(executionProfile.getExecutionData().getArguments().get(2), arg3); }
From source file:com.concursive.connect.web.taglibs.DateTimeHandler.java
public void setDate(Date tmp) { this.timestamp = new Timestamp(tmp.getTime()); }
From source file:me.hqm.plugindev.wget.WGET.java
public static void login(Player player) { WGUser alias = new WGUser(); Db db = Db.open(DB_URL);//from w ww . j a va 2s . com WGUser user = db.from(alias).where(alias.minecraftId).is(player.getUniqueId().toString()).selectFirst(); user.sessionExpires = new Timestamp( System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(DB_SESSION_MINS)); user.lastKnownName = player.getName(); db.update(user); db.close(); player.performCommand("wget " + WGCommand.CACHE.get(player.getName()).toString()); }
From source file:org.cleverbus.core.common.dao.RequestResponseDaoJpaImpl.java
@Override public List<Request> findByCriteria(Date from, Date to, String subUri, String subRequest) { Assert.notNull(from, "the from must not be null"); Assert.notNull(to, "the to must not be null"); String jSql = "SELECT r " + " FROM " + Request.class.getName() + " r " + " WHERE r.reqTimestamp >= :from " + " AND r.reqTimestamp <= :to "; if (hasText(subUri)) { jSql += " AND r.uri like :subUri)"; }//ww w . j a va 2 s . c o m if (hasText(subRequest)) { jSql += " AND r.request like :subRequest)"; } jSql += " ORDER BY r.reqTimestamp"; TypedQuery<Request> q = em.createQuery(jSql, Request.class); q.setParameter("from", new Timestamp(from.getTime())); q.setParameter("to", new Timestamp(to.getTime())); if (hasText(subUri)) { q.setParameter("subUri", "%" + subUri + "%"); } if (hasText(subRequest)) { q.setParameter("subRequest", "%" + subRequest + "%"); } q.setMaxResults(MAX_REQUESTS_IN_ONE_QUERY); return q.getResultList(); }
From source file:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * @param oldDBConn//from w w w. j a va2 s .c o m * @param newDBConn * @return */ public static void convertImagesToWebLinks(final Connection oldDBConn, final Connection newDBConn) { IdMapperIFace ceMapper = IdMapperMgr.getInstance().addTableMapper("collectingevent", "CollectingEventID", false); PreparedStatement pStmt1 = null; try { Timestamp now = new Timestamp(System.currentTimeMillis()); pStmt1 = newDBConn .prepareStatement("UPDATE collectingevent SET VerbatimDate=? WHERE CollectingEventID=?"); int errCnt = 0; int cnt = 0; String sql = "SELECT VerbatimDate, CollectingEventID FROM collectingevent WHERE VerbatimDate IS NOT NULL"; Vector<Object[]> rows = BasicSQLUtils.query(oldDBConn, sql); for (Object[] row : rows) { Integer newId = ceMapper.get((Integer) row[1]); if (newId != null) { String fileName = (String) row[0]; String shortenName = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length()); shortenName = URLDecoder.decode(shortenName, "UTF-8"); URI uri = new URI("file", "/" + shortenName, null); String uriStr = uri.getRawPath(); System.out.println("[" + shortenName + "][" + uriStr + "]"); shortenName = uriStr.substring(uriStr.lastIndexOf('/') + 1, uriStr.length()); System.out.println("[" + shortenName + "][" + fileName + "]"); if (shortenName.length() < 51) { pStmt1.setString(1, shortenName); pStmt1.setInt(2, newId); pStmt1.execute(); cnt++; } else { System.err.println( String.format("Name Length Error %d [%s]", shortenName.length(), shortenName)); errCnt++; } } else { System.err.println(String.format("Couldn't map OldID %d", (Integer) row[1])); errCnt++; } } System.out.println( String.format("Done - convertImagesToWebLinks Transfered : %d, Errors: %d", cnt, errCnt)); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (pStmt1 != null) pStmt1.close(); } catch (Exception ex) { } } }
From source file:edu.depaul.armada.service.ArmadaServiceImpl.java
/** * First this log checks to see if there is an existing ContainerDao with the same unique ID. * If not, a new container is created. After that, a new log is created, and its fields are set. * From there the log is added to the existing (or newly created) container and stored (for more * on storing Containers, see implementation in ContainerDaoHibernate.java). * @param agentContainer/*from www . j a v a 2 s.c o m*/ */ @Override public void send(AgentContainerLog agentContainer) { Timestamp currentTime = new Timestamp(System.currentTimeMillis()); // get container matching unique id Container container = containerDao.findWithContainerUniqueId(agentContainer.containerUniqueId); if (container == null) { container = new Container(); container.setCAdvisorURL(agentContainer.cAdvisorURL); container.setContainerUniqueId(agentContainer.containerUniqueId); container.setName(agentContainer.name); } container.setTimestamp(currentTime); // add entry ContainerLog log = new ContainerLog(); log.setCpuUsed(agentContainer.cpuUsed); log.setCpuTotal(agentContainer.cpuTotal); log.setMemUsed(agentContainer.memUsed); log.setMemTotal(agentContainer.memTotal); log.setDiskUsed(agentContainer.diskUsed); log.setDiskTotal(agentContainer.diskTotal); log.setTimestamp(currentTime); container.addLog(log); // save container containerDao.store(container); logger.info("-- Inserting new logs with timestamp " + currentTime); }
From source file:org.dcache.chimera.H2FsSqlDriver.java
@Override long createTagInode(int uid, int gid, int mode) { final String CREATE_TAG_INODE_WITHOUT_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, " + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,0,?,?,?,NULL)"; Timestamp now = new Timestamp(System.currentTimeMillis()); KeyHolder keyHolder = new GeneratedKeyHolder(); int rc = _jdbc.update(con -> { PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITHOUT_VALUE, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, mode | UnixPermission.S_IFREG); ps.setInt(2, uid);//from w w w . j ava2 s. co m ps.setInt(3, gid); ps.setTimestamp(4, now); ps.setTimestamp(5, now); ps.setTimestamp(6, now); return ps; }, keyHolder); if (rc != 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITHOUT_VALUE, 1, rc); } /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code * in the base class. */ return (Long) keyHolder.getKey(); }
From source file:fr.mcc.ginco.solr.TermSolrConverter.java
/** * Convert a Thesaurus Term into a SolrDocument * * @param thesaurusTerm/* w ww.j av a 2 s .c om*/ * @return SolrInputDocument */ public SolrInputDocument convertSolrTerm(ThesaurusTerm thesaurusTerm) { SolrInputDocument doc = new SolrInputDocument(); doc.addField(SolrField.THESAURUSID, thesaurusTerm.getThesaurusId()); doc.addField(SolrField.THESAURUSTITLE, thesaurusTerm.getThesaurus().getTitle()); doc.addField(SolrField.IDENTIFIER, thesaurusTerm.getIdentifier()); doc.addField(SolrField.LEXICALVALUE, StringEscapeUtils.unescapeHtml4(thesaurusTerm.getLexicalValue().replace("'", "'"))); doc.addField(SolrField.TYPE, ThesaurusTerm.class.getSimpleName()); doc.addField(SolrField.LANGUAGE, thesaurusTerm.getLanguage().getId()); if (thesaurusTerm.getConcept() != null) { doc.addField(SolrField.CONCEPTID, thesaurusTerm.getConcept().getIdentifier()); } boolean preferred; if (thesaurusTerm.getPrefered() == null) { preferred = false; } else { preferred = thesaurusTerm.getPrefered(); } if (preferred) { doc.addField(SolrField.EXT_TYPE, ExtEntityType.TERM_PREF); } else { doc.addField(SolrField.EXT_TYPE, ExtEntityType.TERM_NON_PREF); } Timestamp modifiedDate = new Timestamp(thesaurusTerm.getModified().getTime()); doc.addField(SolrField.MODIFIED, modifiedDate); Timestamp createdDate = new Timestamp(thesaurusTerm.getCreated().getTime()); doc.addField(SolrField.CREATED, createdDate); doc.addField(SolrField.STATUS, thesaurusTerm.getStatus()); List<Note> notes = noteService.getTermNotePaginatedList(thesaurusTerm.getIdentifier(), 0, 0); for (Note note : notes) { doc.addField(SolrField.NOTES, note.getLexicalValue()); } return doc; }
From source file:net.bioclipse.structuredb.persistence.dao.GenericDaoTest.java
protected void addAuditInformation(BaseObject object) { Timestamp now = new Timestamp(System.currentTimeMillis()); object.setCreated(now);/*from w w w. jav a2 s .co m*/ object.setEdited(now); }