Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b29cc25
chore: cleanup and remove warnings
olavloite Oct 7, 2021
3f94d11
cleanup: remove warnings
olavloite Aug 24, 2021
613d810
chore: remove unnecessary throws declarations
olavloite Oct 19, 2021
c2a7e90
chore: fix javadoc issues
olavloite Oct 19, 2021
f860f13
🦉 Updates from OwlBot
gcf-owl-bot[bot] Oct 19, 2021
202a4b8
chore: remove unnecessary type parameters + misc
olavloite Oct 19, 2021
2f25cff
chore: remove unused method
olavloite Oct 19, 2021
6404891
chore: use standard charsets
olavloite Oct 19, 2021
e8795ed
chore: remove unnecessary boxing and unboxing
olavloite Oct 19, 2021
934fdbd
chore: fix overflow issues
olavloite Oct 19, 2021
1d2b936
chore: convert static class members to local variables
olavloite Oct 19, 2021
38e2a9d
chore: replace anonymous classes with lambdas
olavloite Oct 19, 2021
234bc9f
chore: replace l with L in long literals
olavloite Oct 19, 2021
f97f79e
chore: make fields final
olavloite Oct 19, 2021
b4a0595
chore: use singletonList
olavloite Oct 19, 2021
709b9b5
chore: remove unnecessary toString() calls
olavloite Oct 19, 2021
5326c66
chore: remove unnecessary boxing
olavloite Oct 19, 2021
c437c5b
chore: fix empty code blocks
olavloite Oct 19, 2021
0b293b3
chore: deduplicate code
olavloite Oct 19, 2021
1909297
chore: simplify statements
olavloite Oct 19, 2021
b563580
chore: convert to enhanced for-loops
olavloite Oct 19, 2021
4fea79f
chore: replace with lambda method reference
olavloite Oct 19, 2021
8e121fe
chore: remove more redundant throws declarations
olavloite Oct 19, 2021
1b34c69
chore: remove unused interface
olavloite Oct 19, 2021
2f0c98f
chore: cleanup unused code
olavloite Oct 19, 2021
b4f9457
chore: remove redundant semicolons and access modifier
olavloite Oct 19, 2021
174b65d
chore: run code formatter
olavloite Oct 19, 2021
e84f9c6
Merge branch 'cleanup' of github.com:googleapis/java-spanner-jdbc int…
olavloite Oct 19, 2021
35b41b5
fix: re-add public/protected methods
olavloite Nov 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -354,7 +354,7 @@ <T> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -70,15 +71,15 @@ 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
* connection.
*/
default String getStatementTag() throws SQLException {
throw new UnsupportedOperationException();
};
}

/**
* Sets the transaction mode to use for current transaction. This method may only be called when
Expand All @@ -96,10 +97,10 @@ default String getStatementTag() throws SQLException {
* not acquire locks on Cloud Spanner, and read-only transactions never abort.
* <li>{@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 <code>true</code>, 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 <code>true</code>,
* 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.
* </ul>
*/
void setTransactionMode(TransactionMode transactionMode) throws SQLException;
Expand Down Expand Up @@ -175,9 +176,8 @@ default String getStatementTag() throws SQLException {
/**
* @return <code>true</code> 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;

Expand Down Expand Up @@ -323,37 +323,39 @@ 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(
com.google.cloud.spanner.connection.TransactionRetryListener listener) throws SQLException;

/**
* 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)
throws SQLException;

/**
* @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(
com.google.cloud.spanner.connection.TransactionRetryListener listener) throws SQLException;

/**
* 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<com.google.cloud.spanner.jdbc.TransactionRetryListener> getTransactionRetryListeners()
throws SQLException;
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/google/cloud/spanner/jdbc/JdbcArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
Expand Down Expand Up @@ -179,7 +177,7 @@ public ResultSet getResultSet(long startIndex, int count) throws SQLException {
Object value = ((Object[]) data)[index - 1];
ValueBinder<Struct.Builder> 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);
Expand Down Expand Up @@ -237,7 +235,7 @@ public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
}

@Override
public void free() throws SQLException {
public void free() {
this.freed = true;
this.data = null;
}
Expand All @@ -257,7 +255,7 @@ public String toString() {
if (o == null) {
builder.append("null");
} else {
builder.append(o.toString());
builder.append(o);
}
}
builder.append("}");
Expand Down
Loading