private void keepAlive() { markUsed(); delegate .singleUse(TimestampBound.ofMaxStaleness(60, TimeUnit.SECONDS)) .executeQuery(Statement.newBuilder("SELECT 1").build()) .next(); }
DatabaseClient getDatabaseClient() { // [START get_db_client] SpannerOptions options = SpannerOptions.newBuilder().build(); Spanner spanner = options.getService(); final String project = "test-project"; final String instance = "test-instance"; final String database = "example-db"; DatabaseId db = DatabaseId.of(project, instance, database); DatabaseClient dbClient = spanner.getDatabaseClient(db); // [END get_db_client] return dbClient; }
private void initPool() { synchronized (lock) { poolMaintainer.init(); for (int i = 0; i < options.getMinSessions(); i++) { createSession(); } } }
@Override public Void run(TransactionContext transaction) throws UserException { transaction.buffer(Mutation.newInsertOrUpdateBuilder("T").set("K").to(key).build()); throw new UserException("User failure"); } };
DatabaseAdminClient getDatabaseAdminClient() { // [START get_dbadmin_client] SpannerOptions options = SpannerOptions.newBuilder().build(); Spanner spanner = options.getService(); DatabaseAdminClient dbAdminClient = spanner.getDatabaseAdminClient(); // [END get_dbadmin_client] return dbAdminClient; }
InstanceAdminClient getInstanceAdminClient() { // [START get_instance_admin_client] SpannerOptions options = SpannerOptions.newBuilder().build(); Spanner spanner = options.getService(); InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient(); // [END get_instance_admin_client] return instanceAdminClient; }
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; }
SpannerImpl(SpannerRpc gapicRpc, int defaultPrefetchChunks, SpannerOptions options) { super(options); this.gapicRpc = gapicRpc; this.defaultPrefetchChunks = defaultPrefetchChunks; this.dbAdminClient = new DatabaseAdminClientImpl(options.getProjectId(), gapicRpc); this.instanceClient = new InstanceAdminClientImpl(options.getProjectId(), gapicRpc, dbAdminClient); }
@Override public boolean getBoolean(int columnIndex) { checkNonNullOfType(columnIndex, Type.bool(), columnIndex); return getBooleanInternal(columnIndex); }
@Override public Date getDate(int columnIndex) { checkNonNullOfType(columnIndex, Type.date(), columnIndex); return getDateInternal(columnIndex); }
@Override public ReadOnlyTransaction readOnlyTransaction() { try { return new AutoClosingReadTransaction(delegate.readOnlyTransaction(), this, false); } catch (Exception e) { close(); throw e; } }
@Override public ReadContext singleUse() { try { return new AutoClosingReadContext(delegate.singleUse(), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { try { return new AutoClosingReadTransaction( delegate.singleUseReadOnlyTransaction(bound), this, true); } catch (Exception e) { close(); throw e; } }
@Override public TransactionManager transactionManager() { markUsed(); return new AutoClosingTransactionManager(delegate.transactionManager(), this); } }
@Override public Void run(TransactionContext transaction) { transaction.buffer(Mutation.newInsertOrUpdateBuilder("T").set("K").to(key).build()); throw newSpannerException(ErrorCode.OUT_OF_RANGE, "User failure"); } };
@Override public ReadOnlyTransaction readOnlyTransaction(TimestampBound bound) { try { return new AutoClosingReadTransaction(delegate.readOnlyTransaction(bound), this, false); } catch (Exception e) { close(); throw e; } }
@Override public ReadContext singleUse(TimestampBound bound) { try { return new AutoClosingReadContext(delegate.singleUse(bound), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction() { try { return new AutoClosingReadTransaction(delegate.singleUseReadOnlyTransaction(), this, true); } catch (Exception e) { close(); throw e; } }