List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:com.hp.rest.UtilitiesHandle.java
@POST @Path("/putTimeKeeper") @Consumes(MediaType.APPLICATION_JSON)// w w w .ja v a 2 s .co m public Response putTimeKeeper(String pData) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); ObjectMapper mapper = new ObjectMapper(); TimeKeeper timeKeeper = new TimeKeeper(); try { timeKeeper = mapper.readValue(pData, TimeKeeper.class); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (timeKeeper == null) return Response.status(200).entity("false").build(); //Check calendar exist CalendarDAO calendarDAO = new CalendarDAOImpl(); // List<Calendar> calendarList = calendarDAO.getCalendarList(timeKeeper.getProvince(), timeKeeper.getTimeAt()); // // if(calendarList == null || calendarList.size() == 0){ // return Response.status(200).entity("nocalendar").build(); // } timeKeeper.setTimeAt(Timestamp.valueOf(dateFormat.format(new Date()))); TimeKeeperDAO timeKeeperDAO = new TimeKeeperDAOImpl(); List<TimeKeeper> todayList = timeKeeperDAO.getTimeKeeperList(timeKeeper.getStaff(), df.parse(df.format(timeKeeper.getTimeAt()))); if (todayList != null && todayList.size() > 0) { TimeKeeper start = todayList.get(0); int diffInDays = (int) ((timeKeeper.getTimeAt().getTime() - start.getTimeAt().getTime()) / (1000 * 60 * 60 * 24)); long duration = timeKeeper.getTimeAt().getTime() - start.getTimeAt().getTime(); long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration); long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration); long diffInHours = TimeUnit.MILLISECONDS.toHours(duration); System.out.println("diffInSeconds: " + diffInSeconds + " diffInMinutes: " + diffInMinutes + " diffInHours: " + diffInHours); DecimalFormat dc = new DecimalFormat("####0.0"); System.out.println(Float.parseFloat(dc.format(diffInMinutes / 60f))); timeKeeper.setTimeBetween(Float.parseFloat(dc.format(diffInMinutes / 60f))); } return Response.status(200).entity(timeKeeperDAO.saveOrUpdate(timeKeeper) + "").build(); }
From source file:com.ebay.nest.io.sede.RegexSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { Text rowText = (Text) blob; Matcher m = inputPattern.matcher(rowText.toString()); if (m.groupCount() != numColumns) { throw new SerDeException("Number of matching groups doesn't match the number of columns"); }/*from w w w . ja v a2 s .c o m*/ // If do not match, ignore the line, return a row with all nulls. if (!m.matches()) { unmatchedRowsCount++; if (!alreadyLoggedNoMatch) { // Report the row if its the first time LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText); alreadyLoggedNoMatch = true; } return null; } // Otherwise, return the row. for (int c = 0; c < numColumns; c++) { try { String t = m.group(c + 1); TypeInfo typeInfo = columnTypes.get(c); String typeName = typeInfo.getTypeName(); // Convert the column to the correct type when needed and set in row obj if (typeName.equals(serdeConstants.STRING_TYPE_NAME)) { row.set(c, t); } else if (typeName.equals(serdeConstants.TINYINT_TYPE_NAME)) { Byte b; b = Byte.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.SMALLINT_TYPE_NAME)) { Short s; s = Short.valueOf(t); row.set(c, s); } else if (typeName.equals(serdeConstants.INT_TYPE_NAME)) { Integer i; i = Integer.valueOf(t); row.set(c, i); } else if (typeName.equals(serdeConstants.BIGINT_TYPE_NAME)) { Long l; l = Long.valueOf(t); row.set(c, l); } else if (typeName.equals(serdeConstants.FLOAT_TYPE_NAME)) { Float f; f = Float.valueOf(t); row.set(c, f); } else if (typeName.equals(serdeConstants.DOUBLE_TYPE_NAME)) { Double d; d = Double.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.BOOLEAN_TYPE_NAME)) { Boolean b; b = Boolean.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) { Timestamp ts; ts = Timestamp.valueOf(t); row.set(c, ts); } else if (typeName.equals(serdeConstants.DATE_TYPE_NAME)) { Date d; d = Date.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.DECIMAL_TYPE_NAME)) { HiveDecimal bd; bd = new HiveDecimal(t); row.set(c, bd); } else if (typeInfo instanceof PrimitiveTypeInfo && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory() == PrimitiveCategory.VARCHAR) { VarcharTypeParams varcharParams = (VarcharTypeParams) ParameterizedPrimitiveTypeUtils .getTypeParamsFromTypeInfo(typeInfo); HiveVarchar hv = new HiveVarchar(t, varcharParams != null ? varcharParams.length : -1); row.set(c, hv); } } catch (RuntimeException e) { partialMatchedRowsCount++; if (!alreadyLoggedPartialMatch) { // Report the row if its the first row LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, " + " cannot find group " + c + ": " + rowText); alreadyLoggedPartialMatch = true; } row.set(c, null); } } return row; }
From source file:org.apache.calcite.adapter.druid.DruidDateTimeUtils.java
private static Comparable toTimestamp(Object literal) { if (literal instanceof Timestamp) { return (Timestamp) literal; }/*w w w . j a v a 2 s .co m*/ if (literal instanceof Date) { return new Timestamp(((Date) literal).getTime()); } if (literal instanceof Calendar) { return new Timestamp(((Calendar) literal).getTime().getTime()); } if (literal instanceof Number) { return new Timestamp(((Number) literal).longValue()); } if (literal instanceof String) { String string = (String) literal; if (StringUtils.isNumeric(string)) { return new Timestamp(Long.valueOf(string)); } try { return Timestamp.valueOf(string); } catch (NumberFormatException e) { // ignore } } return null; }
From source file:com.example.caique.educam.Activities.TimelineActivity.java
private List<Post> listPosts(JSONArray posts) throws JSONException { List<Post> list = new ArrayList<Post>(); Log.e(getLocalClassName(), "on listPost" + posts.length()); for (int i = 0; i < posts.length(); i++) { JSONObject JSONpost = posts.getJSONObject(i); Log.e(getLocalClassName(), "on listPost: " + JSONpost); Post post = new Post(); post.setId(JSONpost.getInt("id")); post.setUser(JSONpost.getInt("user")); post.setUserName(JSONpost.getString("email")); post.setPhoto(Constants.MAIN_URL + "uploads/" + post.getId() + ".jpg"); post.setLikes(JSONpost.getInt("likes")); post.setTitle(JSONpost.getString("title")); post.setLocation(JSONpost.getString("location")); post.setCreated_at(Timestamp.valueOf(JSONpost.getString("created_at"))); list.add(post);//w ww . j av a 2 s.com } return list; }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiResourceDAO.java
static int updateTextResource(Connection connection, String resourceID, String resourceValue, String updatedBy) throws SQLException { final String query = "UPDATE AM_API_RESOURCES SET RESOURCE_TEXT_VALUE = ?, UPDATED_BY = ?, " + "LAST_UPDATED_TIME = ? WHERE UUID = ?"; try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setString(1, resourceValue); statement.setString(2, updatedBy); statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now())); statement.setString(4, resourceID); return statement.executeUpdate(); }/* w ww. j a v a 2s .c o m*/ }
From source file:com.hihframework.core.utils.DateUtils.java
/** * ?00:00:00.000? param:2004-08-20 return:2004-08-01 * 00.00.00.000/*from w ww . j a va 2s . com*/ * * @param date * @return ? */ public static Timestamp getMinDayInMonth(java.sql.Date date) { Calendar cale = Calendar.getInstance(); cale.setTime(date); cale.set(Calendar.DAY_OF_MONTH, cale.getActualMinimum(Calendar.DAY_OF_MONTH)); java.sql.Date newDate = new java.sql.Date(cale.getTimeInMillis()); cale = null; return Timestamp.valueOf(newDate.toString() + " 00:00:00.000"); }
From source file:org.apache.ddlutils.model.Column.java
/** * Tries to parse the default value of the column and returns it as an object of the * corresponding java type. If the value could not be parsed, then the original * definition is returned./*from w w w . j a v a 2s . c om*/ * * @return The parsed default value */ public Object getParsedDefaultValue() { if ((_defaultValue != null) && (_defaultValue.length() > 0)) { try { switch (_typeCode) { case Types.TINYINT: case Types.SMALLINT: return new Short(_defaultValue); case Types.INTEGER: return new Integer(_defaultValue); case Types.BIGINT: return new Long(_defaultValue); case Types.DECIMAL: case Types.NUMERIC: return new BigDecimal(_defaultValue); case Types.REAL: return new Float(_defaultValue); case Types.DOUBLE: case Types.FLOAT: return new Double(_defaultValue); case Types.DATE: return Date.valueOf(_defaultValue); case Types.TIME: return Time.valueOf(_defaultValue); case Types.TIMESTAMP: return Timestamp.valueOf(_defaultValue); case Types.BIT: case Types.BOOLEAN: return ConvertUtils.convert(_defaultValue, Boolean.class); } } catch (NumberFormatException ex) { return null; } catch (IllegalArgumentException ex) { return null; } } return _defaultValue; }
From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java
@SuppressWarnings("unchecked") protected <T> T get(Cursor cursor, Class<T> clazz, int columnIndex) { Object result = null;/*from w w w .j av a2s .co m*/ if (clazz.equals(String.class)) { result = (String) cursor.getString(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Integer) cursor.getInt(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Double) cursor.getDouble(columnIndex); } else if (clazz.equals(Float.class)) { result = (Float) cursor.getFloat(columnIndex); } else if (clazz.equals(Long.class)) { result = (Long) cursor.getLong(columnIndex); } else if (clazz.equals(Date.class) || clazz.equals(Timestamp.class)) { String dateString = cursor.getString(columnIndex); if (dateString.contains("-")) { result = Timestamp.valueOf(dateString); } else { result = new Timestamp(Long.parseLong(dateString)); } } else if (clazz.equals(Short.class)) { result = (Short) cursor.getShort(columnIndex); } else if (clazz.equals(byte[].class)) { result = (byte[]) cursor.getBlob(columnIndex); } else { throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); } return (T) result; }
From source file:cn.mljia.common.notify.utils.DateUtils.java
public static Timestamp strToTimestamp(String dateStr) { return Timestamp.valueOf(dateStr); }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertStringTypes(Object val, String javaColType) { String valStr = val.toString(); if (javaColType.equals(BIG_DECIMAL_TYPE)) { return new BigDecimal(valStr); } else if (javaColType.equals(DATE_TYPE) || javaColType.equals(TIME_TYPE) || javaColType.equals(TIMESTAMP_TYPE)) { // Oracle expects timestamps for Date also by default based on version // Just allow all date types to be assignment compatible if (valStr.length() == 10 && valStr.matches("^\\d{4}-\\d{2}-\\d{2}$")) { // Date in yyyy-mm-dd format Date d = Date.valueOf(valStr); if (javaColType.equals(DATE_TYPE)) { return d; } else if (javaColType.equals(TIME_TYPE)) { return new Time(d.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(d.getTime()); }/*from w ww . j av a 2s . co m*/ } else if (valStr.length() == 8 && valStr.matches("^\\d{2}:\\d{2}:\\d{2}$")) { // time in hh:mm:ss Time t = Time.valueOf(valStr); if (javaColType.equals(DATE_TYPE)) { return new Date(t.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return t; } else if (javaColType.equals(TIMESTAMP_TYPE)) { return new Timestamp(t.getTime()); } } else if (valStr.length() >= 19 && valStr.length() <= 26 && valStr.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d+)?$")) { // timestamp in yyyy-mm-dd hh:mm:ss Timestamp ts = Timestamp.valueOf(valStr); if (javaColType.equals(DATE_TYPE)) { return new Date(ts.getTime()); } else if (javaColType.equals(TIME_TYPE)) { return new Time(ts.getTime()); } else if (javaColType.equals(TIMESTAMP_TYPE)) { return ts; } } else { return null; } } else if (javaColType.equals(STRING_TYPE)) { return valStr; } else if (javaColType.equals(BOOLEAN_TYPE)) { return Boolean.valueOf(valStr); } else if (javaColType.equals(BYTE_TYPE)) { return Byte.parseByte(valStr); } else if (javaColType.equals(SHORT_TYPE)) { return Short.parseShort(valStr); } else if (javaColType.equals(INTEGER_TYPE)) { return Integer.parseInt(valStr); } else if (javaColType.equals(LONG_TYPE)) { return Long.parseLong(valStr); } else if (javaColType.equals(FLOAT_TYPE)) { return Float.parseFloat(valStr); } else if (javaColType.equals(DOUBLE_TYPE)) { return Double.parseDouble(valStr); } return null; }