diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index b712292013b..a6177d5b0ef 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -10,6 +10,7 @@ branchProtectionRules: requiredStatusCheckContexts: - dependencies (17) - lint + - javadoc - units (8) - units (11) - 'Kokoro - Test: Integration' @@ -28,6 +29,7 @@ branchProtectionRules: requiredStatusCheckContexts: - dependencies (11) - lint + - javadoc - units (7) - units (8) - units (11) @@ -42,6 +44,7 @@ branchProtectionRules: requiredStatusCheckContexts: - dependencies (11) - lint + - javadoc - units (7) - units (8) - units (11) @@ -56,6 +59,7 @@ branchProtectionRules: requiredStatusCheckContexts: - dependencies (11) - lint + - javadoc - units (7) - units (8) - units (11) @@ -69,6 +73,7 @@ branchProtectionRules: requiresStrictStatusChecks: false requiredStatusCheckContexts: - lint + - javadoc - units (8) - units (11) - 'Kokoro - Test: Integration' @@ -81,6 +86,7 @@ branchProtectionRules: requiresStrictStatusChecks: false requiredStatusCheckContexts: - lint + - javadoc - units (8) - units (11) - 'Kokoro - Test: Integration' @@ -95,6 +101,7 @@ branchProtectionRules: requiresStrictStatusChecks: false requiredStatusCheckContexts: - lint + - javadoc - units (8) - units (11) - 'Kokoro - Test: Integration' @@ -109,6 +116,7 @@ branchProtectionRules: requiresStrictStatusChecks: false requiredStatusCheckContexts: - lint + - javadoc - units (8) - units (11) - 'Kokoro - Test: Integration' diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractLazyInitializer.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractLazyInitializer.java index bc595b14662..73436852602 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractLazyInitializer.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AbstractLazyInitializer.java @@ -19,6 +19,8 @@ /** * Generic {@link AbstractLazyInitializer} for any heavy-weight object that might throw an exception * during initialization. The underlying object is initialized at most once. + * + * @param Object which is to be initialized lazily */ public abstract class AbstractLazyInitializer { private final Object lock = new Object(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java index 501ae054e9f..dfedcc4f8be 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java @@ -60,7 +60,8 @@ enum CallbackResponse { CONTINUE, /** - * Tell the cursor to suspend all callbacks until application calls {@link RowCursor#resume()}. + * Tell the cursor to suspend all callbacks until application calls {@link + * ForwardingAsyncResultSet#resume()}. */ PAUSE, @@ -68,8 +69,8 @@ enum CallbackResponse { * Tell the cursor you are done receiving results, even if there are more results sitting in the * buffer. Once you return DONE, you will receive no further callbacks. * - *

Approximately equivalent to calling {@link RowCursor#cancel()}, and then returning {@code - * PAUSE}, but more clear, immediate, and idiomatic. + *

Approximately equivalent to calling {@link ForwardingAsyncResultSet#cancel()}, and then + * returning {@code PAUSE}, but more clear, immediate, and idiomatic. * *

It is legal to commit a transaction that owns this read before actually returning {@code * DONE}. @@ -105,17 +106,18 @@ interface ReadyCallback { *

  • Callback will stop being called once any of the following occurs: *
      *
    1. Callback returns {@link CallbackResponse#DONE}. - *
    2. {@link ResultSet#tryNext()} returns {@link CursorState#DONE}. - *
    3. {@link ResultSet#tryNext()} throws an exception. + *
    4. {@link ForwardingAsyncResultSet#tryNext()} returns {@link CursorState#DONE}. + *
    5. {@link ForwardingAsyncResultSet#tryNext()} throws an exception. *
    - *
  • Callback may possibly be invoked after a call to {@link ResultSet#cancel()} call, but the - * subsequent call to {@link #tryNext()} will yield a SpannerException. + *
  • Callback may possibly be invoked after a call to {@link + * ForwardingAsyncResultSet#cancel()} call, but the subsequent call to {@link #tryNext()} + * will yield a SpannerException. *
  • Spurious callbacks are possible where cursors are not actually ready. Typically callback * should return {@link CallbackResponse#CONTINUE} any time it sees {@link * CursorState#NOT_READY}. * * - *

    Flow Control

    + *

    Flow Control

    * * If no flow control is needed (say because result sizes are known in advance to be finite in * size) then async processing is simple. The following is a code example that transfers work from diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncRunner.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncRunner.java index 1703ef1ab27..3df3b9068b2 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncRunner.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncRunner.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.cloud.Timestamp; +import io.grpc.Status.Code; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -40,8 +41,8 @@ interface AsyncWork { *

    In most cases, the implementation will not need to catch {@code SpannerException}s from * Spanner operations, instead letting these propagate to the framework. The transaction runner * will take appropriate action based on the type of exception. In particular, implementations - * should never catch an exception of type {@link SpannerErrors#isAborted}: these indicate that - * some reads may have returned inconsistent data and the transaction attempt must be aborted. + * should never catch an exception of type {@link Code#ABORTED}: these indicate that some reads + * may have returned inconsistent data and the transaction attempt must be aborted. * * @param txn the transaction * @return future over the result of the work diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManager.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManager.java index 391be3d190b..c6ead432046 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManager.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManager.java @@ -18,7 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture; +import com.google.cloud.spanner.Options.TransactionOption; import com.google.cloud.spanner.TransactionManager.TransactionState; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; @@ -43,7 +43,7 @@ * so can cause resources to be leaked and deadlocks. Easiest way to guarantee this is by calling * {@link #close()} in a finally block. * - * @see DatabaseClient#transactionManagerAsync() + * @see DatabaseClient#transactionManagerAsync(TransactionOption...) */ public interface AsyncTransactionManager extends AutoCloseable { /** @@ -91,10 +91,10 @@ Timestamp get(long timeout, TimeUnit unit) /** * {@link AsyncTransactionStep} is returned by {@link - * TransactionContextFuture#then(AsyncTransactionFunction)} and {@link - * AsyncTransactionStep#then(AsyncTransactionFunction)} and allows transaction steps that should - * be executed serially to be chained together. Each step can contain one or more statements that - * may execute in parallel. + * TransactionContextFuture#then(AsyncTransactionFunction, Executor)} and {@link + * AsyncTransactionStep#then(AsyncTransactionFunction, Executor)} and allows transaction steps + * that should be executed serially to be chained together. Each step can contain one or more + * statements that may execute in parallel. * *

    Example usage: * @@ -115,6 +115,9 @@ Timestamp get(long timeout, TimeUnit unit) * executor) * .commitAsync(); * } + * + * @param + * @param */ interface AsyncTransactionStep extends ApiFuture { /** @@ -140,6 +143,9 @@ AsyncTransactionStep then( * a {@link TransactionContext} and the output value of the previous transaction step as its input * parameters. The method should return an {@link ApiFuture} that will return the result of this * step. + * + * @param + * @param */ interface AsyncTransactionFunction { /** @@ -151,8 +157,8 @@ interface AsyncTransactionFunction { * @param input the result of the previous transaction step. * @return an {@link ApiFuture} that will return the result of this step, and that will be the * input of the next transaction step. This method should never return null. - * Instead, if the method does not have a return value, the method should return {@link - * ApiFutures#immediateFuture(null)}. + * Instead, if the method does not have a return value, the method should return + * ApiFutures#immediateFuture(null). */ ApiFuture apply(TransactionContext txn, I input) throws Exception; } @@ -160,7 +166,7 @@ interface AsyncTransactionFunction { /** * Creates a new read write transaction. This must be called before doing any other operation and * can only be called once. To create a new transaction for subsequent retries, see {@link - * #resetForRetry()}. + * #resetForRetryAsync()}. */ TransactionContextFuture beginAsync(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java index 9168c2a11dd..8372bb61fd3 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java @@ -137,7 +137,7 @@ default OperationFuture createDatabase( * Database db = op.waitFor().getResult(); * } * - * @see also #createDatabase(String, String, Iterable) + * @see #createDatabase(String, String, Iterable) */ OperationFuture createDatabase( Database database, Iterable statements) throws SpannerException; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java index a82225d5f44..f6acf04b6ca 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseClient.java @@ -368,8 +368,8 @@ CommitResponse writeAtLeastOnceWithOptions( /** * Returns a transaction manager which allows manual management of transaction lifecycle. This API - * is meant for advanced users. Most users should instead use the {@link #readWriteTransaction()} - * API instead. + * is meant for advanced users. Most users should instead use the {@link + * #readWriteTransaction(TransactionOption...)} API instead. * *

    Example of using {@link TransactionManager}. * @@ -412,7 +412,7 @@ CommitResponse writeAtLeastOnceWithOptions( * *

    Example of a read write transaction. * - *

     
    +   * 
    {@code
        * Executor executor = Executors.newSingleThreadExecutor();
        * final long singerId = my_singer_id;
        * AsyncRunner runner = client.runAsync();
    @@ -432,7 +432,7 @@ CommitResponse writeAtLeastOnceWithOptions(
        *                   .build());
        *         },
        *         executor);
    -   * 
    + * }
    * * Options for a transaction can include: * @@ -449,7 +449,7 @@ CommitResponse writeAtLeastOnceWithOptions( /** * Returns an asynchronous transaction manager which allows manual management of transaction * lifecycle. This API is meant for advanced users. Most users should instead use the {@link - * #runAsync()} API instead. + * #runAsync(TransactionOption...)} API instead. * *

    Example of using {@link AsyncTransactionManager}. * @@ -514,12 +514,13 @@ CommitResponse writeAtLeastOnceWithOptions( * *

    Partitioned DML updates are used to execute a single DML statement with a different * execution strategy that provides different, and often better, scalability properties for large, - * table-wide operations than DML in a {@link #readWriteTransaction()} transaction. Smaller scoped - * statements, such as an OLTP workload, should prefer using {@link - * TransactionContext#executeUpdate(Statement)} with {@link #readWriteTransaction()}. + * table-wide operations than DML in a {@link #readWriteTransaction(TransactionOption...)} + * transaction. Smaller scoped statements, such as an OLTP workload, should prefer using {@link + * TransactionContext#executeUpdate(Statement,UpdateOption...)} with {@link + * #readWriteTransaction(TransactionOption...)}. * *

    That said, Partitioned DML is not a drop-in replacement for standard DML used in {@link - * #readWriteTransaction()}. + * #readWriteTransaction(TransactionOption...)}. * *

      *
    • The DML statement must be fully-partitionable. Specifically, the statement must be diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceConfigInfo.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceConfigInfo.java index f2b256fff40..39d32fc8a80 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceConfigInfo.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/InstanceConfigInfo.java @@ -117,9 +117,9 @@ public List getOptionalReplicas() { } /** - * Base configuration, e.g. projects//instanceConfigs/nam3, based on which this - * configuration is created. Only set for user managed configurations. The base config must refer - * to a configuration of type GOOGLE_MANAGED. + * Base configuration, e.g. {@code projects//instanceConfigs/nam3}, based on which + * this configuration is created. Only set for user managed configurations. The base config must + * refer to a configuration of type GOOGLE_MANAGED. */ public InstanceConfigInfo getBaseConfig() { return baseConfig; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java index bd238d3ef8b..f8f9d1e9779 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Operation.java @@ -32,7 +32,12 @@ import javax.annotation.Nullable; import org.threeten.bp.Duration; -/** Represents a long running operation. */ +/** + * Represents a long-running operation. + * + * @param + * @param + */ // TODO(user): Implement other operations on Operation. public class Operation { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java index 9712b508d5f..0d804bfd933 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java @@ -156,9 +156,9 @@ public static ListOption pageSize(int pageSize) { } /** - * If this is for a partitioned read & query and this field is set to `true`, the request will be - * executed via Spanner independent compute resources. The method is available in Beta mode (and - * is not generally available now). + * If this is for a partitioned read and query and this field is set to `true`, the request will + * be executed via Spanner independent compute resources. The method is available in Beta mode + * (and is not generally available now). */ @BetaApi public static DataBoostQueryOption dataBoostEnabled(Boolean dataBoostEnabled) { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Session.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Session.java index d322e0fb6d0..98c40b49ccc 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Session.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Session.java @@ -18,6 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; +import com.google.cloud.spanner.Options.TransactionOption; import com.google.protobuf.Empty; /** @@ -48,11 +49,12 @@ public interface Session extends DatabaseClient, AutoCloseable { String getName(); /** - * Prepares a transaction for use by a subsequent {@link #readWriteTransaction()} or {@link - * #write(Iterable)} call. It is not necessary to call this method before running a transaction or - * performing a write, but doing so may allow one round trip of the protocol to be performed in - * advance; calling this method on an idle session that is expected to execute a transaction or - * write in the near future may reduce the latency of the subsequent transaction/write. + * Prepares a transaction for use by a subsequent {@link + * DatabaseClient#readWriteTransaction(TransactionOption...)} or {@link #write(Iterable)} call. It + * is not necessary to call this method before running a transaction or performing a write, but + * doing so may allow one round trip of the protocol to be performed in advance; calling this + * method on an idle session that is expected to execute a transaction or write in the near future + * may reduce the latency of the subsequent transaction/write. */ void prepareReadWriteTransaction(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java index 063ef8af4cf..5df163ecd87 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java @@ -32,6 +32,7 @@ import com.google.cloud.grpc.GcpManagedChannelOptions; import com.google.cloud.grpc.GrpcTransportOptions; import com.google.cloud.spanner.Options.QueryOption; +import com.google.cloud.spanner.Options.UpdateOption; import com.google.cloud.spanner.admin.database.v1.DatabaseAdminSettings; import com.google.cloud.spanner.admin.database.v1.stub.DatabaseAdminStubSettings; import com.google.cloud.spanner.admin.instance.v1.InstanceAdminSettings; @@ -134,10 +135,7 @@ public class SpannerOptions extends ServiceOptions { private final String compressorName; private final boolean leaderAwareRoutingEnabled; - /** - * Interface that can be used to provide {@link CallCredentials} instead of {@link Credentials} to - * {@link SpannerOptions}. - */ + /** Interface that can be used to provide {@link CallCredentials} to {@link SpannerOptions}. */ public interface CallCredentialsProvider { /** Return the {@link CallCredentials} to use for a gRPC call. */ CallCredentials getCallCredentials(); @@ -970,7 +968,7 @@ public DatabaseAdminStubSettings.Builder getDatabaseAdminStubSettingsBuilder() { /** * Sets a timeout specifically for Partitioned DML statements executed through {@link - * DatabaseClient#executePartitionedUpdate(Statement)}. The default is 2 hours. + * DatabaseClient#executePartitionedUpdate(Statement, UpdateOption...)}. The default is 2 hours. */ public Builder setPartitionedDmlTimeout(Duration timeout) { this.partitionedDmlTimeout = timeout; @@ -1065,9 +1063,7 @@ QueryOptions getEnvironmentQueryOptions() { /** * Sets a {@link CallCredentialsProvider} that can deliver {@link CallCredentials} to use on a - * per-gRPC basis. Any credentials returned by this {@link CallCredentialsProvider} will have - * preference above any {@link Credentials} that may have been set on the {@link SpannerOptions} - * instance. + * per-gRPC basis. */ public Builder setCallCredentialsProvider(CallCredentialsProvider callCredentialsProvider) { this.callCredentialsProvider = callCredentialsProvider; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java index b767bd6d82c..ad085ca2dcc 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java @@ -52,323 +52,423 @@ */ public interface StructReader { /** - * Returns the type of the underlying data. This will always be a {@code STRUCT} type, with fields - * corresponding to the data's columns. For the result of a read or query, this will always match - * the columns passed to the {@code read()} call or named in the query text, in order. + * @return the type of the underlying data. This will always be a {@code STRUCT} type, with fields + * corresponding to the data's columns. For the result of a read or query, this will always + * match the columns passed to the {@code read()} call or named in the query text, in order. */ Type getType(); /** - * Returns the number of columns in the underlying data. This includes any columns with {@code - * NULL} values. + * @return the number of columns in the underlying data. This includes any columns with {@code + * NULL} values. */ int getColumnCount(); /** - * Returns the index of the column named {@code columnName}. - * + * @param columnName name of the column + * @return the index of the column named {@code columnName}. * @throws IllegalArgumentException if there is not exactly one element of {@code * type().structFields()} with {@link Type.StructField#getName()} equal to {@code columnName} */ int getColumnIndex(String columnName); - /** Returns the type of a column. */ + /** + * @param columnIndex index of the column + * @return the type of a column. + */ Type getColumnType(int columnIndex); - /** Returns the type of a column. */ + /** + * @param columnName name of the column + * @return the type of a column. + */ Type getColumnType(String columnName); - /** Returns {@code true} if a column contains a {@code NULL} value. */ + /** + * @param columnIndex index of the column + * @return {@code true} if a column contains a {@code NULL} value. + */ boolean isNull(int columnIndex); - /** Returns {@code true} if a column contains a {@code NULL} value. */ + /** + * @param columnName name of the column + * @return {@code true} if a column contains a {@code NULL} value. + */ boolean isNull(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#bool()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#bool()}. + */ boolean getBoolean(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#bool()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#bool()}. + */ boolean getBoolean(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#int64()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#int64()}. + */ long getLong(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#int64()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#int64()}. + */ long getLong(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#float64()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#float64()}. + */ double getDouble(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#float64()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#float64()}. + */ double getDouble(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#numeric()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#numeric()}. + */ BigDecimal getBigDecimal(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#numeric()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#numeric()}. + */ BigDecimal getBigDecimal(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#string()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#string()}. + */ String getString(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#string()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#string()}. + */ String getString(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#json()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#json()}. + */ default String getJson(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); } - /** Returns the value of a non-{@code NULL} column with type {@link Type#json()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#json()}. + */ default String getJson(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); } - /** Returns the value of a non-{@code NULL} column with type {@link Type#pgJsonb()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#pgJsonb()}. + */ default String getPgJsonb(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); } - /** Returns the value of a non-{@code NULL} column with type {@link Type#pgJsonb()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#pgJsonb()}. + */ default String getPgJsonb(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); } - /** Returns the value of a non-{@code NULL} column with type {@link Type#bytes()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#bytes()}. + */ ByteArray getBytes(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#bytes()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#bytes()}. + */ ByteArray getBytes(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#timestamp()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#timestamp()}. + */ Timestamp getTimestamp(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#timestamp()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#timestamp()}. + */ Timestamp getTimestamp(String columnName); - /** Returns the value of a non-{@code NULL} column with type {@link Type#date()}. */ + /** + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@link Type#date()}. + */ Date getDate(int columnIndex); - /** Returns the value of a non-{@code NULL} column with type {@link Type#date()}. */ + /** + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@link Type#date()}. + */ Date getDate(String columnName); - /** Returns the value of a nullable column as a {@link Value}. */ + /** + * @param columnIndex index of the column + * @return the value of a nullable column as a {@link Value}. + */ default Value getValue(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); } - /** Returns the value of a nullable column as a {@link Value}. */ + /** + * @param columnName name of the column + * @return the value of a nullable column as a {@link Value}. + */ default Value getValue(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); } /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. - * + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getBooleanList(int)} instead. */ boolean[] getBooleanArray(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. - * + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getBooleanList(String)} instead. */ boolean[] getBooleanArray(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBooleanList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bool())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBooleanList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. - * + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getLongList(int)} instead. */ long[] getLongArray(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. - * + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getLongList(String)} instead. */ long[] getLongArray(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getLongList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.int64())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getLongList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())}. - * + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getDoubleList(int)} instead. */ double[] getDoubleArray(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())}. - * + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())}. * @throws NullPointerException if any element of the array value is {@code NULL}. If the array * may contain {@code NULL} values, use {@link #getDoubleList(String)} instead. */ double[] getDoubleArray(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getDoubleList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float64())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getDoubleList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.numeric())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.numeric())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBigDecimalList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.numeric())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.numeric())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBigDecimalList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.string())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.string())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getStringList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.string())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.string())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getStringList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.json())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.json())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ default List getJsonList(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); }; /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.json())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.json())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ default List getJsonList(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); }; /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.pgJsonb())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.pgJsonb())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ default List getPgJsonbList(int columnIndex) { throw new UnsupportedOperationException("method should be overwritten"); }; /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.pgJsonb())} The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.pgJsonb())} The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ default List getPgJsonbList(String columnName) { throw new UnsupportedOperationException("method should be overwritten"); }; /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bytes())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bytes())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBytesList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.bytes())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.bytes())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getBytesList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.timestamp())} - * The list returned by this method is lazily constructed. Create a copy of it if you intend to - * access each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.timestamp())} + * The list returned by this method is lazily constructed. Create a copy of it if you intend + * to access each element in the list multiple times. */ List getTimestampList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.timestamp())} - * The list returned by this method is lazily constructed. Create a copy of it if you intend to - * access each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.timestamp())} + * The list returned by this method is lazily constructed. Create a copy of it if you intend + * to access each element in the list multiple times. */ List getTimestampList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.date())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.date())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getDateList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.date())}. The - * list returned by this method is lazily constructed. Create a copy of it if you intend to access - * each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.date())}. The + * list returned by this method is lazily constructed. Create a copy of it if you intend to + * access each element in the list multiple times. */ List getDateList(String columnName); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.struct(...))} - * The list returned by this method is lazily constructed. Create a copy of it if you intend to - * access each element in the list multiple times. + * @param columnIndex index of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.struct(...))} + * The list returned by this method is lazily constructed. Create a copy of it if you intend + * to access each element in the list multiple times. */ List getStructList(int columnIndex); /** - * Returns the value of a non-{@code NULL} column with type {@code Type.array(Type.struct(...))} - * The list returned by this method is lazily constructed. Create a copy of it if you intend to - * access each element in the list multiple times. + * @param columnName name of the column + * @return the value of a non-{@code NULL} column with type {@code Type.array(Type.struct(...))} + * The list returned by this method is lazily constructed. Create a copy of it if you intend + * to access each element in the list multiple times. */ List getStructList(String columnName); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TimestampBound.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TimestampBound.java index 5d14687b4c0..6502077cd65 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TimestampBound.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TimestampBound.java @@ -46,7 +46,7 @@ * *

      Each type of timestamp bound is discussed in detail below. * - *

      Strong reads

      + *

      Strong reads

      * *

      Strong reads are guaranteed to see the effects of all transactions that have committed before * the start of the read. Furthermore, all rows yielded by a single read are consistent with each @@ -59,7 +59,7 @@ * *

      Use {@link #strong()} to create a bound of this type. * - *

      Exact Staleness

      + *

      Exact Staleness

      * *

      These timestamp bounds execute reads at a user-specified timestamp. Reads at a timestamp are * guaranteed to see a consistent prefix of the global transaction history: they observe @@ -78,7 +78,7 @@ *

      Use {@link #ofReadTimestamp(Timestamp)} and {@link #ofExactStaleness(long, TimeUnit)} to * create a bound of this type. * - *

      Bounded Staleness

      + *

      Bounded Staleness

      * *

      Bounded staleness modes allow Cloud Spanner to pick the read timestamp, subject to a * user-provided staleness bound. Cloud Spanner chooses the newest timestamp within the staleness @@ -103,7 +103,7 @@ *

      Use {@link #ofMinReadTimestamp(Timestamp)} and {@link #ofMaxStaleness(long, TimeUnit)} to * create a bound of this type. * - *

      Old Read Timestamps and Garbage Collection

      + *

      Old Read Timestamps and Garbage Collection

      * *

      Cloud Spanner continuously garbage collects deleted and overwritten data in the background to * reclaim storage space. This process is known as "version GC". By default, version GC reclaims diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionContext.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionContext.java index b858616c131..4a21d9c2cca 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionContext.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionContext.java @@ -17,6 +17,7 @@ package com.google.cloud.spanner; import com.google.api.core.ApiFuture; +import com.google.cloud.spanner.Options.TransactionOption; import com.google.cloud.spanner.Options.UpdateOption; import com.google.spanner.v1.ResultSetStats; @@ -44,7 +45,7 @@ *

      Conceptually, a read-write transaction consists of zero or more reads or SQL queries followed * by a commit. * - *

      Semantics

      + *

      Semantics

      * *

      Cloud Spanner can commit the transaction if all read locks it acquired are still valid at * commit time, and it is able to acquire write locks for all writes. Cloud Spanner can abort the @@ -55,7 +56,7 @@ * transaction's locks were held for. It is an error to use Cloud Spanner locks for any sort of * mutual exclusion other than between Cloud Spanner transactions themselves. * - *

      Retrying Aborted Transactions

      + *

      Retrying Aborted Transactions

      * *

      When a transaction aborts, the application can choose to retry the whole transaction again. To * maximize the chances of successfully committing the retry, the client should execute the retry in @@ -71,7 +72,7 @@ *

      Application code does not need to retry explicitly; {@link TransactionRunner} will * automatically retry a transaction if an attempt results in an abort. * - *

      Idle Transactions

      + *

      Idle Transactions

      * *

      A transaction is considered idle if it has no outstanding reads or SQL queries and has not * started a read or SQL query within the last 10 seconds. Idle transactions can be aborted by Cloud @@ -81,7 +82,7 @@ *

      If this behavior is undesirable, periodically executing a simple SQL query in the transaction * (e.g., {@code SELECT 1}) prevents the transaction from becoming idle. * - * @see Session#readWriteTransaction() + * @see DatabaseClient#readWriteTransaction(TransactionOption...) * @see TransactionRunner */ public interface TransactionContext extends ReadContext { @@ -118,13 +119,13 @@ default ApiFuture bufferAsync(Iterable mutations) { long executeUpdate(Statement statement, UpdateOption... options); /** - * Same as {@link #executeUpdate(Statement)}, but is guaranteed to be non-blocking. If multiple - * asynchronous update statements are submitted to the same read/write transaction, the statements - * are guaranteed to be submitted to Cloud Spanner in the order that they were submitted in the - * client. This does however not guarantee that an asynchronous update statement will see the - * results of all previously submitted statements, as the execution of the statements can be - * parallel. If you rely on the results of a previous statement, you should block until the result - * of that statement is known and has been returned to the client. + * Same as {@link #executeUpdate(Statement,UpdateOption...)}, but is guaranteed to be + * non-blocking. If multiple asynchronous update statements are submitted to the same read/write + * transaction, the statements are guaranteed to be submitted to Cloud Spanner in the order that + * they were submitted in the client. This does however not guarantee that an asynchronous update + * statement will see the results of all previously submitted statements, as the execution of the + * statements can be parallel. If you rely on the results of a previous statement, you should + * block until the result of that statement is known and has been returned to the client. */ ApiFuture executeUpdateAsync(Statement statement, UpdateOption... options); @@ -179,13 +180,13 @@ default ResultSet analyzeUpdateStatement( long[] batchUpdate(Iterable statements, UpdateOption... options); /** - * Same as {@link #batchUpdate(Iterable)}, but is guaranteed to be non-blocking. If multiple - * asynchronous update statements are submitted to the same read/write transaction, the statements - * are guaranteed to be submitted to Cloud Spanner in the order that they were submitted in the - * client. This does however not guarantee that an asynchronous update statement will see the - * results of all previously submitted statements, as the execution of the statements can be - * parallel. If you rely on the results of a previous statement, you should block until the result - * of that statement is known and has been returned to the client. + * Same as {@link #batchUpdate(Iterable, UpdateOption...)}, but is guaranteed to be non-blocking. + * If multiple asynchronous update statements are submitted to the same read/write transaction, + * the statements are guaranteed to be submitted to Cloud Spanner in the order that they were + * submitted in the client. This does however not guarantee that an asynchronous update statement + * will see the results of all previously submitted statements, as the execution of the statements + * can be parallel. If you rely on the results of a previous statement, you should block until the + * result of that statement is known and has been returned to the client. */ ApiFuture batchUpdateAsync(Iterable statements, UpdateOption... options); } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java index 0615e45b940..76656efea28 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java @@ -17,6 +17,7 @@ package com.google.cloud.spanner; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.Options.TransactionOption; /** * An interface for managing the life cycle of a read write transaction including all its retries. @@ -33,7 +34,7 @@ * can cause resources to be leaked and deadlocks. Easiest way to guarantee this is by calling * {@link #close()} in a finally block. * - * @see DatabaseClient#transactionManager() + * @see DatabaseClient#transactionManager(TransactionOption...) */ public interface TransactionManager extends AutoCloseable { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunner.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunner.java index e7167451f01..09bc11f152b 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunner.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunner.java @@ -17,13 +17,14 @@ package com.google.cloud.spanner; import com.google.cloud.Timestamp; +import com.google.cloud.spanner.Options.TransactionOption; import javax.annotation.Nullable; /** * An interface for executing a body of work in the context of a read-write transaction, with * retries for transaction aborts. See {@link TransactionContext} for a description of transaction * semantics. {@code TransactionRunner} instances are obtained by calling {@link - * Session#readWriteTransaction()}. + * DatabaseClient#readWriteTransaction(TransactionOption...)}. * *

      A {@code TransactionRunner} instance can only be used for a single invocation of {@link * #run(TransactionCallable)}. diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java index e16b858faa8..07066470da6 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ValueBinder.java @@ -31,6 +31,8 @@ * *

      {@code ValueBinder} subclasses typically carry state and are therefore not thread-safe, * although the core implementation itself is thread-safe. + * + * @param The context which is used to bind the {@link Value}. */ public abstract class ValueBinder { /** diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java index b0ae8863e6f..0d9c431e171 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java @@ -57,7 +57,12 @@ public abstract class AbstractStatementParser { Dialect.POSTGRESQL, PostgreSQLStatementParser.class); - /** Get an instance of {@link AbstractStatementParser} for the specified dialect. */ + /** + * Get an instance of {@link AbstractStatementParser} for the specified dialect. + * + * @param dialect + * @return + */ public static AbstractStatementParser getInstance(Dialect dialect) { synchronized (lock) { if (!INSTANCES.containsKey(dialect)) { @@ -227,21 +232,21 @@ public boolean equals(Object other) { && Objects.equals(this.sqlWithoutComments, o.sqlWithoutComments); } - /** Returns the type of statement that was recognized by the parser. */ + /** @return the type of statement that was recognized by the parser. */ @InternalApi public StatementType getType() { return type; } - /** Returns whether the statement has a returning clause or not. * */ + /** @return whether the statement has a returning clause or not. */ @InternalApi public boolean hasReturningClause() { return this.returningClause; } /** - * Returns true if the statement is a query that will return a {@link - * com.google.cloud.spanner.ResultSet}. + * @return true if the statement is a query that will return a {@link + * com.google.cloud.spanner.ResultSet}. */ @InternalApi public boolean isQuery() { @@ -259,8 +264,8 @@ public boolean isQuery() { } /** - * Returns true if the statement is a DML statement or a client side statement that will return - * an update count. + * @return true if the statement is a DML statement or a client side statement that will return + * an update count. */ @InternalApi public boolean isUpdate() { @@ -277,7 +282,7 @@ public boolean isUpdate() { return false; } - /** Returns true if the statement is a DDL statement. */ + /** @return true if the statement is a DDL statement. */ @InternalApi public boolean isDdl() { switch (type) { @@ -293,8 +298,8 @@ public boolean isDdl() { } /** - * Returns the {@link ClientSideStatementType} of this statement. This method may only be called - * on statements of type {@link StatementType#CLIENT_SIDE}. + * @return the {@link ClientSideStatementType} of this statement. This method may only be called + * on statements of type {@link StatementType#CLIENT_SIDE}. */ @InternalApi public ClientSideStatementType getClientSideStatementType() { @@ -326,7 +331,7 @@ Statement mergeQueryOptions(Statement statement, QueryOptions defaultQueryOption .build(); } - /** Returns the SQL statement with all comments removed from the SQL string. */ + /** @return the SQL statement with all comments removed from the SQL string. */ @InternalApi public String getSqlWithoutComments() { return sqlWithoutComments; @@ -494,6 +499,12 @@ private boolean statementStartsWith(String sql, Iterable checkStatements @InternalApi abstract String removeCommentsAndTrimInternal(String sql); + /** + * Removes comments from and trims the given sql statement using the dialect of this parser. + * + * @param sql The sql statement to remove comments from and to trim. + * @return the sql statement without the comments and leading and trailing spaces. + */ @InternalApi public String removeCommentsAndTrim(String sql) { return removeCommentsAndTrimInternal(sql); @@ -531,6 +542,19 @@ public static class ParametersInfo { abstract ParametersInfo convertPositionalParametersToNamedParametersInternal( char paramChar, String sql); + /** + * Converts all positional parameters (?) in the given sql string into named parameters. The + * parameters are named @p1, @p2, etc. This method is used when converting a JDBC statement that + * uses positional parameters to a Cloud Spanner {@link Statement} instance that requires named + * parameters. The input SQL string may not contain any comments. There is an exception case if + * the statement starts with a GSQL comment which forces it to be interpreted as a GoogleSql + * statement. + * + * @param sql The sql string without comments that should be converted + * @return A {@link ParametersInfo} object containing a string with named parameters instead of + * positional parameters and the number of parameters. + * @throws SpannerException If the input sql string contains an unclosed string/byte literal. + */ @InternalApi public ParametersInfo convertPositionalParametersToNamedParameters(char paramChar, String sql) { return convertPositionalParametersToNamedParametersInternal(paramChar, sql); @@ -557,6 +581,13 @@ static int countOccurrencesOf(char c, String string) { @InternalApi protected abstract boolean checkReturningClauseInternal(String sql); + /** + * Checks if the given SQL string contains a Returning clause. This method is used only in case of + * a DML statement. + * + * @param sql The sql string without comments that has to be evaluated. + * @return A boolean indicating whether the sql string has a Returning clause or not. + */ @InternalApi public boolean checkReturningClause(String sql) { return checkReturningClauseInternal(sql); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java index 490eff3aca8..e35ecf9ad9a 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GrpcResultSetTest.java @@ -51,7 +51,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Unit tests for {@link com.google.cloud.spanner.SpannerImpl.GrpcResultSet}. */ +/** Unit tests for {@link com.google.cloud.spanner.AbstractResultSet.GrpcResultSet}. */ @RunWith(JUnit4.class) public class GrpcResultSetTest { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminClientImplTest.java index d8134ef29d6..7084290b24a 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminClientImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/InstanceAdminClientImplTest.java @@ -54,7 +54,7 @@ import org.junit.runners.JUnit4; import org.mockito.Mock; -/** Unit tests for {@link com.google.cloud.spanner.SpannerImpl.InstanceAdminClientImpl}. */ +/** Unit tests for {@link com.google.cloud.spanner.InstanceAdminClientImpl}. */ @RunWith(JUnit4.class) public class InstanceAdminClientImplTest { private static final String PROJECT_ID = "my-project"; diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java index df8245e6acb..e13b7b75093 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/TransactionRunnerImplTest.java @@ -73,7 +73,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -/** Unit test for {@link com.google.cloud.spanner.SpannerImpl.TransactionRunnerImpl} */ +/** Unit test for {@link com.google.cloud.spanner.TransactionRunnerImpl} */ @RunWith(JUnit4.class) public class TransactionRunnerImplTest { private static final class TestExecutorFactory diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractSqlScriptVerifier.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractSqlScriptVerifier.java index ec40c8c0d0b..15d6cf65808 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractSqlScriptVerifier.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractSqlScriptVerifier.java @@ -70,9 +70,9 @@ * equal. The value of a variable can be set using a @PUT statement. *

    * - * The parser can set a temporary variable value using a @PUT statement: - * @PUT 'variable_name'\nSQL statement The SQL statement must be a statement that returns a - * {@link ResultSet} containing exactly one row and one column. + * The parser can set a temporary variable value using a @PUT statement: {@code @PUT + * 'variable_name'\nSQL statement} The SQL statement must be a statement that returns a {@link + * ResultSet} containing exactly one row and one column. * *

    In addition the verifier can create new connections if the script contains NEW_CONNECTION; * statements and the verifier has been created with a {@link GenericConnectionProvider}. See {@link @@ -130,7 +130,7 @@ protected abstract static class GenericStatementResult { /** * Generic wrapper around a connection to a database. The underlying connection could be a Spanner - * {@link com.google.cloud.spanner.jdbc.Connection} or a JDBC {@link java.sql.Connection} + * {@link com.google.cloud.spanner.connection.Connection} or a JDBC {@link java.sql.Connection} */ public abstract static class GenericConnection implements AutoCloseable { protected abstract GenericStatementResult execute(String sql) throws Exception; @@ -208,8 +208,8 @@ public AbstractSqlScriptVerifier(GenericConnectionProvider provider) { * Statements without an @EXPECT statement will be executed and its result will be ignored, unless * the statement throws an exception, which will fail the test case. * - *

    The {@link com.google.cloud.spanner.jdbc.Connection}s that the statements are executed on - * must be created by a {@link GenericConnectionProvider} + *

    The {@link com.google.cloud.spanner.connection.Connection}s that the statements are executed + * on must be created by a {@link GenericConnectionProvider} * * @param filename The file name containing the statements. Statements must be separated by a * semicolon (;) @@ -229,8 +229,8 @@ public void verifyStatementsInFile(String filename, Class resourceClass, bool * Statements without an @EXPECT statement will be executed and its result will be ignored, unless * the statement throws an exception, which will fail the test case. * - *

    The {@link com.google.cloud.spanner.jdbc.Connection}s that the statements are executed on - * must be created by a {@link GenericConnectionProvider} + *

    The {@link com.google.cloud.spanner.connection.Connection}s that the statements are executed + * on must be created by a {@link GenericConnectionProvider} * * @param filename The file name containing the statements. Statements must be separated by a * semicolon (;) @@ -250,8 +250,8 @@ public void verifyStatementsInFile(String filename, Class resourceClass) thro * Statements without an @EXPECT statement will be executed and its result will be ignored, unless * the statement throws an exception, which will fail the test case. * - * @param providedConnection The {@link com.google.cloud.spanner.jdbc.Connection} to execute the - * statements against + * @param providedConnection The {@link com.google.cloud.spanner.connection.Connection} to execute + * the statements against * @param filename The file name containing the statements. Statements must be separated by a * semicolon (;) * @param resourceClass The class that defines the package where to find the input file @@ -271,8 +271,8 @@ public void verifyStatementsInFile( * Statements without an @EXPECT statement will be executed and its result will be ignored, unless * the statement throws an exception, which will fail the test case. * - * @param providedConnection The {@link com.google.cloud.spanner.jdbc.Connection} to execute the - * statements against + * @param providedConnection The {@link com.google.cloud.spanner.connection.Connection} to execute + * the statements against * @param filename The file name containing the statements. Statements must be separated by a * semicolon (;) * @param resourceClass The class that defines the package where to find the input file diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java index 15b031705e3..8e88d4a1420 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SqlScriptVerifier.java @@ -28,7 +28,8 @@ import com.google.cloud.spanner.connection.StatementResult.ResultType; /** - * SQL script verifier implementation for Spanner {@link com.google.cloud.spanner.jdbc.Connection} + * SQL script verifier implementation for Spanner {@link + * com.google.cloud.spanner.connection.Connection} * * @see AbstractSqlScriptVerifier for more information */