From 4bc28718cdbe31914297c399129769de889be3d8 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:39:12 -0400 Subject: [PATCH 1/7] refactor parameter names --- .../jdbc/BigQueryCallableStatement.java | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java index b3fc5d43172e..d7585ba34692 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java @@ -259,19 +259,19 @@ public Date getDate(String parameterName) throws SQLException { } @Override - public Date getDate(int parameterIndex, Calendar cal) throws SQLException { + public Date getDate(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Date date = getDate(parameterIndex); this.lastReadWasNull = (date == null); - return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, cal); + return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, calendar); } @Override - public Date getDate(String parameterName, Calendar cal) throws SQLException { + public Date getDate(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Date date = getDate(parameterName); this.lastReadWasNull = (date == null); - return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, cal); + return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, calendar); } @Override @@ -629,19 +629,19 @@ public Time getTime(String parameterName) throws SQLException { } @Override - public Time getTime(int parameterIndex, Calendar cal) throws SQLException { + public Time getTime(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Time time = getTime(parameterIndex); this.lastReadWasNull = (time == null); - return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, cal); + return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, calendar); } @Override - public Time getTime(String parameterName, Calendar cal) throws SQLException { + public Time getTime(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Time time = getTime(parameterName); this.lastReadWasNull = (time == null); - return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, cal); + return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, calendar); } @Override @@ -669,19 +669,19 @@ public Timestamp getTimestamp(String parameterName) throws SQLException { } @Override - public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { + public Timestamp getTimestamp(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Timestamp ts = getTimestamp(parameterIndex); this.lastReadWasNull = (ts == null); - return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, cal); + return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, calendar); } @Override - public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { + public Timestamp getTimestamp(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Timestamp ts = getTimestamp(parameterName); this.lastReadWasNull = (ts == null); - return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, cal); + return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, calendar); } @Override @@ -703,12 +703,12 @@ public URL getURL(String parameterName) throws SQLException { } @Override - public void registerOutParameter(int paramIndex, int sqlType) throws SQLException { - LOG.finer("registerOutParameter: paramIndex %s, sqlType %s", paramIndex, sqlType); + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { + LOG.finer("registerOutParameter: parameterIndex %s, sqlType %s", parameterIndex, sqlType); checkClosed(); try { this.parameterHandler.setParameter( - paramIndex, + parameterIndex, null, BigQueryJdbcTypeMappings.getJavaType(sqlType), BigQueryParameterHandler.BigQueryStatementParameterType.OUT, @@ -721,12 +721,12 @@ public void registerOutParameter(int paramIndex, int sqlType) throws SQLExceptio } @Override - public void registerOutParameter(String paramName, int sqlType) throws SQLException { - LOG.finer("registerOutParameter: paramName %s, sqlType %s", paramName, sqlType); + public void registerOutParameter(String parameterName, int sqlType) throws SQLException { + LOG.finer("registerOutParameter: parameterName %s, sqlType %s", parameterName, sqlType); checkClosed(); try { this.parameterHandler.setParameter( - paramName, + parameterName, null, BigQueryJdbcTypeMappings.getJavaType(sqlType), BigQueryParameterHandler.BigQueryStatementParameterType.OUT, @@ -739,9 +739,9 @@ public void registerOutParameter(String paramName, int sqlType) throws SQLExcept } @Override - public void registerOutParameter(int paramIndex, int sqlType, int scale) throws SQLException { + public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { LOG.finer( - "registerOutParameter: paramIndex %s, sqlType %s, scale %s", paramIndex, sqlType, scale); + "registerOutParameter: parameterIndex %s, sqlType %s, scale %s", parameterIndex, sqlType, scale); checkClosed(); if (sqlType != Types.NUMERIC && sqlType != Types.DECIMAL) { IllegalArgumentException ex = @@ -752,7 +752,7 @@ public void registerOutParameter(int paramIndex, int sqlType, int scale) throws } try { this.parameterHandler.setParameter( - paramIndex, + parameterIndex, null, BigQueryJdbcTypeMappings.getJavaType(sqlType), BigQueryParameterHandler.BigQueryStatementParameterType.OUT, @@ -765,19 +765,19 @@ public void registerOutParameter(int paramIndex, int sqlType, int scale) throws } @Override - public void registerOutParameter(int paramIndex, int sqlType, String typeName) + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { LOG.finer( - "registerOutParameter: paramIndex %s, sqlType %s, typeName %s", - paramIndex, sqlType, typeName); + "registerOutParameter: parameterIndex %s, sqlType %s, typeName %s", + parameterIndex, sqlType, typeName); // fully qualified sql typeName is not supported by the driver and hence ignored. - registerOutParameter(paramIndex, sqlType); + registerOutParameter(parameterIndex, sqlType); } @Override - public void registerOutParameter(String paramName, int sqlType, int scale) throws SQLException { + public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { LOG.finer( - "registerOutParameter: paramIndex %s, sqlType %s, scale %s", paramName, sqlType, scale); + "registerOutParameter: parameterName %s, sqlType %s, scale %s", parameterName, sqlType, scale); checkClosed(); if (sqlType != Types.NUMERIC && sqlType != Types.DECIMAL) { IllegalArgumentException ex = @@ -788,7 +788,7 @@ public void registerOutParameter(String paramName, int sqlType, int scale) throw } try { this.parameterHandler.setParameter( - paramName, + parameterName, null, BigQueryJdbcTypeMappings.getJavaType(sqlType), BigQueryParameterHandler.BigQueryStatementParameterType.OUT, @@ -801,91 +801,91 @@ public void registerOutParameter(String paramName, int sqlType, int scale) throw } @Override - public void registerOutParameter(String paramName, int sqlType, String typeName) + public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { LOG.finer( - "registerOutParameter: paramIndex %s, sqlType %s, typeName %s", - paramName, sqlType, typeName); + "registerOutParameter: parameterName %s, sqlType %s, typeName %s", + parameterName, sqlType, typeName); // fully qualified sql typeName is not supported by the driver and hence ignored. - registerOutParameter(paramName, sqlType); + registerOutParameter(parameterName, sqlType); } @Override - public void setAsciiStream(String parameterName, InputStream x) throws SQLException { + public void setAsciiStream(String parameterName, InputStream value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException { + public void setAsciiStream(String parameterName, InputStream value, int length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException { + public void setAsciiStream(String parameterName, InputStream value, long length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { - if (x == null) { + public void setBigDecimal(String parameterName, BigDecimal value) throws SQLException { + if (value == null) { setNull(parameterName, Types.NUMERIC); return; } this.parameterHandler.setParameter( - parameterName, x, BigDecimal.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, BigDecimal.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setBinaryStream(String parameterName, InputStream x) throws SQLException { + public void setBinaryStream(String parameterName, InputStream value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException { + public void setBinaryStream(String parameterName, InputStream value, int length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBinaryStream(String parameterName, InputStream x, long length) + public void setBinaryStream(String parameterName, InputStream value, long length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBlob(String parameterName, Blob x) throws SQLException { + public void setBlob(String parameterName, Blob value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBlob(String parameterName, InputStream x) throws SQLException { + public void setBlob(String parameterName, InputStream value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBlob(String parameterName, InputStream x, long length) throws SQLException { + public void setBlob(String parameterName, InputStream value, long length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setBoolean(String parameterName, boolean x) throws SQLException { + public void setBoolean(String parameterName, boolean value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Boolean.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Boolean.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setByte(String parameterName, byte x) throws SQLException { + public void setByte(String parameterName, byte value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Byte.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Byte.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setBytes(String parameterName, byte[] x) throws SQLException { - if (x == null) { + public void setBytes(String parameterName, byte[] value) throws SQLException { + if (value == null) { setNull(parameterName, Types.VARBINARY); return; } this.parameterHandler.setParameter( - parameterName, x, byte[].class, BigQueryStatementParameterType.IN, 0); + parameterName, value, byte[].class, BigQueryStatementParameterType.IN, 0); } @Override @@ -906,7 +906,7 @@ public void setCharacterStream(String parameterName, Reader reader, long length) } @Override - public void setClob(String parameterName, Clob x) throws SQLException { + public void setClob(String parameterName, Clob value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @@ -921,52 +921,52 @@ public void setClob(String parameterName, Reader reader, long length) throws SQL } @Override - public void setDate(String parameterName, Date x) throws SQLException { - if (x == null) { + public void setDate(String parameterName, Date value) throws SQLException { + if (value == null) { setNull(parameterName, Types.DATE); return; } this.parameterHandler.setParameter( - parameterName, x, Date.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Date.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setDate(String parameterName, Date x, Calendar cal) throws SQLException { + public void setDate(String parameterName, Date value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterName, Types.DATE); return; } this.parameterHandler.setParameter( parameterName, - BigQueryTypeCoercionUtility.convertDateToCalendar(x, cal), + BigQueryTypeCoercionUtility.convertDateToCalendar(value, calendar), Date.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setDouble(String parameterName, double x) throws SQLException { + public void setDouble(String parameterName, double value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Double.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Double.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setFloat(String parameterName, float x) throws SQLException { + public void setFloat(String parameterName, float value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Float.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Float.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setInt(String parameterName, int x) throws SQLException { + public void setInt(String parameterName, int value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Integer.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Integer.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setLong(String parameterName, long x) throws SQLException { + public void setLong(String parameterName, long value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Long.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Long.class, BigQueryStatementParameterType.IN, 0); } @Override @@ -996,13 +996,13 @@ public void setNClob(String parameterName, Reader reader, long length) throws SQ } @Override - public void setNString(String parameterName, String x) throws SQLException { - if (x == null) { + public void setNString(String parameterName, String value) throws SQLException { + if (value == null) { setNull(parameterName, Types.NVARCHAR); return; } this.parameterHandler.setParameter( - parameterName, x, String.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, String.class, BigQueryStatementParameterType.IN, 0); } @Override @@ -1022,23 +1022,23 @@ public void setNull(String parameterName, int sqlType, String typeName) throws S } @Override - public void setObject(String parameterName, Object x) throws SQLException { - if (x == null) { + public void setObject(String parameterName, Object value) throws SQLException { + if (value == null) { setNull(parameterName, Types.OTHER); return; } this.parameterHandler.setParameter( - parameterName, x, x.getClass(), BigQueryStatementParameterType.IN, 0); + parameterName, value, value.getClass(), BigQueryStatementParameterType.IN, 0); } @Override - public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { - if (x == null) { + public void setObject(String parameterName, Object value, int targetSqlType) throws SQLException { + if (value == null) { setNull(parameterName, targetSqlType); return; } this.parameterHandler.setParameter( - parameterName, x, x.getClass(), BigQueryStatementParameterType.IN, 0); + parameterName, value, value.getClass(), BigQueryStatementParameterType.IN, 0); StandardSQLTypeName sqlType = this.parameterHandler.getSqlType(parameterName); if (BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.containsKey(sqlType)) { int javaSqlType = BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.get(sqlType); @@ -1053,14 +1053,14 @@ public void setObject(String parameterName, Object x, int targetSqlType) throws } @Override - public void setObject(String parameterName, Object x, int targetSqlType, int scaleOrLength) + public void setObject(String parameterName, Object value, int targetSqlType, int scaleOrLength) throws SQLException { - if (x == null) { + if (value == null) { setNull(parameterName, targetSqlType); return; } this.parameterHandler.setParameter( - parameterName, x, x.getClass(), BigQueryStatementParameterType.IN, scaleOrLength); + parameterName, value, value.getClass(), BigQueryStatementParameterType.IN, scaleOrLength); StandardSQLTypeName sqlType = this.parameterHandler.getSqlType(parameterName); if (BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.containsKey(sqlType)) { int javaSqlType = BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.get(sqlType); @@ -1075,7 +1075,7 @@ public void setObject(String parameterName, Object x, int targetSqlType, int sca } @Override - public void setRowId(String parameterName, RowId x) throws SQLException { + public void setRowId(String parameterName, RowId value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @@ -1085,73 +1085,73 @@ public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLExceptio } @Override - public void setShort(String parameterName, short x) throws SQLException { + public void setShort(String parameterName, short value) throws SQLException { this.parameterHandler.setParameter( - parameterName, x, Short.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Short.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setString(String parameterName, String x) throws SQLException { - if (x == null) { + public void setString(String parameterName, String value) throws SQLException { + if (value == null) { setNull(parameterName, Types.VARCHAR); return; } this.parameterHandler.setParameter( - parameterName, x, String.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, String.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setTime(String parameterName, Time x) throws SQLException { - if (x == null) { + public void setTime(String parameterName, Time value) throws SQLException { + if (value == null) { setNull(parameterName, Types.TIME); return; } this.parameterHandler.setParameter( - parameterName, x, Time.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Time.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setTime(String parameterName, Time x, Calendar cal) throws SQLException { + public void setTime(String parameterName, Time value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterName, Types.TIME); return; } this.parameterHandler.setParameter( parameterName, - BigQueryTypeCoercionUtility.convertTimeWithCalendar(x, cal), + BigQueryTypeCoercionUtility.convertTimeWithCalendar(value, calendar), Time.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setTimestamp(String parameterName, Timestamp x) throws SQLException { - if (x == null) { + public void setTimestamp(String parameterName, Timestamp value) throws SQLException { + if (value == null) { setNull(parameterName, Types.TIMESTAMP); return; } this.parameterHandler.setParameter( - parameterName, x, Timestamp.class, BigQueryStatementParameterType.IN, 0); + parameterName, value, Timestamp.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException { + public void setTimestamp(String parameterName, Timestamp value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterName, Types.TIMESTAMP); return; } this.parameterHandler.setParameter( parameterName, - BigQueryTypeCoercionUtility.convertTimestampWithCalendar(x, cal), + BigQueryTypeCoercionUtility.convertTimestampWithCalendar(value, calendar), Timestamp.class, BigQueryStatementParameterType.IN, 0); } @Override - public void setURL(String parameterName, URL val) throws SQLException { + public void setURL(String parameterName, URL value) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } From 14b6eb5938220af39722b951b88e4baeb25ee50d Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:43:33 -0400 Subject: [PATCH 2/7] add checkClosed --- .../jdbc/BigQueryCallableStatement.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java index d7585ba34692..4b451ec30655 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java @@ -63,6 +63,7 @@ protected BigQueryParameterHandler getParameterHandler() { @Override public Array getArray(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Array) { return (Array) param; @@ -72,6 +73,7 @@ public Array getArray(int parameterIndex) throws SQLException { @Override public Array getArray(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Array) { return (Array) param; @@ -81,6 +83,7 @@ public Array getArray(String parameterName) throws SQLException { @Override public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof BigDecimal) { return (BigDecimal) param; @@ -90,6 +93,7 @@ public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { @Override public BigDecimal getBigDecimal(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof BigDecimal) { return (BigDecimal) param; @@ -101,11 +105,13 @@ public BigDecimal getBigDecimal(String parameterName) throws SQLException { @Deprecated @SuppressWarnings("deprecation") public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { + checkClosed(); return getBigDecimal(parameterIndex); } @Override public Blob getBlob(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Blob) { return (Blob) param; @@ -115,6 +121,7 @@ public Blob getBlob(int parameterIndex) throws SQLException { @Override public Blob getBlob(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Blob) { return (Blob) param; @@ -124,6 +131,7 @@ public Blob getBlob(String parameterName) throws SQLException { @Override public boolean getBoolean(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Boolean) { return (Boolean) param; @@ -134,6 +142,7 @@ public boolean getBoolean(int parameterIndex) throws SQLException { @Override public boolean getBoolean(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Boolean) { return (Boolean) param; @@ -144,6 +153,7 @@ public boolean getBoolean(String parameterName) throws SQLException { @Override public byte getByte(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Byte) { return (Byte) param; @@ -157,6 +167,7 @@ public byte getByte(int parameterIndex) throws SQLException { @Override public byte getByte(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Byte) { return (Byte) param; @@ -170,6 +181,7 @@ public byte getByte(String parameterName) throws SQLException { @Override public byte[] getBytes(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof byte[]) { return (byte[]) param; @@ -182,6 +194,7 @@ public byte[] getBytes(int parameterIndex) throws SQLException { @Override public byte[] getBytes(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof byte[]) { return (byte[]) param; @@ -194,6 +207,7 @@ public byte[] getBytes(String parameterName) throws SQLException { @Override public Reader getCharacterStream(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Reader) { return (Reader) param; @@ -206,6 +220,7 @@ public Reader getCharacterStream(int parameterIndex) throws SQLException { @Override public Reader getCharacterStream(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Reader) { return (Reader) param; @@ -218,6 +233,7 @@ public Reader getCharacterStream(String parameterName) throws SQLException { @Override public Clob getClob(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Clob) { return (Clob) param; @@ -227,6 +243,7 @@ public Clob getClob(int parameterIndex) throws SQLException { @Override public Clob getClob(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Clob) { return (Clob) param; @@ -236,6 +253,7 @@ public Clob getClob(String parameterName) throws SQLException { @Override public Date getDate(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Date) { return (Date) param; @@ -248,6 +266,7 @@ public Date getDate(int parameterIndex) throws SQLException { @Override public Date getDate(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Date) { return (Date) param; @@ -276,6 +295,7 @@ public Date getDate(String parameterName, Calendar calendar) throws SQLException @Override public double getDouble(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Double) { return (Double) param; @@ -289,6 +309,7 @@ public double getDouble(int parameterIndex) throws SQLException { @Override public double getDouble(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Double) { return (Double) param; @@ -302,6 +323,7 @@ public double getDouble(String parameterName) throws SQLException { @Override public float getFloat(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Float) { return (Float) param; @@ -315,6 +337,7 @@ public float getFloat(int parameterIndex) throws SQLException { @Override public float getFloat(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Float) { return (Float) param; @@ -328,6 +351,7 @@ public float getFloat(String parameterName) throws SQLException { @Override public int getInt(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Integer) { return (Integer) param; @@ -341,6 +365,7 @@ public int getInt(int parameterIndex) throws SQLException { @Override public int getInt(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Integer) { return (Integer) param; @@ -354,6 +379,7 @@ public int getInt(String parameterName) throws SQLException { @Override public long getLong(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Long) { return (Long) param; @@ -367,6 +393,7 @@ public long getLong(int parameterIndex) throws SQLException { @Override public long getLong(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Long) { return (Long) param; @@ -380,16 +407,19 @@ public long getLong(String parameterName) throws SQLException { @Override public Reader getNCharacterStream(int parameterIndex) throws SQLException { + checkClosed(); return getCharacterStream(parameterIndex); } @Override public Reader getNCharacterStream(String parameterName) throws SQLException { + checkClosed(); return getCharacterStream(parameterName); } @Override public NClob getNClob(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof NClob) { return (NClob) param; @@ -399,6 +429,7 @@ public NClob getNClob(int parameterIndex) throws SQLException { @Override public NClob getNClob(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof NClob) { return (NClob) param; @@ -408,6 +439,7 @@ public NClob getNClob(String parameterName) throws SQLException { @Override public String getNString(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof String) { return param.toString(); @@ -417,6 +449,7 @@ public String getNString(int parameterIndex) throws SQLException { @Override public String getNString(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof String) { return param.toString(); @@ -532,6 +565,7 @@ public Ref getRef(String parameterName) throws SQLException { @Override public RowId getRowId(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof RowId) { return (RowId) param; @@ -541,6 +575,7 @@ public RowId getRowId(int parameterIndex) throws SQLException { @Override public RowId getRowId(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof RowId) { return (RowId) param; @@ -562,6 +597,7 @@ public SQLXML getSQLXML(String parameterName) throws SQLException { @Override public short getShort(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Short) { return (Short) param; @@ -575,6 +611,7 @@ public short getShort(int parameterIndex) throws SQLException { @Override public short getShort(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Short) { return (Short) param; @@ -588,6 +625,7 @@ public short getShort(String parameterName) throws SQLException { @Override public String getString(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof String) { return param.toString(); @@ -597,6 +635,7 @@ public String getString(int parameterIndex) throws SQLException { @Override public String getString(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof String) { return param.toString(); @@ -606,6 +645,7 @@ public String getString(String parameterName) throws SQLException { @Override public Time getTime(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Time) { return (Time) param; @@ -618,6 +658,7 @@ public Time getTime(int parameterIndex) throws SQLException { @Override public Time getTime(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Time) { return (Time) param; @@ -646,6 +687,7 @@ public Time getTime(String parameterName, Calendar calendar) throws SQLException @Override public Timestamp getTimestamp(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof Timestamp) { return (Timestamp) param; @@ -658,6 +700,7 @@ public Timestamp getTimestamp(int parameterIndex) throws SQLException { @Override public Timestamp getTimestamp(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof Timestamp) { return (Timestamp) param; @@ -686,6 +729,7 @@ public Timestamp getTimestamp(String parameterName, Calendar calendar) throws SQ @Override public URL getURL(int parameterIndex) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterIndex); if (param instanceof URL) { return (URL) param; @@ -695,6 +739,7 @@ public URL getURL(int parameterIndex) throws SQLException { @Override public URL getURL(String parameterName) throws SQLException { + checkClosed(); Object param = this.parameterHandler.getParameter(parameterName); if (param instanceof URL) { return (URL) param; @@ -827,6 +872,7 @@ public void setAsciiStream(String parameterName, InputStream value, long length) @Override public void setBigDecimal(String parameterName, BigDecimal value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.NUMERIC); return; @@ -868,18 +914,21 @@ public void setBlob(String parameterName, InputStream value, long length) throws @Override public void setBoolean(String parameterName, boolean value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Boolean.class, BigQueryStatementParameterType.IN, 0); } @Override public void setByte(String parameterName, byte value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Byte.class, BigQueryStatementParameterType.IN, 0); } @Override public void setBytes(String parameterName, byte[] value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.VARBINARY); return; @@ -922,6 +971,7 @@ public void setClob(String parameterName, Reader reader, long length) throws SQL @Override public void setDate(String parameterName, Date value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.DATE); return; @@ -947,24 +997,28 @@ public void setDate(String parameterName, Date value, Calendar calendar) throws @Override public void setDouble(String parameterName, double value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Double.class, BigQueryStatementParameterType.IN, 0); } @Override public void setFloat(String parameterName, float value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Float.class, BigQueryStatementParameterType.IN, 0); } @Override public void setInt(String parameterName, int value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Integer.class, BigQueryStatementParameterType.IN, 0); } @Override public void setLong(String parameterName, long value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Long.class, BigQueryStatementParameterType.IN, 0); } @@ -997,6 +1051,7 @@ public void setNClob(String parameterName, Reader reader, long length) throws SQ @Override public void setNString(String parameterName, String value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.NVARCHAR); return; @@ -1023,6 +1078,7 @@ public void setNull(String parameterName, int sqlType, String typeName) throws S @Override public void setObject(String parameterName, Object value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.OTHER); return; @@ -1033,6 +1089,7 @@ public void setObject(String parameterName, Object value) throws SQLException { @Override public void setObject(String parameterName, Object value, int targetSqlType) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, targetSqlType); return; @@ -1055,6 +1112,7 @@ public void setObject(String parameterName, Object value, int targetSqlType) thr @Override public void setObject(String parameterName, Object value, int targetSqlType, int scaleOrLength) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, targetSqlType); return; @@ -1086,12 +1144,14 @@ public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLExceptio @Override public void setShort(String parameterName, short value) throws SQLException { + checkClosed(); this.parameterHandler.setParameter( parameterName, value, Short.class, BigQueryStatementParameterType.IN, 0); } @Override public void setString(String parameterName, String value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.VARCHAR); return; @@ -1102,6 +1162,7 @@ public void setString(String parameterName, String value) throws SQLException { @Override public void setTime(String parameterName, Time value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.TIME); return; @@ -1127,6 +1188,7 @@ public void setTime(String parameterName, Time value, Calendar calendar) throws @Override public void setTimestamp(String parameterName, Timestamp value) throws SQLException { + checkClosed(); if (value == null) { setNull(parameterName, Types.TIMESTAMP); return; From 97faef2178eef0eeeb03f79fc31fcb15b3806f8a Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:45:55 -0400 Subject: [PATCH 3/7] logging --- .../google/cloud/bigquery/jdbc/BigQueryCallableStatement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java index 4b451ec30655..c4f4e21b7bd3 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java @@ -49,6 +49,7 @@ class BigQueryCallableStatement extends BigQueryPreparedStatement implements Cal BigQueryCallableStatement(BigQueryConnection connection, String callableStmtSql) throws SQLException { super(connection, callableStmtSql); + LOG.finer("++enter++"); } @VisibleForTesting From 45b2017106a2b11c7b278f4eae6580adc7c8e192 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:49:28 -0400 Subject: [PATCH 4/7] align PreparedStatement --- .../jdbc/BigQueryPreparedStatement.java | 156 ++++++++++-------- 1 file changed, 90 insertions(+), 66 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java index bdae55fd2b0c..233a9b9b084e 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java @@ -129,156 +129,176 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException { } @Override - public void setBoolean(int parameterIndex, boolean x) throws SQLException { + public void setBoolean(int parameterIndex, boolean value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Boolean.class); + this.parameterHandler.setParameter(parameterIndex, value, Boolean.class); } @Override - public void setByte(int parameterIndex, byte x) throws SQLException { + public void setByte(int parameterIndex, byte value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Byte.class); + this.parameterHandler.setParameter(parameterIndex, value, Byte.class); } @Override - public void setShort(int parameterIndex, short x) throws SQLException { + public void setShort(int parameterIndex, short value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Short.class); + this.parameterHandler.setParameter(parameterIndex, value, Short.class); } @Override - public void setInt(int parameterIndex, int x) throws SQLException { + public void setInt(int parameterIndex, int value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Integer.class); + this.parameterHandler.setParameter(parameterIndex, value, Integer.class); } @Override - public void setLong(int parameterIndex, long x) throws SQLException { + public void setLong(int parameterIndex, long value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Long.class); + this.parameterHandler.setParameter(parameterIndex, value, Long.class); } @Override - public void setFloat(int parameterIndex, float x) throws SQLException { + public void setFloat(int parameterIndex, float value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Float.class); + this.parameterHandler.setParameter(parameterIndex, value, Float.class); } @Override - public void setDouble(int parameterIndex, double x) throws SQLException { + public void setDouble(int parameterIndex, double value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Double.class); + this.parameterHandler.setParameter(parameterIndex, value, Double.class); } @Override - public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, BigDecimal.class); + if (value == null) { + setNull(parameterIndex, Types.NUMERIC); + return; + } + this.parameterHandler.setParameter(parameterIndex, value, BigDecimal.class); } @Override - public void setString(int parameterIndex, String x) throws SQLException { + public void setString(int parameterIndex, String value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, String.class); + if (value == null) { + setNull(parameterIndex, Types.VARCHAR); + return; + } + this.parameterHandler.setParameter(parameterIndex, value, String.class); } @Override - public void setBytes(int parameterIndex, byte[] x) throws SQLException { + public void setBytes(int parameterIndex, byte[] value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, byte[].class); + if (value == null) { + setNull(parameterIndex, Types.VARBINARY); + return; + } + this.parameterHandler.setParameter(parameterIndex, value, byte[].class); } @Override - public void setDate(int parameterIndex, Date x) throws SQLException { + public void setDate(int parameterIndex, Date value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x.toString(), String.class); + if (value == null) { + setNull(parameterIndex, Types.DATE); + return; + } + this.parameterHandler.setParameter(parameterIndex, value.toString(), String.class); } @Override - public void setTime(int parameterIndex, Time x) throws SQLException { + public void setTime(int parameterIndex, Time value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x.toString(), String.class); + if (value == null) { + setNull(parameterIndex, Types.TIME); + return; + } + this.parameterHandler.setParameter(parameterIndex, value.toString(), String.class); } @Override - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException { checkClosed(); - if (x == null) { - this.parameterHandler.setParameter(parameterIndex, null, String.class); + if (value == null) { + setNull(parameterIndex, Types.TIMESTAMP); return; } - Timestamp copy = new Timestamp(x.getTime()); - copy.setNanos((x.getNanos() / 1000) * 1000); + Timestamp copy = new Timestamp(value.getTime()); + copy.setNanos((value.getNanos() / 1000) * 1000); this.parameterHandler.setParameter(parameterIndex, copy.toString(), String.class); } @Override - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + public void setAsciiStream(int parameterIndex, InputStream value, int length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setAsciiStream is not supported."); } @Override @Deprecated @SuppressWarnings("deprecation") - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + public void setUnicodeStream(int parameterIndex, InputStream value, int length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setUnicodeStream is not supported."); } @Override - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + public void setBinaryStream(int parameterIndex, InputStream value, int length) throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setBinaryStream is not supported."); } @Override - public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + public void setObject(int parameterIndex, Object value, int targetSqlType) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterIndex, targetSqlType); return; } - if (setTemporalObject(parameterIndex, x)) { + if (setTemporalObject(parameterIndex, value)) { return; } Class javaType = BigQueryJdbcTypeMappings.getJavaType(targetSqlType); - this.parameterHandler.setParameter(parameterIndex, x, javaType); + this.parameterHandler.setParameter(parameterIndex, value, javaType); } @Override - public void setObject(int parameterIndex, Object x) throws SQLException { + public void setObject(int parameterIndex, Object value) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterIndex, Types.NULL); return; } - if (setTemporalObject(parameterIndex, x)) { + if (setTemporalObject(parameterIndex, value)) { return; } - this.parameterHandler.setParameter(parameterIndex, x, x.getClass()); + this.parameterHandler.setParameter(parameterIndex, value, value.getClass()); } - private boolean setTemporalObject(int parameterIndex, Object x) throws SQLException { - if (x instanceof LocalDate) { - setDate(parameterIndex, Date.valueOf((LocalDate) x)); + private boolean setTemporalObject(int parameterIndex, Object value) throws SQLException { + if (value instanceof LocalDate) { + setDate(parameterIndex, Date.valueOf((LocalDate) value)); return true; } - if (x instanceof LocalTime) { - setTime(parameterIndex, Time.valueOf((LocalTime) x)); + if (value instanceof LocalTime) { + setTime(parameterIndex, Time.valueOf((LocalTime) value)); return true; } - if (x instanceof LocalDateTime) { - setTimestamp(parameterIndex, Timestamp.valueOf((LocalDateTime) x)); + if (value instanceof LocalDateTime) { + setTimestamp(parameterIndex, Timestamp.valueOf((LocalDateTime) value)); return true; } - if (x instanceof OffsetDateTime) { - setTimestamp(parameterIndex, Timestamp.from(((OffsetDateTime) x).toInstant())); + if (value instanceof OffsetDateTime) { + setTimestamp(parameterIndex, Timestamp.from(((OffsetDateTime) value).toInstant())); return true; } - if (x instanceof Instant) { - setTimestamp(parameterIndex, Timestamp.from((Instant) x)); + if (value instanceof Instant) { + setTimestamp(parameterIndex, Timestamp.from((Instant) value)); return true; } - if (x instanceof ZonedDateTime) { - setTimestamp(parameterIndex, Timestamp.from(((ZonedDateTime) x).toInstant())); + if (value instanceof ZonedDateTime) { + setTimestamp(parameterIndex, Timestamp.from(((ZonedDateTime) value).toInstant())); return true; } return false; @@ -504,9 +524,13 @@ public void setClob(int parameterIndex, Clob x) throws SQLException { } @Override - public void setArray(int parameterIndex, Array x) throws SQLException { + public void setArray(int parameterIndex, Array value) throws SQLException { checkClosed(); - this.parameterHandler.setParameter(parameterIndex, x, Array.class); + if (value == null) { + setNull(parameterIndex, Types.ARRAY); + return; + } + this.parameterHandler.setParameter(parameterIndex, value, Array.class); } @Override @@ -519,33 +543,33 @@ public ResultSetMetaData getMetaData() throws SQLException { } @Override - public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + public void setDate(int parameterIndex, Date value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterIndex, Types.DATE); return; } - setDate(parameterIndex, BigQueryTypeCoercionUtility.convertDateWithCalendar(x, cal)); + setDate(parameterIndex, BigQueryTypeCoercionUtility.convertDateWithCalendar(value, calendar)); } @Override - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + public void setTime(int parameterIndex, Time value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterIndex, Types.TIME); return; } - setTime(parameterIndex, BigQueryTypeCoercionUtility.convertTimeWithCalendar(x, cal)); + setTime(parameterIndex, BigQueryTypeCoercionUtility.convertTimeWithCalendar(value, calendar)); } @Override - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) throws SQLException { checkClosed(); - if (x == null) { + if (value == null) { setNull(parameterIndex, Types.TIMESTAMP); return; } - setTimestamp(parameterIndex, BigQueryTypeCoercionUtility.convertTimestampWithCalendar(x, cal)); + setTimestamp(parameterIndex, BigQueryTypeCoercionUtility.convertTimestampWithCalendar(value, calendar)); } @Override @@ -612,10 +636,10 @@ public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException * #setObject(int, Object, int)}. */ @Override - public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) + public void setObject(int parameterIndex, Object value, int targetSqlType, int scaleOrLength) throws SQLException { checkClosed(); - setObject(parameterIndex, x, targetSqlType); + setObject(parameterIndex, value, targetSqlType); } @Override From 993a9bcff4f4b5f2427ce9d4f207503aa8b147ed Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:58:34 -0400 Subject: [PATCH 5/7] getRawParameter --- .../jdbc/BigQueryCallableStatement.java | 128 +++++++++--------- 1 file changed, 62 insertions(+), 66 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java index c4f4e21b7bd3..e902b2c92eaa 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java @@ -46,6 +46,18 @@ class BigQueryCallableStatement extends BigQueryPreparedStatement implements Cal private final BigQueryJdbcCustomLogger LOG = new BigQueryJdbcCustomLogger(this.toString()); private boolean lastReadWasNull = false; + private Object getRawParameter(int parameterIndex) { + Object value = this.parameterHandler.getParameter(parameterIndex); + this.lastReadWasNull = (value == null); + return value; + } + + private Object getRawParameter(String parameterName) { + Object value = this.parameterHandler.getParameter(parameterName); + this.lastReadWasNull = (value == null); + return value; + } + BigQueryCallableStatement(BigQueryConnection connection, String callableStmtSql) throws SQLException { super(connection, callableStmtSql); @@ -65,7 +77,7 @@ protected BigQueryParameterHandler getParameterHandler() { @Override public Array getArray(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Array) { return (Array) param; } @@ -75,7 +87,7 @@ public Array getArray(int parameterIndex) throws SQLException { @Override public Array getArray(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Array) { return (Array) param; } @@ -85,7 +97,7 @@ public Array getArray(String parameterName) throws SQLException { @Override public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof BigDecimal) { return (BigDecimal) param; } @@ -95,7 +107,7 @@ public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { @Override public BigDecimal getBigDecimal(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof BigDecimal) { return (BigDecimal) param; } @@ -113,7 +125,7 @@ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLExcepti @Override public Blob getBlob(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Blob) { return (Blob) param; } @@ -123,7 +135,7 @@ public Blob getBlob(int parameterIndex) throws SQLException { @Override public Blob getBlob(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Blob) { return (Blob) param; } @@ -133,7 +145,7 @@ public Blob getBlob(String parameterName) throws SQLException { @Override public boolean getBoolean(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Boolean) { return (Boolean) param; } @@ -144,7 +156,7 @@ public boolean getBoolean(int parameterIndex) throws SQLException { @Override public boolean getBoolean(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Boolean) { return (Boolean) param; } @@ -155,7 +167,7 @@ public boolean getBoolean(String parameterName) throws SQLException { @Override public byte getByte(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Byte) { return (Byte) param; } @@ -169,7 +181,7 @@ public byte getByte(int parameterIndex) throws SQLException { @Override public byte getByte(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Byte) { return (Byte) param; } @@ -183,7 +195,7 @@ public byte getByte(String parameterName) throws SQLException { @Override public byte[] getBytes(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof byte[]) { return (byte[]) param; } @@ -196,7 +208,7 @@ public byte[] getBytes(int parameterIndex) throws SQLException { @Override public byte[] getBytes(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof byte[]) { return (byte[]) param; } @@ -209,7 +221,7 @@ public byte[] getBytes(String parameterName) throws SQLException { @Override public Reader getCharacterStream(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Reader) { return (Reader) param; } @@ -222,7 +234,7 @@ public Reader getCharacterStream(int parameterIndex) throws SQLException { @Override public Reader getCharacterStream(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Reader) { return (Reader) param; } @@ -235,7 +247,7 @@ public Reader getCharacterStream(String parameterName) throws SQLException { @Override public Clob getClob(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Clob) { return (Clob) param; } @@ -245,7 +257,7 @@ public Clob getClob(int parameterIndex) throws SQLException { @Override public Clob getClob(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Clob) { return (Clob) param; } @@ -255,7 +267,7 @@ public Clob getClob(String parameterName) throws SQLException { @Override public Date getDate(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Date) { return (Date) param; } @@ -268,7 +280,7 @@ public Date getDate(int parameterIndex) throws SQLException { @Override public Date getDate(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Date) { return (Date) param; } @@ -282,7 +294,6 @@ public Date getDate(String parameterName) throws SQLException { public Date getDate(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Date date = getDate(parameterIndex); - this.lastReadWasNull = (date == null); return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, calendar); } @@ -290,14 +301,13 @@ public Date getDate(int parameterIndex, Calendar calendar) throws SQLException { public Date getDate(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Date date = getDate(parameterName); - this.lastReadWasNull = (date == null); return BigQueryTypeCoercionUtility.convertDateWithCalendar(date, calendar); } @Override public double getDouble(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Double) { return (Double) param; } @@ -311,7 +321,7 @@ public double getDouble(int parameterIndex) throws SQLException { @Override public double getDouble(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Double) { return (Double) param; } @@ -325,7 +335,7 @@ public double getDouble(String parameterName) throws SQLException { @Override public float getFloat(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Float) { return (Float) param; } @@ -339,7 +349,7 @@ public float getFloat(int parameterIndex) throws SQLException { @Override public float getFloat(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Float) { return (Float) param; } @@ -353,7 +363,7 @@ public float getFloat(String parameterName) throws SQLException { @Override public int getInt(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Integer) { return (Integer) param; } @@ -367,7 +377,7 @@ public int getInt(int parameterIndex) throws SQLException { @Override public int getInt(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Integer) { return (Integer) param; } @@ -381,7 +391,7 @@ public int getInt(String parameterName) throws SQLException { @Override public long getLong(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Long) { return (Long) param; } @@ -395,7 +405,7 @@ public long getLong(int parameterIndex) throws SQLException { @Override public long getLong(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Long) { return (Long) param; } @@ -421,7 +431,7 @@ public Reader getNCharacterStream(String parameterName) throws SQLException { @Override public NClob getNClob(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof NClob) { return (NClob) param; } @@ -431,7 +441,7 @@ public NClob getNClob(int parameterIndex) throws SQLException { @Override public NClob getNClob(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof NClob) { return (NClob) param; } @@ -441,7 +451,7 @@ public NClob getNClob(String parameterName) throws SQLException { @Override public String getNString(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof String) { return param.toString(); } @@ -451,7 +461,7 @@ public String getNString(int parameterIndex) throws SQLException { @Override public String getNString(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof String) { return param.toString(); } @@ -461,17 +471,13 @@ public String getNString(String parameterName) throws SQLException { @Override public Object getObject(int parameterIndex) throws SQLException { checkClosed(); - Object value = this.parameterHandler.getParameter(parameterIndex); - this.lastReadWasNull = (value == null); - return value; + return getRawParameter(parameterIndex); } @Override public Object getObject(String parameterName) throws SQLException { checkClosed(); - Object value = this.parameterHandler.getParameter(parameterName); - this.lastReadWasNull = (value == null); - return value; + return getRawParameter(parameterName); } @Override @@ -523,8 +529,7 @@ public T getObject(int parameterIndex, Class type) throws SQLException { if (type == null) { throw new BigQueryJdbcException("Type cannot be null."); } - Object value = this.parameterHandler.getParameter(parameterIndex); - this.lastReadWasNull = (value == null); + Object value = getRawParameter(parameterIndex); if (value == null) { return null; } @@ -541,8 +546,7 @@ public T getObject(String parameterName, Class type) throws SQLException if (type == null) { throw new BigQueryJdbcException("Type cannot be null."); } - Object value = this.parameterHandler.getParameter(parameterName); - this.lastReadWasNull = (value == null); + Object value = getRawParameter(parameterName); if (value == null) { return null; } @@ -554,20 +558,18 @@ public T getObject(String parameterName, Class type) throws SQLException @Override public Ref getRef(int parameterIndex) throws SQLException { - // Auto-generated method stub - return null; + throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override public Ref getRef(String parameterName) throws SQLException { - // Auto-generated method stub - return null; + throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override public RowId getRowId(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof RowId) { return (RowId) param; } @@ -577,7 +579,7 @@ public RowId getRowId(int parameterIndex) throws SQLException { @Override public RowId getRowId(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof RowId) { return (RowId) param; } @@ -586,20 +588,18 @@ public RowId getRowId(String parameterName) throws SQLException { @Override public SQLXML getSQLXML(int parameterIndex) throws SQLException { - // Auto-generated method stub - return null; + throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override public SQLXML getSQLXML(String parameterName) throws SQLException { - // Auto-generated method stub - return null; + throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override public short getShort(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Short) { return (Short) param; } @@ -613,7 +613,7 @@ public short getShort(int parameterIndex) throws SQLException { @Override public short getShort(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Short) { return (Short) param; } @@ -627,7 +627,7 @@ public short getShort(String parameterName) throws SQLException { @Override public String getString(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof String) { return param.toString(); } @@ -637,7 +637,7 @@ public String getString(int parameterIndex) throws SQLException { @Override public String getString(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof String) { return param.toString(); } @@ -647,7 +647,7 @@ public String getString(String parameterName) throws SQLException { @Override public Time getTime(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Time) { return (Time) param; } @@ -660,7 +660,7 @@ public Time getTime(int parameterIndex) throws SQLException { @Override public Time getTime(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Time) { return (Time) param; } @@ -674,7 +674,6 @@ public Time getTime(String parameterName) throws SQLException { public Time getTime(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Time time = getTime(parameterIndex); - this.lastReadWasNull = (time == null); return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, calendar); } @@ -682,14 +681,13 @@ public Time getTime(int parameterIndex, Calendar calendar) throws SQLException { public Time getTime(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Time time = getTime(parameterName); - this.lastReadWasNull = (time == null); return BigQueryTypeCoercionUtility.convertTimeWithCalendar(time, calendar); } @Override public Timestamp getTimestamp(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof Timestamp) { return (Timestamp) param; } @@ -702,7 +700,7 @@ public Timestamp getTimestamp(int parameterIndex) throws SQLException { @Override public Timestamp getTimestamp(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof Timestamp) { return (Timestamp) param; } @@ -716,7 +714,6 @@ public Timestamp getTimestamp(String parameterName) throws SQLException { public Timestamp getTimestamp(int parameterIndex, Calendar calendar) throws SQLException { checkClosed(); Timestamp ts = getTimestamp(parameterIndex); - this.lastReadWasNull = (ts == null); return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, calendar); } @@ -724,14 +721,13 @@ public Timestamp getTimestamp(int parameterIndex, Calendar calendar) throws SQLE public Timestamp getTimestamp(String parameterName, Calendar calendar) throws SQLException { checkClosed(); Timestamp ts = getTimestamp(parameterName); - this.lastReadWasNull = (ts == null); return BigQueryTypeCoercionUtility.convertTimestampWithCalendar(ts, calendar); } @Override public URL getURL(int parameterIndex) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterIndex); + Object param = getRawParameter(parameterIndex); if (param instanceof URL) { return (URL) param; } @@ -741,7 +737,7 @@ public URL getURL(int parameterIndex) throws SQLException { @Override public URL getURL(String parameterName) throws SQLException { checkClosed(); - Object param = this.parameterHandler.getParameter(parameterName); + Object param = getRawParameter(parameterName); if (param instanceof URL) { return (URL) param; } From f3c27ff6f56cee6b2eab00b887150d91dc20064b Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 13:59:02 -0400 Subject: [PATCH 6/7] lint --- .../jdbc/BigQueryCallableStatement.java | 21 ++++++++++++------- .../jdbc/BigQueryPreparedStatement.java | 15 ++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java index e902b2c92eaa..dfde72722de8 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryCallableStatement.java @@ -783,7 +783,8 @@ public void registerOutParameter(String parameterName, int sqlType) throws SQLEx @Override public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { LOG.finer( - "registerOutParameter: parameterIndex %s, sqlType %s, scale %s", parameterIndex, sqlType, scale); + "registerOutParameter: parameterIndex %s, sqlType %s, scale %s", + parameterIndex, sqlType, scale); checkClosed(); if (sqlType != Types.NUMERIC && sqlType != Types.DECIMAL) { IllegalArgumentException ex = @@ -817,9 +818,11 @@ public void registerOutParameter(int parameterIndex, int sqlType, String typeNam } @Override - public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { + public void registerOutParameter(String parameterName, int sqlType, int scale) + throws SQLException { LOG.finer( - "registerOutParameter: parameterName %s, sqlType %s, scale %s", parameterName, sqlType, scale); + "registerOutParameter: parameterName %s, sqlType %s, scale %s", + parameterName, sqlType, scale); checkClosed(); if (sqlType != Types.NUMERIC && sqlType != Types.DECIMAL) { IllegalArgumentException ex = @@ -858,12 +861,14 @@ public void setAsciiStream(String parameterName, InputStream value) throws SQLEx } @Override - public void setAsciiStream(String parameterName, InputStream value, int length) throws SQLException { + public void setAsciiStream(String parameterName, InputStream value, int length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @Override - public void setAsciiStream(String parameterName, InputStream value, long length) throws SQLException { + public void setAsciiStream(String parameterName, InputStream value, long length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @@ -884,7 +889,8 @@ public void setBinaryStream(String parameterName, InputStream value) throws SQLE } @Override - public void setBinaryStream(String parameterName, InputStream value, int length) throws SQLException { + public void setBinaryStream(String parameterName, InputStream value, int length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("Data type not supported"); } @@ -1195,7 +1201,8 @@ public void setTimestamp(String parameterName, Timestamp value) throws SQLExcept } @Override - public void setTimestamp(String parameterName, Timestamp value, Calendar calendar) throws SQLException { + public void setTimestamp(String parameterName, Timestamp value, Calendar calendar) + throws SQLException { checkClosed(); if (value == null) { setNull(parameterName, Types.TIMESTAMP); diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java index 233a9b9b084e..fffb57fa4554 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java @@ -233,19 +233,22 @@ public void setTimestamp(int parameterIndex, Timestamp value) throws SQLExceptio } @Override - public void setAsciiStream(int parameterIndex, InputStream value, int length) throws SQLException { + public void setAsciiStream(int parameterIndex, InputStream value, int length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setAsciiStream is not supported."); } @Override @Deprecated @SuppressWarnings("deprecation") - public void setUnicodeStream(int parameterIndex, InputStream value, int length) throws SQLException { + public void setUnicodeStream(int parameterIndex, InputStream value, int length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setUnicodeStream is not supported."); } @Override - public void setBinaryStream(int parameterIndex, InputStream value, int length) throws SQLException { + public void setBinaryStream(int parameterIndex, InputStream value, int length) + throws SQLException { throw new BigQueryJdbcSqlFeatureNotSupportedException("setBinaryStream is not supported."); } @@ -563,13 +566,15 @@ public void setTime(int parameterIndex, Time value, Calendar calendar) throws SQ } @Override - public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) throws SQLException { + public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) + throws SQLException { checkClosed(); if (value == null) { setNull(parameterIndex, Types.TIMESTAMP); return; } - setTimestamp(parameterIndex, BigQueryTypeCoercionUtility.convertTimestampWithCalendar(value, calendar)); + setTimestamp( + parameterIndex, BigQueryTypeCoercionUtility.convertTimestampWithCalendar(value, calendar)); } @Override From 749f5fcc9078622be4cd1bc2848c9e4ce271266d Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 21 Jul 2026 14:17:02 -0400 Subject: [PATCH 7/7] bind date/time to temoral classes intead of String --- .../jdbc/BigQueryPreparedStatement.java | 10 ++++------ .../jdbc/BigQueryTypeCoercionUtility.java | 19 +++++++++++++++++-- .../BigQueryPreparedStatementSettersTest.java | 14 +++++++------- .../bigquery/jdbc/it/ITConnectionTest.java | 13 +++---------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java index fffb57fa4554..d7413d660639 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatement.java @@ -207,7 +207,7 @@ public void setDate(int parameterIndex, Date value) throws SQLException { setNull(parameterIndex, Types.DATE); return; } - this.parameterHandler.setParameter(parameterIndex, value.toString(), String.class); + this.parameterHandler.setParameter(parameterIndex, value, Date.class); } @Override @@ -217,7 +217,7 @@ public void setTime(int parameterIndex, Time value) throws SQLException { setNull(parameterIndex, Types.TIME); return; } - this.parameterHandler.setParameter(parameterIndex, value.toString(), String.class); + this.parameterHandler.setParameter(parameterIndex, value, Time.class); } @Override @@ -227,9 +227,7 @@ public void setTimestamp(int parameterIndex, Timestamp value) throws SQLExceptio setNull(parameterIndex, Types.TIMESTAMP); return; } - Timestamp copy = new Timestamp(value.getTime()); - copy.setNanos((value.getNanos() / 1000) * 1000); - this.parameterHandler.setParameter(parameterIndex, copy.toString(), String.class); + this.parameterHandler.setParameter(parameterIndex, value, Timestamp.class); } @Override @@ -552,7 +550,7 @@ public void setDate(int parameterIndex, Date value, Calendar calendar) throws SQ setNull(parameterIndex, Types.DATE); return; } - setDate(parameterIndex, BigQueryTypeCoercionUtility.convertDateWithCalendar(value, calendar)); + setDate(parameterIndex, BigQueryTypeCoercionUtility.convertDateToCalendar(value, calendar)); } @Override diff --git a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercionUtility.java b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercionUtility.java index 931fa0afc644..aa21307db1ef 100644 --- a/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercionUtility.java +++ b/java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercionUtility.java @@ -63,8 +63,13 @@ static Calendar getSafeCalendar(Calendar cal) { } /** - * Converts a java.sql.Date by shifting its wall-clock year, month, and day fields into the target - * Calendar's timezone per JDBC specification. + * Converts a {@link Date} for reading/outbound operations (e.g., {@code getDate(..., Calendar)}) + * by shifting its wall-clock year, month, and day fields into the target {@link Calendar}'s + * timezone per the JDBC specification. + * + * @param date the date in system-default time representation + * @param cal the target Calendar containing the desired timezone + * @return the adjusted Date starting at 00:00:00 in the target Calendar's timezone */ static Date convertDateWithCalendar(Date date, Calendar cal) { if (date == null || cal == null) { @@ -80,6 +85,16 @@ static Date convertDateWithCalendar(Date date, Calendar cal) { return new Date(zdt.toInstant().toEpochMilli()); } + /** + * Converts a {@link Date} for writing/inbound parameter setting operations (e.g., {@code + * setDate(..., Calendar)}) by extracting its local date fields as interpreted in the target + * {@link Calendar}'s timezone and normalizing them back into start-of-day in the system-default + * timezone. + * + * @param date the date instant specified relative to the target Calendar + * @param cal the Calendar containing the source timezone + * @return the normalized Date starting at 00:00:00 in the system-default timezone + */ static Date convertDateToCalendar(Date date, Calendar cal) { if (date == null || cal == null) { return date; diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatementSettersTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatementSettersTest.java index 60cc9b8d4a6d..29175fee5122 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatementSettersTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryPreparedStatementSettersTest.java @@ -203,7 +203,7 @@ public void testSetDateWithCalendar() throws Exception { Date date = new Date(1700000000000L); // 2023-11-14 preparedStatement.setDate(1, date, cal); - assertEquals(String.class, preparedStatement.parameterHandler.getType(1)); + assertEquals(Date.class, preparedStatement.parameterHandler.getType(1)); assertEquals(originalMillis, cal.getTimeInMillis()); } @@ -215,7 +215,7 @@ public void testSetTimeWithCalendar() throws Exception { Time time = new Time(43200000L); // 12:00:00 preparedStatement.setTime(1, time, cal); - assertEquals(String.class, preparedStatement.parameterHandler.getType(1)); + assertEquals(Time.class, preparedStatement.parameterHandler.getType(1)); assertEquals(originalMillis, cal.getTimeInMillis()); } @@ -227,7 +227,7 @@ public void testSetTimestampWithCalendar() throws Exception { Timestamp ts = new Timestamp(1700000000000L); preparedStatement.setTimestamp(1, ts, cal); - assertEquals(String.class, preparedStatement.parameterHandler.getType(1)); + assertEquals(Timestamp.class, preparedStatement.parameterHandler.getType(1)); assertEquals(originalMillis, cal.getTimeInMillis()); } @@ -255,18 +255,18 @@ public void testGetMetaData() throws Exception { public void testSetObjectWithJavaTime() throws Exception { LocalDate localDate = LocalDate.of(2025, 12, 3); preparedStatement.setObject(1, localDate); - assertEquals(String.class, preparedStatement.parameterHandler.getType(1)); + assertEquals(Date.class, preparedStatement.parameterHandler.getType(1)); LocalTime localTime = LocalTime.of(12, 30, 0); preparedStatement.setObject(2, localTime); - assertEquals(String.class, preparedStatement.parameterHandler.getType(2)); + assertEquals(Time.class, preparedStatement.parameterHandler.getType(2)); LocalDateTime localDateTime = LocalDateTime.of(2025, 12, 3, 12, 30, 0); preparedStatement.setObject(3, localDateTime); - assertEquals(String.class, preparedStatement.parameterHandler.getType(3)); + assertEquals(Timestamp.class, preparedStatement.parameterHandler.getType(3)); Instant instant = Instant.now(); preparedStatement.setObject(4, instant); - assertEquals(String.class, preparedStatement.parameterHandler.getType(4)); + assertEquals(Timestamp.class, preparedStatement.parameterHandler.getType(4)); } } diff --git a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java index 79a8f398f0cf..506edf807e26 100644 --- a/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java +++ b/java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITConnectionTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.cloud.ServiceOptions; -import java.sql.Array; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -341,15 +340,9 @@ public void testCreateSQLXML() throws SQLException { @Test public void testCreateArray() throws SQLException { Connection connection = DriverManager.getConnection(ITBase.connectionUrl); - try { - Array array = connection.createArrayOf("INTEGER", new Object[] {1, 2, 3}); - assertNotNull(array); - - array.free(); // Remember to free resources - } catch (SQLException e) { - e.printStackTrace(); - } - connection.close(); + assertThrows( + SQLFeatureNotSupportedException.class, + () -> connection.createArrayOf("INTEGER", new Object[] {1, 2, 3})); } @Test