use of com.google.cloud.spanner.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ITReadOnlyTxnTest method queryRow.
private static Struct queryRow(ReadContext ctx) {
ResultSet resultSet = Statement.of("SELECT StringValue FROM TestTable").executeQuery(ctx);
// TODO(user): Consider a library routine to consume a single row from a query.
assertThat(resultSet.next()).isTrue();
Struct row = resultSet.getCurrentRowAsStruct();
assertThat(resultSet.next()).isFalse();
return row;
}
use of com.google.cloud.spanner.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ITReadTest method emptyRead.
@Test
public void emptyRead() {
ResultSet resultSet = client.singleUse(TimestampBound.strong()).read(TABLE_NAME, KeySet.range(KeyRange.closedOpen(Key.of("k99"), Key.of("z"))), ALL_COLUMNS);
assertThat(resultSet.next()).isFalse();
assertThat(resultSet.getType()).isEqualTo(TABLE_TYPE);
}
use of com.google.cloud.spanner.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ITReadTest method checkReadRange.
private void checkReadRange(Source source, KeySet keySet, long limit, int[] expectedRows) {
Map<String, String> expected = new LinkedHashMap<>();
for (int expectedRow : expectedRows) {
expected.put("k" + expectedRow, "v" + expectedRow);
}
ResultSet resultSet;
switch(source) {
case INDEX:
resultSet = limit != 0 ? client.singleUse(TimestampBound.strong()).readUsingIndex(TABLE_NAME, INDEX_NAME, keySet, ALL_COLUMNS, Options.limit(limit)) : client.singleUse(TimestampBound.strong()).readUsingIndex(TABLE_NAME, INDEX_NAME, keySet, ALL_COLUMNS);
break;
case DESC_INDEX:
resultSet = limit != 0 ? client.singleUse(TimestampBound.strong()).readUsingIndex(TABLE_NAME, DESC_INDEX_NAME, keySet, ALL_COLUMNS, Options.limit(limit)) : client.singleUse(TimestampBound.strong()).readUsingIndex(TABLE_NAME, DESC_INDEX_NAME, keySet, ALL_COLUMNS);
break;
case BASE_TABLE:
resultSet = limit != 0 ? client.singleUse(TimestampBound.strong()).read(TABLE_NAME, keySet, ALL_COLUMNS, Options.limit(limit)) : client.singleUse(TimestampBound.strong()).read(TABLE_NAME, keySet, ALL_COLUMNS);
break;
default:
throw new IllegalArgumentException("Invalid source");
}
Map<String, String> rows = new LinkedHashMap<>();
while (resultSet.next()) {
rows.put(resultSet.getString(0), resultSet.getString(1));
}
assertThat(rows).named("read of " + keySet).isEqualTo(expected);
}
use of com.google.cloud.spanner.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ITReadTest method indexEmptyRead.
@Test
public void indexEmptyRead() {
ResultSet resultSet = client.singleUse(TimestampBound.strong()).readUsingIndex(TABLE_NAME, INDEX_NAME, KeySet.range(KeyRange.closedOpen(Key.of("v99"), Key.of("z"))), ALL_COLUMNS);
assertThat(resultSet.next()).isFalse();
assertThat(resultSet.getType()).isEqualTo(TABLE_TYPE);
}
use of com.google.cloud.spanner.ResultSet in project google-cloud-java by GoogleCloudPlatform.
the class ITReadTest method cursorErrorDeferred.
@Test
public void cursorErrorDeferred() {
// Error should be deferred until next(). This gives consistent behavior with respect to
// non-blocking implementations (e.g., gRPC).
ResultSet resultSet = client.singleUse(TimestampBound.strong()).read("BadTableName", KeySet.singleKey(Key.of("k1")), ALL_COLUMNS);
expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
expectedException.expectMessage("BadTableName");
resultSet.next();
}
Aggregations