Tabnine Logo
ReadContext.readRow
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: googleapis/google-cloud-java

@Override
@Nullable
public Struct readRow(String table, Key key, Iterable<String> columns) {
 try {
  session.markUsed();
  return delegate.readRow(table, key, columns);
 } finally {
  if (isSingleUse) {
   close();
  }
 }
}
origin: googleapis/google-cloud-java

Struct readRow() {
 // [START read_context_read_row]
 ReadContext readContext = dbClient.singleUse();
 Struct row = readContext.readRow("Albums", Key.of(2, 1), Arrays.asList("MarketingBudget"));
 // [END read_context_read_row]
 return row;
}
origin: googleapis/google-cloud-java

/** Example of single use. */
// [TARGET singleUse()]
// [VARIABLE my_singer_id]
public String singleUse(long singerId) {
 // [START singleUse]
 String column = "FirstName";
 Struct row =
   dbClient.singleUse().readRow("Singers", Key.of(singerId), Collections.singleton(column));
 String firstName = row.getString(column);
 // [END singleUse]
 return firstName;
}
origin: googleapis/google-cloud-java

 @Override
 public Struct read(ReadContext ctx, String key) {
  return ctx.readRow("T", Key.of(key), Arrays.asList("V"));
 }
});
origin: brianfrankcooper/YCSB

@Override
public Status read(
  String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
 if (queriesForReads) {
  return readUsingQuery(table, key, fields, result);
 }
 Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
 try {
  Struct row = dbClient.singleUse(timestampBound).readRow(table, Key.of(key), columns);
  decodeStruct(columns, row, result);
  return Status.OK;
 } catch (Exception e) {
  LOGGER.log(Level.INFO, "read()", e);
  return Status.ERROR;
 }
}
origin: googleapis/google-cloud-java

/** Example of single use with timestamp bound. */
// [TARGET singleUse(TimestampBound)]
// [VARIABLE my_singer_id]
public String singleUseStale(long singerId) {
 // [START singleUseStale]
 String column = "FirstName";
 Struct row =
   dbClient
     .singleUse(TimestampBound.ofMaxStaleness(10, TimeUnit.SECONDS))
     .readRow("Singers", Key.of(singerId), Collections.singleton(column));
 String firstName = row.getString(column);
 // [END singleUseStale]
 return firstName;
}
origin: googleapis/google-cloud-java

private static Struct readRow(ReadContext ctx) {
 return ctx.readRow(TABLE_NAME, Key.of(), Arrays.asList("StringValue"));
}
origin: googleapis/google-cloud-java

private Struct readLastRow(String... columns) {
 return client
   .singleUse(TimestampBound.strong())
   .readRow("T", Key.of(lastKey), Arrays.asList(columns));
}
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

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

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

@Test
public void columnNotFound() {
 expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
 expectedException.expectMessage("BadColumnName");
 client
   .singleUse(TimestampBound.strong())
   .readRow(TABLE_NAME, Key.of("k1"), Arrays.asList("Key", "BadColumnName"));
}
origin: googleapis/google-cloud-java

@Test
public void standardDML() {
 executeUpdate(DML_COUNT, INSERT_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(1);
 executeUpdate(DML_COUNT, UPDATE_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(100);
 executeUpdate(DML_COUNT, DELETE_DML);
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V")))
   .isNull();
}
origin: googleapis/google-cloud-java

@Test
public void standardDMLWithDuplicates() {
 executeUpdate(DML_COUNT, INSERT_DML);
 executeUpdate(
   4,
   "UPDATE T SET v = 200 WHERE k = 'boo1';",
   "UPDATE T SET v = 300 WHERE k = 'boo1';",
   "UPDATE T SET v = 400 WHERE k = 'boo1';",
   "UPDATE T SET v = 500 WHERE k = 'boo1';");
 assertThat(
     client
       .singleUse(TimestampBound.strong())
       .readRow("T", Key.of("boo1"), Arrays.asList("V"))
       .getLong(0))
   .isEqualTo(500);
 executeUpdate(DML_COUNT, DELETE_DML, DELETE_DML);
}
origin: googleapis/google-cloud-java

@Test
public void pointRead() {
 Struct row =
   client.singleUse(TimestampBound.strong()).readRow(TABLE_NAME, Key.of("k1"), ALL_COLUMNS);
 assertThat(row).isNotNull();
 assertThat(row.getString(0)).isEqualTo("k1");
 assertThat(row.getString(1)).isEqualTo("v1");
 // Ensure that the Struct implementation supports equality properly.
 assertThat(row)
   .isEqualTo(Struct.newBuilder().set("Key").to("k1").set("StringValue").to("v1").build());
}
origin: googleapis/google-cloud-java

@Test
public void userExceptionIsSpannerException() {
 final String key = uniqueKey();
 TransactionCallable<Void> callable =
   new TransactionCallable<Void>() {
    @Override
    public Void run(TransactionContext transaction) {
     transaction.buffer(Mutation.newInsertOrUpdateBuilder("T").set("K").to(key).build());
     throw newSpannerException(ErrorCode.OUT_OF_RANGE, "User failure");
    }
   };
 try {
  client.readWriteTransaction().run(callable);
  fail("Expected user exception");
 } catch (SpannerException e) {
  assertThat(e.getErrorCode()).isEqualTo(ErrorCode.OUT_OF_RANGE);
  assertThat(e.getMessage()).contains("User failure");
 }
 Struct row =
   client.singleUse(TimestampBound.strong()).readRow("T", Key.of(key), Arrays.asList("K"));
 assertThat(row).isNull();
}
origin: googleapis/google-cloud-java

@Test
public void tableNotFound() {
 expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
 expectedException.expectMessage("BadTableName");
 client.singleUse(TimestampBound.strong()).readRow("BadTableName", Key.of("k1"), ALL_COLUMNS);
}
origin: googleapis/google-cloud-java

@Test
public void simpleInsert() {
 TransactionManager manager = client.transactionManager();
 TransactionContext txn = manager.begin();
 assertThat(manager.getState()).isEqualTo(TransactionState.STARTED);
 txn.buffer(
   Mutation.newInsertBuilder("T").set("K").to("Key1").set("BoolValue").to(true).build());
 manager.commit();
 assertThat(manager.getState()).isEqualTo(TransactionState.COMMITTED);
 Struct row = client.singleUse().readRow("T", Key.of("Key1"), Arrays.asList("K", "BoolValue"));
 assertThat(row.getString(0)).isEqualTo("Key1");
 assertThat(row.getBoolean(1)).isTrue();
}
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: googleapis/google-cloud-java

@Test
public void invalidDatabase() {
 RemoteSpannerHelper helper = env.getTestHelper();
 DatabaseClient invalidClient =
   helper.getClient().getDatabaseClient(DatabaseId.of(helper.getInstanceId(), "invalid"));
 expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
 invalidClient
   .singleUse(TimestampBound.strong())
   .readRow(TABLE_NAME, Key.of("k99"), ALL_COLUMNS);
}
com.google.cloud.spannerReadContextreadRow

Javadoc

Reads a single row from a database, returning null if the row does not exist.
 
ReadContext readContext = dbClient.singleUse();

Popular methods of ReadContext

  • 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(...
  • 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

  • Creating JSON documents from java classes using gson
  • startActivity (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • Path (java.nio.file)
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JFileChooser (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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