List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java
/** * ??/* w ww . ja v a 2s .com*/ * * @param map * @return */ private List<UserArticle> getTopCommendArticles(Map<String, Object> map) { List<UserArticle> userArticles = userArticleMapper.getTopCommendArticles(map); List<UserArticle> recommendUserArticle = userArticleMapper .getArticleCommentByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(recommendUserArticle)) { //??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.getTopReadArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:vn.edu.vttu.ui.PanelStatiticsPaymentRawmaterialInvoice.java
private void statiticsMonth() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String datetimeStart = formatter.format(dtFormDate.getDate()); Timestamp tsStart = Timestamp.valueOf(datetimeStart); String datetimeEnd = formatter.format(dtToDate.getDate()); Timestamp tsToDate = Timestamp.valueOf(datetimeEnd); tbResult.setModel(//ww w . ja v a 2 s .c o m PaymentInvoice.getPaymentInvoiceRawmaterialInvoiceByMonth(tsStart, tsToDate, ConnectDB.conn())); }
From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java
@Test public void testNamedQueryNotFound() throws IOException { Assertions.assertThrows(IllegalArgumentException.class, () -> { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1)); params.add("createdTime", tomorrow); namedQueryService.get("sproc.getAttributesCreatedBefore", params); });//from w ww .ja va 2 s. c om }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiResourceDAO.java
static void addBinaryResource(Connection connection, String apiID, String resourceID, ResourceCategory category, String dataType, InputStream binaryValue, String createdBy) throws SQLException { final String query = "INSERT INTO AM_API_RESOURCES (UUID, API_ID, RESOURCE_CATEGORY_ID, " + "DATA_TYPE, RESOURCE_BINARY_VALUE, CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME) " + "VALUES (?,?,?,?,?,?,?,?,?)"; try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setString(1, resourceID); statement.setString(2, apiID);/* w w w .ja va2 s .c om*/ statement.setInt(3, ResourceCategoryDAO.getResourceCategoryID(connection, category)); statement.setString(4, dataType); statement.setBinaryStream(5, binaryValue); statement.setString(6, createdBy); statement.setTimestamp(7, Timestamp.valueOf(LocalDateTime.now())); statement.setString(8, createdBy); statement.setTimestamp(9, Timestamp.valueOf(LocalDateTime.now())); statement.execute(); } }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastUsageHourlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {//from w w w.ja v a2 s .c o m connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM USAGE_LAST_HOURLY_TS WHERE ID='LatestTS'"; PreparedStatement ps = connection.prepareStatement(sql); ResultSet resultSet = ps.executeQuery(); if (resultSet.next()) { lastSummaryTs = resultSet.getTimestamp("TIMESTMP"); } else { lastSummaryTs = new Timestamp(0); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO USAGE_LAST_HOURLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?"; PreparedStatement ps1 = connection.prepareStatement(currentSql); ps1.setTimestamp(1, currentTs); ps1.setTimestamp(2, currentTs); ps1.execute(); } catch (SQLException e) { log.error("Error occurred while trying to get and update the last hourly timestamp. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:com.hp.rest.UtilitiesHandle.java
@POST @Path("/putCalendar") @Consumes(MediaType.APPLICATION_JSON)/*from w w w . j a va2 s. com*/ public Response putCalendar(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(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (calendar == null) return Response.status(200).entity("false").build(); List<Calendar> calendarList = calendarDAO.getCalendarList(calendar.getStaff().getId(), calendar.getProvince(), calendar.getCalendarDate()); if (calendarList != null && calendarList.size() > 0) { return Response.status(200).entity("existcalendar").build(); } Date today = new Date(); calendar.setCreatedTime(Timestamp.valueOf(dateFormat.format(today))); calendar.setUpdatedTime(Timestamp.valueOf(dateFormat.format(today))); return Response.status(200).entity(calendarDAO.saveOrUpdate(calendar) + "").build(); }
From source file:org.nuxeo.ecm.directory.DirectoryCSVLoader.java
protected static Object decode(Field field, String value) { Type type = field.getType();// w w w. j a va2s.com if (type instanceof DateType) { // compat with earlier code, interpret in the local timezone and not UTC Calendar cal = new GregorianCalendar(); cal.setTime(Timestamp.valueOf(value)); return cal; } else { return type.decode(value); } }
From source file:com.impetus.kundera.property.accessor.SQLTimestampAccessor.java
@Override public Timestamp fromString(Class targetClass, String s) { if (s == null) { return null; }// ww w.j a v a 2 s . co m if (StringUtils.isNumeric(s)) { return new Timestamp(Long.parseLong(s)); } Timestamp t = Timestamp.valueOf(s); return t; }
From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCJourneyDAO.java
@Override public Journey create(Journey journey) throws DAOException, ValidationException { logger.debug("Creating Journey", journey); JourneyValidator.validate(journey);//from ww w . j a va2 s . c o m for (Journey element : readAll()) { if (element.getName().equals(journey.getName()) && element.getStartDate() == journey.getStartDate() && element.getEndDate() == journey.getStartDate()) return element; } Map<String, Object> parameters = new HashMap<String, Object>(1); parameters.put("name", journey.getName()); parameters.put("start", Timestamp.valueOf(journey.getStartDate())); parameters.put("end", Timestamp.valueOf(journey.getEndDate())); try { Number newId = insertJourney.executeAndReturnKey(parameters); journey.setId((int) newId.longValue()); addedCallbacks.forEach(cb -> cb.accept(journey)); return journey; } catch (DataAccessException ex) { logger.error("Failed to create journey", ex); throw new DAOException("Failed to create journey", ex); } }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonProfessionalData.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 novos = 0; int notImported = 0; int dontExist = 0; int deleted = 0; int totalInFenix = 0; int repeted = 0; Set<Person> importedButInvalid = new HashSet<Person>(); while (result.next()) { count++;//from w w w . jav a2 s . c o m final String personNumberString = result.getString("emp_num"); final Person person = metadata.getPerson(personNumberString, logger); if (person == null) { logger.debug("Invalid person with number: " + personNumberString); dontExist++; continue; } final Space campus = getCampus(result.getInt("EMP_LOC_TRAB")); String institutionEntryDateString = result.getString("emp_adm_emp_dt"); final LocalDate institutionEntryDate = StringUtils.isEmpty(institutionEntryDateString) ? null : new LocalDate(Timestamp.valueOf(institutionEntryDateString)); final String contractSituationGiafId = result.getString("emp_sit"); final ContractSituation contractSituation = metadata.situation(contractSituationGiafId); if (contractSituation == null) { logger.debug("Empty situation: " + contractSituationGiafId + " for person number: " + personNumberString); importedButInvalid.add(person); } String contractSituationDateString = result.getString("emp_sit_dt"); final LocalDate contractSituationDate = StringUtils.isEmpty(contractSituationDateString) ? null : new LocalDate(Timestamp.valueOf(contractSituationDateString)); String terminationSituationDateString = result.getString("emp_rz_dem_dt"); if ((!StringUtils.isEmpty(terminationSituationDateString) || !StringUtils.isEmpty(terminationSituationDateString)) && (contractSituation == null || !contractSituation.getEndSituation())) { logger.debug("Non end situation with endSituationDate: " + contractSituationGiafId + " for person number: " + personNumberString); } final LocalDate terminationSituationDate = StringUtils.isEmpty(terminationSituationDateString) ? null : new LocalDate(Timestamp.valueOf(terminationSituationDateString)); final String professionalRelationGiafId = result.getString("EMP_VINCULO"); final ProfessionalRelation professionalRelation = metadata.relation(professionalRelationGiafId); if (professionalRelation == null) { logger.debug("Empty relation: " + professionalRelationGiafId + " for person number: " + personNumberString); importedButInvalid.add(person); } String professionalRelationDateString = result.getString("EMP_VINCULO_DT"); final LocalDate professionalRelationDate = StringUtils.isEmpty(professionalRelationDateString) ? null : new LocalDate(Timestamp.valueOf(professionalRelationDateString)); final String professionalContractTypeGiafId = result.getString("EMP_TP_FUNC"); final ProfessionalContractType professionalContractType = metadata .contractType(professionalContractTypeGiafId); final String professionalCategoryGiafId = result.getString("EMP_CAT_FUNC"); final ProfessionalCategory professionalCategory = metadata.category(professionalCategoryGiafId); if (professionalCategory == null) { logger.debug("Empty category: " + professionalCategoryGiafId + " for person number: " + personNumberString); importedButInvalid.add(person); } String professionalCategoryDateString = result.getString("EMP_CAT_FUNC_DT"); final LocalDate professionalCategoryDate = StringUtils.isEmpty(professionalCategoryDateString) ? null : new LocalDate(Timestamp.valueOf(professionalCategoryDateString)); final String professionalRegimeGiafId = result.getString("EMP_REGIME"); final ProfessionalRegime professionalRegime = metadata.regime(professionalRegimeGiafId); if (professionalRegime == null) { logger.debug( "Empty regime: " + professionalRegimeGiafId + " for person number: " + personNumberString); importedButInvalid.add(person); } String professionalRegimeDateString = result.getString("EMP_REGIME_DT"); final LocalDate professionalRegimeDate = StringUtils.isEmpty(professionalRegimeDateString) ? null : new LocalDate(Timestamp.valueOf(professionalRegimeDateString)); String creationDateString = result.getString("data_criacao"); final DateTime creationDate = StringUtils.isEmpty(creationDateString) ? null : new DateTime(Timestamp.valueOf(creationDateString)); String modifiedDateString = result.getString("data_alteracao"); final DateTime modifiedDate = StringUtils.isEmpty(modifiedDateString) ? null : new DateTime(Timestamp.valueOf(modifiedDateString)); final PersonProfessionalData personProfessionalData = person.getPersonProfessionalData(); if (personProfessionalData == null) { modifications.add(new Modification() { @Override public void execute() { PersonProfessionalData personProfessionalData = new PersonProfessionalData(person); new GiafProfessionalData(personProfessionalData, personNumberString, institutionEntryDate, contractSituation, contractSituationGiafId, contractSituationDate, terminationSituationDate, professionalRelation, professionalRelationGiafId, professionalRelationDate, professionalContractType, professionalContractTypeGiafId, professionalCategory, professionalCategoryGiafId, professionalCategoryDate, professionalRegime, professionalRegimeGiafId, professionalRegimeDate, campus, creationDate, modifiedDate); } }); novos++; } else { final GiafProfessionalData giafProfessionalData = personProfessionalData .getGiafProfessionalDataByGiafPersonIdentification(personNumberString); if (giafProfessionalData == null) { modifications.add(new Modification() { @Override public void execute() { new GiafProfessionalData(personProfessionalData, personNumberString, institutionEntryDate, contractSituation, contractSituationGiafId, contractSituationDate, terminationSituationDate, professionalRelation, professionalRelationGiafId, professionalRelationDate, professionalContractType, professionalContractTypeGiafId, professionalCategory, professionalCategoryGiafId, professionalCategoryDate, professionalRegime, professionalRegimeGiafId, professionalRegimeDate, campus, creationDate, modifiedDate); } }); novos++; } else { if (!hasDiferences(giafProfessionalData, institutionEntryDate, contractSituation, contractSituationGiafId, contractSituationDate, terminationSituationDate, professionalRelation, professionalRelationGiafId, professionalRelationDate, professionalContractType, professionalContractTypeGiafId, professionalCategory, professionalCategoryGiafId, professionalCategoryDate, professionalRegime, professionalRegimeGiafId, professionalRegimeDate, campus, creationDate, modifiedDate)) { modifications.add(new Modification() { @Override public void execute() { giafProfessionalData.setInstitutionEntryDate(institutionEntryDate); giafProfessionalData.setContractSituation(contractSituation); giafProfessionalData.setContractSituationGiafId(contractSituationGiafId); giafProfessionalData.setContractSituationDate(contractSituationDate); giafProfessionalData.setTerminationSituationDate(terminationSituationDate); giafProfessionalData.setProfessionalRelation(professionalRelation); giafProfessionalData.setProfessionalRelationGiafId(professionalRelationGiafId); giafProfessionalData.setProfessionalRelationDate(professionalRelationDate); giafProfessionalData.setProfessionalContractType(professionalContractType); giafProfessionalData .setProfessionalContractTypeGiafId(professionalContractTypeGiafId); giafProfessionalData.setProfessionalCategory(professionalCategory); giafProfessionalData.setProfessionalCategoryGiafId(professionalCategoryGiafId); giafProfessionalData.setProfessionalCategoryDate(professionalCategoryDate); giafProfessionalData.setProfessionalRegime(professionalRegime); giafProfessionalData.setProfessionalRegimeGiafId(professionalRegimeGiafId); giafProfessionalData.setProfessionalRegimeDate(professionalRegimeDate); giafProfessionalData.setCampus(campus); giafProfessionalData.setCreationDate(creationDate); giafProfessionalData.setModifiedDate(modifiedDate); } }); } } } } result.close(); preparedStatement.close(); oracleConnection.closeConnection(); totalInFenix = Bennu.getInstance().getGiafProfessionalDataSet().size(); log.println("-- Professional data --"); log.println("Total GIAF: " + count); log.println("New: " + novos); 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; }