List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java
@Override public Timestamp fromString(Class targetClass, String s) { if (s == null) { return null; }// w ww .ja v a 2 s .c o m if (StringUtils.isNumeric(s)) { return new Timestamp(Long.parseLong(s)); } Timestamp t = Timestamp.valueOf(s); return t; }
From source file:com.nettyhttpserver.server.NettyChannelTrafficShapingHandler.java
private void trafficAccounting() { TrafficCounter tc = trafficCounter(); connectionInfo.setRecivedBytes(Math.abs(tc.cumulativeReadBytes())); connectionInfo.setSentBytes(tc.cumulativeWrittenBytes()); connectionInfo.setSpeed(tc.lastWrittenBytes() * 1000 / (tc.checkInterval())); connectionInfo.setTimestamp(new Timestamp(System.currentTimeMillis())); /*//from ww w. j a va 2s .c o m * Instance is added to List on last place (the last the newest) */ if (serverConnectionList.contains(connectionInfo)) { serverConnectionList.remove(connectionInfo); addToConnectionList(); } else { addToConnectionList(); } }
From source file:com.chingo247.structureapi.persistence.service.ValidationService.java
/** * Gets the world data for all worlds that have/had structure tasks assigned within them * * @return Map of all structure-tasked worlds with worldname as key and timestamp as value */// w w w. ja v a 2s. c o m private HashMap<String, Timestamp> getWorldData() { HashMap<String, Timestamp> worldData = new HashMap<>(); for (World world : Bukkit.getWorlds()) { try { if (!firstTime(world)) { continue; } } catch (IOException ex) { continue; } if (isSettlerCraftWorld(world)) { Timestamp t = new Timestamp(world.getWorldFolder().lastModified()); worldData.put(world.getName(), t); } } return worldData; }
From source file:org.web4thejob.orm.test.AbstractHibernateDependentTest.java
@Before public void initializeData() { if (initialized) { return;/*from ww w . ja va 2 s . c o m*/ } Properties datasource = new Properties(); try { datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } JobletInstaller jobletInstaller; jobletInstaller = ContextUtil.getBean(JobletInstaller.class); jobletInstaller.setConnectionInfo(datasource); List<Exception> errors = jobletInstaller.installAll(); if (errors.isEmpty()) { ContextUtil.addActiveProfile("installed"); ContextUtil.refresh(); } else { throw new RuntimeException("Test Context initialization failed."); } initialized = true; final DataWriterService dataWriterService = ContextUtil.getDWS(); for (int i = 1; i <= iterations; i++) { Reference2 reference2 = new Reference2(UUID.randomUUID().toString()); dataWriterService.save(reference2); Reference1 reference1 = new Reference1(reference2, UUID.randomUUID().toString()); dataWriterService.save(reference1); final Master1 master1 = new Master1(); master1.setName(master1.getEntityType().getName()); master1.setReference1(reference1); dataWriterService.save(master1); final Master2 master2 = new Master2(); master2.setKey(UUID.randomUUID().toString()); master2.setName(master2.getEntityType().getName()); dataWriterService.save(master2); final Detail detail = new Detail(); detail.setId(new DetailId(master1, master2, UUID.randomUUID().toString(), new Random(master1.getId()).nextLong())); detail.setFclass(detail.getEntityType()); detail.setFdate(new Date()); detail.setFdouble(java.lang.Math.PI); detail.setFint(new LocalDate().getMonthOfYear()); detail.setFstring(new LocalDate().toString()); detail.setFtimestamp(new Timestamp(System.currentTimeMillis())); dataWriterService.save(detail); } }
From source file:com.clustercontrol.jobmanagement.util.JobKickFilterPropertyUtil.java
/** * DTO?????/*from w w w .j a v a2s .co m*/ * * @param property * @return */ public static JobKickFilterInfo property2dto(Property property) { JobKickFilterInfo info = new JobKickFilterInfo(); ArrayList<?> values = null; // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_ID); if (!"".equals(values.get(0))) { info.setJobkickId((String) values.get(0)); } // ?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_NAME); if (!"".equals(values.get(0))) { info.setJobkickName((String) values.get(0)); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_TYPE); if (!"".equals(values.get(0))) { info.setJobkickType((Integer) JobKickTypeMessage.stringToType((String) values.get(0))); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBUNIT_ID); if (!"".equals(values.get(0))) { info.setJobunitId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOB_ID); if (!"".equals(values.get(0))) { info.setJobId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.CALENDAR_ID); if (!"".equals(values.get(0))) { info.setCalendarId((String) values.get(0)); } // Boolean validFlg = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.VALID_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { validFlg = true; } else { validFlg = false; } } info.setValidFlg(validFlg); //?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_USER); if (!"".equals(values.get(0))) { info.setRegUser((String) values.get(0)); } //?(From) Timestamp regFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_FROM_DATE); if (values.get(0) instanceof Date) { regFromDate = new Timestamp(((Date) values.get(0)).getTime()); regFromDate.setNanos(999999999); info.setRegFromDate(regFromDate.getTime()); } //?(To) Timestamp regToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_TO_DATE); if (values.get(0) instanceof Date) { regToDate = new Timestamp(((Date) values.get(0)).getTime()); regToDate.setNanos(999999999); info.setRegToDate(regToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_USER); if (!"".equals(values.get(0))) { info.setUpdateUser((String) values.get(0)); } //(From) Timestamp updateFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_FROM_DATE); if (values.get(0) instanceof Date) { updateFromDate = new Timestamp(((Date) values.get(0)).getTime()); updateFromDate.setNanos(999999999); info.setUpdateFromDate(updateFromDate.getTime()); } //(To) Timestamp updateToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_TO_DATE); if (values.get(0) instanceof Date) { updateToDate = new Timestamp(((Date) values.get(0)).getTime()); updateToDate.setNanos(999999999); info.setUpdateToDate(updateToDate.getTime()); } //ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.OWNER_ROLE_ID); if (!"".equals(values.get(0))) { info.setOwnerRoleId((String) values.get(0)); } return info; }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlTimestampConverter.java
/** * Convert the specified input object into an output object of the specified type. * //from w ww . jav a 2s . c o m * @param type Data type to which this value should be converted * @param value The input value to be converted * @exception ConversionException if conversion cannot be performed successfully */ public Object convert(Class type, Object value) { if (value == null) { if (useDefault) { return (defaultValue); } else { throw new ConversionException("No value specified"); } } if (value instanceof java.sql.Date && java.sql.Date.class.equals(type)) { return value; } else if (value instanceof java.sql.Time && java.sql.Time.class.equals(type)) { return value; } else if (value instanceof java.sql.Timestamp && java.sql.Timestamp.class.equals(type)) { return value; } else { try { if (java.sql.Date.class.equals(type)) { return new java.sql.Date(convertTimestamp2TimeMillis(value.toString())); } else if (java.sql.Time.class.equals(type)) { return new java.sql.Time(convertTimestamp2TimeMillis(value.toString())); } else if (java.sql.Timestamp.class.equals(type)) { return new java.sql.Timestamp(convertTimestamp2TimeMillis(value.toString())); } else { return new Timestamp(convertTimestamp2TimeMillis(value.toString())); } } catch (Exception e) { throw new ConversionException("Value format invalid: " + e.getMessage(), e); } } }
From source file:org.cloudfoundry.identity.uaa.scim.endpoints.PasswordResetEndpointsTest.java
@Test public void testChangingAPasswordWithAValidCode() throws Exception { Mockito.when(expiringCodeStore.retrieveCode("secret_code")) .thenReturn(new ExpiringCode("secret_code", new Timestamp(System.currentTimeMillis()), "eyedee")); ScimUser scimUser = new ScimUser("eyedee", "userman", "User", "Man"); scimUser.addEmail("user@example.com"); Mockito.when(scimUserProvisioning.retrieve("eyedee")).thenReturn(scimUser); MockHttpServletRequestBuilder post = post("/password_change").contentType(APPLICATION_JSON) .content("{\"code\":\"secret_code\",\"new_password\":\"new_secret\"}").accept(APPLICATION_JSON); SecurityContextHolder.getContext().setAuthentication(new MockAuthentication()); mockMvc.perform(post).andExpect(status().isOk()).andExpect(content().string("userman")); Mockito.verify(scimUserProvisioning).changePassword("eyedee", null, "new_secret"); }
From source file:controllers.OldSensorReadingController.java
private static Long convertTimeToTimestamp(String timeString) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy'T'HH:mm:ss"); Long result = null;/*from www. j a v a 2s . c om*/ Date date = dateFormat.parse(timeString); System.out.println(date); Timestamp timestamp = new Timestamp(date.getTime()); result = timestamp.getTime(); System.out.println(result); return result; }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.BookingRoomController.java
@Override public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object comm, BindException bindException) throws Exception { try {/*from w w w .ja v a 2s . c o m*/ BookRoomCommand command = (BookRoomCommand) comm; status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.unknown", null, RequestContextUtils.getLocale(request)); Person user = personDao.getLoggedPerson(); int group = command.getSelectedGroup(); int repType = command.getRepType(); int repCount = command.getRepCount(); String startStr = BookingRoomUtils.getHoursAndMinutes(command.getStartTimeCal()); String endStr = BookingRoomUtils.getHoursAndMinutes(command.getEndTimeCal()); Reservation res = new Reservation(); Timestamp createTime = new Timestamp(new GregorianCalendar().getTimeInMillis()); res.setCreationTime(createTime); res.setStartTime(command.getStartTimeTimestamp()); res.setEndTime(command.getEndTimeTimestamp()); res.setPerson(user); //searching for ResearchGroup ResearchGroup grp = getResearchGroup(group); res.setResearchGroup(grp); log.debug("Reservation has been created: " + ((res == null) ? "false" : "true")); reservationDao.create(res); if (repCount > 0) { comment = messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part1", null, RequestContextUtils.getLocale(request)); comment += command.getDate() + ", from " + startStr + " to " + endStr + "<br>\n"; GregorianCalendar nextS = command.getStartTimeCal(); GregorianCalendar nextE = command.getEndTimeCal(); for (int i = 0; i < repCount; i++) { //shift of dates int add = BookingRoomUtils.getWeeksAddCount(repType, i); nextS.add(Calendar.WEEK_OF_YEAR, add); nextE.add(Calendar.WEEK_OF_YEAR, add); Reservation newReservation = new Reservation(); newReservation.setCreationTime(createTime); newReservation.setStartTime(new Timestamp(nextS.getTimeInMillis())); newReservation.setEndTime(new Timestamp(nextE.getTimeInMillis())); newReservation.setPerson(user); newReservation.setResearchGroup(grp); reservationDao.create(newReservation); comment += BookingRoomUtils.getDate(nextS) + ", from " + BookingRoomUtils.getHoursAndMinutes(nextS) + " to " + BookingRoomUtils.getHoursAndMinutes(nextE) + "<br>\n"; } comment += String.format( messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part2", null, RequestContextUtils.getLocale(request)), repCount + 1);//+1 because we need count "original" reservation! } else { comment = String .format(messageSource.getMessage("bookRoom.controllerMessages.comment.booked.single", null, RequestContextUtils.getLocale(request)), command.getDate(), startStr, endStr); } status = messageSource.getMessage("bookRoom.controllerMessages.status.ok", null, RequestContextUtils.getLocale(request)); } catch (Exception e) { log.error("Exception: " + e.getMessage() + "\n" + e.getStackTrace()[0].getFileName() + " at line " + e.getStackTrace()[0].getLineNumber(), e); status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.exception", null, RequestContextUtils.getLocale(request)) + " " + e.getMessage(); } log.debug("Returning MAV" + " with status=" + status + "&comment=" + comment); ModelAndView mav = new ModelAndView(getSuccessView()/* + "?status=" + status + "&comment=" + comment*/); return mav; }
From source file:ch.bfh.srs.srv.service.ReservationServiceTest.java
@Test public void testModReservation() { DateTime from = DateTime.now();/*from w w w . ja v a2 s . c o m*/ DateTime to = DateTime.now().plus(Period.hours(4)); boolean modified = service.modReservation(1, from, to, false); assertTrue(modified); Reservation reservationEntity = service.getById(Reservation.class, 1); assertNotNull(reservationEntity); assertEquals(new Timestamp(from.getMillis()), reservationEntity.getFrom()); assertEquals(new Timestamp(to.getMillis()), reservationEntity.getTo()); assertFalse(reservationEntity.getFullDay()); }