congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
ReadContext
Code IndexAdd Tabnine to your IDE (free)

How to use
ReadContext
in
com.google.cloud.spanner

Best Java code snippets using com.google.cloud.spanner.ReadContext (Showing top 20 results out of 315)

Refine searchRefine arrow

  • DatabaseClient
  • ResultSet
  • Key
  • TimestampBound
  • KeySet
origin: googleapis/google-cloud-java

private void keepAlive() {
 markUsed();
 delegate
   .singleUse(TimestampBound.ofMaxStaleness(60, TimeUnit.SECONDS))
   .executeQuery(Statement.newBuilder("SELECT 1").build())
   .next();
}
origin: googleapis/google-cloud-java

@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);
}
origin: googleapis/google-cloud-java

 @Override
 public void run() {
  client
    .singleUse(TimestampBound.strong())
    .readRow(TABLE_NAME, Key.of("k1"), ALL_COLUMNS);
 }
});
origin: googleapis/google-cloud-java

  spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId));
try (ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"))) {
 System.out.println("\n\nResults:");
 while (resultSet.next()) {
  System.out.printf("%d\n\n", resultSet.getLong(0));
origin: googleapis/google-cloud-java

@Test
public void newMultiUseReadOnlyTransactionContextClosesOldSingleUseContext() {
 ReadContext ctx = session.singleUse(TimestampBound.strong());
 session.readOnlyTransaction(TimestampBound.strong());
 expectedException.expect(IllegalStateException.class);
 expectedException.expectMessage("invalidated");
 ctx.read("Dummy", KeySet.all(), Arrays.asList("C"));
}
origin: GoogleCloudPlatform/java-docs-samples

static void readUsingIndex(DatabaseClient dbClient) {
 ResultSet resultSet =
   dbClient
     .singleUse()
     .readUsingIndex(
       "Albums",
       "AlbumsByAlbumTitle",
       KeySet.all(),
       Arrays.asList("AlbumId", "AlbumTitle"));
 while (resultSet.next()) {
  System.out.printf("%d %s\n", resultSet.getLong(0), resultSet.getString(1));
 }
}
// [END spanner_read_data_with_index]
origin: googleapis/google-cloud-java

@Test
public void rowsAreSnapshots() {
 List<Struct> rows = new ArrayList<>();
 ResultSet resultSet =
   client
     .singleUse(TimestampBound.strong())
     .read(
       TABLE_NAME,
       KeySet.newBuilder()
         .addKey(Key.of("k2"))
         .addKey(Key.of("k3"))
         .addKey(Key.of("k4"))
         .build(),
       ALL_COLUMNS);
 while (resultSet.next()) {
  rows.add(resultSet.getCurrentRowAsStruct());
 }
 assertThat(rows.size()).isEqualTo(3);
 assertThat(rows.get(0).getString(0)).isEqualTo("k2");
 assertThat(rows.get(0).getString(1)).isEqualTo("v2");
 assertThat(rows.get(1).getString(0)).isEqualTo("k3");
 assertThat(rows.get(1).getString(1)).isEqualTo("v3");
 assertThat(rows.get(2).getString(0)).isEqualTo("k4");
 assertThat(rows.get(2).getString(1)).isEqualTo("v4");
}
origin: googleapis/google-cloud-java

KeySet.Builder keys = KeySet.newBuilder();
for (String key : expected.keySet()) {
 keys.addKey(Key.of(key));
    .singleUse(TimestampBound.strong())
    .read("T", keys.build(), Arrays.asList("K", "BytesValue"));
while (resultSet.next()) {
 String key = resultSet.getString(0);
 ByteArray value = resultSet.getBytes(1);
 assertThat(expected).containsKey(key);
 ByteArray expectedValue = expected.remove(key);
origin: googleapis/google-cloud-java

TransactionRunner runner = client.readWriteTransaction();
runner.run(callable);
KeySet.Builder keys = KeySet.newBuilder();
keys.addKey(Key.of(key1)).addKey(Key.of(key2));
ResultSet resultSet =
  client.singleUse(TimestampBound.strong()).read("T", keys.build(), Arrays.asList("K"));
int rowCount = 0;
while (resultSet.next()) {
 rowCount++;
origin: googleapis/google-cloud-java

 TransactionRunner runner = client.readWriteTransaction();
 runner.run(callable);
 fail("Expected user exception");
    .singleUse(TimestampBound.strong())
    .read("T", KeySet.range(KeyRange.prefix(Key.of("boo"))), Arrays.asList("K"));
assertThat(resultSet.next()).isFalse();
origin: googleapis/google-cloud-java

@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();
}
origin: googleapis/google-cloud-java

@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);
}
origin: googleapis/google-cloud-java

   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:
   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:
     ? 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:
origin: googleapis/google-cloud-java

@Test
public void rollback() {
 TransactionManager manager = client.transactionManager();
 TransactionContext txn = manager.begin();
 txn.buffer(
   Mutation.newInsertBuilder("T").set("K").to("Key2").set("BoolValue").to(true).build());
 manager.rollback();
 assertThat(manager.getState()).isEqualTo(TransactionState.ROLLED_BACK);
 // Row should not have been inserted.
 assertThat(client.singleUse().readRow("T", Key.of("Key2"), Arrays.asList("K", "BoolValue")))
   .isNull();
}
origin: GoogleCloudPlatform/java-docs-samples

static void readStaleData(DatabaseClient dbClient) {
 ResultSet resultSet =
   dbClient
     .singleUse(TimestampBound.ofExactStaleness(15, TimeUnit.SECONDS))
     .read("Albums", KeySet.all(), Arrays.asList("SingerId", "AlbumId", "MarketingBudget"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s\n",
    resultSet.getLong(0),
    resultSet.getLong(1),
    resultSet.isNull(2) ? "NULL" : resultSet.getLong("MarketingBudget"));
 }
}
// [END spanner_read_stale_data]
origin: GoogleCloudPlatform/java-docs-samples

static void read(DatabaseClient dbClient) {
 ResultSet resultSet =
   dbClient
     .singleUse()
     .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"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
 }
}
// [END spanner_read_data]
origin: brianfrankcooper/YCSB

@Override
public Status scan(
  String table, String startKey, int recordCount, Set<String> fields,
  Vector<HashMap<String, ByteIterator>> result) {
 if (queriesForReads) {
  return scanUsingQuery(table, startKey, recordCount, fields, result);
 }
 Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
 KeySet keySet =
   KeySet.newBuilder().addRange(KeyRange.closedClosed(Key.of(startKey), Key.of())).build();
 try (ResultSet resultSet = dbClient.singleUse(timestampBound)
                   .read(table, keySet, columns, Options.limit(recordCount))) {
  while (resultSet.next()) {
   HashMap<String, ByteIterator> row = new HashMap<>();
   decodeStruct(columns, resultSet, row);
   result.add(row);
  }
  return Status.OK;
 } catch (Exception e) {
  LOGGER.log(Level.INFO, "scan()", e);
  return Status.ERROR;
 }
}
origin: googleapis/google-cloud-java

@Test
public void indexPointReadNotFound() {
 Struct row =
   client
     .singleUse(TimestampBound.strong())
     .readRowUsingIndex(TABLE_NAME, INDEX_NAME, Key.of("v999"), ALL_COLUMNS);
 assertThat(row).isNull();
}
origin: googleapis/google-cloud-java

 ResultSetStats analyzeQuery() {
  // [START read_context_analyze_query]
  ReadContext rc = dbClient.singleUse();
  ResultSet resultSet =
    rc.analyzeQuery(
      Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"),
      ReadContext.QueryAnalyzeMode.PROFILE);
  while (resultSet.next()) {
   // Discard the results. We're only processing because getStats() below requires it.
   resultSet.getCurrentRowAsStruct();
  }
  ResultSetStats stats = resultSet.getStats();
  // [END read_context_analyze_query]
  return stats;
 }
}
origin: googleapis/google-cloud-java

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;
}
com.google.cloud.spannerReadContext

Javadoc

A concurrency context in which to run a read or SQL statement. All ReadContexts are implicitly bound to a Session and therefore a particular Database.

Most used methods

  • executeQuery
    Executes a query against the database.Implementations may or may not block in the initial executeQue
  • read
    Reads zero or more rows from a database.Implementations may or may not block in the initial read(...
  • readRow
    Reads a single row from a database, returning null if the row does not exist. ReadContext readConte
  • readUsingIndex
    Reads zero or more rows from a database using an index.Implementations may or may not block in the i
  • readRowUsingIndex
    Reads a single row from a database using an index, returning null if the row does not exist. ReadCo
  • analyzeQuery
    Analyzes a query and returns query plan and/or query execution statistics information.The query plan
  • close
    Closes this read context and frees up the underlying resources.

Popular in Java

  • Running tasks concurrently on multiple threads
  • setRequestProperty (URLConnection)
  • setScale (BigDecimal)
  • findViewById (Activity)
  • Menu (java.awt)
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • JComboBox (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now