List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:cherry.foundation.type.converter.LocalDateTimeConverterTest.java
@Test public void testConvert() { LocalDateTime now = LocalDateTime.now(); for (int i = -86400 * 16; i <= 86400 * 16; i += 10) { LocalDateTime ldt = now.plusSeconds(i); Timestamp ts = new Timestamp(ldt.toDate().getTime()); assertThat(cs.convert(ts, LocalDateTime.class), is(ldt)); assertThat(cs.convert(ldt, Timestamp.class), is(ts)); }/* w ww.jav a 2s . c o m*/ }
From source file:com.frameworkset.platform.sanylog.common.BeanConvertUtil.java
/** * Map??Bean?./*from ww w .j a v a 2s . c om*/ * * @param clazz * @param dataMap ?Map * @param fieldMap Map??fieldName * @return * @throws InstantiationException * @throws IllegalAccessException * @throws IllegalArgumentException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static <T> T convert(Class<T> clazz, Map<String, Object> dataMap, Map<String, String> fieldMap) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException { T obj = clazz.newInstance(); ClassInfo classInfo = ClassUtil.getClassInfo(clazz); for (String mapKey : fieldMap.keySet()) { Object value = dataMap.get(mapKey); String fieldName = fieldMap.get(mapKey); if (value != null) { //classInfo.getDeclaredField(fieldName).set(obj, value); PropertieDescription pd = classInfo.getPropertyDescriptor(fieldName); //?? Class<?> pclazz = pd.getPropertyType(); if (Timestamp.class.isAssignableFrom(pclazz)) { if (value instanceof Date) { pd.setValue(obj, new Timestamp(((Date) value).getTime())); } } else if (Date.class.isAssignableFrom(pclazz)) { //String if (value instanceof Date) { pd.setValue(obj, value); } } else { Object targetValue = pclazz.getConstructor(String.class).newInstance(value.toString()); if (String.class.isAssignableFrom(pclazz) && value instanceof Number) { targetValue = new DecimalFormat("0").format(value); } pd.setValue(obj, targetValue); } //PropertyUtils.setProperty(obj, fieldName, value); } } return obj; }
From source file:md.ibanc.rm.spring.service.SingInOutSessionsServiceImpl.java
@Override @Transactional// www . j a v a 2 s . c o m public SingInOutSessions save(String guidId, Customers customers, HttpServletRequest request) { Sessions sessions = new Sessions(); Calendar cal = Calendar.getInstance(); Timestamp timestamp = new Timestamp(cal.getTimeInMillis()); sessions.setCreatedAt(timestamp); sessions.setSessionUid(guidId); sessionsDAO.save(sessions); SingInOutSessions singInOutSessions = new SingInOutSessions(); singInOutSessions.setCustomers(customers); singInOutSessions.setSessions(sessions); singInOutSessions.setSingInDate(timestamp); singInOutSessions.setIp(request.getRemoteAddr()); singInOutSessions.setLocation(request.getRemoteUser()); singInOutSessionsDAO.save(singInOutSessions); return singInOutSessions; }
From source file:name.richardson.james.bukkit.alias.persistence.InetAddressRecordManager.java
public InetAddressRecord create(String address) { InetAddressRecord record = find(address); if (record == null) { logger.log(Level.FINER, "Creating new InetAddressRecord for {0}.", address); record = new InetAddressRecord(); record.setAddress(address);/*from w w w. j a va 2 s. c om*/ record.setLastSeen(new Timestamp(System.currentTimeMillis())); save(record); record = find(address); } return record; }
From source file:gallery.web.validator.wallpaper.comment.WallpaperCommentValidator.java
@Override public BindingResult bindAndValidate(Object command, HttpServletRequest request) { BindingResult res = super.bindAndValidate(command, request); if (!res.hasErrors()) { WallpaperComment p = (WallpaperComment) command; //checking if there is such wallpaper if (wallpaperService.getRowCount("id", p.getId_photo()) == 1) { p.setCreationTime(new Timestamp(System.currentTimeMillis())); //setting user p.setUser(security.Utils.getCurrentUser(request)); } else {//from w ww . jav a 2 s. c o m common.CommonAttributes.addErrorMessage("not_exists.wallpaper", request); res.reject("not_exists.wallpaper"); } } return res; }
From source file:gr.uoa.di.madgik.utils.UtilFunctions.java
public static Metadata convertMapToMetadata(Map<String, String> metadataMap, String group) { Metadata metadata = new Metadata(); for (Map.Entry<String, String> entry : metadataMap.entrySet()) { if (entry.getKey().equals("username")) { metadata.setUsername(entry.getValue()); } else if (entry.getKey().equals("content-type")) { metadata.setContentType(entry.getValue()); } else if (entry.getKey().equals("author")) { metadata.setAuthor(entry.getValue()); } else if (entry.getKey().equals("comments")) { metadata.setComments(entry.getValue()); } else if (entry.getKey().equals("size")) { metadata.setSize(Integer.parseInt(entry.getValue())); } else if (entry.getKey().equals("tags")) { metadata.setTags(entry.getValue()); } else if (entry.getKey().equals("dataset_name")) { metadata.setDatasetName(entry.getValue()); } else if (entry.getKey().equals("description")) { metadata.setDescription(entry.getValue()); } else if (entry.getKey().equals("license")) { metadata.setLicense(entry.getValue()); } else if (entry.getKey().equals("owner_group")) { metadata.setLicense(entry.getValue()); } else if (entry.getKey().equals("maintainer")) { metadata.setMaintainer(entry.getValue()); } else if (entry.getKey().equals("maintainer_email")) { metadata.setMaintainerEmail(entry.getValue()); } else if (entry.getKey().equals("author_email")) { metadata.setAuthorEmail(entry.getValue()); } else if (entry.getKey().equals("source")) { metadata.setSource(entry.getValue()); } else if (entry.getKey().equals("access")) { metadata.setAccess(entry.getValue()); }//from ww w.ja v a2s. co m Timestamp timestamp = new Timestamp(System.currentTimeMillis()); metadata.setTimeCreated(timestamp); metadata.setLastUpdated(timestamp); System.out.println(entry.getKey() + "/" + entry.getValue()); } metadata.setOwnerGroup(group); //metadata = addDerrivedMetadata(metadata); return metadata; }
From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.TimestampDataConverter.java
@Override public Timestamp stringToValue(String rawData) throws ParseException { return StringUtils.isNotEmpty(rawData) ? new Timestamp(getDateTimeFormatter().parse(rawData).getTime()) : null;/* w w w . jav a 2 s . c o m*/ }
From source file:dsd.dao.ParametersDAO.java
public static List<Parameter> GetValidParameters(Calendar cal) { try {/*from w ww . j a v a 2s . c om*/ Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<Parameter> parametersList = new ArrayList<Parameter>(); try { Object[] parameters = new Object[1]; parameters[0] = new Timestamp(cal.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure( // table part tableNameParameters + " join " + tableNameParameterData + " on " + tableNameParameters + ".ID = " + tableNameParameterData + "." + tableParameterDataFields[0], // select part tableNameParameterData + "." + "ID" + " as " + tableNameParameterData + "_" + "ID" + ", " + tableNameParameterData + "." + tableParameterDataFields[0] + " as " + tableNameParameterData + "_" + tableParameterDataFields[0] + ", " + tableNameParameterData + "." + tableParameterDataFields[1] + " as " + tableNameParameterData + "_" + tableParameterDataFields[1] + ", " + tableNameParameterData + "." + tableParameterDataFields[2] + " as " + tableNameParameterData + "_" + tableParameterDataFields[2] + ", " + tableNameParameterData + "." + tableParameterDataFields[3] + " as " + tableNameParameterData + "_" + tableParameterDataFields[3] + ", " + "parameters.* ", // where part " (parameters_id, timestamp) in (select parameters_id, max(timestamp) " + " from parameter_data " + " where timestamp < ? " + " group by parameters_id " + "); ", // order by part "", con, parameters); while (results.next()) { Parameter parameter = new Parameter(); parameter.setParameterID(results.getLong("ID")); parameter.setAbbreviation(results.getString(tableParametersFields[1])); parameter.setCategory( eParameterCategory.getParameterCategory(results.getInt(tableParametersFields[4]))); parameter.setName(results.getString(tableParametersFields[0])); parameter.setParameterDataID(results.getLong(tableNameParameterData + "_ID")); parameter.setTimestamp(results .getTimestamp(tableNameParameterData + "_" + tableParameterDataFields[3]).getTime()); parameter.setUnit(results.getString(tableParametersFields[2])); parameter.setUserID(results.getInt(tableNameParameterData + "_" + tableParameterDataFields[2])); parameter .setValue(results.getFloat(tableNameParameterData + "_" + tableParameterDataFields[1])); parametersList.add(parameter); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return parametersList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:mtsar.api.csv.TaskCSV.java
public static Iterator<Task> parse(Stage stage, CSVParser csv) { final Set<String> header = csv.getHeaderMap().keySet(); checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s", String.join(",", header)); return StreamSupport.stream(csv.spliterator(), false).map(row -> { final String id = row.isSet("id") ? row.get("id") : null; final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags")) ? row.get("tags").split("\\|") : new String[0]; final String type = row.get("type"); final String description = row.isSet("description") ? row.get("description") : null; final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers")) ? row.get("answers").split("\\|") : new String[0]; final String datetime = row.isSet("datetime") ? row.get("datetime") : null; return new Task.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id)) .setStage(stage.getId()).addAllTags(Arrays.asList(tags)) .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis() : Long.parseLong(datetime) * 1000L)) .setType(StringUtils.defaultIfEmpty(type, TaskDAO.TASK_TYPE_SINGLE)).setDescription(description) .addAllAnswers(Arrays.asList(answers)).build(); }).iterator();/*w w w . j a v a 2s. co m*/ }
From source file:org.killbill.billing.plugin.dao.PluginDao.java
protected static Timestamp toTimestamp(@Nullable final Date date) { return date == null ? null : new Timestamp(date.getTime()); }