Java Code Examples for com.google.cloud.spanner.ReadContext#read()

The following examples show how to use com.google.cloud.spanner.ReadContext#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpannerTemplate.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
private ResultSet executeRead(String tableName, KeySet keys, Iterable<String> columns,
		SpannerReadOptions options) {

	long startTime = LOGGER.isDebugEnabled() ? System.currentTimeMillis() : 0;

	ReadContext readContext = (options != null && options.getTimestampBound() != null)
			? getReadContext(options.getTimestampBound())
			: getReadContext();

	final ResultSet resultSet = options != null && options.getIndex() != null
			? readContext.readUsingIndex(tableName, options.getIndex(), keys, columns, options.getOptions())
			: readContext.read(tableName, keys, columns, options == null ? ArrayUtils.toArray() : options.getOptions());

	if (LOGGER.isDebugEnabled()) {
		StringBuilder logs = logColumns(tableName, keys, columns);
		logReadOptions(options, logs);
		LOGGER.debug(logs.toString());

		LOGGER.debug("Read elapsed milliseconds: " + (System.currentTimeMillis() - startTime));
	}

	return resultSet;
}
 
Example 2
Source File: ReadContextSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
ResultSet read() {
  // [START read_context_read]
  ReadContext readContext = dbClient.singleUse();
  ResultSet resultSet =
      readContext.read(
          "Albums",
          // KeySet.all() can be used to read all rows in a table. KeySet exposes other
          // methods to read only a subset of the table.
          KeySet.all(),
          Arrays.asList("SingerId", "AlbumId", "AlbumTitle"));
  // [END read_context_read]

  return resultSet;
}