Codota Logo
ReadContext.executeQuery
Code IndexAdd Codota to your IDE (free)

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: googleapis/google-cloud-java

/**
 * Executes the query in {@code context}. {@code statement.executeQuery(context)} is exactly
 * equivalent to {@code context.executeQuery(statement)}.
 *
 * @see ReadContext#executeQuery(Statement, Options.QueryOption...)
 */
public ResultSet executeQuery(ReadContext context, Options.QueryOption... options) {
 return context.executeQuery(this, options);
}
origin: googleapis/google-cloud-java

@Override
public ResultSet executeQuery(Statement statement, QueryOption... options) {
 return wrap(delegate.executeQuery(statement, options));
}
origin: googleapis/google-cloud-java

ResultSet executeQuery() {
 // [START read_context_execute_query]
 // Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
 // null.
 ReadContext readContext = dbClient.singleUse();
 ResultSet resultSet =
   readContext.executeQuery(
     Statement.of("SELECT SingerId, AlbumId, MarketingBudget, LastUpdateTime FROM Albums"));
 // [END read_context_execute_query]
 return resultSet;
}
origin: googleapis/google-cloud-java

private void mockKeepAlive(Session session) {
 ReadContext context = mock(ReadContext.class);
 ResultSet resultSet = mock(ResultSet.class);
 when(session.singleUse(any(TimestampBound.class))).thenReturn(context);
 when(context.executeQuery(any(Statement.class))).thenReturn(resultSet);
}
origin: googleapis/google-cloud-java

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

private Status readUsingQuery(
  String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
 Statement query;
 Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
 if (fields == null || fields.size() == fieldCount) {
  query = Statement.newBuilder(standardQuery).bind("key").to(key).build();
 } else {
  Joiner joiner = Joiner.on(',');
  query = Statement.newBuilder("SELECT ")
    .append(joiner.join(fields))
    .append(" FROM ")
    .append(table)
    .append(" WHERE id=@key")
    .bind("key").to(key)
    .build();
 }
 try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
  resultSet.next();
  decodeStruct(columns, resultSet, result);
  if (resultSet.next()) {
   throw new Exception("Expected exactly one row for each read.");
  }
  return Status.OK;
 } catch (Exception e) {
  LOGGER.log(Level.INFO, "readUsingQuery()", e);
  return Status.ERROR;
 }
}
origin: googleapis/google-cloud-java

final ResultSet mockResult = mock(ResultSet.class);
when(session.singleUse(any(TimestampBound.class))).thenReturn(mockContext);
when(mockContext.executeQuery(any(Statement.class)))
  .thenAnswer(
    new Answer<ResultSet>() {
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:");
origin: brianfrankcooper/YCSB

private Status scanUsingQuery(
  String table, String startKey, int recordCount, Set<String> fields,
  Vector<HashMap<String, ByteIterator>> result) {
 Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
 Statement query;
 if (fields == null || fields.size() == fieldCount) {
  query = Statement.newBuilder(standardScan).bind("startKey").to(startKey).bind("count").to(recordCount).build();
 } else {
  Joiner joiner = Joiner.on(',');
  query = Statement.newBuilder("SELECT ")
    .append(joiner.join(fields))
    .append(" FROM ")
    .append(table)
    .append(" WHERE id>=@startKey LIMIT @count")
    .bind("startKey").to(startKey)
    .bind("count").to(recordCount)
    .build();
 }
 try (ResultSet resultSet = dbClient.singleUse(timestampBound).executeQuery(query)) {
  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, "scanUsingQuery()", e);
  return Status.ERROR;
 }
}
origin: googleapis/google-cloud-java

@Test
public void query() {
 try (ResultSet resultSet =
   client
     .singleUse()
     .executeQuery(
       Statement.of(
         "SELECT Key, Data, Fingerprint, Size FROM " + TABLE_NAME + " ORDER BY Key"))) {
  validate(resultSet);
 }
}
origin: googleapis/google-cloud-java

@Test
public void queryWithSmallPrefetchChunks() {
 try (ResultSet resultSet =
   client
     .singleUse()
     .executeQuery(
       Statement.of(
         "SELECT Key, Data, Fingerprint, Size FROM " + TABLE_NAME + " ORDER BY Key"),
       Options.prefetchChunks(1))) {
  validate(resultSet);
 }
}
origin: googleapis/google-cloud-java

 @Override
 public Struct read(ReadContext ctx, String key) {
  ResultSet resultSet =
    ctx.executeQuery(
      Statement.newBuilder("SELECT V FROM T WHERE K = @key")
        .bind("key")
        .to(key)
        .build());
  assertThat(resultSet.next()).isTrue();
  Struct row = resultSet.getCurrentRowAsStruct();
  assertThat(resultSet.next()).isFalse();
  return row;
 }
});
origin: GoogleCloudPlatform/java-docs-samples

static void query(DatabaseClient dbClient) {
 // singleUse() can be used to execute a single read or query against Cloud Spanner.
 ResultSet resultSet =
   dbClient
     .singleUse()
     .executeQuery(Statement.of("SELECT SingerId, AlbumId, AlbumTitle FROM Albums"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
 }
}
// [END spanner_query_data]
origin: GoogleCloudPlatform/java-docs-samples

static void querySingersTable(DatabaseClient dbClient) {
 ResultSet resultSet =
   dbClient
     .singleUse()
     .executeQuery(
       Statement.of(
         "SELECT SingerId, FirstName, LastName FROM Singers"));
 while (resultSet.next()) {
  System.out.printf(
    "%s %s %s\n",
    resultSet.getLong("SingerId"),
    resultSet.getString("FirstName"),
    resultSet.getString("LastName"));
 }
}
origin: GoogleCloudPlatform/java-docs-samples

static void queryMarketingBudget(DatabaseClient dbClient) {
 // Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
 // null.
 ResultSet resultSet =
   dbClient
     .singleUse()
     .executeQuery(Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s\n",
    resultSet.getLong("SingerId"),
    resultSet.getLong("AlbumId"),
    // We check that the value is non null. ResultSet getters can only be used to retrieve
    // non null values.
    resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"));
 }
}
// [END spanner_query_data_with_new_column]
origin: GoogleCloudPlatform/java-docs-samples

static void queryPerformancesTable(DatabaseClient dbClient) {
 // Rows without an explicit value for Revenue will have a Revenue equal to
 // null.
 ResultSet resultSet =
   dbClient
     .singleUse()
     .executeQuery(
       Statement.of(
         "SELECT SingerId, VenueId, EventDate, Revenue, LastUpdateTime "
           + "FROM Performances ORDER BY LastUpdateTime DESC"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s %s %s\n",
    resultSet.getLong("SingerId"),
    resultSet.getLong("VenueId"),
    resultSet.getDate("EventDate"),
    // We check that the value is non null. ResultSet getters can only be used to retrieve
    // non null values.
    resultSet.isNull("Revenue") ? "NULL" : resultSet.getLong("Revenue"),
    resultSet.getTimestamp("LastUpdateTime"));
 }
}
origin: GoogleCloudPlatform/java-docs-samples

static void queryMarketingBudgetWithTimestamp(DatabaseClient dbClient) {
 // Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
 // null.
 ResultSet resultSet =
   dbClient
     .singleUse()
     .executeQuery(
       Statement.of(
         "SELECT SingerId, AlbumId, MarketingBudget, LastUpdateTime FROM Albums"
           + " ORDER BY LastUpdateTime DESC"));
 while (resultSet.next()) {
  System.out.printf(
    "%d %d %s %s\n",
    resultSet.getLong("SingerId"),
    resultSet.getLong("AlbumId"),
    // We check that the value is non null. ResultSet getters can only be used to retrieve
    // non null values.
    resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"),
    resultSet.isNull("LastUpdateTime") ? "NULL" : resultSet.getTimestamp("LastUpdateTime"));
 }
}
// [END spanner_query_data_with_timestamp_column]
origin: GoogleCloudPlatform/java-docs-samples

static void queryStructField(DatabaseClient dbClient) {
 Statement s =
   Statement.newBuilder("SELECT SingerId FROM Singers WHERE FirstName = @name.FirstName")
     .bind("name")
     .to(
       Struct.newBuilder()
         .set("FirstName")
         .to("Elena")
         .set("LastName")
         .to("Campbell")
         .build())
     .build();
 ResultSet resultSet = dbClient.singleUse().executeQuery(s);
 while (resultSet.next()) {
  System.out.printf("%d\n", resultSet.getLong("SingerId"));
 }
}
// [END spanner_field_access_on_struct_parameters]
origin: GoogleCloudPlatform/java-docs-samples

static void queryUsingIndex(DatabaseClient dbClient) {
 Statement statement =
   Statement
     // We use FORCE_INDEX hint to specify which index to use. For more details see
     // https://cloud.google.com/spanner/docs/query-syntax#from-clause
     .newBuilder(
       "SELECT AlbumId, AlbumTitle, MarketingBudget\n"
         + "FROM Albums@{FORCE_INDEX=AlbumsByAlbumTitle}\n"
         + "WHERE AlbumTitle >= @StartTitle AND AlbumTitle < @EndTitle")
     // We use @BoundParameters to help speed up frequently executed queries.
     //  For more details see https://cloud.google.com/spanner/docs/sql-best-practices
     .bind("StartTitle")
     .to("Aardvark")
     .bind("EndTitle")
     .to("Goo")
     .build();
 ResultSet resultSet = dbClient.singleUse().executeQuery(statement);
 while (resultSet.next()) {
  System.out.printf(
    "%d %s %s\n",
    resultSet.getLong("AlbumId"),
    resultSet.getString("AlbumTitle"),
    resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"));
 }
}
// [END spanner_query_data_with_index]
origin: GoogleCloudPlatform/java-docs-samples

static void queryWithStruct(DatabaseClient dbClient) {
 // [START spanner_create_struct_with_data]
 Struct name =
   Struct.newBuilder().set("FirstName").to("Elena").set("LastName").to("Campbell").build();
 // [END spanner_create_struct_with_data]
 // [START spanner_query_data_with_struct]
 Statement s =
   Statement.newBuilder(
       "SELECT SingerId FROM Singers "
         + "WHERE STRUCT<FirstName STRING, LastName STRING>(FirstName, LastName) "
         + "= @name")
     .bind("name")
     .to(name)
     .build();
 ResultSet resultSet = dbClient.singleUse().executeQuery(s);
 while (resultSet.next()) {
  System.out.printf("%d\n", resultSet.getLong("SingerId"));
 }
 // [END spanner_query_data_with_struct]
}
com.google.cloud.spannerReadContextexecuteQuery

Javadoc

Executes a query against the database.

Implementations may or may not block in the initial executeQuery(...) call; for those that do not, the remote call will be initiated immediately but blocking on the response is deferred to the first ResultSet#next() call. Regardless of blocking behavior, any SpannerException is deferred to the first or subsequent ResultSet#next() call.

 
// Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to

Popular methods of ReadContext

  • 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

  • Start an intent from android
  • onCreateOptionsMenu (Activity)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • getSharedPreferences (Context)
  • Kernel (java.awt.image)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Hashtable (java.util)
    Hashtable is a synchronized implementation of Map. All optional operations are supported.Neither key
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • DataSource (javax.sql)
    A factory for connections to the physical data source that this DataSource object represents. An alt
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now