77import com .clickhouse .client .api .query .QuerySettings ;
88import com .clickhouse .client .api .sql .SQLUtils ;
99import com .clickhouse .jdbc .internal .ExceptionUtils ;
10+ import com .clickhouse .jdbc .internal .FeatureManager ;
1011import com .clickhouse .jdbc .internal .ParsedStatement ;
1112import org .slf4j .Logger ;
1213import org .slf4j .LoggerFactory ;
@@ -29,6 +30,7 @@ public class StatementImpl implements Statement, JdbcV2Wrapper {
2930 ConnectionImpl connection ;
3031 protected int queryTimeout ;
3132 protected boolean isPoolable = false ; // Statement is not poolable by default
33+ private final FeatureManager featureManager ;
3234
3335 // State
3436 private volatile boolean closed ;
@@ -41,7 +43,7 @@ public class StatementImpl implements Statement, JdbcV2Wrapper {
4143 protected volatile String lastQueryId ;
4244 private long maxRows ;
4345 private boolean closeOnCompletion ;
44- private boolean resultSetAutoClose ;
46+ private final boolean resultSetAutoClose ;
4547 private int maxFieldSize ;
4648 private boolean escapeProcessingEnabled ;
4749
@@ -60,6 +62,7 @@ public StatementImpl(ConnectionImpl connection) throws SQLException {
6062 this .resultSets = new ConcurrentLinkedQueue <>();
6163 this .resultSetAutoClose = connection .getJdbcConfig ().isSet (DriverProperties .RESULTSET_AUTO_CLOSE );
6264 this .escapeProcessingEnabled = true ;
65+ this .featureManager = new FeatureManager (connection .getJdbcConfig ());
6366 }
6467
6568 protected void ensureOpen () throws SQLException {
@@ -323,6 +326,7 @@ public void clearWarnings() throws SQLException {
323326
324327 @ Override
325328 public void setCursorName (String name ) throws SQLException {
329+ featureManager .unsupportedFeatureThrow ("setCursorName(String)" , true );
326330 ensureOpen ();
327331 }
328332
@@ -458,22 +462,22 @@ public boolean getMoreResults(int current) throws SQLException {
458462 return false ; // false indicates that no more results (or it is an update count)
459463 }
460464
461- // @Override
465+ // @Override -- because doesn't exist in Java 8
462466 public String enquoteLiteral (String val ) throws SQLException {
463467 return SQLUtils .enquoteLiteral (val );
464468 }
465469
466- // @Override
470+ // @Override -- because doesn't exist in Java 8
467471 public String enquoteIdentifier (String identifier , boolean alwaysQuote ) throws SQLException {
468472 return SQLUtils .enquoteIdentifier (identifier , alwaysQuote );
469473 }
470474
471- // @Override
475+ // @Override -- because doesn't exist in Java 8
472476 public boolean isSimpleIdentifier (String identifier ) throws SQLException {
473477 return SQLUtils .isSimpleIdentifier (identifier );
474478 }
475479
476- // @Override
480+ // @Override -- because doesn't exist in Java 8
477481 public String enquoteNCharLiteral (String val ) throws SQLException {
478482 if (val == null ) {
479483 throw new NullPointerException ();
@@ -489,31 +493,37 @@ public ResultSet getGeneratedKeys() throws SQLException {
489493
490494 @ Override
491495 public int executeUpdate (String sql , int autoGeneratedKeys ) throws SQLException {
496+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, int)" , autoGeneratedKeys != Statement .NO_GENERATED_KEYS );
492497 return executeUpdate (sql );
493498 }
494499
495500 @ Override
496501 public int executeUpdate (String sql , int [] columnIndexes ) throws SQLException {
502+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, int[])" );
497503 return executeUpdate (sql );
498504 }
499505
500506 @ Override
501507 public int executeUpdate (String sql , String [] columnNames ) throws SQLException {
508+ featureManager .unsupportedFeatureThrow ("executeUpdate(String, String[])" );
502509 return executeUpdate (sql );
503510 }
504511
505512 @ Override
506513 public boolean execute (String sql , int autoGeneratedKeys ) throws SQLException {
514+ featureManager .unsupportedFeatureThrow ("execute(String, int)" , autoGeneratedKeys != Statement .NO_GENERATED_KEYS );
507515 return execute (sql );
508516 }
509517
510518 @ Override
511519 public boolean execute (String sql , int [] columnIndexes ) throws SQLException {
520+ featureManager .unsupportedFeatureThrow ("execute(String, int[])" );
512521 return execute (sql );
513522 }
514523
515524 @ Override
516525 public boolean execute (String sql , String [] columnNames ) throws SQLException {
526+ featureManager .unsupportedFeatureThrow ("execute(String, String[])" );
517527 return execute (sql );
518528 }
519529
@@ -573,20 +583,23 @@ public long getLargeUpdateCount() throws SQLException {
573583 public void setLargeMaxRows (long max ) throws SQLException {
574584 ensureOpen ();
575585 maxRows = max ;
576- // This method override user set overflow mode on purpose:
577- // 1. Spec clearly states that after calling this method with a limit > 0 all rows over limit are dropped.
578- // 2. Calling this method should not cause throwing exception for future queries what only `break` can guarantee
579- // 3. If user wants different behavior then they are can use connection properties.
580- if (max > 0 ) {
581- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), maxRows );
582- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
583- ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
584- } else {
585- // overriding potential client settings (set thru connection setup)
586- // there is no no limit value so we use very large limit.
587- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), Long .MAX_VALUE );
588- localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
589- ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
586+
587+ if (connection .getJdbcConfig ().isFlagSet (DriverProperties .USE_MAX_RESULT_ROWS )) {
588+ // This method override user set overflow mode on purpose:
589+ // 1. Spec clearly states that after calling this method with a limit > 0 all rows over limit are dropped.
590+ // 2. Calling this method should not cause throwing exception for future queries what only `break` can guarantee
591+ // 3. If user wants different behavior then they are can use connection properties.
592+ if (max > 0 ) {
593+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), maxRows );
594+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
595+ ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
596+ } else {
597+ // overriding potential client settings (set thru connection setup)
598+ // there is no no limit value so we use very large limit.
599+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .MAX_RESULT_ROWS ), Long .MAX_VALUE );
600+ localSettings .setOption (ClientConfigProperties .serverSetting (ServerSettings .RESULT_OVERFLOW_MODE ),
601+ ServerSettings .RESULT_OVERFLOW_MODE_BREAK );
602+ }
590603 }
591604 }
592605
@@ -611,16 +624,19 @@ public long executeLargeUpdate(String sql) throws SQLException {
611624
612625 @ Override
613626 public long executeLargeUpdate (String sql , int autoGeneratedKeys ) throws SQLException {
627+ featureManager .unsupportedFeatureThrow ("executeLargeUpdate(String, int)" , autoGeneratedKeys != Statement .NO_GENERATED_KEYS );
614628 return executeLargeUpdate (sql );
615629 }
616630
617631 @ Override
618632 public long executeLargeUpdate (String sql , int [] columnIndexes ) throws SQLException {
633+ featureManager .unsupportedFeatureThrow ("executeLargeUpdate(String, int[])" );
619634 return executeLargeUpdate (sql );
620635 }
621636
622637 @ Override
623638 public long executeLargeUpdate (String sql , String [] columnNames ) throws SQLException {
639+ featureManager .unsupportedFeatureThrow ("executeLargeUpdate(String, String[])" );
624640 return executeLargeUpdate (sql );
625641 }
626642
0 commit comments