本文整理了Java中com.google.cloud.Timestamp.toSqlTimestamp()
方法的一些代码示例,展示了Timestamp.toSqlTimestamp()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.toSqlTimestamp()
方法的具体详情如下:
包路径:com.google.cloud.Timestamp
类名称:Timestamp
方法名:toSqlTimestamp
[英]Returns a JDBC timestamp initialized to the same point in time as this.
[中]返回初始化到与此相同时间点的JDBC时间戳。
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void toFromSqlTimestamp() {
long seconds = TEST_TIME_SECONDS;
int nanos = 500000000;
java.sql.Timestamp sqlTs = new java.sql.Timestamp(seconds * 1000);
sqlTs.setNanos(nanos);
Timestamp ts = Timestamp.of(sqlTs);
assertThat(ts.getSeconds()).isEqualTo(seconds);
assertThat(ts.getNanos()).isEqualTo(nanos);
assertThat(ts.toSqlTimestamp()).isEqualTo(sqlTs);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void multiExactStaleness() {
setUpPrivateDatabase();
// See singleExactStaleness() for why we pick this timestamp. We expect to see no value.
long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime;
try (ReadOnlyTransaction readContext =
client.readOnlyTransaction(
TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS))) {
Struct row = readRow(readContext);
assertThat(row).isNull();
assertThat(readContext.getReadTimestamp().toSqlTimestamp())
.isLessThan(history.get(0).timestamp.toSqlTimestamp());
insertAndReadAgain(readContext, readContext.getReadTimestamp(), null);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void singleExactStaleness() {
// TODO(user): Use a shorter deadline (when supported) and pass on the call to Cloud Spanner.
long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
// The only exact staleness values that can be tested reliably are before the first item or
// later than the last item: we choose the former.
//
// Pick a staleness that is "guaranteed" not to observe the first write. Note that this
// guarantee doesn't strictly hold in the absence of enforced read deadlines, but we use a
// deadline large enough to make it practically true.
long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime;
TimestampBound bound = TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS);
ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound);
Struct row = readRow(readContext);
assertThat(row).isNull();
assertThat(readContext.getReadTimestamp().toSqlTimestamp())
.isLessThan(history.get(0).timestamp.toSqlTimestamp());
row = readRow(client.singleUse(bound));
assertThat(row).isNull();
}
代码示例来源:origin: objectify/objectify
@Override
protected Date toPojo(final Value<Timestamp> value) {
return new java.sql.Date(value.get().toSqlTimestamp().getTime());
}
代码示例来源:origin: objectify/objectify
@Override
protected Date toPojo(final Value<Timestamp> value) {
return new Date(value.get().toSqlTimestamp().getTime());
}
代码示例来源:origin: objectify/objectify
@Override
protected ReadableInstant loadValue(final Value<Timestamp> value, final LoadContext ctx, final Path path) throws SkipException {
return TypeUtils.invoke(ctor, value.get().toSqlTimestamp().getTime());
}
内容来源于网络,如有侵权,请联系作者删除!