Skip to content

Commit ce8293e

Browse files
authored
Merge branch 'main' into set-local-retry-aborts-internally
2 parents c57a89c + 134be9b commit ce8293e

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
import io.opentelemetry.api.trace.Span;
9595
import io.opentelemetry.api.trace.Tracer;
9696
import java.io.File;
97-
import java.io.FileInputStream;
9897
import java.io.InputStream;
98+
import java.nio.file.Files;
9999
import java.time.Duration;
100100
import java.time.Instant;
101101
import java.util.ArrayList;
@@ -109,7 +109,6 @@
109109
import java.util.UUID;
110110
import java.util.concurrent.ExecutionException;
111111
import java.util.concurrent.RejectedExecutionException;
112-
import java.util.concurrent.ThreadFactory;
113112
import java.util.concurrent.TimeUnit;
114113
import java.util.concurrent.TimeoutException;
115114
import java.util.stream.Collectors;
@@ -130,9 +129,6 @@ class ConnectionImpl implements Connection {
130129
"This method may only be called while in autocommit mode";
131130
private static final String NOT_ALLOWED_IN_AUTOCOMMIT =
132131
"This method may not be called while in autocommit mode";
133-
134-
private static final ParsedStatement BEGIN_STATEMENT =
135-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("BEGIN"));
136132
private static final ParsedStatement COMMIT_STATEMENT =
137133
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
138134
.parse(Statement.of("COMMIT"));
@@ -145,9 +141,6 @@ class ConnectionImpl implements Connection {
145141
private static final ParsedStatement START_BATCH_DML_STATEMENT =
146142
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
147143
.parse(Statement.of("START BATCH DML"));
148-
private static final ParsedStatement RUN_BATCH_STATEMENT =
149-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
150-
.parse(Statement.of("RUN BATCH"));
151144

152145
// These SAVEPOINT statements are used as sentinels to recognize the start/rollback/release of a
153146
// savepoint.
@@ -185,17 +178,6 @@ private LeakedConnectionException() {
185178
private final ConnectionStatementExecutor connectionStatementExecutor =
186179
new ConnectionStatementExecutorImpl(this);
187180

188-
/** Simple thread factory that is used for fire-and-forget rollbacks. */
189-
static final class DaemonThreadFactory implements ThreadFactory {
190-
@Override
191-
public Thread newThread(Runnable r) {
192-
Thread t = new Thread(r);
193-
t.setName("connection-rollback-executor");
194-
t.setDaemon(true);
195-
return t;
196-
}
197-
}
198-
199181
/**
200182
* Statements are executed using a separate thread in order to be able to cancel these. Statements
201183
* are automatically cancelled if the configured {@link ConnectionImpl#statementTimeout} is
@@ -507,11 +489,6 @@ UnitOfWorkType getUnitOfWorkType() {
507489
return unitOfWorkType;
508490
}
509491

510-
/** Get the current batch mode of this connection. */
511-
BatchMode getBatchMode() {
512-
return batchMode;
513-
}
514-
515492
/** @return <code>true</code> if this connection is in a batch. */
516493
boolean isInBatch() {
517494
return batchMode != BatchMode.NONE;
@@ -900,7 +877,7 @@ public byte[] getProtoDescriptors() {
900877
String.format(
901878
"File %s is not a valid proto descriptors file", this.protoDescriptorsFilePath));
902879
}
903-
InputStream pdStream = new FileInputStream(protoDescriptorsFile);
880+
InputStream pdStream = Files.newInputStream(protoDescriptorsFile.toPath());
904881
this.protoDescriptors = ByteArray.copyFrom(pdStream).toByteArray();
905882
} catch (Exception exception) {
906883
throw SpannerExceptionFactory.newSpannerException(exception);
@@ -1424,7 +1401,7 @@ public ResultSet executeQuery(Statement query, QueryOption... options) {
14241401

14251402
@Override
14261403
public AsyncResultSet executeQueryAsync(Statement query, QueryOption... options) {
1427-
return parseAndExecuteQueryAsync(CallType.ASYNC, query, AnalyzeMode.NONE, options);
1404+
return parseAndExecuteQueryAsync(query, options);
14281405
}
14291406

14301407
@Override
@@ -1624,8 +1601,7 @@ private ResultSet parseAndExecuteQuery(
16241601
+ parsedStatement.getSqlWithoutComments());
16251602
}
16261603

1627-
private AsyncResultSet parseAndExecuteQueryAsync(
1628-
CallType callType, Statement query, AnalyzeMode analyzeMode, QueryOption... options) {
1604+
private AsyncResultSet parseAndExecuteQueryAsync(Statement query, QueryOption... options) {
16291605
Preconditions.checkNotNull(query);
16301606
ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG);
16311607
ParsedStatement parsedStatement = getStatementParser().parse(query, buildQueryOptions());
@@ -1640,7 +1616,8 @@ private AsyncResultSet parseAndExecuteQueryAsync(
16401616
spanner.getAsyncExecutorProvider(),
16411617
options);
16421618
case QUERY:
1643-
return internalExecuteQueryAsync(callType, parsedStatement, analyzeMode, options);
1619+
return internalExecuteQueryAsync(
1620+
CallType.ASYNC, parsedStatement, AnalyzeMode.NONE, options);
16441621
case UPDATE:
16451622
if (parsedStatement.hasReturningClause()) {
16461623
// Cannot execute DML statement with returning clause in read-only mode or in
@@ -1653,7 +1630,8 @@ private AsyncResultSet parseAndExecuteQueryAsync(
16531630
"DML statement with returning clause cannot be executed in read-only mode: "
16541631
+ parsedStatement.getSqlWithoutComments());
16551632
}
1656-
return internalExecuteQueryAsync(callType, parsedStatement, analyzeMode, options);
1633+
return internalExecuteQueryAsync(
1634+
CallType.ASYNC, parsedStatement, AnalyzeMode.NONE, options);
16571635
}
16581636
case DDL:
16591637
case UNKNOWN:

0 commit comments

Comments
 (0)