List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonGrantOwnerEquivalentFromGiaf.java
@Override public List<Modification> processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { List<Modification> modifications = new ArrayList<>(); PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery()); ResultSet result = preparedStatement.executeQuery(); int count = 0; int news = 0; int notImported = 0; int dontExist = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;/*ww w .j a va2 s. com*/ String numberString = result.getString("emp_num"); Person person = metadata.getPerson(numberString, logger); if (person == null) { logger.debug("Invalid person with number: " + numberString); dontExist++; continue; } PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { logger.debug("Empty personProfessionalData: " + numberString); dontExist++; continue; } final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(numberString); if (giafProfessionalData == null) { logger.debug("Empty giafProfessionalData: " + numberString); dontExist++; continue; } final String grantOwnerEquivalentGiafId = result.getString("tipo_equip"); final GrantOwnerEquivalent grantOwnerEquivalent = metadata .grantOwnerEquivalent(grantOwnerEquivalentGiafId); if (grantOwnerEquivalent == null) { logger.debug("Empty grantOwnerEquivalent: " + grantOwnerEquivalentGiafId + ". Person number: " + numberString); importedButInvalid.add(person); } String beginDateString = result.getString("DATA_INICIO"); final LocalDate beginDate = StringUtils.isEmpty(beginDateString) ? null : new LocalDate(Timestamp.valueOf(beginDateString)); if (beginDate == null) { logger.debug("Empty beginDate. Person number: " + numberString + " ServiceExemption: " + grantOwnerEquivalentGiafId); importedButInvalid.add(person); } String endDateString = result.getString("DATA_FIM"); final LocalDate endDate = StringUtils.isEmpty(endDateString) ? null : new LocalDate(Timestamp.valueOf(endDateString)); if (endDate != null) { if (beginDate.isAfter(endDate)) { logger.debug("BeginDate after EndDate. Person number: " + numberString + " beginDate: " + beginDate + " endDate: " + endDate); importedButInvalid.add(person); } } final String motive = result.getString("motivo"); final String local = result.getString("local"); final String giafCountryName = result.getString("nac_dsc"); final Country country = StringUtils.isEmpty(giafCountryName) ? null : metadata.country(StringNormalizer.normalize(giafCountryName)); if (country == null) { importedButInvalid.add(person); } String creationDateString = result.getString("data_criacao"); if (StringUtils.isEmpty(creationDateString)) { logger.debug("Empty creationDate. Person number: " + numberString + " grantOwnerEquivalent: " + grantOwnerEquivalentGiafId); notImported++; continue; } final DateTime creationDate = new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = StringUtils.isEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); if (!hasPersonGrantOwnerEquivalent(giafProfessionalData, beginDate, endDate, motive, local, giafCountryName, country, grantOwnerEquivalent, grantOwnerEquivalentGiafId, creationDate, modifiedDate)) { modifications.add(new Modification() { @Override public void execute() { new PersonGrantOwnerEquivalent(giafProfessionalData, beginDate, endDate, motive, local, giafCountryName, country, grantOwnerEquivalent, grantOwnerEquivalentGiafId, creationDate, modifiedDate); } }); news++; } } result.close(); preparedStatement.close(); int deleted = 0; int totalInFenix = 0; int repeted = 0; for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) { for (PersonProfessionalExemption pesonProfessionalExemption : giafProfessionalData .getPersonProfessionalExemptionsSet()) { if (pesonProfessionalExemption instanceof PersonGrantOwnerEquivalent && pesonProfessionalExemption.getAnulationDate() == null) { final PersonGrantOwnerEquivalent personGrantOwnerEquivalent = (PersonGrantOwnerEquivalent) pesonProfessionalExemption; int countThisPersonGrantOwnerEquivalentOnGiaf = countThisPersonGrantOwnerEquivalentOnGiaf( oracleConnection, personGrantOwnerEquivalent, logger); if (countThisPersonGrantOwnerEquivalentOnGiaf == 0) { modifications.add(new Modification() { @Override public void execute() { personGrantOwnerEquivalent.setAnulationDate(new DateTime()); } }); deleted++; } else { totalInFenix++; if (countThisPersonGrantOwnerEquivalentOnGiaf > 1) { repeted += countThisPersonGrantOwnerEquivalentOnGiaf - 1; } } } } } oracleConnection.closeConnection(); log.println("-- Grant owner equivalences --"); log.println("Total GIAF: " + count); log.println("New: " + news); log.println("Deleted: " + deleted); log.println("Not imported: " + notImported); log.println("Imported with errors: " + importedButInvalid.size()); log.println("Repeted: " + repeted); log.println("Invalid persons: " + dontExist); log.println("Total Fnix: " + totalInFenix); log.println("Total Fnix without errors: " + (totalInFenix - importedButInvalid.size())); log.println("Missing in Fnix: " + (count - totalInFenix)); return modifications; }
From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java
/** * ????// w w w . j a v a2 s . c o m * * @param map * @return */ public List<UserArticle> getTopRecommendArticlesByCategoryIdAndTime(Map<String, Object> map) { List<UserArticle> userArticles = userArticleService.getTopRecommendArticles(map); List<UserArticle> articles = userArticleService .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) { //??DEFAULT_DAYS_BEFORE_PLUS map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME)) .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS))); userArticles = this.getTopRecommendArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:com.hp.rest.UtilitiesHandle.java
@POST @Path("/updateCalendar") @Consumes(MediaType.APPLICATION_JSON)//ww w . j a v a2 s .co m public Response updateCalendar(String pData) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); CalendarDAO calendarDAO = new CalendarDAOImpl(); ObjectMapper mapper = new ObjectMapper(); Calendar calendar = new Calendar(); try { calendar = mapper.readValue(pData, Calendar.class); } catch (JsonGenerationException e) { e.printStackTrace(); return Response.status(200).entity("false").build(); } catch (JsonMappingException e) { e.printStackTrace(); return Response.status(200).entity("false").build(); } catch (IOException e) { e.printStackTrace(); return Response.status(200).entity("false").build(); } if (calendar == null) return Response.status(200).entity("false").build(); //Read only if (calendarDAO.getCalendar(calendar.getStt()).getStatus() != 0) { return Response.status(200).entity("readonly").build(); } calendar.setStatus(1); Date today = new Date(); calendar.setUpdatedTime(Timestamp.valueOf(dateFormat.format(today))); //get city in this day SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); RoadManagementDAO roadManagementDAO = new RoadManagementDAOImpl(); System.out.println(calendar.getStaff().getId() + " " + sdf.format(today)); String fromDate = sdf.format(today); java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(today); c.add(java.util.Calendar.DAY_OF_MONTH, 1); String endDate = sdf.format(c.getTime()); List<List<RoadManagement>> roads = new ArrayList<List<RoadManagement>>(); roads = roadManagementDAO.getRoad(null, calendar.getStaff().getId(), "", fromDate, fromDate); String cities = ""; if (roads != null && roads.size() > 0) { List<RoadManagement> roads1 = roads.get(0); if (roads1 != null && roads1.size() > 0) for (RoadManagement rm : roads1) { String city = getAddress(rm); if (cities.equals("")) cities = city; else if (cities.indexOf(city) == -1) cities += ", " + city; } } if (!cities.equalsIgnoreCase("")) calendar.setNote(cities); return Response.status(200).entity(calendarDAO.update(calendar) + "").build(); }
From source file:org.apache.kylin.jdbc.KylinClient.java
public static Object wrapObject(String value, int sqlType) { if (null == value) { return null; }//from w ww . jav a2 s . co m switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return value; case Types.NUMERIC: case Types.DECIMAL: return new BigDecimal(value); case Types.BIT: return Boolean.parseBoolean(value); case Types.TINYINT: return Byte.valueOf(value); case Types.SMALLINT: return Short.valueOf(value); case Types.INTEGER: return Integer.parseInt(value); case Types.BIGINT: return Long.parseLong(value); case Types.FLOAT: return Float.parseFloat(value); case Types.REAL: case Types.DOUBLE: return Double.parseDouble(value); case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return value.getBytes(); case Types.DATE: return Date.valueOf(value); case Types.TIME: return Time.valueOf(value); case Types.TIMESTAMP: return Timestamp.valueOf(value); default: //do nothing break; } return value; }
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCJourneyDAO.java
@Override public void update(Journey journey) throws DAOException, ValidationException { logger.debug("Updating Journey", journey); JourneyValidator.validateID(journey.getId()); JourneyValidator.validate(journey);/*from ww w .j a v a 2 s. co m*/ try { jdbcTemplate.update(updateStatement, journey.getName(), Timestamp.valueOf(journey.getStartDate()), Timestamp.valueOf(journey.getEndDate()), journey.getId()); logger.debug("Successfully updated Journey", journey); } catch (DataAccessException ex) { logger.error("Failed updating Journey", journey); throw new DAOException("Failed updating Journey", ex); } }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiResourceDAO.java
static void updateTextValueForCategory(Connection connection, String apiID, ResourceCategory category, String resourceValue, String updatedBy) throws SQLException { final String query = "UPDATE AM_API_RESOURCES SET RESOURCE_TEXT_VALUE = ?, UPDATED_BY = ?, " + "LAST_UPDATED_TIME = ? WHERE API_ID = ? AND RESOURCE_CATEGORY_ID = ?"; try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setString(1, resourceValue); statement.setString(2, updatedBy); statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now())); statement.setString(4, apiID);//from w w w. java 2s.co m statement.setInt(5, ResourceCategoryDAO.getResourceCategoryID(connection, category)); statement.execute(); } }
From source file:com.hp.rest.OrdersHandle.java
@POST @Path("/putSaleOrder") @Consumes(MediaType.APPLICATION_JSON)/* w w w.j a va 2s .c o m*/ public Response putSaleOrder(String pTakeOrder) { SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); String time = sdf2.format(cal.getTime()); TakeOrderDAO takeOrderDAO = new TakeOrderDAOImpl(); SaleOrder saleOrder = new SaleOrder(takeOrderDAO.getTakeOrder(pTakeOrder)); saleOrder.setTakeOrderDate(Timestamp.valueOf(time)); saleOrder.setOrderEstablishDate(Timestamp.valueOf(time)); saleOrder.setDeliveryDate(Timestamp.valueOf(time)); SaleOrderDAO saleOrderDAO = new SaleOrderDAOImpl(); boolean status1 = saleOrderDAO.saveOrUpdate(saleOrder); if (status1) { TakeOrderDetailDAO takeOrderDetailDAO = new TakeOrderDetailDAOImpl(); List<TakeOrderDetail> list = new ArrayList<TakeOrderDetail>(); list = takeOrderDetailDAO.getDetailTakeOrdersList(pTakeOrder); for (int i = 0; i < list.size(); i++) { SaleOrderDetail saleOrderDetail = new SaleOrderDetail(list.get(i)); SaleOrderDetailDAO saleOrderDetailDAO = new SaleOrderDetailDAOImpl(); saleOrderDetailDAO.saveOrUpdate(saleOrderDetail); } } return Response.status(200).entity(status1 + "").build(); }
From source file:org.adempiere.pipo2.IDFinder.java
/** * Get ID from column value for a table. * * @param tableName/*from www . j av a2s . co m*/ * @param columName * @param value * @param AD_Client_ID * @param trxName */ public static int findIdByColumn(String tableName, String columnName, Object value, int AD_Client_ID, boolean ignorecase, String trxName) { int id = 0; if (value == null) return id; //construct cache key StringBuilder key = new StringBuilder(); key.append(tableName).append(".").append(columnName).append("=").append(value.toString()) .append(" AND AD_Client_ID=").append(AD_Client_ID); //check cache if (idCache.containsKey(key.toString())) return idCache.get(key.toString()); StringBuffer sqlB = new StringBuffer("SELECT ").append(tableName).append("_ID FROM ").append(tableName) .append(" WHERE ").append(" AD_Client_ID IN (0, ?) AND "); Object[] params = null; String[] columns = null; if (columnName.indexOf(",") > 0 && value instanceof String) { columns = columnName.split("[,]"); String[] values = ((String) value).split("[,]"); List<Object> paramList = new ArrayList<Object>(); for (int i = 0; i < columns.length; i++) { if (i > 0) sqlB.append(" AND "); if (ignorecase) { sqlB.append("UPPER(").append(columns[i]).append(")=? "); } else { sqlB.append(columns[i]).append("=? "); } try { byte[] bytes = Hex.decodeHex(values[i].toCharArray()); String s = new String(bytes, "UTF-8"); if (ignorecase) { paramList.add(s.toUpperCase()); } else { paramList.add(s); } } catch (DecoderException e) { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } params = paramList.toArray(); } else { if (ignorecase && value != null && value instanceof String) { sqlB.append("UPPER(").append(columnName).append(") =? "); params = new Object[] { ((String) value).toUpperCase() }; } else { sqlB.append(columnName).append(" =? "); params = new Object[] { value }; } columns = new String[] { columnName }; } sqlB.append(" Order By AD_Client_ID Desc, ").append(tableName).append("_ID"); MTable table = MTable.get(Env.getCtx(), tableName); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sqlB.toString(), trxName); pstmt.setInt(1, AD_Client_ID); for (int i = 0; i < params.length; i++) { Object param = params[i]; if (param instanceof String) { String s = (String) param; MColumn column = table.getColumn(columns[i]); if (column.getAD_Reference_ID() == DisplayType.Amount || column.getAD_Reference_ID() == DisplayType.Number || column.getAD_Reference_ID() == DisplayType.CostPrice || column.getAD_Reference_ID() == DisplayType.Quantity) pstmt.setBigDecimal(i + 2, new BigDecimal(s)); else if (column.getAD_Reference_ID() == DisplayType.Date || column.getAD_Reference_ID() == DisplayType.DateTime) pstmt.setTimestamp(i + 2, Timestamp.valueOf(s)); else if (column.getAD_Reference_ID() == DisplayType.Integer) pstmt.setInt(i + 2, Integer.parseInt(s)); else pstmt.setString(i + 2, s); } else if (param instanceof Integer) { pstmt.setInt(i + 2, ((Integer) param).intValue()); } else { pstmt.setObject(i + 2, param); } } rs = pstmt.executeQuery(); if (rs.next()) id = rs.getInt(1); } catch (Exception e) { throw new DatabaseAccessException(e); } finally { DB.close(rs, pstmt); } //update cache if (id > 0) idCache.put(key.toString(), id); return id; }
From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java
/** * ????/*from www.j av a 2s . c om*/ * * @param map * @return */ private List<UserArticle> getTopRecommendArticlesByCategoryIdAndTime(Map<String, Object> map) { List<UserArticle> userArticles = userArticleMapper.getTopRecommendArticles(map); List<UserArticle> articles = userArticleMapper .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) { //??DEFAULT_DAYS_BEFORE_PLUS map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME)) .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS))); userArticles = this.getTopRecommendArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:com.antsdb.saltedfish.util.UberUtil.java
@SuppressWarnings("unchecked") public static <T> T toObject(Class<T> klass, Object val) { if (val == null) { return null; }//w w w . j ava 2s.c o m if (klass.isInstance(val)) { return (T) val; } if (val instanceof byte[]) { if (((byte[]) val).length == 0) { return null; } val = new String((byte[]) val, Charsets.UTF_8); } if (klass == String.class) { return (T) String.valueOf(val); } if (val instanceof String) { String text = (String) val; if (klass == String.class) { return (T) text; } if (text.length() == 0) { return null; } if (klass == Integer.class) { return (T) new Integer(text); } else if (klass == Long.class) { return (T) new Long(text); } else if (klass == BigDecimal.class) { return (T) new BigDecimal(text); } else if (klass == Timestamp.class) { return (T) Timestamp.valueOf(text); } else if (klass == Date.class) { return (T) Date.valueOf(text); } else if (klass == Boolean.class) { return (T) new Boolean(text); } else if (klass == Double.class) { return (T) new Double(text); } } if (val instanceof BigDecimal) { if (klass == Long.class) { Long n = ((BigDecimal) val).longValueExact(); return (T) n; } else if (klass == Integer.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) n; } else if (klass == Double.class) { Double n = ((BigDecimal) val).doubleValue(); return (T) n; } else if (klass == Boolean.class) { Integer n = ((BigDecimal) val).intValueExact(); return (T) (Boolean) (n != 0); } } if (val instanceof Integer) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Integer) val); } else if (klass == Long.class) { return (T) Long.valueOf((Integer) val); } else if (klass == Boolean.class) { Integer n = (Integer) val; return (T) (Boolean) (n != 0); } } if (val instanceof Long) { if (klass == BigDecimal.class) { return (T) BigDecimal.valueOf((Long) val); } else if (klass == Boolean.class) { Long n = (Long) val; return (T) (Boolean) (n != 0); } } if (val instanceof Boolean) { if (klass == Long.class) { return (T) Long.valueOf((Boolean) val ? 1 : 0); } } throw new IllegalArgumentException("class: " + val.getClass()); }