99import com .clickhouse .data .ClickHouseColumn ;
1010import com .clickhouse .data .ClickHouseDataType ;
1111import com .clickhouse .jdbc .internal .ExceptionUtils ;
12+ import com .clickhouse .jdbc .internal .FeatureManager ;
1213import com .clickhouse .jdbc .internal .JdbcConfiguration ;
1314import com .clickhouse .jdbc .internal .JdbcUtils ;
1415import com .clickhouse .jdbc .internal .ParsedPreparedStatement ;
3637import java .sql .Statement ;
3738import java .sql .Struct ;
3839import java .time .Duration ;
39- import java .util .Arrays ;
4040import java .util .Calendar ;
4141import java .util .Collections ;
4242import java .util .HashSet ;
43- import java .util .List ;
4443import java .util .Map ;
4544import java .util .Properties ;
4645import java .util .Set ;
4746import java .util .concurrent .Executor ;
48- import java .util .stream .Collectors ;
4947
5048public class ConnectionImpl implements Connection , JdbcV2Wrapper {
5149 private static final Logger log = LoggerFactory .getLogger (ConnectionImpl .class );
@@ -69,6 +67,8 @@ public class ConnectionImpl implements Connection, JdbcV2Wrapper {
6967
7068 private final SqlParser sqlParser ;
7169
70+ private final FeatureManager featureManager ;
71+
7272 public ConnectionImpl (String url , Properties info ) throws SQLException {
7373 try {
7474 this .url = url ;//Raw URL
@@ -117,6 +117,7 @@ public ConnectionImpl(String url, Properties info) throws SQLException {
117117 this .defaultCalendar = Calendar .getInstance ();
118118
119119 this .sqlParser = new SqlParser ();
120+ this .featureManager = new FeatureManager (this .config );
120121 } catch (SQLException e ) {
121122 throw e ;
122123 } catch (Exception e ) {
@@ -167,10 +168,7 @@ public PreparedStatement prepareStatement(String sql) throws SQLException {
167168 @ Override
168169 public CallableStatement prepareCall (String sql ) throws SQLException {
169170 ensureOpen ();
170- if (!config .isIgnoreUnsupportedRequests ()) {
171- throw new SQLFeatureNotSupportedException ("CallableStatement not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
172- }
173-
171+ featureManager .unsupportedFeatureThrow ("prepareCall(String sql)" );
174172 return null ;
175173 }
176174
@@ -184,10 +182,7 @@ public String nativeSQL(String sql) throws SQLException {
184182 @ Override
185183 public void setAutoCommit (boolean autoCommit ) throws SQLException {
186184 ensureOpen ();
187-
188- if (!config .isIgnoreUnsupportedRequests () && !autoCommit ) {
189- throw new SQLFeatureNotSupportedException ("setAutoCommit = false not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
190- }
185+ featureManager .unsupportedFeatureThrow ("setAutoCommit(false)" , !autoCommit );
191186 }
192187
193188 @ Override
@@ -198,16 +193,12 @@ public boolean getAutoCommit() throws SQLException {
198193
199194 @ Override
200195 public void commit () throws SQLException {
201- if (!config .isIgnoreUnsupportedRequests () ) {
202- throw new SQLFeatureNotSupportedException ("Commit/Rollback not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
203- }
196+ featureManager .unsupportedFeatureThrow ("commit()" );
204197 }
205198
206199 @ Override
207200 public void rollback () throws SQLException {
208- if (!config .isIgnoreUnsupportedRequests ()) {
209- throw new SQLFeatureNotSupportedException ("Commit/Rollback not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
210- }
201+ featureManager .unsupportedFeatureThrow ("rollback()" );
211202 }
212203
213204 @ Override
@@ -260,9 +251,7 @@ public String getCatalog() throws SQLException {
260251 @ Override
261252 public void setTransactionIsolation (int level ) throws SQLException {
262253 ensureOpen ();
263- if (!config .isIgnoreUnsupportedRequests () && TRANSACTION_NONE != level ) {
264- throw new SQLFeatureNotSupportedException ("setTransactionIsolation not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
265- }
254+ featureManager .unsupportedFeatureThrow ("setTransactionIsolation(TRANSACTION_NONE)" , TRANSACTION_NONE != level );
266255 }
267256
268257 @ Override
@@ -297,29 +286,21 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
297286 @ Override
298287 public CallableStatement prepareCall (String sql , int resultSetType , int resultSetConcurrency ) throws SQLException {
299288 ensureOpen ();
300- if (!config .isIgnoreUnsupportedRequests ()) {
301- throw new SQLFeatureNotSupportedException ("CallableStatement not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
302- }
303-
289+ featureManager .unsupportedFeatureThrow ("prepareCall(String sql, int resultSetType, int resultSetConcurrency)" );
304290 return null ;
305291 }
306292
307293 @ Override
308294 public Map <String , Class <?>> getTypeMap () throws SQLException {
309295 ensureOpen ();
310- if (!config .isIgnoreUnsupportedRequests ()) {
311- throw new SQLFeatureNotSupportedException ("getTypeMap not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
312- }
313-
314- return null ;
296+ featureManager .unsupportedFeatureThrow ("getTypeMap()" );
297+ return Collections .emptyMap ();
315298 }
316299
317300 @ Override
318301 public void setTypeMap (Map <String , Class <?>> map ) throws SQLException {
319302 ensureOpen ();
320- if (!config .isIgnoreUnsupportedRequests ()) {
321- throw new SQLFeatureNotSupportedException ("setTypeMap not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
322- }
303+ featureManager .unsupportedFeatureThrow ("setTypeMap(Map<String, Class<?>>)" );
323304 }
324305
325306 @ Override
@@ -343,37 +324,27 @@ public int getHoldability() throws SQLException {
343324 @ Override
344325 public Savepoint setSavepoint () throws SQLException {
345326 ensureOpen ();
346- if (!config .isIgnoreUnsupportedRequests ()) {
347- throw new SQLFeatureNotSupportedException ("Savepoint not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
348- }
349-
327+ featureManager .unsupportedFeatureThrow ("setSavepoint()" );
350328 return null ;
351329 }
352330
353331 @ Override
354332 public Savepoint setSavepoint (String name ) throws SQLException {
355333 ensureOpen ();
356- if (!config .isIgnoreUnsupportedRequests ()) {
357- throw new SQLFeatureNotSupportedException ("Savepoint not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
358- }
359-
334+ featureManager .unsupportedFeatureThrow ("setSavepoint(String name)" );
360335 return null ;
361336 }
362337
363338 @ Override
364339 public void rollback (Savepoint savepoint ) throws SQLException {
365340 ensureOpen ();
366- if (!config .isIgnoreUnsupportedRequests ()) {
367- throw new SQLFeatureNotSupportedException ("Commit/Rollback not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
368- }
341+ featureManager .unsupportedFeatureThrow ("rollback(Savepoint savepoint)" );
369342 }
370343
371344 @ Override
372345 public void releaseSavepoint (Savepoint savepoint ) throws SQLException {
373346 ensureOpen ();
374- if (!config .isIgnoreUnsupportedRequests ()) {
375- throw new SQLFeatureNotSupportedException ("Savepoint not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
376- }
347+ featureManager .unsupportedFeatureThrow ("releaseSavepoint(Savepoint savepoint)" );
377348 }
378349
379350 @ Override
@@ -429,10 +400,7 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
429400 @ Override
430401 public CallableStatement prepareCall (String sql , int resultSetType , int resultSetConcurrency , int resultSetHoldability ) throws SQLException {
431402 ensureOpen ();
432- if (!config .isIgnoreUnsupportedRequests ()) {
433- throw new SQLFeatureNotSupportedException ("CallableStatement not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
434- }
435-
403+ featureManager .unsupportedFeatureThrow ("prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)" );
436404 return null ;
437405 }
438406
@@ -472,40 +440,29 @@ public PreparedStatement prepareStatement(String sql, String[] columnNames) thro
472440 @ Override
473441 public Clob createClob () throws SQLException {
474442 ensureOpen ();
475- if (!config .isIgnoreUnsupportedRequests ()) {
476- throw new SQLFeatureNotSupportedException ("Clob not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
477- }
443+ featureManager .unsupportedFeatureThrow ("createClob()" );
478444
479445 return null ;
480446 }
481447
482448 @ Override
483449 public Blob createBlob () throws SQLException {
484450 ensureOpen ();
485- if (!config .isIgnoreUnsupportedRequests ()) {
486- throw new SQLFeatureNotSupportedException ("Blob not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
487- }
488-
451+ featureManager .unsupportedFeatureThrow ("createBlob()" );
489452 return null ;
490453 }
491454
492455 @ Override
493456 public NClob createNClob () throws SQLException {
494457 ensureOpen ();
495- if (!config .isIgnoreUnsupportedRequests ()) {
496- throw new SQLFeatureNotSupportedException ("NClob not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
497- }
498-
458+ featureManager .unsupportedFeatureThrow ("createNClob()" );
499459 return null ;
500460 }
501461
502462 @ Override
503463 public SQLXML createSQLXML () throws SQLException {
504464 ensureOpen ();
505- if (!config .isIgnoreUnsupportedRequests ()) {
506- throw new SQLFeatureNotSupportedException ("SQLXML not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
507- }
508-
465+ featureManager .unsupportedFeatureThrow ("createSQLXML()" );
509466 return null ;
510467 }
511468
@@ -586,7 +543,7 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
586543 String clickhouseDataTypeName = (typeName .substring (0 , endPos )).trim ();
587544 ClickHouseDataType dataType = ClickHouseDataType .valueOf (clickhouseDataTypeName );
588545 if (dataType .equals (ClickHouseDataType .Array )) {
589- throw new SQLFeatureNotSupportedException ("Array cannot be a base type. In case of nested array provide most deep element type name." );
546+ throw new SQLException ("Array cannot be a base type. In case of nested array provide most deep element type name." );
590547 }
591548 try {
592549 return new com .clickhouse .jdbc .types .Array (elements , typeName ,
@@ -626,26 +583,19 @@ public String getSchema() throws SQLException {
626583
627584 @ Override
628585 public void abort (Executor executor ) throws SQLException {
629- if (!config .isIgnoreUnsupportedRequests ()) {
630- throw new SQLFeatureNotSupportedException ("abort not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
631- }
586+ featureManager .unsupportedFeatureThrow ("abort()" );
632587 }
633588
634589 @ Override
635590 public void setNetworkTimeout (Executor executor , int milliseconds ) throws SQLException {
636591 //TODO: Should this be supported?
637- if (!config .isIgnoreUnsupportedRequests ()) {
638- throw new SQLFeatureNotSupportedException ("setNetworkTimeout not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
639- }
592+ featureManager .unsupportedFeatureThrow ("setNetworkTimeout()" );
640593 }
641594
642595 @ Override
643596 public int getNetworkTimeout () throws SQLException {
644597 //TODO: Should this be supported?
645- if (!config .isIgnoreUnsupportedRequests ()) {
646- throw new SQLFeatureNotSupportedException ("getNetworkTimeout not supported" , ExceptionUtils .SQL_STATE_FEATURE_NOT_SUPPORTED );
647- }
648-
598+ featureManager .unsupportedFeatureThrow ("getNetworkTimeout()" );
649599 return -1 ;
650600 }
651601
0 commit comments