gpt4 book ai didi

java - 新的 cassandra 绑定(bind)语句 getDate 方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:29 24 4
gpt4 key购买 nike

在一个有些遗留的项目中,我们在 Spring 应用程序中使用了版本 2 的 cassandra 驱动程序。这个版本,特别是 BoundStatement 类公开了一个方法 getDate它返回一个 java Date .我们都知道旧的 java date api 非常糟糕,但如果谨慎使用它就可以了。

现在,由于某些需要,我们决定将 cassandra 驱动程序升级到 3.4 版。首先要注意的是,在此版本中,相同的方法getDate现在返回 LocalDate 类型的日期datastax 团队实现了一个类来替换 java 的类。文档中记录了关于此类的有趣之处:

A date with no time components, no time zone, in the ISO 8601 calendar. Note that ISO 8601 has a number of differences with the default gregorian calendar used in Java: it uses a proleptic gregorian calendar, meaning that it's gregorian indefinitely back in the past (there is no gregorian change); there is a year 0. This class implements these differences, so that year/month/day fields match exactly the ones in CQL string literals.

基本上,此类会截断时间 信息。此更改导致基于日期比较的单元测试失败,需要进行一些测试修改。对我来说这实际上看起来很奇怪,但我想 datastax 团队做出这样的选择一定有充分的理由。我很乐意听取在这方面了解更多的人的意见。

最佳答案

驱动程序 2 中的

getDate 已移至驱动程序 3.0 中的 getTimestamp,如 upgrade guide 中所述。 :

  1. Getters and setters have been added to “data-container” classes for new CQL types:

    • getByte/setByte for the TINYINT type
    • getShort/setShort for the SMALLINT type
    • getTime/setTime for the TIME type
    • getDate/setDate for the DATE type

The methods for the TIMESTAMP CQL type have been renamed to getTimestamp and setTimestamp.

This affects Row, BoundStatement, TupleValue and UDTValue.

这样做的主要理由是在 Cassandra 3.0 中添加了一个 date 类型。为防止将来出现混淆,我们将现有的 getDate 移至 getTimestamp,以便 get 方法与其 cql 类型名称相匹配。

关于java - 新的 cassandra 绑定(bind)语句 getDate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com