Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
731c9c9
chore: refactor c style array declaration
thiagotnunes Apr 16, 2021
f8b6eff
chore: refactor to use ut8 standard charset
thiagotnunes Apr 16, 2021
314f3da
chore: removes redundant string conversions
thiagotnunes Apr 16, 2021
ab5af29
chore: refactor enums
thiagotnunes Apr 16, 2021
b1fbb8e
chore: refactor interfaces
thiagotnunes Apr 16, 2021
c25da73
chore: removes unnecessary semicolons
thiagotnunes Apr 16, 2021
3a9aecd
chore: remove redundant local variable declaration
thiagotnunes Apr 16, 2021
db550eb
chore: removes redundant throws clause
thiagotnunes Apr 16, 2021
4fbfa24
chore: removes redundant call to close method
thiagotnunes Apr 16, 2021
b175930
chore: optimise imports
thiagotnunes Apr 16, 2021
93944dc
chore: removes dangling javadoc comment
thiagotnunes Apr 16, 2021
ee8f86a
chore: removes self-references in javadoc
thiagotnunes Apr 16, 2021
2db7499
chore: refactor long literals
thiagotnunes Apr 16, 2021
e11a186
chore: removes octal integers from tests
thiagotnunes Apr 16, 2021
e499a28
chore: simplify arithmetic expressions
thiagotnunes Apr 16, 2021
9524265
chore: fixes malformed string.format
thiagotnunes Apr 16, 2021
34ab1df
chore: removes ignored method call results
thiagotnunes Apr 16, 2021
364cef4
chore: compare strings with equals instead of ==
thiagotnunes Apr 16, 2021
11b4125
chore: simplifies test assertions
thiagotnunes Apr 16, 2021
386bfcb
chore: removes redundant calls to string.format
thiagotnunes Apr 16, 2021
f3ed7d1
chore: explicit type argument replaced by <>
thiagotnunes Apr 16, 2021
4ff774c
chore: uses try with resources
thiagotnunes Apr 16, 2021
4b70a33
chore: replaces if block by switch statement
thiagotnunes Apr 16, 2021
7b64485
chore: uses enhanced for loop
thiagotnunes Apr 16, 2021
4c6ae60
chore: removes unnecessary boxing
thiagotnunes Apr 16, 2021
a6f0c18
chore: removes unnecessary unboxing
thiagotnunes Apr 16, 2021
447a507
chore: refactors to use map.computeIfAbsent
thiagotnunes Apr 16, 2021
64e704d
chore: addresses PR comments
thiagotnunes Apr 19, 2021
2a9243f
chore: fixes compilation errors
thiagotnunes Apr 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken
return stream;
}
};
GrpcResultSet resultSet = new GrpcResultSet(stream, this);
return resultSet;
return new GrpcResultSet(stream, this);
}

private Struct consumeSingleRow(ResultSet resultSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected com.google.protobuf.Value computeNext() {
Object merged =
kind == KindCase.STRING_VALUE
? value.getStringValue()
: new ArrayList<com.google.protobuf.Value>(value.getListValue().getValuesList());
: new ArrayList<>(value.getListValue().getValuesList());
while (current.getChunkedValue() && pos == current.getValuesCount()) {
if (!ensureReady(StreamValue.RESULT)) {
throw newSpannerException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ enum CursorState {
* Non-blocking call that attempts to step the cursor to the next position in the stream. The
* cursor may be inspected only if the cursor returns {@code CursorState.OK}.
*
* <p>A caller will typically call {@link #tryNext()} in a loop inside the ReadyCallback,
* consuming all results available. For more information see {@link #setCallback(Executor,
* ReadyCallback)}.
* <p>A caller will typically call tryNext in a loop inside the ReadyCallback, consuming all
* results available. For more information see {@link #setCallback(Executor, ReadyCallback)}.
*
* <p>Currently this method may only be called if a ReadyCallback has been registered. This is for
* safety purposes only, and may be relaxed in future.
Expand Down Expand Up @@ -146,8 +145,8 @@ interface ReadyCallback {
* <ul>
* <li>Semi-async: make {@code upstream.emit()} a blocking call. This will block the callback
* thread until progress is possible. When coding in this way the threads in the Executor
* provided to {@link #setCallback(Executor, ReadyCallback)} must be blockable without
* causing harm to progress in your system.
* provided to setCallback must be blockable without causing harm to progress in your
* system.
* <li>Full-async: call {@code cursor.pause()} and return from the callback with data still in
* the Cursor. Once in this state cursor waits until resume() is called before calling
* callback again.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ private enum State {
/** Does this state mean that the result set should permanently stop producing rows. */
private final boolean shouldStop;

private State() {
State() {
shouldStop = false;
}

private State(boolean shouldStop) {
State(boolean shouldStop) {
this.shouldStop = shouldStop;
}
}
Expand Down Expand Up @@ -116,32 +116,31 @@ private State(boolean shouldStop) {
private State state = State.INITIALIZED;

/**
* {@link #finished} indicates whether all the results from the underlying result set have been
* read.
* This variable indicates whether all the results from the underlying result set have been read.
*/
private volatile boolean finished;

private volatile ApiFuture<Void> result;

/**
* {@link #cursorReturnedDoneOrException} indicates whether {@link #tryNext()} has returned {@link
* CursorState#DONE} or a {@link SpannerException}.
* This variable indicates whether {@link #tryNext()} has returned {@link CursorState#DONE} or a
* {@link SpannerException}.
*/
private volatile boolean cursorReturnedDoneOrException;

/**
* {@link #pausedLatch} is used to pause the producer when the {@link AsyncResultSet} is paused.
* The production of rows that are put into the buffer is only paused once the buffer is full.
* This variable is used to pause the producer when the {@link AsyncResultSet} is paused. The
* production of rows that are put into the buffer is only paused once the buffer is full.
*/
private volatile CountDownLatch pausedLatch = new CountDownLatch(1);
/**
* {@link #bufferConsumptionLatch} is used to pause the producer when the buffer is full and the
* consumer needs some time to catch up.
* This variable is used to pause the producer when the buffer is full and the consumer needs some
* time to catch up.
*/
private volatile CountDownLatch bufferConsumptionLatch = new CountDownLatch(0);
/**
* {@link #consumingLatch} is used to pause the producer when all rows have been put into the
* buffer, but the consumer (the callback) has not yet received and processed all rows.
* This variable is used to pause the producer when all rows have been put into the buffer, but
* the consumer (the callback) has not yet received and processed all rows.
*/
private volatile CountDownLatch consumingLatch = new CountDownLatch(0);

Expand Down Expand Up @@ -531,7 +530,7 @@ public <T> ApiFuture<List<T>> toListAsync(
Preconditions.checkState(
this.state == State.INITIALIZED, "This AsyncResultSet has already been used.");
final SettableApiFuture<List<T>> res = SettableApiFuture.<List<T>>create();
CreateListCallback<T> callback = new CreateListCallback<T>(res, transformer);
CreateListCallback<T> callback = new CreateListCallback<>(res, transformer);
ApiFuture<Void> finished = setCallback(executor, callback);
return ApiFutures.transformAsync(
finished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface AsyncTransactionManager extends AutoCloseable {
* {@link ApiFuture} that returns a {@link TransactionContext} and that supports chaining of
* multiple {@link TransactionContextFuture}s to form a transaction.
*/
public interface TransactionContextFuture extends ApiFuture<TransactionContext> {
interface TransactionContextFuture extends ApiFuture<TransactionContext> {
/**
* Sets the first step to execute as part of this transaction after the transaction has started
* using the specified executor. {@link MoreExecutors#directExecutor()} can be be used for
Expand All @@ -65,7 +65,7 @@ <O> AsyncTransactionStep<Void, O> then(
* is executed using an {@link AsyncTransactionManager}. This future is returned by the call to
* {@link AsyncTransactionStep#commitAsync()} of the last step in the transaction.
*/
public interface CommitTimestampFuture extends ApiFuture<Timestamp> {
interface CommitTimestampFuture extends ApiFuture<Timestamp> {
/**
* Returns the commit timestamp of the transaction. Getting this value should always be done in
* order to ensure that the transaction succeeded. If any of the steps in the transaction fails
Expand Down Expand Up @@ -125,7 +125,7 @@ Timestamp get(long timeout, TimeUnit unit)
* })
* }</pre>
*/
public interface AsyncTransactionStep<I, O> extends ApiFuture<O> {
interface AsyncTransactionStep<I, O> extends ApiFuture<O> {
/**
* Adds a step to the transaction chain that should be executed using the specified executor.
* This step is guaranteed to be executed only after the previous step executed successfully.
Expand All @@ -150,11 +150,11 @@ <RES> AsyncTransactionStep<O, RES> then(
* parameters. The method should return an {@link ApiFuture} that will return the result of this
* step.
*/
public interface AsyncTransactionFunction<I, O> {
interface AsyncTransactionFunction<I, O> {
/**
* {@link #apply(TransactionContext, Object)} is called when this transaction step is executed.
* The input value is the result of the previous step, and this method will only be called if
* the previous step executed successfully.
* This method is called when this transaction step is executed. The input value is the result
* of the previous step, and this method will only be called if the previous step executed
* successfully.
*
* @param txn the {@link TransactionContext} that can be used to execute statements.
* @param input the result of the previous transaction step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public ApiFuture<Void> closeAsync() {
@Override
public TransactionContextFutureImpl beginAsync() {
Preconditions.checkState(txn == null, "begin can only be called once");
TransactionContextFutureImpl begin =
new TransactionContextFutureImpl(this, internalBeginAsync(true));
return begin;
return new TransactionContextFutureImpl(this, internalBeginAsync(true));
}

private ApiFuture<TransactionContext> internalBeginAsync(boolean firstAttempt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public OperationFuture<Database, RestoreDatabaseMetadata> restoreDatabase(Restor
final OperationFuture<com.google.spanner.admin.database.v1.Database, RestoreDatabaseMetadata>
rawOperationFuture = rpc.restoreDatabase(restore);

return new OperationFutureImpl<Database, RestoreDatabaseMetadata>(
return new OperationFutureImpl<>(
rawOperationFuture.getPollingFuture(),
rawOperationFuture.getInitialFuture(),
new ApiFunction<OperationSnapshot, Database>() {
Expand Down Expand Up @@ -308,7 +308,7 @@ public OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
rawOperationFuture =
rpc.createDatabase(
database.getId().getInstanceId().getName(), createStatement, statements, database);
return new OperationFutureImpl<Database, CreateDatabaseMetadata>(
return new OperationFutureImpl<>(
rawOperationFuture.getPollingFuture(),
rawOperationFuture.getInitialFuture(),
new ApiFunction<OperationSnapshot, Database>() {
Expand Down Expand Up @@ -347,7 +347,7 @@ public OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
final String opId = operationId != null ? operationId : randomOperationId();
OperationFuture<Empty, UpdateDatabaseDdlMetadata> rawOperationFuture =
rpc.updateDatabaseDdl(dbName, statements, opId);
return new OperationFutureImpl<Void, UpdateDatabaseDdlMetadata>(
return new OperationFutureImpl<>(
rawOperationFuture.getPollingFuture(),
rawOperationFuture.getInitialFuture(),
new ApiFunction<OperationSnapshot, Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public OperationFuture<Instance, CreateInstanceMetadata> createInstance(Instance
rawOperationFuture =
rpc.createInstance(projectName, instance.getId().getInstance(), instance.toProto());

return new OperationFutureImpl<Instance, CreateInstanceMetadata>(
return new OperationFutureImpl<>(
rawOperationFuture.getPollingFuture(),
rawOperationFuture.getInitialFuture(),
new ApiFunction<OperationSnapshot, Instance>() {
Expand Down Expand Up @@ -172,7 +172,7 @@ public OperationFuture<Instance, UpdateInstanceMetadata> updateInstance(

OperationFuture<com.google.spanner.admin.instance.v1.Instance, UpdateInstanceMetadata>
rawOperationFuture = rpc.updateInstance(instance.toProto(), fieldMask);
return new OperationFutureImpl<Instance, UpdateInstanceMetadata>(
return new OperationFutureImpl<>(
rawOperationFuture.getPollingFuture(),
rawOperationFuture.getInitialFuture(),
new ApiFunction<OperationSnapshot, Instance>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static FieldMask toFieldMask(InstanceField... fields) {
}

/** State of the Instance. */
public static enum State {
public enum State {
UNSPECIFIED,
CREATING,
READY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Operation<R, M> {
.setMaxRetryDelay(Duration.ofMinutes(500L))
.build();

static interface Parser<R, M> {
interface Parser<R, M> {
R parseResult(Any response);

M parseMetadata(Any metadata);
Expand Down Expand Up @@ -85,7 +85,7 @@ private static <R, M> Operation<R, M> failed(
SpannerException e =
SpannerExceptionFactory.newSpannerException(
ErrorCode.fromRpcStatus(status), status.getMessage(), null);
return new Operation<R, M>(rpc, name, metadata, null, e, true, parser, clock);
return new Operation<>(rpc, name, metadata, null, e, true, parser, clock);
}

private static <R, M> Operation<R, M> successful(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public enum RpcPriority {

private final Priority proto;

private RpcPriority(Priority proto) {
RpcPriority(Priority proto) {
this.proto = Preconditions.checkNotNull(proto);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ ApiFuture<Struct> readRowUsingIndexAsync(

/** Closes this read context and frees up the underlying resources. */
@Override
public void close();
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void run() {
* Callback interface to be used for BatchCreateSessions. When sessions become available or
* session creation fails, one of the callback methods will be called.
*/
static interface SessionConsumer {
interface SessionConsumer {
/** Called when a session has been created and is ready for use. */
void onSessionReady(SessionImpl session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void throwIfTransactionsPending() {
* transactions, and read-write transactions. The defining characteristic is that a session may
* only have one such transaction active at a time.
*/
static interface SessionTransaction {
interface SessionTransaction {
/** Invalidates the transaction, generally because a new one has been started on the session. */
void invalidate();
/** Registers the current span on the transaction. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1749,9 +1749,9 @@ private void replenishPool() {
}
}

private static enum Position {
private enum Position {
FIRST,
RANDOM;
RANDOM
}

private final SessionPoolOptions options;
Expand Down Expand Up @@ -2058,7 +2058,7 @@ private PooledSessionFuture checkoutSession(
logger.log(
Level.FINE,
"No session available in the pool. Blocking for one to become available/created");
span.addAnnotation(String.format("Waiting for a session to come available"));
span.addAnnotation("Waiting for a session to come available");
sessionFuture = waiter;
} else {
SettableFuture<PooledSession> fut = SettableFuture.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ public static Builder newBuilder() {
return new Builder();
}

private static enum ActionOnExhaustion {
private enum ActionOnExhaustion {
BLOCK,
FAIL,
}

private static enum ActionOnSessionNotFound {
private enum ActionOnSessionNotFound {
RETRY,
FAIL;
FAIL
}

private static enum ActionOnSessionLeak {
private enum ActionOnSessionLeak {
WARN,
FAIL;
FAIL
}

/** Builder for creating SessionPoolOptions. */
Expand All @@ -204,7 +204,7 @@ public static class Builder {
private int maxSessions = DEFAULT_MAX_SESSIONS;
private int incStep = DEFAULT_INC_STEP;

/** Set a higher value for {@link #minSessions} instead of using {@link #maxIdleSessions}. */
/** Set a higher value for {@link #minSessions} instead of using this field. */
@Deprecated private int maxIdleSessions;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,13 @@ static SpannerException newSpannerExceptionPreformatted(
case NOT_FOUND:
ResourceInfo resourceInfo = extractResourceInfo(cause);
if (resourceInfo != null) {
if (resourceInfo.getResourceType().equals(SESSION_RESOURCE_TYPE)) {
return new SessionNotFoundException(token, message, resourceInfo, cause);
} else if (resourceInfo.getResourceType().equals(DATABASE_RESOURCE_TYPE)) {
return new DatabaseNotFoundException(token, message, resourceInfo, cause);
} else if (resourceInfo.getResourceType().equals(INSTANCE_RESOURCE_TYPE)) {
return new InstanceNotFoundException(token, message, resourceInfo, cause);
switch (resourceInfo.getResourceType()) {
case SESSION_RESOURCE_TYPE:
return new SessionNotFoundException(token, message, resourceInfo, cause);
case DATABASE_RESOURCE_TYPE:
return new DatabaseNotFoundException(token, message, resourceInfo, cause);
case INSTANCE_RESOURCE_TYPE:
return new InstanceNotFoundException(token, message, resourceInfo, cause);
}
}
// Fall through to the default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public Page<S> getNextPage() {
for (T proto : nextPage.getResults()) {
results.add(fromProto(proto));
}
return new PageImpl<S>(this, nextPageToken, results);
return new PageImpl<>(this, nextPageToken, results);
}

void setNextPageToken(String nextPageToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
* Interface that can be used to provide {@link CallCredentials} instead of {@link Credentials} to
* {@link SpannerOptions}.
*/
public static interface CallCredentialsProvider {
public interface CallCredentialsProvider {
/** Return the {@link CallCredentials} to use for a gRPC call. */
CallCredentials getCallCredentials();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public static interface CallCredentialsProvider {
* }
* }</pre>
*/
public static interface CallContextConfigurator {
public interface CallContextConfigurator {
/**
* Configure a {@link ApiCallContext} for a specific RPC call.
*
Expand Down Expand Up @@ -472,7 +472,7 @@ public ServiceRpc create(SpannerOptions options) {
interface CloseableExecutorProvider extends ExecutorProvider, AutoCloseable {
/** Overridden to suppress the throws declaration of the super interface. */
@Override
public void close();
void close();
}

static class FixedCloseableExecutorProvider implements CloseableExecutorProvider {
Expand Down Expand Up @@ -576,7 +576,7 @@ private SpannerOptions(Builder builder) {
* The environment to read configuration values from. The default implementation uses environment
* variables.
*/
public static interface SpannerEnvironment {
public interface SpannerEnvironment {
/**
* The optimizer version to use. Must return an empty string to indicate that no value has been
* set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public interface TransactionManager extends AutoCloseable {

/** State of the transaction manager. */
public enum TransactionState {
enum TransactionState {
// Transaction has been started either by calling {@link #begin()} or via
// {@link resetForRetry()} but has not been commited or rolled back yet.
STARTED,
Expand Down
Loading