Skip to content

Commit 7eedfbc

Browse files
authored
feat!: upgrade to Java 8 and JDBC 4.2 (#397)
* feat!: upgrade to Java 8 and JDBC 4.2 Upgrade to Java 8 and implement new methods added in Java 8 for JDBC. Drops support for Java 7. Closes #396 * fix: remove Java 7 from CI * test: add additional test cases * test: add tests for batches * build: remove java7 configs
1 parent 8482652 commit 7eedfbc

21 files changed

+595
-96
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
java: [7, 8, 11]
12+
java: [8, 11]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-java@v1

.kokoro/nightly/java7.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

.kokoro/presubmit/java7.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@
197197
</dependencies>
198198
<build>
199199
<plugins>
200+
<plugin>
201+
<groupId>org.apache.maven.plugins</groupId>
202+
<artifactId>maven-compiler-plugin</artifactId>
203+
<configuration>
204+
<source>1.8</source>
205+
<target>1.8</target>
206+
<encoding>UTF-8</encoding>
207+
<compilerArgument>-Xlint:unchecked</compilerArgument>
208+
<compilerArgument>-Xlint:deprecation</compilerArgument>
209+
<showDeprecation>true</showDeprecation>
210+
</configuration>
211+
</plugin>
200212
<plugin>
201213
<groupId>org.apache.maven.plugins</groupId>
202214
<artifactId>maven-surefire-plugin</artifactId>

src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcPreparedStatement.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.sql.ResultSet;
3232
import java.sql.RowId;
3333
import java.sql.SQLException;
34+
import java.sql.SQLType;
3435
import java.sql.SQLXML;
3536
import java.sql.Time;
3637
import java.sql.Timestamp;
@@ -321,6 +322,21 @@ public void setObject(int parameterIndex, Object value, int targetSqlType, int s
321322
parameters.setParameter(parameterIndex, value, targetSqlType, scaleOrLength);
322323
}
323324

325+
@Override
326+
public void setObject(int parameterIndex, Object value, SQLType targetSqlType)
327+
throws SQLException {
328+
checkClosed();
329+
parameters.setParameter(parameterIndex, value, targetSqlType.getVendorTypeNumber());
330+
}
331+
332+
@Override
333+
public void setObject(int parameterIndex, Object value, SQLType targetSqlType, int scaleOrLength)
334+
throws SQLException {
335+
checkClosed();
336+
parameters.setParameter(
337+
parameterIndex, value, targetSqlType.getVendorTypeNumber(), scaleOrLength);
338+
}
339+
324340
@Override
325341
public void setAsciiStream(int parameterIndex, InputStream value, long length)
326342
throws SQLException {

src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcResultSet.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.sql.RowId;
3030
import java.sql.SQLException;
3131
import java.sql.SQLFeatureNotSupportedException;
32+
import java.sql.SQLType;
3233
import java.sql.SQLWarning;
3334
import java.sql.SQLXML;
3435
import java.sql.Time;
@@ -233,11 +234,22 @@ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQ
233234
throw new SQLFeatureNotSupportedException();
234235
}
235236

237+
@Override
238+
public void updateObject(int columnIndex, Object x, SQLType type, int scaleOrLength)
239+
throws SQLException {
240+
throw new SQLFeatureNotSupportedException();
241+
}
242+
236243
@Override
237244
public void updateObject(int columnIndex, Object x) throws SQLException {
238245
throw new SQLFeatureNotSupportedException();
239246
}
240247

248+
@Override
249+
public void updateObject(int columnIndex, Object x, SQLType type) throws SQLException {
250+
throw new SQLFeatureNotSupportedException();
251+
}
252+
241253
@Override
242254
public void updateNull(String columnLabel) throws SQLException {
243255
throw new SQLFeatureNotSupportedException();
@@ -335,6 +347,17 @@ public void updateObject(String columnLabel, Object x) throws SQLException {
335347
throw new SQLFeatureNotSupportedException();
336348
}
337349

350+
@Override
351+
public void updateObject(String columnLabel, Object x, SQLType type) throws SQLException {
352+
throw new SQLFeatureNotSupportedException();
353+
}
354+
355+
@Override
356+
public void updateObject(String columnLabel, Object x, SQLType type, int scaleOrLength)
357+
throws SQLException {
358+
throw new SQLFeatureNotSupportedException();
359+
}
360+
338361
@Override
339362
public void insertRow() throws SQLException {
340363
throw new SQLFeatureNotSupportedException();

src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,32 @@ private ResultSet executeQuery(
201201
* Executes a SQL statement on the connection of this {@link Statement} as an update (DML)
202202
* statement.
203203
*
204-
* @param statement The SQL statement to execute.
205-
* @return the number of rows that was inserted/updated/deleted.
204+
* @param statement The SQL statement to execute
205+
* @return the number of rows that was inserted/updated/deleted
206206
* @throws SQLException if a database error occurs, or if the number of rows affected is larger
207-
* than {@link Integer#MAX_VALUE}.
207+
* than {@link Integer#MAX_VALUE}
208208
*/
209209
int executeUpdate(com.google.cloud.spanner.Statement statement) throws SQLException {
210+
long count = executeLargeUpdate(statement);
211+
if (count > Integer.MAX_VALUE) {
212+
throw JdbcSqlExceptionFactory.of(
213+
"update count too large for executeUpdate: " + count, Code.OUT_OF_RANGE);
214+
}
215+
return (int) count;
216+
}
217+
218+
/**
219+
* Executes a SQL statement on the connection of this {@link Statement} as an update (DML)
220+
* statement.
221+
*
222+
* @param statement The SQL statement to execute
223+
* @return the number of rows that was inserted/updated/deleted
224+
* @throws SQLException if a database error occurs
225+
*/
226+
long executeLargeUpdate(com.google.cloud.spanner.Statement statement) throws SQLException {
210227
StatementTimeout originalTimeout = setTemporaryStatementTimeout();
211228
try {
212-
long count = connection.getSpannerConnection().executeUpdate(statement);
213-
if (count > Integer.MAX_VALUE) {
214-
throw JdbcSqlExceptionFactory.of(
215-
"update count too large for executeUpdate: " + count, Code.OUT_OF_RANGE);
216-
}
217-
return (int) count;
229+
return connection.getSpannerConnection().executeUpdate(statement);
218230
} catch (SpannerException e) {
219231
throw JdbcSqlExceptionFactory.of(e);
220232
} finally {
@@ -357,11 +369,22 @@ public int getMaxRows() throws SQLException {
357369
return 0;
358370
}
359371

372+
@Override
373+
public long getLargeMaxRows() throws SQLException {
374+
checkClosed();
375+
return 0L;
376+
}
377+
360378
@Override
361379
public void setMaxRows(int max) throws SQLException {
362380
checkClosed();
363381
}
364382

383+
@Override
384+
public void setLargeMaxRows(long max) throws SQLException {
385+
checkClosed();
386+
}
387+
365388
@Override
366389
public void setEscapeProcessing(boolean enable) throws SQLException {
367390
checkClosed();

src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcWrapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static String getSpannerTypeName(int sqlType) {
6666
if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL)
6767
return Type.numeric().getCode().name();
6868
if (sqlType == Types.NVARCHAR) return Type.string().getCode().name();
69-
if (sqlType == Types.TIMESTAMP) return Type.timestamp().getCode().name();
69+
if (sqlType == Types.TIMESTAMP || sqlType == Types.TIMESTAMP_WITH_TIMEZONE)
70+
return Type.timestamp().getCode().name();
7071
if (sqlType == Types.ARRAY) return Code.ARRAY.name();
7172

7273
return OTHER_NAME;
@@ -84,7 +85,8 @@ static String getClassName(int sqlType) {
8485
|| sqlType == Types.TINYINT) return Long.class.getName();
8586
if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL) return BigDecimal.class.getName();
8687
if (sqlType == Types.NVARCHAR) return String.class.getName();
87-
if (sqlType == Types.TIMESTAMP) return Timestamp.class.getName();
88+
if (sqlType == Types.TIMESTAMP || sqlType == Types.TIMESTAMP_WITH_TIMEZONE)
89+
return Timestamp.class.getName();
8890
if (sqlType == Types.ARRAY) return Object.class.getName();
8991

9092
return null;

src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,4 +1630,15 @@ public ResultSet getPseudoColumns(
16301630
public boolean generatedKeyAlwaysReturned() throws SQLException {
16311631
return false;
16321632
}
1633+
1634+
@Override
1635+
public long getMaxLogicalLobSize() throws SQLException {
1636+
// BYTES(MAX)
1637+
return 10485760L;
1638+
}
1639+
1640+
@Override
1641+
public boolean supportsRefCursors() throws SQLException {
1642+
return false;
1643+
}
16331644
}

src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
*/
107107
public class JdbcDriver implements Driver {
108108
private static final String JDBC_API_CLIENT_LIB_TOKEN = "sp-jdbc";
109-
static final int MAJOR_VERSION = 1;
109+
// Updated to version 2 when upgraded to Java 8 (JDBC 4.2)
110+
static final int MAJOR_VERSION = 2;
110111
static final int MINOR_VERSION = 0;
111112
private static final String JDBC_URL_FORMAT =
112113
"jdbc:" + ConnectionOptions.Builder.SPANNER_URI_FORMAT;
@@ -245,12 +246,12 @@ private String parseUriProperty(String uri, String property, String defaultValue
245246

246247
@Override
247248
public int getMajorVersion() {
248-
return 1;
249+
return MAJOR_VERSION;
249250
}
250251

251252
@Override
252253
public int getMinorVersion() {
253-
return 0;
254+
return MINOR_VERSION;
254255
}
255256

256257
@Override

0 commit comments

Comments
 (0)