List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java
@Override public List<Map> queryJobExecutions(String status) { String where = ""; if (!StringUtils.isEmpty(status)) { where = " where e.status='" + status + "'"; }/*from w ww . j a v a2 s. c o m*/ String getjobs = "select e.job_execution_id as job_execution_id, e.start_time as start_time, e.end_time, e.status, e.exit_code, e.exit_message, e.create_time, e.last_updated, e.version, i.job_instance_id, i.job_name from batch_job_execution e join batch_job_instance i on e.job_instance_id=i.job_instance_id " + where + " order by job_execution_id desc"; Query query = em.createNativeQuery(getjobs); SQLQuery nativeQuery = query.unwrap(SQLQuery.class); nativeQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP); List<Map> list = null; try { list = nativeQuery.list(); } catch (Exception e) { LogUtil.getCoreLog().warn("SQL {} Error {}", getjobs, e.getMessage()); } //? List<Map> newlist = new ArrayList<Map>(); if (list != null) { for (Map map : list) { //duration Timestamp t1 = (Timestamp) map.get("START_TIME"); Timestamp t2 = (Timestamp) map.get("END_TIME"); String duration = ""; if (t2 != null) duration = format(new Date(t2.getTime() - t1.getTime()), "HH:mm:ss"); Map newmap = new HashMap<String, Object>(); newmap.put("duration", duration); Iterator<Entry<String, Object>> it = map.entrySet().iterator(); while (it.hasNext()) { Entry<String, Object> entry = it.next(); newmap.put(entry.getKey().toLowerCase(), entry.getValue()); } newlist.add(newmap); } } return newlist; }
From source file:org.freebxml.omar.server.persistence.rdb.AuditableEventDAO.java
protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {/*from w ww .j a va 2 s.c o m*/ if (!(obj instanceof AuditableEvent)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.AuditableEventExpected", new Object[] { obj })); } AuditableEvent ae = (AuditableEvent) obj; super.loadObject(obj, rs); //TODO: Fix so requestId is properly supported String requestId = rs.getString("requestId"); if (requestId == null) { requestId = "Unknown"; } ae.setRequestId(requestId); String eventType = rs.getString("eventType"); ae.setEventType(eventType); //Workaround for bug in PostgreSQL 7.2.2 JDBC driver //java.sql.Timestamp timeStamp = rs.getTimestamp("timeStamp_"); --old String timestampStr = rs.getString("timeStamp_").substring(0, 19); Timestamp timeStamp = Timestamp.valueOf(timestampStr); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timeStamp.getTime()); ae.setTimestamp(cal); String userId = rs.getString("user_"); ObjectRef ref = bu.rimFac.createObjectRef(); ref.setId(userId); context.getObjectRefs().add(ref); ae.setUser(userId); AffectedObjectDAO affectedDAO = new AffectedObjectDAO(context); affectedDAO.setParent(ae); List affectedObjects = affectedDAO.getByParent(); ObjectRefListType orefList = BindingUtility.getInstance().rimFac.createObjectRefListType(); orefList.getObjectRef().addAll(affectedObjects); ae.setAffectedObjects(orefList); } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } catch (JAXBException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } }
From source file:com.memetro.android.alerts.MapFragment.java
private long dateToTime(String str_date) { try {// w w w .j a v a 2s. c om java.text.DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date date = formatter.parse(str_date); java.sql.Timestamp timeStampDate = new Timestamp(date.getTime()); return timeStampDate.getTime() / 1000; } catch (Exception e) { e.printStackTrace(); return 0; } }
From source file:org.envirocar.aggregation.AggregatedTracksServlet.java
private String createAggregatedTracksList() throws SQLException { ResultSet rs = this.connection.executeQueryStatement(query); ArrayNode array = om.createArrayNode(); ObjectNode object;//w w w .j a va2s.c o m String id; Timestamp ts; while (rs.next()) { object = om.createObjectNode(); id = rs.getString("id"); ts = rs.getTimestamp(AGGREGATION_DATE); object.put(id, df.format(new Date(ts.getTime()))); array.add(object); } rs.close(); ObjectNode node = om.createObjectNode(); node.put("tracks", array); return node.toString(); }
From source file:kuona.jenkins.analyser.JenkinsProcessor.java
public void collectMetrics(BuildMetrics metrics) { try {//from w w w. j a v a 2 s. c o m Utils.puts("Updating " + getURI()); final int[] jobCount = { 0 }; final int[] buildCount = { 0 }; Set<String> jobNames = getJobs().keySet(); jobCount[0] = jobNames.size(); jobNames.stream().forEach(key -> { try { JobWithDetails job = getJob(key); Utils.puts("Updating " + key); final List<Build> builds = job.details().getBuilds(); buildCount[0] += builds.size(); builds.stream().forEach(buildDetails -> { try { final BuildWithDetails details = buildDetails.details(); Timestamp timestamp = new Timestamp(details.getTimestamp()); Date buildDate = new Date(timestamp.getTime()); int year = buildDate.getYear() + 1900; if (!metrics.activity.containsKey(year)) { metrics.activity.put(year, new int[12]); } int[] yearMap = metrics.activity.get(year); yearMap[buildDate.getMonth()] += 1; if (details.getResult() == null) { metrics.buildCountsByResult.put(BuildResult.UNKNOWN, metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1); } else { metrics.buildCountsByResult.put(details.getResult(), metrics.buildCountsByResult.get(details.getResult()) + 1); } metrics.byDuration.collect(details.getDuration()); final List<Map> actions = details.getActions(); actions.stream().filter(action -> action != null).forEach(action -> { if (action.containsKey("causes")) { List<HashMap> causes = (List<HashMap>) action.get("causes"); causes.stream().filter(cause -> cause.containsKey("shortDescription")) .forEach(cause -> { metrics.triggers.add((String) cause.get("shortDescription")); }); } }); metrics.completedBuilds.add(details); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }); metrics.dashboardServers.add(new HashMap<String, Object>() { { MainView serverInfo = getServerInfo(); put("name", serverInfo.getName()); put("description", serverInfo.getDescription()); put("uri", getURI().toString()); put("jobs", jobCount[0]); put("builds", buildCount[0]); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.cloudfoundry.identity.uaa.codestore.JdbcExpiringCodeStore.java
@Override public ExpiringCode generateCode(String data, Timestamp expiresAt, String intent) { cleanExpiredEntries();//from w ww .j a v a 2s . c om if (data == null || expiresAt == null) { throw new NullPointerException(); } if (expiresAt.getTime() < timeService.getCurrentTimeMillis()) { throw new IllegalArgumentException(); } int count = 0; while (count < 3) { count++; String code = generator.generate(); try { int update = jdbcTemplate.update(insert, code, expiresAt.getTime(), data, intent); if (update == 1) { ExpiringCode expiringCode = new ExpiringCode(code, expiresAt, data, intent); return expiringCode; } else { logger.warn("Unable to store expiring code:" + code); } } catch (DataIntegrityViolationException x) { if (count == 3) { throw x; } } } return null; }
From source file:com.sangupta.fileanalysis.db.DBResultViewer.java
private void format(Timestamp timestamp, int size) { if (timestamp == null) { format((String) null, size, true); return;/* ww w . ja v a 2s .c o m*/ } long l = timestamp.getTime(); Date d = new Date(l); format(FileAnalysisHelper.LOG_DATE_FORMAT.format(d), size, false); }
From source file:kuona.processor.JenkinsProcessor.java
public void collectMetrics(BuildMetrics metrics) { try {/*from www. j a v a2 s .c o m*/ puts("Updating " + getURI()); final int[] jobCount = { 0 }; final int[] buildCount = { 0 }; Set<String> jobNames = getJobs().keySet(); jobCount[0] = jobNames.size(); jobNames.stream().forEach(key -> { try { JobWithDetails job = getJob(key); puts("Updating " + key); final List<Build> builds = job.details().getBuilds(); buildCount[0] += builds.size(); builds.stream().forEach(buildDetails -> { try { final BuildWithDetails details = buildDetails.details(); Timestamp timestamp = new Timestamp(details.getTimestamp()); Date buildDate = new Date(timestamp.getTime()); int year = buildDate.getYear() + 1900; if (!metrics.activity.containsKey(year)) { metrics.activity.put(year, new int[12]); } int[] yearMap = metrics.activity.get(year); yearMap[buildDate.getMonth()] += 1; if (details.getResult() == null) { metrics.buildCountsByResult.put(BuildResult.UNKNOWN, metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1); } else { metrics.buildCountsByResult.put(details.getResult(), metrics.buildCountsByResult.get(details.getResult()) + 1); } metrics.byDuration.collect(details.getDuration()); final List<Map> actions = details.getActions(); actions.stream().filter(action -> action != null).forEach(action -> { if (action.containsKey("causes")) { List<HashMap> causes = (List<HashMap>) action.get("causes"); causes.stream().filter(cause -> cause.containsKey("shortDescription")) .forEach(cause -> { metrics.triggers.add((String) cause.get("shortDescription")); }); } }); metrics.completedBuilds.add(details); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } }); metrics.dashboardServers.add(new HashMap<String, Object>() { { MainView serverInfo = getServerInfo(); put("name", serverInfo.getName()); put("description", serverInfo.getDescription()); put("uri", getURI().toString()); put("jobs", jobCount[0]); put("builds", buildCount[0]); } }); } catch (IOException e) { e.printStackTrace(); } }
From source file:dk.nsi.haiba.lprimporter.dao.impl.LPRContactRowMapper.java
@Override public Administration mapRow(ResultSet rs, int rowNum) throws SQLException { Administration adm = new Administration(); adm.setRecordNumber(rs.getString("v_recnum")); adm.setSygehusCode(rs.getString("c_sgh")); adm.setAfdelingsCode(rs.getString("c_afd")); adm.setCpr(rs.getString("v_cpr")); adm.setPatientType(rs.getInt("c_pattype")); Timestamp tsIn = rs.getTimestamp("d_inddto"); // Rule #4 - no minutes and seconds are used in LPR if (tsIn != null) { tsIn.setMinutes(0);/*from w w w . j av a 2 s . co m*/ tsIn.setSeconds(0); adm.setIndlaeggelsesDatetime(new Date(tsIn.getTime())); } Timestamp tsOut = rs.getTimestamp("d_uddto"); if (tsOut != null) { tsOut.setMinutes(0); tsOut.setSeconds(0); adm.setUdskrivningsDatetime(new Date(tsOut.getTime())); } String type = rs.getString("v_type"); if (type != null) { if (DIAGNOSIS.equalsIgnoreCase(type)) { LPRDiagnose d = new LPRDiagnose(); d.setRecordNumber(rs.getString("v_recnum")); d.setDiagnoseCode(rs.getString("c_kode")); d.setTillaegsDiagnose(rs.getString("c_tilkode")); d.setDiagnoseType(rs.getString("c_kodeart")); adm.addLprDiagnose(d); } else { // everything not a diagnosis is a procedure. LPRProcedure p = new LPRProcedure(); p.setRecordNumber(rs.getString("v_recnum")); p.setProcedureCode(rs.getString("c_kode")); p.setTillaegsProcedureCode(rs.getString("c_tilkode")); p.setProcedureType(rs.getString("c_kodeart")); p.setSygehusCode(rs.getString("c_psgh")); p.setAfdelingsCode(rs.getString("c_pafd")); Timestamp ts = rs.getTimestamp("d_pdto"); if (ts != null) { ts.setMinutes(0); ts.setSeconds(0); p.setProcedureDatetime(new Date(ts.getTime())); } adm.addLprProcedure(p); } } return adm; }
From source file:com.heliumv.factory.impl.ZeiterfassungCall.java
private Timestamp updateTimeWithNow(Timestamp theirsTs) { if (theirsTs == null) return null; Calendar theirs = Calendar.getInstance(); theirs.setTimeInMillis(theirsTs.getTime()); Calendar mine = Calendar.getInstance(); theirs.set(Calendar.HOUR, mine.get(Calendar.HOUR)); theirs.set(Calendar.MINUTE, mine.get(Calendar.MINUTE)); theirs.set(Calendar.SECOND, 0); return new Timestamp(theirs.getTimeInMillis()); }