com.google.cloud.Timestamp.toSqlTimestamp()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中com.google.cloud.Timestamp.toSqlTimestamp()方法的一些代码示例,展示了Timestamp.toSqlTimestamp()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.toSqlTimestamp()方法的具体详情如下:
包路径:com.google.cloud.Timestamp
类名称:Timestamp
方法名:toSqlTimestamp

Timestamp.toSqlTimestamp介绍

[英]Returns a JDBC timestamp initialized to the same point in time as this.
[中]返回初始化到与此相同时间点的JDBC时间戳。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void toFromSqlTimestamp() {
  3. long seconds = TEST_TIME_SECONDS;
  4. int nanos = 500000000;
  5. java.sql.Timestamp sqlTs = new java.sql.Timestamp(seconds * 1000);
  6. sqlTs.setNanos(nanos);
  7. Timestamp ts = Timestamp.of(sqlTs);
  8. assertThat(ts.getSeconds()).isEqualTo(seconds);
  9. assertThat(ts.getNanos()).isEqualTo(nanos);
  10. assertThat(ts.toSqlTimestamp()).isEqualTo(sqlTs);
  11. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void multiExactStaleness() {
  3. setUpPrivateDatabase();
  4. // See singleExactStaleness() for why we pick this timestamp. We expect to see no value.
  5. long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
  6. long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime;
  7. try (ReadOnlyTransaction readContext =
  8. client.readOnlyTransaction(
  9. TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS))) {
  10. Struct row = readRow(readContext);
  11. assertThat(row).isNull();
  12. assertThat(readContext.getReadTimestamp().toSqlTimestamp())
  13. .isLessThan(history.get(0).timestamp.toSqlTimestamp());
  14. insertAndReadAgain(readContext, readContext.getReadTimestamp(), null);
  15. }
  16. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void singleExactStaleness() {
  3. // TODO(user): Use a shorter deadline (when supported) and pass on the call to Cloud Spanner.
  4. long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
  5. // The only exact staleness values that can be tested reliably are before the first item or
  6. // later than the last item: we choose the former.
  7. //
  8. // Pick a staleness that is "guaranteed" not to observe the first write. Note that this
  9. // guarantee doesn't strictly hold in the absence of enforced read deadlines, but we use a
  10. // deadline large enough to make it practically true.
  11. long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime;
  12. TimestampBound bound = TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS);
  13. ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound);
  14. Struct row = readRow(readContext);
  15. assertThat(row).isNull();
  16. assertThat(readContext.getReadTimestamp().toSqlTimestamp())
  17. .isLessThan(history.get(0).timestamp.toSqlTimestamp());
  18. row = readRow(client.singleUse(bound));
  19. assertThat(row).isNull();
  20. }

代码示例来源:origin: objectify/objectify

  1. @Override
  2. protected Date toPojo(final Value<Timestamp> value) {
  3. return new java.sql.Date(value.get().toSqlTimestamp().getTime());
  4. }

代码示例来源:origin: objectify/objectify

  1. @Override
  2. protected Date toPojo(final Value<Timestamp> value) {
  3. return new Date(value.get().toSqlTimestamp().getTime());
  4. }

代码示例来源:origin: objectify/objectify

  1. @Override
  2. protected ReadableInstant loadValue(final Value<Timestamp> value, final LoadContext ctx, final Path path) throws SkipException {
  3. return TypeUtils.invoke(ctor, value.get().toSqlTimestamp().getTime());
  4. }

相关文章