Skip to content

Commit 155be2f

Browse files
committed
Add support for SOURCE special CQL command
and add method setOptionSet in CassandraConnection
1 parent 7c12829 commit 155be2f

21 files changed

+683
-212
lines changed

Diff for: .editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ indent_size = 2
2525

2626
[{*.yml,*.yaml}]
2727
indent_size = 2
28+
29+
[*.cql]
30+
insert_final_newline = false

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to
55
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Add support for the special CQL command `SOURCE <filename>` in `CassandraStatement`.
10+
- Add a method `CassandraConnection.setOptionSet(OptionSet)` to programmatically define a custom compliance mode option
11+
set on a pre-existing connection.
12+
713
## [4.14.0] - 2024-12-24
814
### Added
915
- Add support for IPv6 addresses in JDBC URL (see PR [#62](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/62)).

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraConnection.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class CassandraConnection extends AbstractConnection implements Connectio
147147
private final boolean debugMode;
148148
private Properties clientInfo;
149149
private volatile boolean isClosed;
150-
private final OptionSet optionSet;
150+
private OptionSet optionSet = new Default();
151151
private DriverExecutionProfile activeExecutionProfile;
152152
private DriverExecutionProfile lastUsedExecutionProfile;
153153

@@ -683,6 +683,16 @@ public OptionSet getOptionSet() {
683683
return this.optionSet;
684684
}
685685

686+
/**
687+
* Sets the compliance mode option set used for the connection.
688+
*
689+
* @param optionSet The compliance mode option set used for the connection.
690+
*/
691+
public void setOptionSet(final OptionSet optionSet) {
692+
optionSet.setConnection(this);
693+
this.optionSet = optionSet;
694+
}
695+
686696
private OptionSet lookupOptionSet(final String property) {
687697
final ServiceLoader<OptionSet> loader = ServiceLoader.load(OptionSet.class);
688698
for (final OptionSet optionSet : loader) {

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraResultSet.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public class CassandraResultSet extends AbstractResultSet
204204
private boolean isClosed;
205205
// Result set from the Cassandra driver.
206206
private ResultSet driverResultSet;
207+
private final List<String> driverWarnings = new ArrayList<>();
207208

208209
/**
209210
* No argument constructor.
@@ -231,6 +232,9 @@ public class CassandraResultSet extends AbstractResultSet
231232
this.driverResultSet = resultSet;
232233
this.rowsIterator = resultSet.iterator();
233234
this.isClosed = false;
235+
if (!resultSet.getExecutionInfos().isEmpty()) {
236+
this.driverWarnings.addAll(resultSet.getExecutionInfo().getWarnings());
237+
}
234238

235239
// Initialize the column values from the first row.
236240
if (hasMoreRows()) {
@@ -255,8 +259,14 @@ public class CassandraResultSet extends AbstractResultSet
255259
this.fetchSize = statement.getFetchSize();
256260
this.isClosed = false;
257261

258-
// We have several result sets, but we will use only the first one for metadata needs.
262+
// We have several result sets, but we will use only the first one for metadata needs. However, we aggregate the
263+
// warnings of all the available result sets.
259264
this.driverResultSet = resultSets.get(0);
265+
for (final ResultSet rs : resultSets) {
266+
if (!rs.getExecutionInfos().isEmpty()) {
267+
this.driverWarnings.addAll(rs.getExecutionInfo().getWarnings());
268+
}
269+
}
260270

261271
// Now, we concatenate iterators of the different result sets into a single one.
262272
// This may lead to StackOverflowException when there are too many result sets.
@@ -1530,12 +1540,11 @@ public CqlVector<?> getVector(final String columnLabel) throws SQLException {
15301540
@Override
15311541
public SQLWarning getWarnings() throws SQLException {
15321542
checkNotClosed();
1533-
final List<String> driverWarnings = this.driverResultSet.getExecutionInfo().getWarnings();
1534-
if (!driverWarnings.isEmpty()) {
1543+
if (!this.driverWarnings.isEmpty()) {
15351544
SQLWarning firstWarning = null;
15361545
SQLWarning previousWarning = null;
15371546

1538-
for (final String warningMessage : driverWarnings) {
1547+
for (final String warningMessage : this.driverWarnings) {
15391548
final SQLWarning warning = new SQLWarning(warningMessage);
15401549
if (previousWarning == null) {
15411550
firstWarning = warning;

Diff for: src/main/java/com/ing/data/cassandra/jdbc/CassandraStatement.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.datastax.oss.driver.internal.core.cql.MultiPageResultSet;
2525
import com.datastax.oss.driver.internal.core.cql.SinglePageResultSet;
2626
import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures;
27+
import com.ing.data.cassandra.jdbc.commands.SpecialCommandExecutor;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
2930

@@ -62,8 +63,8 @@
6263
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.NO_RESULT_SET;
6364
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.TOO_MANY_QUERIES;
6465
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.WAS_CLOSED_STMT;
65-
import static com.ing.data.cassandra.jdbc.utils.SpecialCommandsUtil.containsSpecialCommands;
66-
import static com.ing.data.cassandra.jdbc.utils.SpecialCommandsUtil.getCommandExecutor;
66+
import static com.ing.data.cassandra.jdbc.commands.SpecialCommandsUtil.containsSpecialCommands;
67+
import static com.ing.data.cassandra.jdbc.commands.SpecialCommandsUtil.getCommandExecutor;
6768
import static org.apache.commons.lang3.StringUtils.countMatches;
6869

6970
/**
@@ -414,7 +415,7 @@ private com.datastax.oss.driver.api.core.cql.ResultSet executeSingleStatement(fi
414415

415416
// If the CQL statement is a special command, execute it using the appropriate special command executor and
416417
// return the result. Otherwise, execute the statement through the driver.
417-
final SpecialCommands.SpecialCommandExecutor commandExecutor = getCommandExecutor(cql);
418+
final SpecialCommandExecutor commandExecutor = getCommandExecutor(cql);
418419
if (commandExecutor != null) {
419420
return commandExecutor.execute(this, cql);
420421
}

Diff for: src/main/java/com/ing/data/cassandra/jdbc/SpecialCommands.java

-187
This file was deleted.

0 commit comments

Comments
 (0)