java-新的Cassandra绑定语句getDate方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-新的Cassandra绑定语句getDate方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1675字,纯文字阅读大概需要3分钟。
内容图文
![java-新的Cassandra绑定语句getDate方法](/upload/InfoBanner/zyjiaocheng/686/b70bfe327079457d9932497d70a9760a.jpg)
在一个有点遗留的项目中,我们在Spring应用程序中使用了cassandra驱动程序的版本2.
这个版本,特别是类BoundStatement公开了一个方法getDate,该方法返回一个JavaDate.我们都知道旧的Java日期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中所述:
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中添加了日期类型.为了避免将来造成混乱,我们将现有的getDate移到了getTimestamp上,以便get方法匹配其cql类型名称.
内容总结
以上是互联网集市为您收集整理的java-新的Cassandra绑定语句getDate方法全部内容,希望文章能够帮你解决java-新的Cassandra绑定语句getDate方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。