-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(bigquery-jdbc): implement PreparedStatement ParameterMetaData and Calendar date setters #13794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Neenu1995
wants to merge
4
commits into
ps-part1-setters
Choose a base branch
from
ps-part2-metadata
base: ps-part1-setters
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
defb44a
feat(bigquery-jdbc): implement PreparedStatement ParameterMetaData an…
Neenu1995 12348a6
add date/time handling in setObject
Neenu1995 1e293fb
fix(jdbc): clone Calendar parameter in date/time setters to prevent m…
Neenu1995 7611ee7
Merge branch 'ps-part1-setters' into ps-part2-metadata
Neenu1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
...bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryParameterMetaData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.bigquery.jdbc; | ||
|
|
||
| import com.google.cloud.bigquery.StandardSQLTypeName; | ||
| import com.google.cloud.bigquery.exception.BigQueryJdbcException; | ||
| import java.sql.ParameterMetaData; | ||
| import java.sql.SQLException; | ||
| import java.sql.Types; | ||
|
|
||
| /** ParameterMetaData implementation for BigQuery JDBC PreparedStatement parameters. */ | ||
| class BigQueryParameterMetaData implements ParameterMetaData { | ||
| private final int parameterCount; | ||
| private final BigQueryParameterHandler parameterHandler; | ||
|
|
||
| BigQueryParameterMetaData(int parameterCount, BigQueryParameterHandler parameterHandler) { | ||
| this.parameterCount = parameterCount; | ||
| this.parameterHandler = parameterHandler; | ||
| } | ||
|
|
||
| private void checkValidIndex(int param) throws SQLException { | ||
| if (param < 1 || param > this.parameterCount) { | ||
| throw new BigQueryJdbcException("Invalid parameter index: " + param); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int getParameterCount() { | ||
| return this.parameterCount; | ||
| } | ||
|
|
||
| @Override | ||
| public int isNullable(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| return parameterNullable; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSigned(int param) throws SQLException { | ||
| int type = getParameterType(param); | ||
| return type == Types.SMALLINT | ||
| || type == Types.TINYINT | ||
| || type == Types.INTEGER | ||
| || type == Types.BIGINT | ||
| || type == Types.FLOAT | ||
| || type == Types.DOUBLE | ||
| || type == Types.DECIMAL | ||
| || type == Types.NUMERIC; | ||
| } | ||
|
|
||
| @Override | ||
| public int getPrecision(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| StandardSQLTypeName sqlType = getStandardSQLTypeName(param); | ||
| if (sqlType != null) { | ||
| BigQueryJdbcTypeMappings.ColumnTypeInfo typeInfo = | ||
| BigQueryJdbcTypeMappings.STANDARD_TYPE_INFO.get(sqlType); | ||
| if (typeInfo != null && typeInfo.columnSize != null) { | ||
| return typeInfo.columnSize; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int getScale(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| StandardSQLTypeName sqlType = getStandardSQLTypeName(param); | ||
| if (sqlType != null) { | ||
| BigQueryJdbcTypeMappings.ColumnTypeInfo typeInfo = | ||
| BigQueryJdbcTypeMappings.STANDARD_TYPE_INFO.get(sqlType); | ||
| if (typeInfo != null && typeInfo.decimalDigits != null) { | ||
| return typeInfo.decimalDigits; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public int getParameterType(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| StandardSQLTypeName sqlType = getStandardSQLTypeName(param); | ||
| if (sqlType != null) { | ||
| Integer jdbcType = BigQueryJdbcTypeMappings.standardSQLToJavaSqlTypesMapping.get(sqlType); | ||
| if (jdbcType != null) { | ||
| return jdbcType; | ||
| } | ||
| } | ||
| return Types.OTHER; | ||
| } | ||
|
|
||
| @Override | ||
| public String getParameterTypeName(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| StandardSQLTypeName sqlType = getStandardSQLTypeName(param); | ||
| return sqlType != null ? sqlType.name() : "UNKNOWN"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getParameterClassName(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| StandardSQLTypeName sqlType = getStandardSQLTypeName(param); | ||
| if (sqlType != null) { | ||
| Class<?> clazz = BigQueryJdbcTypeMappings.standardSQLToJavaTypeMapping.get(sqlType); | ||
| if (clazz != null) { | ||
| return clazz.getName(); | ||
| } | ||
| } | ||
| Class<?> boundType = this.parameterHandler.getType(param); | ||
| if (boundType != null) { | ||
| return boundType.getName(); | ||
| } | ||
| return Object.class.getName(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getParameterMode(int param) throws SQLException { | ||
| checkValidIndex(param); | ||
| return parameterModeIn; | ||
| } | ||
|
|
||
| private StandardSQLTypeName getStandardSQLTypeName(int param) { | ||
| if (this.parameterHandler != null) { | ||
| StandardSQLTypeName sqlType = this.parameterHandler.getSqlType(param); | ||
| if (sqlType != null) { | ||
| return sqlType; | ||
| } | ||
| Class<?> javaType = this.parameterHandler.getType(param); | ||
| if (javaType != null) { | ||
| try { | ||
| return BigQueryJdbcTypeMappings.classToType(javaType); | ||
| } catch (SQLException ignored) { | ||
| // fall back to default | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T unwrap(Class<T> iface) throws SQLException { | ||
| if (iface.isInstance(this)) { | ||
| return iface.cast(this); | ||
| } | ||
| throw new BigQueryJdbcException("Cannot unwrap to " + iface.getName()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWrapperFor(Class<?> iface) throws SQLException { | ||
| return iface != null && iface.isInstance(this); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.