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:org.carlspring.tools.csv.dao.CSVDao.java

private void setField(PreparedStatement ps, int i, Field field, String value) throws SQLException {
    // Handle primitives
    if (field.getType().equals("int")) {
        ps.setInt(i, StringUtils.isBlank(value) ? 0 : Integer.parseInt(value));
    } else if (field.getType().equals("long")) {
        ps.setLong(i, StringUtils.isBlank(value) ? 0l : Long.parseLong(value));
    } else if (field.getType().equals("float")) {
        ps.setFloat(i, StringUtils.isBlank(value) ? 0f : Float.parseFloat(value));
    } else if (field.getType().equals("double")) {
        ps.setDouble(i, StringUtils.isBlank(value) ? 0d : Double.parseDouble(value));
    } else if (field.getType().equals("boolean")) {
        ps.setBoolean(i, StringUtils.isBlank(value) && Boolean.parseBoolean(value));
    }// www. jav a 2  s . c om
    // Handle objects
    else if (field.getType().equals("java.lang.String")) {
        ps.setString(i, StringUtils.isBlank(value) ? null : value);
    } else if (field.getType().equals("java.sql.Date")) {
        ps.setDate(i, StringUtils.isBlank(value) ? null : Date.valueOf(value));
    } else if (field.getType().equals("java.sql.Timestamp")) {
        ps.setTimestamp(i, StringUtils.isBlank(value) ? null : Timestamp.valueOf(value));
    } else if (field.getType().equals("java.math.BigDecimal")) {
        ps.setBigDecimal(i, StringUtils.isBlank(value) ? null : new BigDecimal(Long.parseLong(value)));
    }
}

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

/**
 * ???//from ww w .j a va  2s .  c om
 *
 * @return
 */
@Cacheable(value = GuavaCacheConfig.BLOG_CACHE, key = "#root.methodName")
public List<ArticleRankResponseDto> getArticlesRank() {
    List<ArticleCategory> articleCategories = articleCategoryServiceManager.getAllArticleCategory();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();

    List<ArticleRankResponseDto> articleRankResponseDtos = Lists.newArrayList();

    //??
    ArticleRankResponseDto recommentArticleRankResponseDto = new ArticleRankResponseDto();
    recommentArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_RECOMMEND);

    Map<String, Object> recommendMap = Maps.newHashMap();
    List<UserArticle> recommendUserArticles;
    List<ArticleRankResponseDataResult> recommendArticleRankResponseDataResultList = Lists.newArrayList();
    ArticleRankResponseDataResult recommendDataResult;
    for (ArticleCategory articleCategory : articleCategories) {
        recommendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        recommendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        recommendUserArticles = this.getTopRecommendArticlesByCategoryIdAndTime(recommendMap);
        if (!CollectionUtils.isEmpty(recommendUserArticles)) {
            recommendDataResult = new ArticleRankResponseDataResult();
            recommendDataResult.setCategoryInfo(articleCategory);
            recommendDataResult.setArticleInfo(recommendUserArticles.get(TOP_NUM - 1));
            recommendArticleRankResponseDataResultList.add(recommendDataResult);
        }
    }
    recommentArticleRankResponseDto.setDataResult(recommendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(recommentArticleRankResponseDto);

    //
    ArticleRankResponseDto readArticleRankResponseDto = new ArticleRankResponseDto();
    readArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_READ);

    Map<String, Object> readMap = Maps.newHashMap();
    List<UserArticle> readUserArticles;
    ArticleRankResponseDataResult readDataResult;
    List<ArticleRankResponseDataResult> readArticleRankResponseDataResultList = Lists.newArrayList();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        readMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        readMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        readUserArticles = this.getTopReadArticlesByCategoryIdAndTime(readMap);
        if (!CollectionUtils.isEmpty(readUserArticles)) {
            readDataResult = new ArticleRankResponseDataResult();
            readDataResult.setCategoryInfo(articleCategory);
            readDataResult.setArticleInfo(readUserArticles.get(TOP_NUM - 1));
            readArticleRankResponseDataResultList.add(readDataResult);
        }
    }
    readArticleRankResponseDto.setDataResult(readArticleRankResponseDataResultList);
    articleRankResponseDtos.add(readArticleRankResponseDto);

    //
    ArticleRankResponseDto commendArticleRankResponseDto = new ArticleRankResponseDto();
    commendArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_COMMEND);

    Map<String, Object> commendMap = Maps.newHashMap();
    List<UserArticle> commendUserArticles;
    ArticleRankResponseDataResult commendDataResult;
    List<ArticleRankResponseDataResult> commendArticleRankResponseDataResultList = Lists.newArrayList();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        commendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        commendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        commendUserArticles = this.getTopCommendArticles(commendMap);
        if (!CollectionUtils.isEmpty(commendUserArticles)) {
            commendDataResult = new ArticleRankResponseDataResult();
            commendDataResult.setCategoryInfo(articleCategory);
            commendDataResult.setArticleInfo(commendUserArticles.get(TOP_NUM - 1));
            commendArticleRankResponseDataResultList.add(commendDataResult);
        }
    }
    commendArticleRankResponseDto.setDataResult(commendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(commendArticleRankResponseDto);

    return articleRankResponseDtos;
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcAnnotationDao.java

@Override
public List<Number> getFilteredAnnotationIDs(Number ownerID, String text, String namespace, String after,
        String before) {//from w  w w .ja  va 2  s. c o  m

    StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
    sql.append(annotation_id).append(" FROM ").append(annotationTableName).append(" WHERE TRUE ");
    Map<String, Object> params = new HashMap<String, Object>();

    if (ownerID != null) {
        sql.append(" AND ").append(owner_id).append("  = :ownerId");
        params.put("ownerId", ownerID);
    }

    if (after != null) {
        sql.append(" AND ").append(last_modified).append("  > :afterTimestamp");
        params.put("afterTimestamp", Timestamp.valueOf(after));
    }

    if (before != null) {
        sql.append(" AND ").append(last_modified).append("  < :beforeTimestamp");
        params.put("beforeTimestamp", Timestamp.valueOf(before));
    }

    if (text != null) {
        sql.append(" AND ").append(body_text).append("  LIKE '%").append(text).append("%'");
    }

    return this.loggedQuery(sql.toString(), internalIDRowMapper, params);
}

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

/**
 * ???/*from  w  ww . j  a v a2 s.  c om*/
 *
 * @return
 */
public List<ArticleRankResponseDto> getArticlesRank() {
    List<ArticleCategory> articleCategories = articleCategoryServiceManager.getAllArticleCategory();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();

    List<ArticleRankResponseDto> articleRankResponseDtos = new ArrayList<>();

    //??
    ArticleRankResponseDto recommentArticleRankResponseDto = new ArticleRankResponseDto();
    recommentArticleRankResponseDto.setActionType(ACTION_TYPE_RECOMMEND);

    Map<String, Object> recommendMap = new HashMap<>();
    List<UserArticle> recommendUserArticles;
    List<ArticleRankResponseDataResult> recommendArticleRankResponseDataResultList = new ArrayList<>();
    ArticleRankResponseDataResult recommendDataResult;
    for (ArticleCategory articleCategory : articleCategories) {
        recommendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        recommendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        recommendUserArticles = this.getTopRecommendArticlesByCategoryIdAndTime(recommendMap);
        if (!CollectionUtils.isEmpty(recommendUserArticles)) {
            recommendDataResult = new ArticleRankResponseDataResult();
            recommendDataResult.setCategoryInfo(articleCategory);
            recommendDataResult.setArticleInfo(recommendUserArticles.get(TOP_NUM - 1));
            recommendArticleRankResponseDataResultList.add(recommendDataResult);
        }
    }
    recommentArticleRankResponseDto.setDataResult(recommendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(recommentArticleRankResponseDto);

    //
    ArticleRankResponseDto readArticleRankResponseDto = new ArticleRankResponseDto();
    readArticleRankResponseDto.setActionType(ACTION_TYPE_READ);

    Map<String, Object> readMap = new HashMap<>();
    List<UserArticle> readUserArticles;
    ArticleRankResponseDataResult readDataResult;
    List<ArticleRankResponseDataResult> readArticleRankResponseDataResultList = new ArrayList<>();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        readMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        readMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        readUserArticles = this.getTopReadArticlesByCategoryIdAndTime(readMap);
        if (!CollectionUtils.isEmpty(readUserArticles)) {
            readDataResult = new ArticleRankResponseDataResult();
            readDataResult.setCategoryInfo(articleCategory);
            readDataResult.setArticleInfo(readUserArticles.get(TOP_NUM - 1));
            readArticleRankResponseDataResultList.add(readDataResult);
        }
    }
    readArticleRankResponseDto.setDataResult(readArticleRankResponseDataResultList);
    articleRankResponseDtos.add(readArticleRankResponseDto);

    //
    ArticleRankResponseDto commendArticleRankResponseDto = new ArticleRankResponseDto();
    commendArticleRankResponseDto.setActionType(ACTION_TYPE_COMMENT);

    Map<String, Object> commendMap = new HashMap<>();
    List<UserArticle> commendUserArticles;
    ArticleRankResponseDataResult commendDataResult;
    List<ArticleRankResponseDataResult> commendArticleRankResponseDataResultList = new ArrayList<>();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        commendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        commendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        commendUserArticles = this.getTopCommendArticles(commendMap);
        if (!CollectionUtils.isEmpty(commendUserArticles)) {
            commendDataResult = new ArticleRankResponseDataResult();
            commendDataResult.setCategoryInfo(articleCategory);
            commendDataResult.setArticleInfo(commendUserArticles.get(TOP_NUM - 1));
            commendArticleRankResponseDataResultList.add(commendDataResult);
        }
    }
    commendArticleRankResponseDto.setDataResult(commendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(commendArticleRankResponseDto);

    return articleRankResponseDtos;
}

From source file:com.hihframework.core.utils.DateUtils.java

/**
 * java.sql.Date?java.sql.Timestamp "00:00:00.000"
 *
 * @param date java.sql.Date ??Date/*from   ww  w .  j av  a2s. c  om*/
 * @return java.sql.Timestamp ??Timestamp
 */
public static Timestamp convertDateToTimestampMin(java.sql.Date date) {
    return Timestamp.valueOf(date.toString() + " 00:00:00.000");
}

From source file:edgeserver.Publicador.java

private static ArrayList obtemFila() throws IOException, ClassNotFoundException {
    ArrayList<Publicacao> fila = new ArrayList<>();
    try (BufferedReader br = new BufferedReader(new FileReader("fila.txt"))) {
        String line;/*from   w w  w.  jav  a2 s . com*/
        while ((line = br.readLine()) != null) {
            String[] parts = line.split("::");
            fila.add(new Publicacao(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]),
                    Timestamp.valueOf(parts[2]), Float.parseFloat(parts[3])));
        }
    }

    return fila;
}

From source file:com.indicator_engine.controller.ToolkitAdminController.java

@RequestMapping(value = "/add_eventdata", method = RequestMethod.POST)
public String processAddEventData(@ModelAttribute("addEventDataForm") AdminAddEventDataForm addEventDataForm,
        Map<String, Object> model) {
    log.info("Entering Method : processAddEventData");
    GLAEventDao glaEventBean = (GLAEventDao) appContext.getBean("glaEvent");
    GLACategoryDao glacategoryBean = (GLACategoryDao) appContext.getBean("glaCategory");
    GLAUserDao glauserBean = (GLAUserDao) appContext.getBean("glaUser");
    GLAUser selectedglaUser = glauserBean.loaduserByName(addEventDataForm.getSelectedUser());
    GLACategory selectedglaCategory = glacategoryBean
            .loadCategoryByName(addEventDataForm.getSelectedCategory());
    GLAEvent glaEvent = new GLAEvent();
    glaEvent.setSession(addEventDataForm.getSession());
    glaEvent.setAction(addEventDataForm.getSelectedAction());
    glaEvent.setPlatform(addEventDataForm.getSelectedPlatform());
    glaEvent.setTimestamp(Timestamp.valueOf(addEventDataForm.getTimestamp()));
    glaEvent.setSource(addEventDataForm.getSelectedsource());
    glaEvent.setGlaUser(selectedglaUser);
    glaEvent.setGlaCategory(selectedglaCategory);
    GLAEntity glaEntity = new GLAEntity(addEventDataForm.getEntity(), addEventDataForm.getValue());
    glaEventBean.add(glaEvent, glaEntity);
    addEventDataForm.setSession(null);//w  w  w.  ja  v a2s  .co m
    addEventDataForm.setTimestamp(null);
    addEventDataForm.setEntity(null);
    addEventDataForm.setValue(null);
    addEventDataForm.setUser(glauserBean.selectAllUsers());
    addEventDataForm.setCategory(glacategoryBean.selectAllMinors());
    model.put("addEventDataForm", addEventDataForm);
    return "admin/add_eventdata";
}

From source file:libepg.epg.section.body.eventinformationtable.EventInformationTableRepeatingPartTest.java

/**
 * Test of getStopTime_Object method, of class
 * EventInformationTableRepeatingPart./*from   w w  w.  j av  a  2 s  . c  o  m*/
 */
@Test
public void testGetStopTime_Object() {
    LOG.info("getStopTime_Object");
    EventInformationTableRepeatingPart instance = target;
    Timestamp expResult = Timestamp.valueOf("2016-03-21 18:25:00.0");
    ;
    Timestamp result = instance.getStop_Time_Object();
    assertEquals(expResult, result);
}

From source file:org.lexevs.dao.database.service.Author.EntityRevisionTest.java

@Test
public void testEntityBeforeCreation() throws Exception {
    Entity olderEntity = entityService.resolveEntityByDate("urn:oid:22.22.0.2", "2.0", "midas002",
            "Automobiles", new Date(Timestamp.valueOf("2010-07-29 00:00:00").getTime()));

    assertNull(olderEntity);/*from  ww w.j av  a 2s . c o  m*/
}

From source file:com.softech.tbb.bean.Bean.java

/**
 * Set the contributed date of the article formatted for display
 * <p>//from  w ww.  java  2  s .  co  m
 * 
 * @param contributed
 *            The new contributed date formatted for display
 */
public void setContributedDisplay(String contributedDisplay) {
    if (ConvertUtils.isBlank(contributedDisplay)) {
        this.contributed = ConvertUtils.getTimestamp();
    } else {
        this.contributed = Timestamp.valueOf(contributedDisplay);
    }
}