Example usage for java.sql Timestamp valueOf

List of usage examples for java.sql Timestamp valueOf

Introduction

In this page you can find the example usage for java.sql Timestamp valueOf.

Prototype

@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) 

Source Link

Document

Obtains an instance of Timestamp from a LocalDateTime object, with the same year, month, day of month, hours, minutes, seconds and nanos date-time value as the provided LocalDateTime .

Usage

From source file:vn.edu.vttu.ui.PanelStatiticsPaymentRawmaterialInvoice.java

private void statiticsYear() {
    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(//w  ww.j  a v a  2  s. c  om
            PaymentInvoice.getPaymentInvoiceRawmaterialInvoiceByYear(tsStart, tsToDate, ConnectDB.conn()));
}

From source file:org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImplTests.java

@Test
public void retrievingTokenReturnsCorrectData() {

    template.execute("insert into persistent_logins (series, username, token, last_used) values "
            + "('joesseries', 'joeuser', 'atoken', '2007-10-09 18:19:25.000000000')");
    PersistentRememberMeToken token = repo.getTokenForSeries("joesseries");

    assertThat(token.getUsername()).isEqualTo("joeuser");
    assertThat(token.getSeries()).isEqualTo("joesseries");
    assertThat(token.getTokenValue()).isEqualTo("atoken");
    assertThat(token.getDate()).isEqualTo(Timestamp.valueOf("2007-10-09 18:19:25.000000000"));
}

From source file:com.khartec.waltz.data.changelog.ChangeLogDao.java

public int write(ChangeLog changeLog) {
    checkNotNull(changeLog, "changeLog must not be null");

    return dsl.insertInto(CHANGE_LOG).set(CHANGE_LOG.MESSAGE, changeLog.message())
            .set(CHANGE_LOG.PARENT_ID, changeLog.parentReference().id())
            .set(CHANGE_LOG.PARENT_KIND, changeLog.parentReference().kind().name())
            .set(CHANGE_LOG.USER_ID, changeLog.userId()).set(CHANGE_LOG.SEVERITY, changeLog.severity().name())
            .set(CHANGE_LOG.CREATED_AT, Timestamp.valueOf(changeLog.createdAt())).execute();
}

From source file:org.wso2.carbon.governance.api.util.CheckpointTimeUtils.java

/**
 * This method used to calculate time difference of two timestamps.
 *
 * @param timeStampOne              latest timestamp.
 * @param timeStampTwo              earlier timestamp.
 * @return timeDurationTimestamp    timestamp difference from current time to current lifecycle last state changed
 *                                  time.
 *//*from   w  ww  . j  av  a2 s  .  co  m*/
public static long calculateTimeDifference(String timeStampOne, String timeStampTwo) {
    if (StringUtils.isEmpty(timeStampOne) && StringUtils.isEmpty(timeStampTwo)) {
        throw new IllegalArgumentException("Invalid arguments supplied as timestamp one: '" + timeStampOne
                + "' or" + " " + "timestamp two: '" + timeStampTwo + "' is not set");
    }
    return Timestamp.valueOf(timeStampOne).getTime() - Timestamp.valueOf(timeStampTwo).getTime();
}

From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java

/**
 * ??// w  w w  . j a v a 2  s  .c o m
 *
 * @param map
 * @return
 */
public List<UserArticle> getTopReadArticlesByCategoryIdAndTime(Map<String, Object> map) {
    List<UserArticle> userArticles = userArticleService.getTopReadArticles(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.getTopReadArticlesByCategoryIdAndTime(map);
    }
    return userArticles;
}

From source file:com.fns.grivet.repo.JdbcEntityRepository.java

@Override
public List<EntityAttributeValue> findByCreatedTime(Integer cid, LocalDateTime createdTimeStart,
        LocalDateTime createdTimeEnd) {
    String sql = QueryBuilder.newInstance().appendCreatedTimeRange().build();
    log.trace(String.format("JdbcEntityRepository.findByCreatedTime[sql=%s]", sql));
    return mapRows(jdbcTemplate.query(sql, new SqlRowSetResultSetExtractor(),
            new SqlParameterValue(Types.INTEGER, cid),
            new SqlParameterValue(Types.TIMESTAMP, Timestamp.valueOf(createdTimeStart)),
            new SqlParameterValue(Types.TIMESTAMP, Timestamp.valueOf(createdTimeEnd))));
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportPersonSabbaticalsFromGiaf.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();
    Set<Person> importedButInvalid = new HashSet<Person>();
    int count = 0;
    int news = 0;
    int notImported = 0;
    int dontExist = 0;
    while (result.next()) {
        count++;//from  www .  j a  va  2s.  c  o m
        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;
        }
        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);
            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 != null && beginDate.isAfter(endDate)) {
                logger.debug("BeginDate after EndDate. Person number: " + numberString + " begin: " + beginDate
                        + " end: " + endDate);
                importedButInvalid.add(person);
            }
        }
        String creationDateString = result.getString("data_criacao");
        if (StringUtils.isEmpty(creationDateString)) {
            logger.debug("Empty creationDate. Person number: " + numberString);
            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 (!hasPersonSabbatical(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate)) {
            modifications.add(new Modification() {
                @Override
                public void execute() {
                    new PersonSabbatical(giafProfessionalData, beginDate, endDate, creationDate, modifiedDate);
                }
            });
            news++;
        }
    }
    result.close();
    preparedStatement.close();

    int deleted = 0;
    int totalInFenix = 0;
    int repeted = 0;
    for (GiafProfessionalData giafProfessionalData : Bennu.getInstance().getGiafProfessionalDataSet()) {
        for (PersonProfessionalExemption personProfessionalExemption : giafProfessionalData
                .getPersonProfessionalExemptionsSet()) {
            if (personProfessionalExemption instanceof PersonSabbatical
                    && personProfessionalExemption.getAnulationDate() == null) {
                final PersonSabbatical personSabbatical = (PersonSabbatical) personProfessionalExemption;
                int countThisPersonSabbaticalOnGiaf = countThisPersonSabbaticalOnGiaf(oracleConnection,
                        personSabbatical, logger);
                if (countThisPersonSabbaticalOnGiaf == 0) {
                    modifications.add(new Modification() {
                        @Override
                        public void execute() {
                            personSabbatical.setAnulationDate(new DateTime());
                        }
                    });
                    deleted++;
                } else {
                    totalInFenix++;
                    if (countThisPersonSabbaticalOnGiaf > 1) {
                        repeted += countThisPersonSabbaticalOnGiaf - 1;
                    }
                }
            }
        }
    }

    oracleConnection.closeConnection();
    log.println("-- Sabbaticals --");
    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.indeed.imhotep.index.builder.util.SmartArgs.java

public long getOptionTime(String option) throws ParseException {
    String value = results.getOptionValue(option);

    try {/*from  w  ww. j  av  a2  s. c  om*/
        return Long.parseLong(value);
    } catch (Exception e) {
    }

    try {
        return Timestamp.valueOf(value).getTime();
    } catch (Exception e) {
    }

    throw new ParseException("Invalid time for option: " + option);
}

From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java

/**
 * ??//from   ww w . ja  v  a  2  s  .c om
 *
 * @param map
 * @return
 */
private List<UserArticle> getTopReadArticlesByCategoryIdAndTime(Map<String, Object> map) {
    List<UserArticle> userArticles = userArticleMapper.getTopReadArticles(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.getTopReadArticlesByCategoryIdAndTime(map);
    }
    return userArticles;
}

From source file:org.openmrs.contrib.metadatarepository.util.DateConverterTest.java

public void testConvertTimestampToString() throws Exception {
    final Timestamp timestamp = Timestamp.valueOf("2005-03-10 01:02:03.4");
    final String time = (String) converter.convert(String.class, timestamp);
    assertEquals(DateUtil.getDateTime(DateUtil.getDateTimePattern(), timestamp), time);
}