From a2a8061b9fe810f84ebc992ca68afaf945f53fd5 Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Wed, 27 Oct 2021 17:02:36 +0000
Subject: [PATCH 01/11] chore: release 2.5.2-SNAPSHOT (#654)
:robot: I have created a release \*beep\* \*boop\*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
---
pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
versions.txt | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index d9b697624..899673f1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
google-cloud-spanner-jdbc
- 2.5.1
+ 2.5.2-SNAPSHOT
jar
Google Cloud Spanner JDBC
https://github.com/googleapis/java-spanner-jdbc
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 3771fd68a..6dd2b3033 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -28,7 +28,7 @@
com.google.cloud
google-cloud-spanner-jdbc
- 2.5.1
+ 2.5.2-SNAPSHOT
diff --git a/versions.txt b/versions.txt
index 27d308fe0..00a220568 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,4 +1,4 @@
# Format:
# module:released-version:current-version
-google-cloud-spanner-jdbc:2.5.1:2.5.1
+google-cloud-spanner-jdbc:2.5.1:2.5.2-SNAPSHOT
From bb13da583acd2d35d0495171fcc8fd50df2664e1 Mon Sep 17 00:00:00 2001
From: WhiteSource Renovate
Date: Mon, 1 Nov 2021 03:30:23 +0100
Subject: [PATCH 02/11] chore(deps): update dependency
com.google.cloud:google-cloud-spanner-jdbc to v2.5.1 (#655)
---
samples/install-without-bom/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 9093208b1..46322c634 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud
google-cloud-spanner-jdbc
- 2.5.0
+ 2.5.1
From e98ef8d573f5516f089a6ce9a67f7e929d00dce8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?=
Date: Mon, 1 Nov 2021 08:36:12 +0100
Subject: [PATCH 03/11] cleanup: remove warnings (#574)
Remove as many warnings as possible.
---
.../spanner/jdbc/AbstractJdbcConnection.java | 5 +-
.../spanner/jdbc/AbstractJdbcResultSet.java | 20 +-
.../spanner/jdbc/AbstractJdbcStatement.java | 19 +-
.../spanner/jdbc/AbstractJdbcWrapper.java | 8 +-
.../jdbc/CloudSpannerJdbcConnection.java | 34 +-
.../google/cloud/spanner/jdbc/JdbcArray.java | 14 +-
.../google/cloud/spanner/jdbc/JdbcBlob.java | 10 +-
.../google/cloud/spanner/jdbc/JdbcClob.java | 28 +-
.../cloud/spanner/jdbc/JdbcConnection.java | 17 +-
.../cloud/spanner/jdbc/JdbcConstants.java | 5 +-
.../cloud/spanner/jdbc/JdbcDataSource.java | 12 +-
.../cloud/spanner/jdbc/JdbcDataType.java | 6 +-
.../spanner/jdbc/JdbcDatabaseMetaData.java | 396 +++++++++---------
.../google/cloud/spanner/jdbc/JdbcDriver.java | 4 +-
.../spanner/jdbc/JdbcParameterMetaData.java | 59 ++-
.../spanner/jdbc/JdbcParameterStore.java | 37 +-
.../cloud/spanner/jdbc/JdbcPreconditions.java | 4 +-
.../spanner/jdbc/JdbcPreparedStatement.java | 5 +-
.../cloud/spanner/jdbc/JdbcResultSet.java | 19 +-
.../spanner/jdbc/JdbcResultSetMetaData.java | 50 +--
.../spanner/jdbc/JdbcSqlExceptionFactory.java | 3 +-
.../cloud/spanner/jdbc/JdbcStatement.java | 7 +-
.../cloud/spanner/jdbc/JdbcTypeConverter.java | 70 ++--
.../jdbc/TransactionRetryListener.java | 8 +-
.../jdbc/AbstractJdbcResultSetTest.java | 10 +-
.../spanner/jdbc/AbstractJdbcWrapperTest.java | 62 ++-
.../jdbc/JdbcAbortedTransactionTest.java | 13 +-
.../cloud/spanner/jdbc/JdbcArrayTest.java | 6 +-
.../cloud/spanner/jdbc/JdbcClobTest.java | 11 +-
.../JdbcConnectionGeneratedSqlScriptTest.java | 3 +-
.../spanner/jdbc/JdbcConnectionTest.java | 16 +-
.../spanner/jdbc/JdbcConnectionUrlTest.java | 40 +-
.../jdbc/JdbcDatabaseMetaDataTest.java | 7 +-
...cDatabaseMetaDataWithMockedServerTest.java | 12 +-
.../cloud/spanner/jdbc/JdbcDriverTest.java | 34 +-
.../cloud/spanner/jdbc/JdbcGrpcErrorTest.java | 9 +-
.../spanner/jdbc/JdbcParameterStoreTest.java | 37 +-
.../jdbc/JdbcPreparedStatementTest.java | 40 +-
...PreparedStatementWithMockedServerTest.java | 3 +-
.../jdbc/JdbcResultSetMetaDataTest.java | 93 ++--
.../cloud/spanner/jdbc/JdbcResultSetTest.java | 93 ++--
.../spanner/jdbc/JdbcSqlScriptVerifier.java | 18 +-
.../cloud/spanner/jdbc/JdbcStatementTest.java | 65 ++-
.../spanner/jdbc/JdbcTimeoutSqlTest.java | 4 +-
.../spanner/jdbc/JdbcTypeConverterTest.java | 88 ++--
.../jdbc/SpannerJdbcExceptionMatcher.java | 4 +-
.../spanner/jdbc/it/ITJdbcConnectTest.java | 7 +-
.../cloud/spanner/jdbc/it/ITJdbcDdlTest.java | 2 +-
.../jdbc/it/ITJdbcPreparedStatementTest.java | 49 +--
.../jdbc/it/ITJdbcQueryOptionsTest.java | 5 +
.../spanner/jdbc/it/ITJdbcReadOnlyTest.java | 34 +-
.../it/ITJdbcReadWriteAutocommitTest.java | 2 +-
.../jdbc/it/ITJdbcSimpleStatementsTest.java | 2 +-
.../jdbc/it/ITJdbcSqlMusicScriptTest.java | 2 +-
.../spanner/jdbc/it/ITJdbcSqlScriptTest.java | 92 ++--
55 files changed, 792 insertions(+), 911 deletions(-)
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
index 385a46fae..a666a7490 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
@@ -170,7 +170,7 @@ public SQLXML createSQLXML() throws SQLException {
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
- Properties supported = null;
+ Properties supported;
try {
checkClosed();
supported = JdbcDatabaseMetaData.getDefaultClientInfoProperties();
@@ -255,10 +255,9 @@ public int getNetworkTimeout() throws SQLException {
void pushWarning(SQLWarning warning) {
if (lastWarning == null) {
firstWarning = warning;
- lastWarning = warning;
} else {
lastWarning.setNextWarning(warning);
- lastWarning = warning;
}
+ lastWarning = warning;
}
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSet.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSet.java
index 74d5ccde3..652ed0b25 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSet.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSet.java
@@ -47,12 +47,12 @@ abstract class AbstractJdbcResultSet extends AbstractJdbcWrapper implements Resu
}
@Override
- public SQLWarning getWarnings() throws SQLException {
+ public SQLWarning getWarnings() {
return null;
}
@Override
- public void clearWarnings() throws SQLException {}
+ public void clearWarnings() {}
@Override
public String getCursorName() throws SQLException {
@@ -105,42 +105,42 @@ public void setFetchDirection(int direction) throws SQLException {
}
@Override
- public int getFetchDirection() throws SQLException {
+ public int getFetchDirection() {
return FETCH_FORWARD;
}
@Override
- public void setFetchSize(int rows) throws SQLException {
+ public void setFetchSize(int rows) {
this.fetchSize = rows;
}
@Override
- public int getFetchSize() throws SQLException {
+ public int getFetchSize() {
return fetchSize;
}
@Override
- public int getType() throws SQLException {
+ public int getType() {
return TYPE_FORWARD_ONLY;
}
@Override
- public int getConcurrency() throws SQLException {
+ public int getConcurrency() {
return CONCUR_READ_ONLY;
}
@Override
- public boolean rowUpdated() throws SQLException {
+ public boolean rowUpdated() {
return false;
}
@Override
- public boolean rowInserted() throws SQLException {
+ public boolean rowInserted() {
return false;
}
@Override
- public boolean rowDeleted() throws SQLException {
+ public boolean rowDeleted() {
return false;
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
index 9863f47c0..9c516609a 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
@@ -20,6 +20,7 @@
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
import com.google.cloud.spanner.SpannerException;
+import com.google.cloud.spanner.connection.Connection;
import com.google.cloud.spanner.connection.StatementResult;
import com.google.cloud.spanner.connection.StatementResult.ClientSideStatementType;
import com.google.rpc.Code;
@@ -252,7 +253,7 @@ StatementResult execute(com.google.cloud.spanner.Statement statement) throws SQL
if (mustResetTimeout && resultIsShowStatementTimeout(result)) {
// it was a 'SHOW STATEMENT_TIMEOUT statement, we need to re-run to get the correct value
mustResetTimeout = false;
- result = rerunShowStatementTimeout(statement, result, originalTimeout);
+ result = rerunShowStatementTimeout(statement, originalTimeout);
}
return result;
} catch (SpannerException e) {
@@ -292,9 +293,7 @@ private boolean resultIsShowStatementTimeout(StatementResult result) {
}
private StatementResult rerunShowStatementTimeout(
- com.google.cloud.spanner.Statement statement,
- StatementResult result,
- StatementTimeout originalTimeout)
+ com.google.cloud.spanner.Statement statement, StatementTimeout originalTimeout)
throws SQLException {
resetStatementTimeout(originalTimeout);
return connection.getSpannerConnection().execute(statement);
@@ -319,12 +318,12 @@ public void cancel() throws SQLException {
}
@Override
- public void close() throws SQLException {
+ public void close() {
this.closed = true;
}
@Override
- public boolean isClosed() throws SQLException {
+ public boolean isClosed() {
return closed;
}
@@ -414,22 +413,22 @@ public void setFetchDirection(int direction) throws SQLException {
}
@Override
- public int getFetchDirection() throws SQLException {
+ public int getFetchDirection() {
return ResultSet.FETCH_FORWARD;
}
@Override
- public int getResultSetConcurrency() throws SQLException {
+ public int getResultSetConcurrency() {
return ResultSet.CONCUR_READ_ONLY;
}
@Override
- public int getResultSetType() throws SQLException {
+ public int getResultSetType() {
return ResultSet.TYPE_FORWARD_ONLY;
}
@Override
- public int getResultSetHoldability() throws SQLException {
+ public int getResultSetHoldability() {
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
index 5f2967310..25ff70a6f 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java
@@ -199,7 +199,7 @@ static float checkedCastToFloat(double val) throws SQLException {
static long parseLong(String val) throws SQLException {
Preconditions.checkNotNull(val);
try {
- return Long.valueOf(val);
+ return Long.parseLong(val);
} catch (NumberFormatException e) {
throw JdbcSqlExceptionFactory.of(
String.format("%s is not a valid number", val), com.google.rpc.Code.INVALID_ARGUMENT, e);
@@ -233,7 +233,7 @@ static long checkedCastToLong(BigDecimal val) throws SQLException {
static double parseDouble(String val) throws SQLException {
Preconditions.checkNotNull(val);
try {
- return Double.valueOf(val);
+ return Double.parseDouble(val);
} catch (NumberFormatException e) {
throw JdbcSqlExceptionFactory.of(
String.format("%s is not a valid number", val), com.google.rpc.Code.INVALID_ARGUMENT, e);
@@ -333,7 +333,7 @@ static Timestamp parseTimestamp(String val, Calendar cal) throws SQLException {
}
/** Should return true if this object has been closed */
- public abstract boolean isClosed() throws SQLException;
+ public abstract boolean isClosed();
/** Throws a {@link SQLException} if this object is closed */
void checkClosed() throws SQLException {
@@ -354,7 +354,7 @@ T checkClosedAndThrowUnsupported(String message) throws SQLException {
}
@Override
- public boolean isWrapperFor(Class> iface) throws SQLException {
+ public boolean isWrapperFor(Class> iface) {
return iface != null && iface.isAssignableFrom(getClass());
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java
index 50ae71c56..7801dcfdc 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java
@@ -16,6 +16,7 @@
package com.google.cloud.spanner.jdbc;
+import com.google.cloud.spanner.AbortedDueToConcurrentModificationException;
import com.google.cloud.spanner.AbortedException;
import com.google.cloud.spanner.CommitResponse;
import com.google.cloud.spanner.CommitStats;
@@ -53,12 +54,12 @@ public interface CloudSpannerJdbcConnection extends Connection {
*/
default void setTransactionTag(String tag) throws SQLException {
throw new UnsupportedOperationException();
- };
+ }
/** @return The transaction tag of the current transaction. */
default String getTransactionTag() throws SQLException {
throw new UnsupportedOperationException();
- };
+ }
/**
* Sets the statement tag to use for the next statement that will be executed. The tag is
@@ -70,7 +71,7 @@ default String getTransactionTag() throws SQLException {
*/
default void setStatementTag(String tag) throws SQLException {
throw new UnsupportedOperationException();
- };
+ }
/**
* @return The statement tag that will be used with the next statement that is executed on this
@@ -78,7 +79,7 @@ default void setStatementTag(String tag) throws SQLException {
*/
default String getStatementTag() throws SQLException {
throw new UnsupportedOperationException();
- };
+ }
/**
* Sets the transaction mode to use for current transaction. This method may only be called when
@@ -96,10 +97,10 @@ default String getStatementTag() throws SQLException {
* not acquire locks on Cloud Spanner, and read-only transactions never abort.
* {@link TransactionMode#READ_WRITE_TRANSACTION} this value is only allowed when the
* connection is not in read-only mode and will create a read-write transaction. If
- * {@link Connection#isRetryAbortsInternally()} is true, each read/write
- * transaction will keep track of a running SHA256 checksum for each {@link ResultSet}
- * that is returned in order to be able to retry the transaction in case the transaction
- * is aborted by Spanner.
+ * {@link CloudSpannerJdbcConnection#isRetryAbortsInternally()} is true,
+ * each read/write transaction will keep track of a running SHA256 checksum for each
+ * {@link ResultSet} that is returned in order to be able to retry the transaction in
+ * case the transaction is aborted by Spanner.
*
*/
void setTransactionMode(TransactionMode transactionMode) throws SQLException;
@@ -175,9 +176,8 @@ default String getStatementTag() throws SQLException {
/**
* @return true if this connection has a transaction (that has not necessarily
* started). This method will only return false when the {@link Connection} is in autocommit
- * mode and no explicit transaction has been started by calling {@link
- * Connection#beginTransaction()}. If the {@link Connection} is not in autocommit mode, there
- * will always be a transaction.
+ * mode and no explicit transaction has been started by executing `BEGIN TRANSACTION`. If the
+ * {@link Connection} is not in autocommit mode, there will always be a transaction.
*/
boolean isInTransaction() throws SQLException;
@@ -323,7 +323,7 @@ default String getStatementTag() throws SQLException {
/**
* @see
- * com.google.cloud.spanner.connection.Connection#addTransactionRetryListener(TransactionRetryListener)
+ * com.google.cloud.spanner.connection.Connection#addTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener)
* @throws SQLException if the {@link Connection} is closed.
*/
void addTransactionRetryListener(
@@ -331,7 +331,8 @@ void addTransactionRetryListener(
/**
* Use {@link
- * #addTransactionRetryListener(com.google.cloud.spanner.jdbc.TransactionRetryListener)}
+ * #addTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener)}
+ * instead.
*/
@Deprecated
void addTransactionRetryListener(com.google.cloud.spanner.jdbc.TransactionRetryListener listener)
@@ -339,7 +340,7 @@ void addTransactionRetryListener(com.google.cloud.spanner.jdbc.TransactionRetryL
/**
* @see
- * com.google.cloud.spanner.connection.Connection#removeTransactionRetryListener(TransactionRetryListener)
+ * com.google.cloud.spanner.connection.Connection#removeTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener)
* @throws SQLException if the {@link Connection} is closed.
*/
boolean removeTransactionRetryListener(
@@ -347,13 +348,14 @@ boolean removeTransactionRetryListener(
/**
* Use {@link
- * #removeTransactionRetryListener(com.google.cloud.spanner.jdbc.TransactionRetryListener)}
+ * #removeTransactionRetryListener(com.google.cloud.spanner.connection.TransactionRetryListener)}
+ * instead.
*/
@Deprecated
boolean removeTransactionRetryListener(
com.google.cloud.spanner.jdbc.TransactionRetryListener listener) throws SQLException;
- /** Use {@link #getTransactionRetryListenersFromConnection()} */
+ /** Use {@link #getTransactionRetryListenersFromConnection()} instead. */
@Deprecated
Iterator getTransactionRetryListeners()
throws SQLException;
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcArray.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcArray.java
index 436774050..f712b56ca 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcArray.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcArray.java
@@ -67,13 +67,11 @@ static JdbcArray createArray(String typeName, Object[] elements) throws SQLExcep
/**
* Create a JDBC {@link Array} from the given type name and list.
*
- * @param typeName The Google Cloud Spanner type name to be used as the base type of the array.
+ * @param type The Google Cloud Spanner type to be used as the base type of the array.
* @param elements The elements to store in the array.
* @return the initialized {@link Array}.
- * @throws SQLException if the type name is not a valid Cloud Spanner type or if the contents of
- * the elements array is not compatible with the base type of the array.
*/
- static JdbcArray createArray(JdbcDataType type, List extends Object> elements) {
+ static JdbcArray createArray(JdbcDataType type, List> elements) {
return new JdbcArray(type, elements);
}
@@ -93,7 +91,7 @@ private JdbcArray(JdbcDataType type, Object[] elements) throws SQLException {
}
}
- private JdbcArray(JdbcDataType type, List extends Object> elements) {
+ private JdbcArray(JdbcDataType type, List> elements) {
this.type = type;
if (elements != null) {
this.data = java.lang.reflect.Array.newInstance(type.getJavaClass(), elements.size());
@@ -179,7 +177,7 @@ public ResultSet getResultSet(long startIndex, int count) throws SQLException {
Object value = ((Object[]) data)[index - 1];
ValueBinder binder =
Struct.newBuilder().set("INDEX").to(index).set("VALUE");
- Struct.Builder builder = null;
+ Struct.Builder builder;
switch (type.getCode()) {
case BOOL:
builder = binder.to((Boolean) value);
@@ -237,7 +235,7 @@ public ResultSet getResultSet(long index, int count, Map> map)
}
@Override
- public void free() throws SQLException {
+ public void free() {
this.freed = true;
this.data = null;
}
@@ -257,7 +255,7 @@ public String toString() {
if (o == null) {
builder.append("null");
} else {
- builder.append(o.toString());
+ builder.append(o);
}
}
builder.append("}");
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcBlob.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcBlob.java
index 071e3258c..5a1566f7e 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcBlob.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcBlob.java
@@ -63,7 +63,7 @@ private void checkPositionPlusLength(long pos, long length) {
}
@Override
- public long length() throws SQLException {
+ public long length() {
return value.length;
}
@@ -84,7 +84,7 @@ public byte[] getBytes(long pos, int length) throws SQLException {
}
@Override
- public InputStream getBinaryStream() throws SQLException {
+ public InputStream getBinaryStream() {
return new ByteArrayInputStream(value);
}
@@ -119,7 +119,7 @@ public long position(Blob pattern, long start) throws SQLException {
int totalSize = 0;
List totalBytes = new ArrayList<>();
try (InputStream is = pattern.getBinaryStream()) {
- int bytesRead = 0;
+ int bytesRead;
while ((bytesRead = is.read(buffer)) > -1) {
if (bytesRead == buffer.length) {
totalBytes.add(buffer);
@@ -196,7 +196,7 @@ private BlobOutputStream(int pos) {
}
@Override
- public void write(int b) throws IOException {
+ public void write(int b) {
if (currentPos >= buffer.length) {
byte[] newBuffer = new byte[buffer.length * 2];
System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
@@ -239,7 +239,7 @@ public void truncate(long len) throws SQLException {
}
@Override
- public void free() throws SQLException {
+ public void free() {
setLength(0);
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcClob.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcClob.java
index 40e26733a..2939dee1a 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcClob.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcClob.java
@@ -17,6 +17,7 @@
package com.google.cloud.spanner.jdbc;
import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
@@ -61,17 +62,8 @@ private void checkPositionPlusLength(long pos, long length) {
"position+length larger than " + Integer.MAX_VALUE + " is not supported");
}
- private StringBuilder repeat(char c, long length) {
- checkLength(length);
- StringBuilder res = new StringBuilder((int) length);
- for (int i = 0; i < length; i++) {
- res.append(c);
- }
- return res;
- }
-
@Override
- public long length() throws SQLException {
+ public long length() {
return value.length();
}
@@ -92,12 +84,12 @@ public String getSubString(long pos, int length) throws SQLException {
}
@Override
- public Reader getCharacterStream() throws SQLException {
+ public Reader getCharacterStream() {
return new StringReader(value.toString());
}
@Override
- public InputStream getAsciiStream() throws SQLException {
+ public InputStream getAsciiStream() {
return new ByteArrayInputStream(StandardCharsets.US_ASCII.encode(value.toString()).array());
}
@@ -131,10 +123,11 @@ public int setString(long pos, String str) throws SQLException {
JdbcPreconditions.checkArgument(str != null, "str is null");
JdbcPreconditions.checkArgument(pos >= 1, "Position must be >= 1");
checkPosition(pos);
- if ((pos - 1) > length()) {
- value.append(repeat(' ', pos - length() - 1));
+ int ipos = (int) pos;
+ if ((ipos - 1) > value.length()) {
+ value.append(Strings.repeat(" ", ipos - value.length() - 1));
}
- value.replace((int) pos - 1, (int) pos + str.length() - 1, str);
+ value.replace(ipos - 1, ipos + str.length() - 1, str);
return str.length();
}
@@ -191,7 +184,7 @@ public void truncate(long len) throws SQLException {
}
@Override
- public void free() throws SQLException {
+ public void free() {
value = new StringBuilder();
}
@@ -201,8 +194,7 @@ public Reader getCharacterStream(long pos, long length) throws SQLException {
JdbcPreconditions.checkArgument(length >= 0, "length must be >= 0");
checkPosition(pos);
checkPositionPlusLength(pos, length);
- return new StringReader(
- value.substring((int) pos - 1, (int) pos + (int) length - 1).toString());
+ return new StringReader(value.substring((int) pos - 1, (int) pos + (int) length - 1));
}
@Override
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java
index 53c1dc096..9e4623cab 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java
@@ -25,7 +25,6 @@
import com.google.cloud.spanner.connection.ConnectionOptions;
import com.google.cloud.spanner.connection.StatementParser;
import com.google.cloud.spanner.connection.TransactionMode;
-import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import java.sql.Array;
import java.sql.Blob;
@@ -222,7 +221,7 @@ public void close() throws SQLException {
}
@Override
- public boolean isClosed() throws SQLException {
+ public boolean isClosed() {
return getSpannerConnection().isClosed();
}
@@ -594,17 +593,11 @@ public Iterator getTransactionRetryListeners() throws
checkClosed();
return Iterators.transform(
getSpannerConnection().getTransactionRetryListeners(),
- new Function<
- com.google.cloud.spanner.connection.TransactionRetryListener,
- TransactionRetryListener>() {
- @Override
- public TransactionRetryListener apply(
- com.google.cloud.spanner.connection.TransactionRetryListener input) {
- if (input instanceof JdbcToSpannerTransactionRetryListener) {
- return ((JdbcToSpannerTransactionRetryListener) input).delegate;
- }
- return null;
+ input -> {
+ if (input instanceof JdbcToSpannerTransactionRetryListener) {
+ return ((JdbcToSpannerTransactionRetryListener) input).delegate;
}
+ return null;
});
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConstants.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConstants.java
index 58c9e5bb3..164aec0ee 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConstants.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConstants.java
@@ -30,8 +30,9 @@ public final class JdbcConstants {
/**
* Special value that is used to indicate that a statement had no result. The method {@link
* Statement#getUpdateCount()} will return this value if the previous statement that was executed
- * with {@link Statement#execute(String)} returned {@link ResultType#NO_RESULT}, such as DDL
- * statements {@link ResultType}.
+ * with {@link Statement#execute(String)} returned {@link
+ * com.google.cloud.spanner.connection.StatementResult.ResultType#NO_RESULT}, such as DDL
+ * statements.
*/
public static final int STATEMENT_NO_RESULT = -2;
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataSource.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataSource.java
index 72a641cc9..026406e2b 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataSource.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataSource.java
@@ -35,7 +35,7 @@ public class JdbcDataSource extends AbstractJdbcWrapper implements DataSource {
private Boolean readonly;
private Boolean retryAbortsInternally;
- /** Make sure the JDBC driver class is loaded. */
+ // Make sure the JDBC driver class is loaded.
static {
try {
Class.forName("com.google.cloud.spanner.jdbc.JdbcDriver");
@@ -46,22 +46,22 @@ public class JdbcDataSource extends AbstractJdbcWrapper implements DataSource {
}
@Override
- public PrintWriter getLogWriter() throws SQLException {
+ public PrintWriter getLogWriter() {
return null;
}
@Override
- public void setLogWriter(PrintWriter out) throws SQLException {
+ public void setLogWriter(PrintWriter out) {
// no-op
}
@Override
- public void setLoginTimeout(int seconds) throws SQLException {
+ public void setLoginTimeout(int seconds) {
// no-op
}
@Override
- public int getLoginTimeout() throws SQLException {
+ public int getLoginTimeout() {
return 0;
}
@@ -110,7 +110,7 @@ private Properties createProperties() {
}
@Override
- public boolean isClosed() throws SQLException {
+ public boolean isClosed() {
return false;
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
index 8da36e4c4..1a62775b7 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDataType.java
@@ -111,7 +111,7 @@ public Type getSpannerType() {
}
},
FLOAT64 {
- private Set> classes = new HashSet>(Arrays.asList(Float.class, Double.class));
+ private final Set> classes = new HashSet<>(Arrays.asList(Float.class, Double.class));
@Override
public int getSqlType() {
@@ -144,8 +144,8 @@ public Type getSpannerType() {
}
},
INT64 {
- private Set> classes =
- new HashSet>(Arrays.asList(Byte.class, Integer.class, Long.class));
+ private final Set> classes =
+ new HashSet<>(Arrays.asList(Byte.class, Integer.class, Long.class));
@Override
public int getSqlType() {
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
index 191d991ea..42828fb5c 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
@@ -57,12 +57,11 @@ static String readSqlFromFile(String filename) {
String line = scanner.nextLine();
builder.append(line).append("\n");
}
- scanner.close();
}
return builder.toString();
}
- private JdbcConnection connection;
+ private final JdbcConnection connection;
JdbcDatabaseMetaData(JdbcConnection connection) {
this.connection = connection;
@@ -74,22 +73,22 @@ public boolean isClosed() {
}
@Override
- public boolean allProceduresAreCallable() throws SQLException {
+ public boolean allProceduresAreCallable() {
return true;
}
@Override
- public boolean allTablesAreSelectable() throws SQLException {
+ public boolean allTablesAreSelectable() {
return true;
}
@Override
- public String getURL() throws SQLException {
+ public String getURL() {
return connection.getConnectionUrl();
}
@Override
- public String getUserName() throws SQLException {
+ public String getUserName() {
Credentials credentials = connection.getConnectionOptions().getCredentials();
if (credentials != null) {
if (credentials instanceof ServiceAccountSigner) {
@@ -102,47 +101,47 @@ public String getUserName() throws SQLException {
}
@Override
- public boolean isReadOnly() throws SQLException {
+ public boolean isReadOnly() {
return false;
}
@Override
- public boolean nullsAreSortedHigh() throws SQLException {
+ public boolean nullsAreSortedHigh() {
return false;
}
@Override
- public boolean nullsAreSortedLow() throws SQLException {
+ public boolean nullsAreSortedLow() {
return true;
}
@Override
- public boolean nullsAreSortedAtStart() throws SQLException {
+ public boolean nullsAreSortedAtStart() {
return false;
}
@Override
- public boolean nullsAreSortedAtEnd() throws SQLException {
+ public boolean nullsAreSortedAtEnd() {
return false;
}
@Override
- public String getDatabaseProductName() throws SQLException {
+ public String getDatabaseProductName() {
return PRODUCT_NAME;
}
@Override
- public String getDatabaseProductVersion() throws SQLException {
+ public String getDatabaseProductVersion() {
return getDatabaseMajorVersion() + "." + getDatabaseMinorVersion();
}
@Override
- public String getDriverName() throws SQLException {
+ public String getDriverName() {
return JdbcDriver.class.getName();
}
@Override
- public String getDriverVersion() throws SQLException {
+ public String getDriverVersion() {
return getDriverMajorVersion() + "." + getDriverMinorVersion();
}
@@ -157,528 +156,530 @@ public int getDriverMinorVersion() {
}
@Override
- public boolean usesLocalFiles() throws SQLException {
+ public boolean usesLocalFiles() {
return false;
}
@Override
- public boolean usesLocalFilePerTable() throws SQLException {
+ public boolean usesLocalFilePerTable() {
return false;
}
@Override
- public boolean supportsMixedCaseIdentifiers() throws SQLException {
+ public boolean supportsMixedCaseIdentifiers() {
return false;
}
@Override
- public boolean storesUpperCaseIdentifiers() throws SQLException {
+ public boolean storesUpperCaseIdentifiers() {
return false;
}
@Override
- public boolean storesLowerCaseIdentifiers() throws SQLException {
+ public boolean storesLowerCaseIdentifiers() {
return false;
}
@Override
- public boolean storesMixedCaseIdentifiers() throws SQLException {
+ public boolean storesMixedCaseIdentifiers() {
return true;
}
@Override
- public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
+ public boolean supportsMixedCaseQuotedIdentifiers() {
return false;
}
@Override
- public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
+ public boolean storesUpperCaseQuotedIdentifiers() {
return false;
}
@Override
- public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
+ public boolean storesLowerCaseQuotedIdentifiers() {
return false;
}
@Override
- public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
+ public boolean storesMixedCaseQuotedIdentifiers() {
return true;
}
@Override
- public String getIdentifierQuoteString() throws SQLException {
+ public String getIdentifierQuoteString() {
return "`";
}
@Override
- public String getSQLKeywords() throws SQLException {
+ public String getSQLKeywords() {
return "ASSERT_ROWS_MODIFIED,ENUM,GROUPS,HASH,IGNORE,LOOKUP,PROTO,RESPECT,STRUCT,WINDOW";
}
@Override
- public String getNumericFunctions() throws SQLException {
+ public String getNumericFunctions() {
return "ABS,SIGN,IS_INF,IS_NAN,IEEE_DIVIDE,SQRT,POW,POWER,EXP,LN,LOG,LOG10,GREATEST,LEAST,DIV,MOD,ROUND,TRUNC,CEIL,CEILING,FLOOR,COS,COSH,ACOS,ACOSH,SIN,SINH,ASIN,ASINH,TAN,TANH,ATAN,ATANH,ATAN2,FARM_FINGERPRINT,SHA1,SHA256,SHA512";
}
@Override
- public String getStringFunctions() throws SQLException {
+ public String getStringFunctions() {
return "BYTE_LENGTH,CHAR_LENGTH,CHARACTER_LENGTH,CODE_POINTS_TO_BYTES,CODE_POINTS_TO_STRING,CONCAT,ENDS_WITH,FORMAT,FROM_BASE64,FROM_HEX,LENGTH,LPAD,LOWER,LTRIM,REGEXP_CONTAINS,REGEXP_EXTRACT,REGEXP_EXTRACT_ALL,REGEXP_REPLACE,REPLACE,REPEAT,REVERSE,RPAD,RTRIM,SAFE_CONVERT_BYTES_TO_STRING,SPLIT,STARTS_WITH,STRPOS,SUBSTR,TO_BASE64,TO_CODE_POINTS,TO_HEX,TRIM,UPPER,JSON_QUERY,JSON_VALUE";
}
@Override
- public String getSystemFunctions() throws SQLException {
+ public String getSystemFunctions() {
return "";
}
@Override
- public String getTimeDateFunctions() throws SQLException {
+ public String getTimeDateFunctions() {
return "CURRENT_DATE,EXTRACT,DATE,DATE_ADD,DATE_SUB,DATE_DIFF,DATE_TRUNC,DATE_FROM_UNIX_DATE,FORMAT_DATE,PARSE_DATE,UNIX_DATE,CURRENT_TIMESTAMP,STRING,TIMESTAMP,TIMESTAMP_ADD,TIMESTAMP_SUB,TIMESTAMP_DIFF,TIMESTAMP_TRUNC,FORMAT_TIMESTAMP,PARSE_TIMESTAMP,TIMESTAMP_SECONDS,TIMESTAMP_MILLIS,TIMESTAMP_MICROS,UNIX_SECONDS,UNIX_MILLIS,UNIX_MICROS";
}
@Override
- public String getSearchStringEscape() throws SQLException {
+ public String getSearchStringEscape() {
return "\\";
}
@Override
- public String getExtraNameCharacters() throws SQLException {
+ public String getExtraNameCharacters() {
return "";
}
@Override
- public boolean supportsAlterTableWithAddColumn() throws SQLException {
+ public boolean supportsAlterTableWithAddColumn() {
return true;
}
@Override
- public boolean supportsAlterTableWithDropColumn() throws SQLException {
+ public boolean supportsAlterTableWithDropColumn() {
return true;
}
@Override
- public boolean supportsColumnAliasing() throws SQLException {
+ public boolean supportsColumnAliasing() {
return true;
}
@Override
- public boolean nullPlusNonNullIsNull() throws SQLException {
+ public boolean nullPlusNonNullIsNull() {
return true;
}
@Override
- public boolean supportsConvert() throws SQLException {
+ public boolean supportsConvert() {
return false;
}
@Override
- public boolean supportsConvert(int fromType, int toType) throws SQLException {
+ public boolean supportsConvert(int fromType, int toType) {
return false;
}
@Override
- public boolean supportsTableCorrelationNames() throws SQLException {
+ public boolean supportsTableCorrelationNames() {
return true;
}
@Override
- public boolean supportsDifferentTableCorrelationNames() throws SQLException {
+ public boolean supportsDifferentTableCorrelationNames() {
return false;
}
@Override
- public boolean supportsExpressionsInOrderBy() throws SQLException {
+ public boolean supportsExpressionsInOrderBy() {
return true;
}
@Override
- public boolean supportsOrderByUnrelated() throws SQLException {
+ public boolean supportsOrderByUnrelated() {
return true;
}
@Override
- public boolean supportsGroupBy() throws SQLException {
+ public boolean supportsGroupBy() {
return true;
}
@Override
- public boolean supportsGroupByUnrelated() throws SQLException {
+ public boolean supportsGroupByUnrelated() {
return true;
}
@Override
- public boolean supportsGroupByBeyondSelect() throws SQLException {
+ public boolean supportsGroupByBeyondSelect() {
return true;
}
@Override
- public boolean supportsLikeEscapeClause() throws SQLException {
+ public boolean supportsLikeEscapeClause() {
return true;
}
@Override
- public boolean supportsMultipleResultSets() throws SQLException {
+ public boolean supportsMultipleResultSets() {
return true;
}
@Override
- public boolean supportsMultipleTransactions() throws SQLException {
+ public boolean supportsMultipleTransactions() {
return true;
}
@Override
- public boolean supportsNonNullableColumns() throws SQLException {
+ public boolean supportsNonNullableColumns() {
return true;
}
@Override
- public boolean supportsMinimumSQLGrammar() throws SQLException {
+ public boolean supportsMinimumSQLGrammar() {
return false;
}
@Override
- public boolean supportsCoreSQLGrammar() throws SQLException {
+ public boolean supportsCoreSQLGrammar() {
return false;
}
@Override
- public boolean supportsExtendedSQLGrammar() throws SQLException {
+ public boolean supportsExtendedSQLGrammar() {
return false;
}
@Override
- public boolean supportsANSI92EntryLevelSQL() throws SQLException {
+ public boolean supportsANSI92EntryLevelSQL() {
return false;
}
@Override
- public boolean supportsANSI92IntermediateSQL() throws SQLException {
+ public boolean supportsANSI92IntermediateSQL() {
return false;
}
@Override
- public boolean supportsANSI92FullSQL() throws SQLException {
+ public boolean supportsANSI92FullSQL() {
return false;
}
@Override
- public boolean supportsIntegrityEnhancementFacility() throws SQLException {
+ public boolean supportsIntegrityEnhancementFacility() {
return false;
}
@Override
- public boolean supportsOuterJoins() throws SQLException {
+ public boolean supportsOuterJoins() {
return true;
}
@Override
- public boolean supportsFullOuterJoins() throws SQLException {
+ public boolean supportsFullOuterJoins() {
return true;
}
@Override
- public boolean supportsLimitedOuterJoins() throws SQLException {
+ public boolean supportsLimitedOuterJoins() {
return true;
}
@Override
- public String getSchemaTerm() throws SQLException {
+ public String getSchemaTerm() {
return "SCHEMA";
}
@Override
- public String getProcedureTerm() throws SQLException {
+ public String getProcedureTerm() {
return "PROCEDURE";
}
@Override
- public String getCatalogTerm() throws SQLException {
+ public String getCatalogTerm() {
// Spanner does not support catalogs, but the term is included for compatibility with the SQL
// standard
return "CATALOG";
}
@Override
- public boolean isCatalogAtStart() throws SQLException {
+ public boolean isCatalogAtStart() {
return false;
}
@Override
- public String getCatalogSeparator() throws SQLException {
+ public String getCatalogSeparator() {
return ".";
}
@Override
- public boolean supportsSchemasInDataManipulation() throws SQLException {
+ public boolean supportsSchemasInDataManipulation() {
return false;
}
@Override
- public boolean supportsSchemasInProcedureCalls() throws SQLException {
+ public boolean supportsSchemasInProcedureCalls() {
return false;
}
@Override
- public boolean supportsSchemasInTableDefinitions() throws SQLException {
+ public boolean supportsSchemasInTableDefinitions() {
return false;
}
@Override
- public boolean supportsSchemasInIndexDefinitions() throws SQLException {
+ public boolean supportsSchemasInIndexDefinitions() {
return false;
}
@Override
- public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
+ public boolean supportsSchemasInPrivilegeDefinitions() {
return false;
}
@Override
- public boolean supportsCatalogsInDataManipulation() throws SQLException {
+ public boolean supportsCatalogsInDataManipulation() {
return false;
}
@Override
- public boolean supportsCatalogsInProcedureCalls() throws SQLException {
+ public boolean supportsCatalogsInProcedureCalls() {
return false;
}
@Override
- public boolean supportsCatalogsInTableDefinitions() throws SQLException {
+ public boolean supportsCatalogsInTableDefinitions() {
return false;
}
@Override
- public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
+ public boolean supportsCatalogsInIndexDefinitions() {
return false;
}
@Override
- public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
+ public boolean supportsCatalogsInPrivilegeDefinitions() {
return false;
}
@Override
- public boolean supportsPositionedDelete() throws SQLException {
+ public boolean supportsPositionedDelete() {
return false;
}
@Override
- public boolean supportsPositionedUpdate() throws SQLException {
+ public boolean supportsPositionedUpdate() {
return false;
}
@Override
- public boolean supportsSelectForUpdate() throws SQLException {
+ public boolean supportsSelectForUpdate() {
return false;
}
@Override
- public boolean supportsStoredProcedures() throws SQLException {
+ public boolean supportsStoredProcedures() {
return false;
}
@Override
- public boolean supportsSubqueriesInComparisons() throws SQLException {
+ public boolean supportsSubqueriesInComparisons() {
return true;
}
@Override
- public boolean supportsSubqueriesInExists() throws SQLException {
+ public boolean supportsSubqueriesInExists() {
return true;
}
@Override
- public boolean supportsSubqueriesInIns() throws SQLException {
+ public boolean supportsSubqueriesInIns() {
return true;
}
@Override
- public boolean supportsSubqueriesInQuantifieds() throws SQLException {
+ public boolean supportsSubqueriesInQuantifieds() {
return true;
}
@Override
- public boolean supportsCorrelatedSubqueries() throws SQLException {
+ public boolean supportsCorrelatedSubqueries() {
return true;
}
@Override
- public boolean supportsUnion() throws SQLException {
+ public boolean supportsUnion() {
// Note that Cloud Spanner requires the user to specify 'UNION DISTINCT' or 'UNION ALL' in a
// query. 'UNION DISTINCT' is equal to the SQL operation 'UNION'.
return true;
}
@Override
- public boolean supportsUnionAll() throws SQLException {
+ public boolean supportsUnionAll() {
return true;
}
@Override
- public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
+ public boolean supportsOpenCursorsAcrossCommit() {
return false;
}
@Override
- public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
+ public boolean supportsOpenCursorsAcrossRollback() {
return false;
}
@Override
- public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
+ public boolean supportsOpenStatementsAcrossCommit() {
return true;
}
@Override
- public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
+ public boolean supportsOpenStatementsAcrossRollback() {
return true;
}
@Override
- public int getMaxBinaryLiteralLength() throws SQLException {
+ public int getMaxBinaryLiteralLength() {
return 0;
}
@Override
- public int getMaxCharLiteralLength() throws SQLException {
+ public int getMaxCharLiteralLength() {
return 0;
}
@Override
- public int getMaxColumnNameLength() throws SQLException {
+ public int getMaxColumnNameLength() {
return 128;
}
@Override
- public int getMaxColumnsInGroupBy() throws SQLException {
+ public int getMaxColumnsInGroupBy() {
return 1000;
}
@Override
- public int getMaxColumnsInIndex() throws SQLException {
+ public int getMaxColumnsInIndex() {
return 16;
}
@Override
- public int getMaxColumnsInOrderBy() throws SQLException {
+ public int getMaxColumnsInOrderBy() {
return 0;
}
@Override
- public int getMaxColumnsInSelect() throws SQLException {
+ public int getMaxColumnsInSelect() {
return 0;
}
@Override
- public int getMaxColumnsInTable() throws SQLException {
+ public int getMaxColumnsInTable() {
return 1024;
}
@Override
- public int getMaxConnections() throws SQLException {
+ public int getMaxConnections() {
// there is a max number of sessions, but that is not the same as the max number of connections
return 0;
}
@Override
- public int getMaxCursorNameLength() throws SQLException {
+ public int getMaxCursorNameLength() {
return 0;
}
@Override
- public int getMaxIndexLength() throws SQLException {
+ public int getMaxIndexLength() {
return 8000;
}
@Override
- public int getMaxSchemaNameLength() throws SQLException {
+ public int getMaxSchemaNameLength() {
return 0;
}
@Override
- public int getMaxProcedureNameLength() throws SQLException {
+ public int getMaxProcedureNameLength() {
return 0;
}
@Override
- public int getMaxCatalogNameLength() throws SQLException {
+ public int getMaxCatalogNameLength() {
return 0;
}
@Override
- public int getMaxRowSize() throws SQLException {
- return 1024 * 10000000;
+ public int getMaxRowSize() {
+ // The limit is 1024 columns per table * 10MB per column, which is more than fits in an int.
+ // We therefore return 0 to indicate no limit (or an unknown limit).
+ return 0;
}
@Override
- public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
+ public boolean doesMaxRowSizeIncludeBlobs() {
return true;
}
@Override
- public int getMaxStatementLength() throws SQLException {
+ public int getMaxStatementLength() {
return 1000000;
}
@Override
- public int getMaxStatements() throws SQLException {
+ public int getMaxStatements() {
return 0;
}
@Override
- public int getMaxTableNameLength() throws SQLException {
+ public int getMaxTableNameLength() {
return 128;
}
@Override
- public int getMaxTablesInSelect() throws SQLException {
+ public int getMaxTablesInSelect() {
return 0;
}
@Override
- public int getMaxUserNameLength() throws SQLException {
+ public int getMaxUserNameLength() {
return 0;
}
@Override
- public int getDefaultTransactionIsolation() throws SQLException {
+ public int getDefaultTransactionIsolation() {
return Connection.TRANSACTION_SERIALIZABLE;
}
@Override
- public boolean supportsTransactions() throws SQLException {
+ public boolean supportsTransactions() {
return true;
}
@Override
- public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
+ public boolean supportsTransactionIsolationLevel(int level) {
return Connection.TRANSACTION_SERIALIZABLE == level;
}
@Override
- public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
+ public boolean supportsDataDefinitionAndDataManipulationTransactions() {
return false;
}
@Override
- public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
+ public boolean supportsDataManipulationTransactionsOnly() {
return true;
}
@Override
- public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
+ public boolean dataDefinitionCausesTransactionCommit() {
return false;
}
@Override
- public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
+ public boolean dataDefinitionIgnoredInTransactions() {
return false;
}
@Override
- public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
- throws SQLException {
+ public ResultSet getProcedures(
+ String catalog, String schemaPattern, String procedureNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -691,13 +692,12 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
StructField.of("REMARKS", Type.string()),
StructField.of("PROCEDURE_TYPE", Type.int64()),
StructField.of("SPECIFIC_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
public ResultSet getProcedureColumns(
- String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern)
- throws SQLException {
+ String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -721,7 +721,7 @@ public ResultSet getProcedureColumns(
StructField.of("ORDINAL_POSITION", Type.int64()),
StructField.of("IS_NULLABLE", Type.string()),
StructField.of("SPECIFIC_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
private JdbcPreparedStatement prepareStatementReplaceNullWithAnyString(
@@ -768,15 +768,15 @@ public ResultSet getSchemas() throws SQLException {
}
@Override
- public ResultSet getCatalogs() throws SQLException {
+ public ResultSet getCatalogs() {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(StructField.of("TABLE_CAT", Type.string())),
- Arrays.asList(Struct.newBuilder().set("TABLE_CAT").to("").build())));
+ Collections.singletonList(Struct.newBuilder().set("TABLE_CAT").to("").build())));
}
@Override
- public ResultSet getTableTypes() throws SQLException {
+ public ResultSet getTableTypes() {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(StructField.of("TABLE_TYPE", Type.string())),
@@ -798,7 +798,7 @@ public ResultSet getColumns(
@Override
public ResultSet getColumnPrivileges(
- String catalog, String schema, String table, String columnNamePattern) throws SQLException {
+ String catalog, String schema, String table, String columnNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -810,12 +810,12 @@ public ResultSet getColumnPrivileges(
StructField.of("GRANTEE", Type.string()),
StructField.of("PRIVILEGE", Type.string()),
StructField.of("IS_GRANTABLE", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
- public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern)
- throws SQLException {
+ public ResultSet getTablePrivileges(
+ String catalog, String schemaPattern, String tableNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -826,30 +826,21 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String
StructField.of("GRANTEE", Type.string()),
StructField.of("PRIVILEGE", Type.string()),
StructField.of("IS_GRANTABLE", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
public ResultSet getBestRowIdentifier(
- String catalog, String schema, String table, int scope, boolean nullable)
- throws SQLException {
- return JdbcResultSet.of(
- ResultSets.forRows(
- Type.struct(
- StructField.of("SCOPE", Type.int64()),
- StructField.of("COLUMN_NAME", Type.string()),
- StructField.of("DATA_TYPE", Type.int64()),
- StructField.of("TYPE_NAME", Type.string()),
- StructField.of("COLUMN_SIZE", Type.int64()),
- StructField.of("BUFFER_LENGTH", Type.int64()),
- StructField.of("DECIMAL_DIGITS", Type.int64()),
- StructField.of("PSEUDO_COLUMN", Type.int64())),
- Collections.emptyList()));
+ String catalog, String schema, String table, int scope, boolean nullable) {
+ return getEmptyColumnsResultSet();
}
@Override
- public ResultSet getVersionColumns(String catalog, String schema, String table)
- throws SQLException {
+ public ResultSet getVersionColumns(String catalog, String schema, String table) {
+ return getEmptyColumnsResultSet();
+ }
+
+ private ResultSet getEmptyColumnsResultSet() {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -861,7 +852,7 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
StructField.of("BUFFER_LENGTH", Type.int64()),
StructField.of("DECIMAL_DIGITS", Type.int64()),
StructField.of("PSEUDO_COLUMN", Type.int64())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
@@ -916,7 +907,7 @@ public ResultSet getCrossReference(
}
@Override
- public ResultSet getTypeInfo() throws SQLException {
+ public ResultSet getTypeInfo() {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1268,69 +1259,68 @@ private ResultSet getIndexInfo(
}
@Override
- public boolean supportsResultSetType(int type) throws SQLException {
+ public boolean supportsResultSetType(int type) {
return type == ResultSet.TYPE_FORWARD_ONLY;
}
@Override
- public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
+ public boolean supportsResultSetConcurrency(int type, int concurrency) {
return type == ResultSet.TYPE_FORWARD_ONLY && concurrency == ResultSet.CONCUR_READ_ONLY;
}
@Override
- public boolean ownUpdatesAreVisible(int type) throws SQLException {
+ public boolean ownUpdatesAreVisible(int type) {
return false;
}
@Override
- public boolean ownDeletesAreVisible(int type) throws SQLException {
+ public boolean ownDeletesAreVisible(int type) {
return false;
}
@Override
- public boolean ownInsertsAreVisible(int type) throws SQLException {
+ public boolean ownInsertsAreVisible(int type) {
return false;
}
@Override
- public boolean othersUpdatesAreVisible(int type) throws SQLException {
+ public boolean othersUpdatesAreVisible(int type) {
return false;
}
@Override
- public boolean othersDeletesAreVisible(int type) throws SQLException {
+ public boolean othersDeletesAreVisible(int type) {
return false;
}
@Override
- public boolean othersInsertsAreVisible(int type) throws SQLException {
+ public boolean othersInsertsAreVisible(int type) {
return false;
}
@Override
- public boolean updatesAreDetected(int type) throws SQLException {
+ public boolean updatesAreDetected(int type) {
return false;
}
@Override
- public boolean deletesAreDetected(int type) throws SQLException {
+ public boolean deletesAreDetected(int type) {
return false;
}
@Override
- public boolean insertsAreDetected(int type) throws SQLException {
+ public boolean insertsAreDetected(int type) {
return false;
}
@Override
- public boolean supportsBatchUpdates() throws SQLException {
+ public boolean supportsBatchUpdates() {
return true;
}
@Override
public ResultSet getUDTs(
- String catalog, String schemaPattern, String typeNamePattern, int[] types)
- throws SQLException {
+ String catalog, String schemaPattern, String typeNamePattern, int[] types) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1341,37 +1331,36 @@ public ResultSet getUDTs(
StructField.of("DATA_TYPE", Type.int64()),
StructField.of("REMARKS", Type.string()),
StructField.of("BASE_TYPE", Type.int64())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
- public Connection getConnection() throws SQLException {
+ public Connection getConnection() {
return connection;
}
@Override
- public boolean supportsSavepoints() throws SQLException {
+ public boolean supportsSavepoints() {
return false;
}
@Override
- public boolean supportsNamedParameters() throws SQLException {
+ public boolean supportsNamedParameters() {
return false;
}
@Override
- public boolean supportsMultipleOpenResults() throws SQLException {
+ public boolean supportsMultipleOpenResults() {
return true;
}
@Override
- public boolean supportsGetGeneratedKeys() throws SQLException {
+ public boolean supportsGetGeneratedKeys() {
return false;
}
@Override
- public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern)
- throws SQLException {
+ public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1381,12 +1370,11 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
StructField.of("SUPERTYPE_CAT", Type.string()),
StructField.of("SUPERTYPE_SCHEM", Type.string()),
StructField.of("SUPERTYPE_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
- public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern)
- throws SQLException {
+ public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1394,13 +1382,12 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
StructField.of("TABLE_SCHEM", Type.string()),
StructField.of("TABLE_NAME", Type.string()),
StructField.of("SUPERTABLE_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
public ResultSet getAttributes(
- String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern)
- throws SQLException {
+ String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1425,56 +1412,56 @@ public ResultSet getAttributes(
StructField.of("SCOPE_SCHEMA", Type.string()),
StructField.of("SCOPE_TABLE", Type.string()),
StructField.of("SOURCE_DATA_TYPE", Type.int64())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
- public boolean supportsResultSetHoldability(int holdability) throws SQLException {
+ public boolean supportsResultSetHoldability(int holdability) {
return holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
@Override
- public int getResultSetHoldability() throws SQLException {
+ public int getResultSetHoldability() {
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
@Override
- public int getDatabaseMajorVersion() throws SQLException {
+ public int getDatabaseMajorVersion() {
return DATABASE_MAJOR_VERSION;
}
@Override
- public int getDatabaseMinorVersion() throws SQLException {
+ public int getDatabaseMinorVersion() {
return DATABASE_MINOR_VERSION;
}
@Override
- public int getJDBCMajorVersion() throws SQLException {
+ public int getJDBCMajorVersion() {
return JDBC_MAJOR_VERSION;
}
@Override
- public int getJDBCMinorVersion() throws SQLException {
+ public int getJDBCMinorVersion() {
return JDBC_MINOR_VERSION;
}
@Override
- public int getSQLStateType() throws SQLException {
+ public int getSQLStateType() {
return sqlStateSQL;
}
@Override
- public boolean locatorsUpdateCopy() throws SQLException {
+ public boolean locatorsUpdateCopy() {
return true;
}
@Override
- public boolean supportsStatementPooling() throws SQLException {
+ public boolean supportsStatementPooling() {
return false;
}
@Override
- public RowIdLifetime getRowIdLifetime() throws SQLException {
+ public RowIdLifetime getRowIdLifetime() {
return RowIdLifetime.ROWID_UNSUPPORTED;
}
@@ -1487,12 +1474,12 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
}
@Override
- public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
+ public boolean supportsStoredFunctionsUsingCallSyntax() {
return false;
}
@Override
- public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
+ public boolean autoCommitFailureClosesAllResultSets() {
return false;
}
@@ -1511,7 +1498,7 @@ static Properties getDefaultClientInfoProperties() throws SQLException {
return info;
}
- private static ResultSet getDefaultClientInfo() throws SQLException {
+ private static ResultSet getDefaultClientInfo() {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1556,13 +1543,12 @@ private static ResultSet getDefaultClientInfo() throws SQLException {
}
@Override
- public ResultSet getClientInfoProperties() throws SQLException {
+ public ResultSet getClientInfoProperties() {
return getDefaultClientInfo();
}
@Override
- public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern)
- throws SQLException {
+ public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) {
// TODO: return system functions
return JdbcResultSet.of(
ResultSets.forRows(
@@ -1573,13 +1559,12 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
StructField.of("REMARKS", Type.string()),
StructField.of("FUNCTION_TYPE", Type.int64()),
StructField.of("SPECIFIC_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
public ResultSet getFunctionColumns(
- String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern)
- throws SQLException {
+ String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) {
// TODO: return system functions
return JdbcResultSet.of(
ResultSets.forRows(
@@ -1601,13 +1586,12 @@ public ResultSet getFunctionColumns(
StructField.of("ORDINAL_POSITION", Type.int64()),
StructField.of("IS_NULLABLE", Type.string()),
StructField.of("SPECIFIC_NAME", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
public ResultSet getPseudoColumns(
- String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
- throws SQLException {
+ String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
@@ -1623,22 +1607,22 @@ public ResultSet getPseudoColumns(
StructField.of("REMARKS", Type.string()),
StructField.of("CHAR_OCTET_LENGTH", Type.int64()),
StructField.of("IS_NULLABLE", Type.string())),
- Collections.emptyList()));
+ Collections.emptyList()));
}
@Override
- public boolean generatedKeyAlwaysReturned() throws SQLException {
+ public boolean generatedKeyAlwaysReturned() {
return false;
}
@Override
- public long getMaxLogicalLobSize() throws SQLException {
+ public long getMaxLogicalLobSize() {
// BYTES(MAX)
return 10485760L;
}
@Override
- public boolean supportsRefCursors() throws SQLException {
+ public boolean supportsRefCursors() {
return false;
}
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
index 08dd5fafe..b127e6825 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
@@ -220,12 +220,12 @@ private String appendPropertiesToUrl(String url, Properties info) {
}
@Override
- public boolean acceptsURL(String url) throws SQLException {
+ public boolean acceptsURL(String url) {
return URL_PATTERN.matcher(url).matches();
}
@Override
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
String connectionUri = appendPropertiesToUrl(url.substring(5), info);
DriverPropertyInfo[] res = new DriverPropertyInfo[ConnectionOptions.VALID_PROPERTIES.size()];
int i = 0;
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterMetaData.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterMetaData.java
index 59b10b68f..f5188653b 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterMetaData.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterMetaData.java
@@ -40,19 +40,20 @@ public boolean isClosed() {
}
@Override
- public int getParameterCount() throws SQLException {
+ public int getParameterCount() {
ParametersInfo info = statement.getParametersInfo();
return info.numberOfParameters;
}
@Override
- public int isNullable(int param) throws SQLException {
+ public int isNullable(int param) {
Integer nullable = statement.getParameters().getNullable(param);
- return nullable == null ? parameterNullableUnknown : nullable.intValue();
+ //noinspection MagicConstant
+ return nullable == null ? parameterNullableUnknown : nullable;
}
@Override
- public boolean isSigned(int param) throws SQLException {
+ public boolean isSigned(int param) {
int type = getParameterType(param);
return type == Types.DOUBLE
|| type == Types.FLOAT
@@ -65,20 +66,20 @@ public boolean isSigned(int param) throws SQLException {
}
@Override
- public int getPrecision(int param) throws SQLException {
+ public int getPrecision(int param) {
Integer length = statement.getParameters().getScaleOrLength(param);
- return length == null ? 0 : length.intValue();
+ return length == null ? 0 : length;
}
@Override
- public int getScale(int param) throws SQLException {
+ public int getScale(int param) {
return 0;
}
@Override
- public int getParameterType(int param) throws SQLException {
+ public int getParameterType(int param) {
Integer type = statement.getParameters().getType(param);
- if (type != null) return type.intValue();
+ if (type != null) return type;
Object value = statement.getParameters().getParameter(param);
if (value == null) {
@@ -115,45 +116,41 @@ public int getParameterType(int param) throws SQLException {
}
@Override
- public String getParameterTypeName(int param) throws SQLException {
+ public String getParameterTypeName(int param) {
return getSpannerTypeName(getParameterType(param));
}
@Override
- public String getParameterClassName(int param) throws SQLException {
+ public String getParameterClassName(int param) {
Object value = statement.getParameters().getParameter(param);
if (value != null) return value.getClass().getName();
Integer type = statement.getParameters().getType(param);
- if (type != null) return getClassName(type.intValue());
+ if (type != null) return getClassName(type);
return null;
}
@Override
- public int getParameterMode(int param) throws SQLException {
+ public int getParameterMode(int param) {
return parameterModeIn;
}
@Override
public String toString() {
StringBuilder res = new StringBuilder();
- try {
- res.append("CloudSpannerPreparedStatementParameterMetaData, parameter count: ")
- .append(getParameterCount());
- for (int param = 1; param <= getParameterCount(); param++) {
- res.append("\nParameter ")
- .append(param)
- .append(":\n\t Class name: ")
- .append(getParameterClassName(param));
- res.append(",\n\t Parameter type name: ").append(getParameterTypeName(param));
- res.append(",\n\t Parameter type: ").append(getParameterType(param));
- res.append(",\n\t Parameter precision: ").append(getPrecision(param));
- res.append(",\n\t Parameter scale: ").append(getScale(param));
- res.append(",\n\t Parameter signed: ").append(isSigned(param));
- res.append(",\n\t Parameter nullable: ").append(isNullable(param));
- res.append(",\n\t Parameter mode: ").append(getParameterMode(param));
- }
- } catch (SQLException e) {
- res.append("Error while fetching parameter metadata: ").append(e.getMessage());
+ res.append("CloudSpannerPreparedStatementParameterMetaData, parameter count: ")
+ .append(getParameterCount());
+ for (int param = 1; param <= getParameterCount(); param++) {
+ res.append("\nParameter ")
+ .append(param)
+ .append(":\n\t Class name: ")
+ .append(getParameterClassName(param));
+ res.append(",\n\t Parameter type name: ").append(getParameterTypeName(param));
+ res.append(",\n\t Parameter type: ").append(getParameterType(param));
+ res.append(",\n\t Parameter precision: ").append(getPrecision(param));
+ res.append(",\n\t Parameter scale: ").append(getScale(param));
+ res.append(",\n\t Parameter signed: ").append(isSigned(param));
+ res.append(",\n\t Parameter nullable: ").append(isNullable(param));
+ res.append(",\n\t Parameter mode: ").append(getParameterMode(param));
}
return res.toString();
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterStore.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterStore.java
index 24773cdce..a475646a6 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterStore.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcParameterStore.java
@@ -420,15 +420,13 @@ static ParametersInfo convertPositionalParametersToNamedParameters(String sql)
isInQuoted = false;
startQuote = 0;
}
- } else if (c == '\\') {
- lastCharWasEscapeChar = true;
} else {
- lastCharWasEscapeChar = false;
+ lastCharWasEscapeChar = (c == '\\');
}
named.append(c);
} else {
if (c == POS_PARAM) {
- named.append("@p" + paramIndex);
+ named.append("@p").append(paramIndex);
paramIndex++;
} else {
if (c == SINGLE_QUOTE || c == DOUBLE_QUOTE || c == BACKTICK_QUOTE) {
@@ -487,7 +485,7 @@ Builder setValue(ValueBinder binder, Object value, Integer sqlType) thr
}
if (res == null && value != null) {
throw JdbcSqlExceptionFactory.of(
- "Unsupported parameter type: " + value.getClass().getName() + " - " + value.toString(),
+ "Unsupported parameter type: " + value.getClass().getName() + " - " + value,
Code.INVALID_ARGUMENT);
}
return res;
@@ -497,7 +495,7 @@ private Builder setSingleValue(ValueBinder binder, Object value, Intege
throws SQLException {
if (value == null) {
return setNullValue(binder, sqlType);
- } else if (sqlType == null || sqlType == Integer.valueOf(Types.OTHER)) {
+ } else if (sqlType == null || sqlType.equals(Types.OTHER)) {
return setParamWithUnknownType(binder, value);
} else {
return setParamWithKnownType(binder, value, sqlType);
@@ -559,7 +557,7 @@ private Builder setParamWithKnownType(ValueBinder binder, Object value,
} else if (value instanceof Reader) {
stringValue = getStringFromReader((Reader) value);
} else if (value instanceof URL) {
- stringValue = ((URL) value).toString();
+ stringValue = value.toString();
} else if (value instanceof UUID) {
stringValue = ((UUID) value).toString();
} else {
@@ -621,7 +619,7 @@ private Builder setParamWithKnownType(ValueBinder binder, Object value,
case Types.ARRAY:
if (value instanceof Array) {
Array jdbcArray = (Array) value;
- return setArrayValue(binder, sqlType, jdbcArray == null ? null : jdbcArray.getArray());
+ return setArrayValue(binder, sqlType, jdbcArray.getArray());
}
throw JdbcSqlExceptionFactory.of(value + " is not a valid array", Code.INVALID_ARGUMENT);
case Types.BLOB:
@@ -719,8 +717,7 @@ private Builder setParamWithUnknownType(ValueBinder binder, Object valu
} catch (IOException e) {
throw new IllegalArgumentException("Could not read from readable", e);
}
- } else if (Clob.class.isAssignableFrom(value.getClass())
- || NClob.class.isAssignableFrom(value.getClass())) {
+ } else if (Clob.class.isAssignableFrom(value.getClass())) {
try {
Clob clob = (Clob) value;
return binder.to(CharStreams.toString(clob.getCharacterStream()));
@@ -739,7 +736,7 @@ private Builder setParamWithUnknownType(ValueBinder binder, Object valu
} else if (char[].class.isAssignableFrom(value.getClass())) {
return binder.to(String.valueOf((char[]) value));
} else if (URL.class.isAssignableFrom(value.getClass())) {
- return binder.to(((URL) value).toString());
+ return binder.to(value.toString());
} else if (UUID.class.isAssignableFrom(value.getClass())) {
return binder.to(((UUID) value).toString());
} else if (byte[].class.isAssignableFrom(value.getClass())) {
@@ -761,12 +758,10 @@ private Builder setParamWithUnknownType(ValueBinder binder, Object valu
} else if (Array.class.isAssignableFrom(value.getClass())) {
try {
Array jdbcArray = (Array) value;
- if (value != null) {
- return setArrayValue(binder, jdbcArray.getBaseType(), jdbcArray.getArray());
- }
+ return setArrayValue(binder, jdbcArray.getBaseType(), jdbcArray.getArray());
} catch (SQLException e) {
throw new IllegalArgumentException(
- "Unsupported parameter type: " + value.getClass().getName() + " - " + value.toString());
+ "Unsupported parameter type: " + value.getClass().getName() + " - " + value);
}
}
return null;
@@ -813,7 +808,7 @@ private Builder setArrayValue(ValueBinder binder, int type, Object valu
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
- return binder.toBytesArray((Iterable) null);
+ return binder.toBytesArray(null);
}
throw JdbcSqlExceptionFactory.unsupported("Unknown/unsupported array base type: " + type);
}
@@ -874,16 +869,16 @@ private Builder setArrayValue(ValueBinder binder, int type, Object valu
private List toLongList(Number[] input) {
List res = new ArrayList<>(input.length);
- for (int i = 0; i < input.length; i++) {
- res.add(input[i] == null ? null : input[i].longValue());
+ for (Number number : input) {
+ res.add(number == null ? null : number.longValue());
}
return res;
}
private List toDoubleList(Number[] input) {
List res = new ArrayList<>(input.length);
- for (int i = 0; i < input.length; i++) {
- res.add(input[i] == null ? null : input[i].doubleValue());
+ for (Number number : input) {
+ res.add(number == null ? null : number.doubleValue());
}
return res;
}
@@ -892,7 +887,7 @@ private List toDoubleList(Number[] input) {
* Sets a null value with a specific SQL type. If the sqlType is null, the value will be set as a
* String.
*/
- private Builder setNullValue(ValueBinder binder, Integer sqlType) throws SQLException {
+ private Builder setNullValue(ValueBinder binder, Integer sqlType) {
if (sqlType == null) {
return binder.to((String) null);
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreconditions.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreconditions.java
index a516e68b7..19586efe1 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreconditions.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreconditions.java
@@ -31,7 +31,7 @@ class JdbcPreconditions {
*
* @param expression the boolean expression that should be true.
* @param value the parameter value that is being checked.
- * @throws JdbcSqlException with {@link Code#INVALID_ARGUMENT} if {@code expression} is false
+ * @throws SQLException with {@link Code#INVALID_ARGUMENT} if {@code expression} is false
*/
static void checkArgument(boolean expression, Object value) throws SQLException {
if (!expression) {
@@ -46,7 +46,7 @@ static void checkArgument(boolean expression, Object value) throws SQLException
* @param expression a boolean expression
* @param errorMessage the exception message to use if the check fails; will be converted to a
* string using {@link String#valueOf(Object)}
- * @throws JdbcSqlException with {@link Code#FAILED_PRECONDITION} if {@code expression} is false
+ * @throws SQLException with {@link Code#FAILED_PRECONDITION} if {@code expression} is false
*/
static void checkState(boolean expression, @Nullable Object errorMessage) throws SQLException {
if (!expression) {
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreparedStatement.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreparedStatement.java
index 919aad302..a25b39c04 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreparedStatement.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcPreparedStatement.java
@@ -20,7 +20,6 @@
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
import com.google.cloud.spanner.ResultSets;
import com.google.cloud.spanner.Statement;
-import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.connection.StatementParser;
import com.google.cloud.spanner.jdbc.JdbcParameterStore.ParametersInfo;
@@ -45,7 +44,7 @@ class JdbcPreparedStatement extends AbstractJdbcPreparedStatement {
JdbcParameterStore.convertPositionalParametersToNamedParameters(sqlWithoutComments);
}
- ParametersInfo getParametersInfo() throws SQLException {
+ ParametersInfo getParametersInfo() {
return parameters;
}
@@ -107,7 +106,7 @@ public ResultSetMetaData getMetaData() throws SQLException {
// Return metadata for an empty result set as DML statements do not return any results (as a
// result set).
com.google.cloud.spanner.ResultSet resultSet =
- ResultSets.forRows(Type.struct(), ImmutableList.of());
+ ResultSets.forRows(Type.struct(), ImmutableList.of());
resultSet.next();
return new JdbcResultSetMetaData(JdbcResultSet.of(resultSet), this);
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSet.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSet.java
index 489c2d27f..c06c147f8 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSet.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSet.java
@@ -99,7 +99,7 @@ public boolean next() throws SQLException {
}
@Override
- public void close() throws SQLException {
+ public void close() {
spanner.close();
this.closed = true;
}
@@ -161,15 +161,15 @@ public boolean getBoolean(int columnIndex) throws SQLException {
Code type = spanner.getColumnType(spannerIndex).getCode();
switch (type) {
case BOOL:
- return isNull ? false : spanner.getBoolean(spannerIndex);
+ return !isNull && spanner.getBoolean(spannerIndex);
case FLOAT64:
- return isNull ? false : spanner.getDouble(spannerIndex) != 0D;
+ return !isNull && spanner.getDouble(spannerIndex) != 0D;
case INT64:
- return isNull ? false : spanner.getLong(spannerIndex) != 0L;
+ return !isNull && spanner.getLong(spannerIndex) != 0L;
case NUMERIC:
- return isNull ? false : !spanner.getBigDecimal(spannerIndex).equals(BigDecimal.ZERO);
+ return !isNull && !spanner.getBigDecimal(spannerIndex).equals(BigDecimal.ZERO);
case STRING:
- return isNull ? false : Boolean.valueOf(spanner.getString(spannerIndex));
+ return !isNull && Boolean.parseBoolean(spanner.getString(spannerIndex));
case BYTES:
case JSON:
case DATE:
@@ -591,8 +591,7 @@ private Object getObject(Type type, int columnIndex) throws SQLException {
if (type == Type.json()) return getString(columnIndex);
if (type == Type.timestamp()) return getTimestamp(columnIndex);
if (type.getCode() == Code.ARRAY) return getArray(columnIndex);
- throw JdbcSqlExceptionFactory.of(
- "Unknown type: " + type.toString(), com.google.rpc.Code.INVALID_ARGUMENT);
+ throw JdbcSqlExceptionFactory.of("Unknown type: " + type, com.google.rpc.Code.INVALID_ARGUMENT);
}
@Override
@@ -737,7 +736,7 @@ public Array getArray(int columnIndex) throws SQLException {
"Column with index " + columnIndex + " does not contain an array",
com.google.rpc.Code.INVALID_ARGUMENT);
JdbcDataType dataType = JdbcDataType.getType(type.getArrayElementType().getCode());
- List extends Object> elements = dataType.getArrayElements(spanner, columnIndex - 1);
+ List> elements = dataType.getArrayElements(spanner, columnIndex - 1);
return JdbcArray.createArray(dataType, elements);
}
@@ -864,7 +863,7 @@ public int getHoldability() throws SQLException {
}
@Override
- public boolean isClosed() throws SQLException {
+ public boolean isClosed() {
return closed;
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java
index a598b109e..69162e807 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcResultSetMetaData.java
@@ -46,44 +46,44 @@ public boolean isClosed() {
}
@Override
- public int getColumnCount() throws SQLException {
+ public int getColumnCount() {
return spannerResultSet.getColumnCount();
}
@Override
- public boolean isAutoIncrement(int column) throws SQLException {
+ public boolean isAutoIncrement(int column) {
return false;
}
@Override
- public boolean isCaseSensitive(int column) throws SQLException {
+ public boolean isCaseSensitive(int column) {
int type = getColumnType(column);
return type == Types.NVARCHAR || type == Types.BINARY;
}
@Override
- public boolean isSearchable(int column) throws SQLException {
+ public boolean isSearchable(int column) {
return true;
}
@Override
- public boolean isCurrency(int column) throws SQLException {
+ public boolean isCurrency(int column) {
return false;
}
@Override
- public int isNullable(int column) throws SQLException {
+ public int isNullable(int column) {
return columnNullableUnknown;
}
@Override
- public boolean isSigned(int column) throws SQLException {
+ public boolean isSigned(int column) {
int type = getColumnType(column);
return type == Types.DOUBLE || type == Types.BIGINT || type == Types.NUMERIC;
}
@Override
- public int getColumnDisplaySize(int column) throws SQLException {
+ public int getColumnDisplaySize(int column) {
int colType = getColumnType(column);
switch (colType) {
case Types.ARRAY:
@@ -112,12 +112,12 @@ public int getColumnDisplaySize(int column) throws SQLException {
}
@Override
- public String getColumnLabel(int column) throws SQLException {
+ public String getColumnLabel(int column) {
return spannerResultSet.getType().getStructFields().get(column - 1).getName();
}
@Override
- public String getColumnName(int column) throws SQLException {
+ public String getColumnName(int column) {
return spannerResultSet.getType().getStructFields().get(column - 1).getName();
}
@@ -127,7 +127,7 @@ public String getSchemaName(int column) throws SQLException {
}
@Override
- public int getPrecision(int column) throws SQLException {
+ public int getPrecision(int column) {
int colType = getColumnType(column);
switch (colType) {
case Types.BOOLEAN:
@@ -152,14 +152,14 @@ public int getPrecision(int column) throws SQLException {
}
@Override
- public int getScale(int column) throws SQLException {
+ public int getScale(int column) {
int colType = getColumnType(column);
if (colType == Types.DOUBLE || colType == Types.NUMERIC) return 15;
return 0;
}
@Override
- public String getTableName(int column) throws SQLException {
+ public String getTableName(int column) {
return "";
}
@@ -169,46 +169,42 @@ public String getCatalogName(int column) throws SQLException {
}
@Override
- public int getColumnType(int column) throws SQLException {
+ public int getColumnType(int column) {
return extractColumnType(spannerResultSet.getColumnType(column - 1));
}
@Override
- public String getColumnTypeName(int column) throws SQLException {
+ public String getColumnTypeName(int column) {
return spannerResultSet.getColumnType(column - 1).getCode().name();
}
@Override
- public boolean isReadOnly(int column) throws SQLException {
+ public boolean isReadOnly(int column) {
return false;
}
@Override
- public boolean isWritable(int column) throws SQLException {
+ public boolean isWritable(int column) {
return !isReadOnly(column);
}
@Override
- public boolean isDefinitelyWritable(int column) throws SQLException {
+ public boolean isDefinitelyWritable(int column) {
return false;
}
@Override
- public String getColumnClassName(int column) throws SQLException {
+ public String getColumnClassName(int column) {
return getClassName(spannerResultSet.getColumnType(column - 1));
}
@Override
public String toString() {
StringBuilder res = new StringBuilder();
- try {
- for (int col = 1; col <= getColumnCount(); col++) {
- res.append("Col ").append(col).append(": ");
- res.append(getColumnName(col)).append(" ").append(getColumnTypeName(col));
- res.append("\n");
- }
- } catch (SQLException e) {
- return "An error occurred while generating string: " + e.getMessage();
+ for (int col = 1; col <= getColumnCount(); col++) {
+ res.append("Col ").append(col).append(": ");
+ res.append(getColumnName(col)).append(" ").append(getColumnTypeName(col));
+ res.append("\n");
}
return res.toString();
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcSqlExceptionFactory.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcSqlExceptionFactory.java
index 33d3bb422..6ddc7d683 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcSqlExceptionFactory.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcSqlExceptionFactory.java
@@ -22,7 +22,6 @@
import com.google.cloud.spanner.SpannerException;
import com.google.rpc.Code;
import java.sql.BatchUpdateException;
-import java.sql.ClientInfoStatus;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
@@ -89,7 +88,7 @@ public static class JdbcSqlClientInfoException extends SQLClientInfoException
private final Code code;
private JdbcSqlClientInfoException(String message, Code code) {
- super(message, Collections.emptyMap());
+ super(message, Collections.emptyMap());
this.code = code;
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcStatement.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcStatement.java
index 5a8f69166..3674ae02b 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcStatement.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcStatement.java
@@ -21,7 +21,6 @@
import com.google.cloud.spanner.SpannerBatchUpdateException;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.Statement;
-import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.Type.StructField;
import com.google.cloud.spanner.connection.StatementParser;
@@ -41,7 +40,7 @@ class JdbcStatement extends AbstractJdbcStatement {
enum BatchType {
NONE,
DML,
- DDL;
+ DDL
}
private ResultSet currentResultSet;
@@ -332,7 +331,7 @@ int[] convertUpdateCounts(long[] updateCounts) throws SQLException {
}
@VisibleForTesting
- void convertUpdateCountsToSuccessNoInfo(long[] updateCounts, long[] res) throws SQLException {
+ void convertUpdateCountsToSuccessNoInfo(long[] updateCounts, long[] res) {
Preconditions.checkNotNull(updateCounts);
Preconditions.checkNotNull(res);
Preconditions.checkArgument(res.length >= updateCounts.length);
@@ -355,7 +354,7 @@ public ResultSet getGeneratedKeys() throws SQLException {
Type.struct(
StructField.of("COLUMN_NAME", Type.string()),
StructField.of("VALUE", Type.int64())),
- Collections.emptyList());
+ Collections.emptyList());
return JdbcResultSet.of(rs);
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcTypeConverter.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcTypeConverter.java
index 4b2e4f0f7..56043b041 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcTypeConverter.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcTypeConverter.java
@@ -25,6 +25,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.sql.Array;
import java.sql.SQLException;
import java.sql.Time;
@@ -41,7 +42,7 @@
/** Convenience class for converting values between Java, JDBC and Cloud Spanner. */
class JdbcTypeConverter {
private static final DateTimeFormatter TIMESTAMP_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
- private static final Charset UTF8 = Charset.forName("UTF8");
+ private static final Charset UTF8 = StandardCharsets.UTF_8;
/**
* Converts the given value from the Google {@link Type} to the Java {@link Class} type. The input
@@ -86,10 +87,9 @@ static Object convert(Object value, Type type, Class> targetType) throws SQLEx
}
if (targetType.equals(Boolean.class)) {
if (type.getCode() == Code.BOOL) return value;
- if (type.getCode() == Code.INT64) return Boolean.valueOf((Long) value != 0);
- if (type.getCode() == Code.FLOAT64) return Boolean.valueOf((Double) value != 0d);
- if (type.getCode() == Code.NUMERIC)
- return Boolean.valueOf(!((BigDecimal) value).equals(BigDecimal.ZERO));
+ if (type.getCode() == Code.INT64) return (Long) value != 0;
+ if (type.getCode() == Code.FLOAT64) return (Double) value != 0d;
+ if (type.getCode() == Code.NUMERIC) return !value.equals(BigDecimal.ZERO);
}
if (targetType.equals(BigDecimal.class)) {
if (type.getCode() == Code.BOOL) return (Boolean) value ? BigDecimal.ONE : BigDecimal.ZERO;
@@ -223,40 +223,31 @@ private static void checkValidTypeAndValueForConvert(Type type, Object value)
throws SQLException {
if (value == null) return;
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.ARRAY && Array.class.isAssignableFrom(value.getClass()))
- || type.getCode() != Code.ARRAY,
+ type.getCode() != Code.ARRAY || Array.class.isAssignableFrom(value.getClass()),
"input type is array, but input value is not an instance of java.sql.Array");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.BOOL && value.getClass().equals(Boolean.class))
- || type.getCode() != Code.BOOL,
+ type.getCode() != Code.BOOL || value.getClass().equals(Boolean.class),
"input type is bool, but input value is not an instance of Boolean");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.BYTES && value.getClass().equals(byte[].class))
- || type.getCode() != Code.BYTES,
+ type.getCode() != Code.BYTES || value.getClass().equals(byte[].class),
"input type is bytes, but input value is not an instance of byte[]");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.DATE && value.getClass().equals(java.sql.Date.class))
- || type.getCode() != Code.DATE,
+ type.getCode() != Code.DATE || value.getClass().equals(java.sql.Date.class),
"input type is date, but input value is not an instance of java.sql.Date");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.FLOAT64 && value.getClass().equals(Double.class))
- || type.getCode() != Code.FLOAT64,
+ type.getCode() != Code.FLOAT64 || value.getClass().equals(Double.class),
"input type is float64, but input value is not an instance of Double");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.INT64 && value.getClass().equals(Long.class))
- || type.getCode() != Code.INT64,
+ type.getCode() != Code.INT64 || value.getClass().equals(Long.class),
"input type is int64, but input value is not an instance of Long");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.STRING && value.getClass().equals(String.class))
- || type.getCode() != Code.STRING,
+ type.getCode() != Code.STRING || value.getClass().equals(String.class),
"input type is string, but input value is not an instance of String");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.TIMESTAMP && value.getClass().equals(java.sql.Timestamp.class))
- || type.getCode() != Code.TIMESTAMP,
+ type.getCode() != Code.TIMESTAMP || value.getClass().equals(java.sql.Timestamp.class),
"input type is timestamp, but input value is not an instance of java.sql.Timestamp");
JdbcPreconditions.checkArgument(
- (type.getCode() == Code.NUMERIC && value.getClass().equals(BigDecimal.class))
- || type.getCode() != Code.NUMERIC,
+ type.getCode() != Code.NUMERIC || value.getClass().equals(BigDecimal.class),
"input type is numeric, but input value is not an instance of BigDecimal");
}
@@ -280,7 +271,9 @@ static Date toGoogleDate(java.sql.Timestamp date) {
static List toGoogleDates(java.sql.Date[] dates) {
List res = new ArrayList<>(dates.length);
- for (int index = 0; index < dates.length; index++) res.add(toGoogleDate(dates[index]));
+ for (java.sql.Date date : dates) {
+ res.add(toGoogleDate(date));
+ }
return res;
}
@@ -290,6 +283,7 @@ static java.sql.Date toSqlDate(Date date) {
static java.sql.Date toSqlDate(Date date, Calendar cal) {
if (date != null) {
+ //noinspection MagicConstant
cal.set(date.getYear(), date.getMonth() - 1, date.getDayOfMonth(), 0, 0, 0);
cal.clear(Calendar.MILLISECOND);
return new java.sql.Date(cal.getTimeInMillis());
@@ -329,7 +323,7 @@ static java.sql.Timestamp setTimestampInCalendar(java.sql.Timestamp sqlTs, Calen
private enum GetOrSetTimestampInCalendar {
GET,
- SET;
+ SET
}
private static java.sql.Timestamp getOrSetTimestampInCalendar(
@@ -363,20 +357,10 @@ static List toSqlTimestamps(List timestamps) {
return res;
}
- static Timestamp toGoogleTimestamp(java.sql.Date ts) {
- if (ts != null) {
- long milliseconds = ts.getTime();
- long seconds = milliseconds / 1000l;
- long nanos = (milliseconds - (seconds * 1000)) * 1000000;
- return com.google.cloud.Timestamp.ofTimeSecondsAndNanos(seconds, (int) nanos);
- }
- return null;
- }
-
- static Timestamp toGoogleTimestamp(java.sql.Time ts) {
+ static Timestamp toGoogleTimestamp(java.util.Date ts) {
if (ts != null) {
long milliseconds = ts.getTime();
- long seconds = milliseconds / 1000l;
+ long seconds = milliseconds / 1000L;
long nanos = (milliseconds - (seconds * 1000)) * 1000000;
return com.google.cloud.Timestamp.ofTimeSecondsAndNanos(seconds, (int) nanos);
}
@@ -386,7 +370,7 @@ static Timestamp toGoogleTimestamp(java.sql.Time ts) {
static Timestamp toGoogleTimestamp(java.sql.Timestamp ts) {
if (ts != null) {
long milliseconds = ts.getTime();
- long seconds = milliseconds / 1000l;
+ long seconds = milliseconds / 1000L;
int nanos = ts.getNanos();
return com.google.cloud.Timestamp.ofTimeSecondsAndNanos(seconds, nanos);
}
@@ -395,8 +379,8 @@ static Timestamp toGoogleTimestamp(java.sql.Timestamp ts) {
static List toGoogleTimestamps(java.sql.Timestamp[] timestamps) {
List res = new ArrayList<>(timestamps.length);
- for (int index = 0; index < timestamps.length; index++) {
- res.add(toGoogleTimestamp(timestamps[index]));
+ for (java.sql.Timestamp timestamp : timestamps) {
+ res.add(toGoogleTimestamp(timestamp));
}
return res;
}
@@ -429,7 +413,7 @@ static Time toSqlTime(Timestamp ts, Calendar cal) {
static java.sql.Time parseSqlTime(String val, Calendar cal) {
if (val != null) {
Time time = Time.valueOf(val);
- cal.set(1970, 0, 1, time.getHours(), time.getMinutes(), time.getSeconds());
+ cal.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
cal.clear(Calendar.MILLISECOND);
return new java.sql.Time(cal.getTimeInMillis());
}
@@ -438,8 +422,8 @@ static java.sql.Time parseSqlTime(String val, Calendar cal) {
static List toGoogleBytes(byte[][] bytes) {
List res = new ArrayList<>(bytes.length);
- for (int index = 0; index < bytes.length; index++) {
- res.add(bytes[index] == null ? null : ByteArray.copyFrom(bytes[index]));
+ for (byte[] aByte : bytes) {
+ res.add(aByte == null ? null : ByteArray.copyFrom(aByte));
}
return res;
}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/TransactionRetryListener.java b/src/main/java/com/google/cloud/spanner/jdbc/TransactionRetryListener.java
index 6d85dc7c0..d837e7364 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/TransactionRetryListener.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/TransactionRetryListener.java
@@ -28,14 +28,14 @@ public interface TransactionRetryListener {
/** Use {@link com.google.cloud.spanner.connection.TransactionRetryListener.RetryResult} */
@InternalApi
@Deprecated
- public enum RetryResult {
+ enum RetryResult {
/** The retry executed successfully and the transaction will continue. */
RETRY_SUCCESSFUL,
/** The retry was aborted by Spanner and another retry attempt will be started. */
RETRY_ABORTED_AND_RESTARTING,
/**
- * The retry was aborted by the {@link Connection} because of a concurrent modification. The
- * transaction cannot continue and will throw an {@link
+ * The retry was aborted by the {@link java.sql.Connection} because of a concurrent
+ * modification. The transaction cannot continue and will throw an {@link
* AbortedDueToConcurrentModificationException}.
*/
RETRY_ABORTED_DUE_TO_CONCURRENT_MODIFICATION,
@@ -48,7 +48,7 @@ public enum RetryResult {
* An unexpected error occurred during transaction retry, the transaction cannot continue and
* will throw an exception.
*/
- RETRY_ERROR;
+ RETRY_ERROR
}
/**
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSetTest.java b/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSetTest.java
index 53fd0e6d2..e17f2b49e 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSetTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSetTest.java
@@ -62,7 +62,7 @@ public void setup() {
}
@Test
- public void testFetchSize() throws SQLException {
+ public void testFetchSize() {
assertEquals(0, rs.getFetchSize());
for (int size : new int[] {0, 1, 10, 100}) {
rs.setFetchSize(size);
@@ -71,24 +71,24 @@ public void testFetchSize() throws SQLException {
}
@Test
- public void testGetType() throws SQLException {
+ public void testGetType() {
assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
}
@Test
- public void testGetConcurrency() throws SQLException {
+ public void testGetConcurrency() {
assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
}
@Test
- public void testRowInsertedUpdatedDeleted() throws SQLException {
+ public void testRowInsertedUpdatedDeleted() {
assertFalse(rs.rowInserted());
assertFalse(rs.rowUpdated());
assertFalse(rs.rowDeleted());
}
@Test
- public void testGetFetchDirection() throws SQLException {
+ public void testGetFetchDirection() {
assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapperTest.java b/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapperTest.java
index 593466f75..3569e67c5 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapperTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapperTest.java
@@ -35,7 +35,7 @@ public class AbstractJdbcWrapperTest {
/** Create a concrete sub class to use for testing. */
private static class TestWrapper extends AbstractJdbcWrapper {
@Override
- public boolean isClosed() throws SQLException {
+ public boolean isClosed() {
return false;
}
}
@@ -44,7 +44,7 @@ public boolean isClosed() throws SQLException {
private static class SubTestWrapper extends TestWrapper {}
@Test
- public void testIsWrapperFor() throws SQLException {
+ public void testIsWrapperFor() {
TestWrapper subject = new TestWrapper();
assertThat(subject.isWrapperFor(TestWrapper.class)).isTrue();
assertThat(subject.isWrapperFor(SubTestWrapper.class)).isFalse();
@@ -59,7 +59,7 @@ public void testIsWrapperFor() throws SQLException {
}
@Test
- public void testUnwrap() throws SQLException {
+ public void testUnwrap() {
TestWrapper subject = new TestWrapper();
assertThat(unwrapSucceeds(subject, TestWrapper.class)).isTrue();
assertThat(unwrapSucceeds(subject, SubTestWrapper.class)).isFalse();
@@ -67,12 +67,7 @@ public void testUnwrap() throws SQLException {
assertThat(unwrapSucceeds(subject, getClass())).isFalse();
}
- private static interface CheckedCastChecker {
- boolean cast(V val);
- }
-
- private static final class CheckedCastToByteChecker implements CheckedCastChecker {
- @Override
+ private static final class CheckedCastToByteChecker {
public boolean cast(Long val) {
try {
AbstractJdbcWrapper.checkedCastToByte(val);
@@ -84,21 +79,20 @@ public boolean cast(Long val) {
}
@Test
- public void testCheckedCastToByte() throws SQLException {
+ public void testCheckedCastToByte() {
CheckedCastToByteChecker checker = new CheckedCastToByteChecker();
assertThat(checker.cast(0L)).isTrue();
assertThat(checker.cast(1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Byte.MAX_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Byte.MAX_VALUE) + 1L)).isFalse();
+ assertThat(checker.cast((long) Byte.MAX_VALUE)).isTrue();
+ assertThat(checker.cast((long) Byte.MAX_VALUE + 1L)).isFalse();
assertThat(checker.cast(Long.MAX_VALUE)).isFalse();
assertThat(checker.cast(-1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Byte.MIN_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Byte.MIN_VALUE) - 1L)).isFalse();
+ assertThat(checker.cast((long) Byte.MIN_VALUE)).isTrue();
+ assertThat(checker.cast((long) Byte.MIN_VALUE - 1L)).isFalse();
assertThat(checker.cast(Long.MIN_VALUE)).isFalse();
}
- private static final class CheckedCastToShortChecker implements CheckedCastChecker {
- @Override
+ private static final class CheckedCastToShortChecker {
public boolean cast(Long val) {
try {
AbstractJdbcWrapper.checkedCastToShort(val);
@@ -110,21 +104,20 @@ public boolean cast(Long val) {
}
@Test
- public void testCheckedCastToShort() throws SQLException {
+ public void testCheckedCastToShort() {
CheckedCastToShortChecker checker = new CheckedCastToShortChecker();
assertThat(checker.cast(0L)).isTrue();
assertThat(checker.cast(1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Short.MAX_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Short.MAX_VALUE) + 1L)).isFalse();
+ assertThat(checker.cast((long) Short.MAX_VALUE)).isTrue();
+ assertThat(checker.cast((long) Short.MAX_VALUE + 1L)).isFalse();
assertThat(checker.cast(Long.MAX_VALUE)).isFalse();
assertThat(checker.cast(-1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Short.MIN_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Short.MIN_VALUE) - 1L)).isFalse();
+ assertThat(checker.cast((long) Short.MIN_VALUE)).isTrue();
+ assertThat(checker.cast((long) Short.MIN_VALUE - 1L)).isFalse();
assertThat(checker.cast(Long.MIN_VALUE)).isFalse();
}
- private static final class CheckedCastToIntChecker implements CheckedCastChecker {
- @Override
+ private static final class CheckedCastToIntChecker {
public boolean cast(Long val) {
try {
AbstractJdbcWrapper.checkedCastToInt(val);
@@ -136,21 +129,20 @@ public boolean cast(Long val) {
}
@Test
- public void testCheckedCastToInt() throws SQLException {
+ public void testCheckedCastToInt() {
CheckedCastToIntChecker checker = new CheckedCastToIntChecker();
assertThat(checker.cast(0L)).isTrue();
assertThat(checker.cast(1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Integer.MAX_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Integer.MAX_VALUE) + 1L)).isFalse();
+ assertThat(checker.cast((long) Integer.MAX_VALUE)).isTrue();
+ assertThat(checker.cast((long) Integer.MAX_VALUE + 1L)).isFalse();
assertThat(checker.cast(Long.MAX_VALUE)).isFalse();
assertThat(checker.cast(-1L)).isTrue();
- assertThat(checker.cast(Long.valueOf(Integer.MIN_VALUE))).isTrue();
- assertThat(checker.cast(Long.valueOf(Integer.MIN_VALUE) - 1L)).isFalse();
+ assertThat(checker.cast((long) Integer.MIN_VALUE)).isTrue();
+ assertThat(checker.cast((long) Integer.MIN_VALUE - 1L)).isFalse();
assertThat(checker.cast(Long.MIN_VALUE)).isFalse();
}
- private static final class CheckedCastToFloatChecker implements CheckedCastChecker {
- @Override
+ private static final class CheckedCastToFloatChecker {
public boolean cast(Double val) {
try {
AbstractJdbcWrapper.checkedCastToFloat(val);
@@ -162,16 +154,16 @@ public boolean cast(Double val) {
}
@Test
- public void testCheckedCastToFloat() throws SQLException {
+ public void testCheckedCastToFloat() {
CheckedCastToFloatChecker checker = new CheckedCastToFloatChecker();
assertThat(checker.cast(0D)).isTrue();
assertThat(checker.cast(1D)).isTrue();
- assertThat(checker.cast(Double.valueOf(Float.MAX_VALUE))).isTrue();
- assertThat(checker.cast(Double.valueOf(Float.MAX_VALUE) * 2.0D)).isFalse();
+ assertThat(checker.cast((double) Float.MAX_VALUE)).isTrue();
+ assertThat(checker.cast((double) Float.MAX_VALUE * 2.0D)).isFalse();
assertThat(checker.cast(Double.MAX_VALUE)).isFalse();
assertThat(checker.cast(-1D)).isTrue();
- assertThat(checker.cast(Double.valueOf(Float.MIN_VALUE))).isTrue();
- assertThat(checker.cast(Double.valueOf(-Float.MAX_VALUE * 2))).isFalse();
+ assertThat(checker.cast((double) Float.MIN_VALUE)).isTrue();
+ assertThat(checker.cast(-Float.MAX_VALUE * 2d)).isFalse();
assertThat(checker.cast(-Double.MAX_VALUE)).isFalse();
}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcAbortedTransactionTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcAbortedTransactionTest.java
index 9c5628399..b7253df82 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcAbortedTransactionTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcAbortedTransactionTest.java
@@ -99,13 +99,9 @@ public void retryFinished(
private static final int UPDATE_COUNT = 1;
private static MockSpannerServiceImpl mockSpanner;
- private static MockInstanceAdminImpl mockInstanceAdmin;
- private static MockDatabaseAdminImpl mockDatabaseAdmin;
private static Server server;
- private static InetSocketAddress address;
- @Parameter(0)
- public boolean retryAbortsInternally;
+ @Parameter public boolean retryAbortsInternally;
@Parameters(name = "retryAbortsInternally = {0}")
public static Collection