Skip to content
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

No-op flags #2030

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 79 additions & 19 deletions jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,22 @@ public PreparedStatement prepareStatement(String sql) throws SQLException {
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this is totally valid exception because if this is called then NPE will be thrown anyway.
In most cases we can ignore parameters, but not a whole functionality.

throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
public String nativeSQL(String sql) throws SQLException {
checkOpen();
/// TODO: this is not implemented according to JDBC spec and may not be used.
throw new SQLFeatureNotSupportedException("nativeSQL not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("nativeSQL not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be return the same sql? + javadoc that it is not implemented according to the spec if flag is true

}

@Override
Expand Down Expand Up @@ -181,7 +189,7 @@ public DatabaseMetaData getMetaData() throws SQLException {
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
checkOpen();
if (readOnly) {
if (!config.isIgnoreUnsupportedRequests() && readOnly) {
throw new SQLFeatureNotSupportedException("read-only=true unsupported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}
Expand All @@ -206,7 +214,7 @@ public String getCatalog() throws SQLException {
@Override
public void setTransactionIsolation(int level) throws SQLException {
checkOpen();
if (TRANSACTION_NONE != level) {
if (!config.isIgnoreUnsupportedRequests() && TRANSACTION_NONE != level) {
throw new SQLFeatureNotSupportedException("setTransactionIsolation not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}
Expand Down Expand Up @@ -243,19 +251,29 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same - this is whole functionality and it will be NPE anyway. so Exception should be thrown all the time

}

@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("getTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("getTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of missing functionality. I would return an empty map at least to not cause NPE.
But we need to create an issue and fill this properly

}

@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("setTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("setTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}

@Override
Expand All @@ -273,13 +291,21 @@ public int getHoldability() throws SQLException {
@Override
public Savepoint setSavepoint() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
public Savepoint setSavepoint(String name) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
Expand All @@ -293,7 +319,9 @@ public void rollback(Savepoint savepoint) throws SQLException {
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}

@Override
Expand All @@ -311,7 +339,11 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
Expand Down Expand Up @@ -350,25 +382,41 @@ public PreparedStatement prepareStatement(String sql, String[] columnNames) thro
@Override
public Clob createClob() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("Clob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Clob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
public Blob createBlob() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("Blob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Blob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
public NClob createNClob() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("NClob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("NClob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
public SQLXML createSQLXML() throws SQLException {
checkOpen();
throw new SQLFeatureNotSupportedException("SQLXML not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("SQLXML not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
Expand Down Expand Up @@ -445,7 +493,11 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
//TODO: Should this be supported?
throw new SQLFeatureNotSupportedException("createStruct not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("createStruct not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return null;
}

@Override
Expand All @@ -462,19 +514,27 @@ public String getSchema() throws SQLException {

@Override
public void abort(Executor executor) throws SQLException {
throw new SQLFeatureNotSupportedException("abort not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("abort not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}

@Override
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
//TODO: Should this be supported?
throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}

@Override
public int getNetworkTimeout() throws SQLException {
//TODO: Should this be supported?
throw new SQLFeatureNotSupportedException("getNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!config.isIgnoreUnsupportedRequests()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems something missing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it may be a useful timeout - we should take it from client.

throw new SQLFeatureNotSupportedException("getNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}

return -1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ public void setCharacterStream(int parameterIndex, Reader x, int length) throws
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
checkClosed();
throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
if (!connection.config.isIgnoreUnsupportedRequests()) {
throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
}

@Override
Expand Down
Loading
Loading