Skip to content

Commit

Permalink
Add support for SOURCE special CQL command
Browse files Browse the repository at this point in the history
and add method setOptionSet in CassandraConnection
  • Loading branch information
maximevw committed Dec 29, 2024
1 parent 7c12829 commit 155be2f
Show file tree
Hide file tree
Showing 21 changed files with 683 additions and 212 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ indent_size = 2

[{*.yml,*.yaml}]
indent_size = 2

[*.cql]
insert_final_newline = false
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add support for the special CQL command `SOURCE <filename>` in `CassandraStatement`.
- Add a method `CassandraConnection.setOptionSet(OptionSet)` to programmatically define a custom compliance mode option
set on a pre-existing connection.

## [4.14.0] - 2024-12-24
### Added
- Add support for IPv6 addresses in JDBC URL (see PR [#62](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/62)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class CassandraConnection extends AbstractConnection implements Connectio
private final boolean debugMode;
private Properties clientInfo;
private volatile boolean isClosed;
private final OptionSet optionSet;
private OptionSet optionSet = new Default();
private DriverExecutionProfile activeExecutionProfile;
private DriverExecutionProfile lastUsedExecutionProfile;

Expand Down Expand Up @@ -683,6 +683,16 @@ public OptionSet getOptionSet() {
return this.optionSet;
}

/**
* Sets the compliance mode option set used for the connection.
*
* @param optionSet The compliance mode option set used for the connection.
*/
public void setOptionSet(final OptionSet optionSet) {
optionSet.setConnection(this);
this.optionSet = optionSet;
}

private OptionSet lookupOptionSet(final String property) {
final ServiceLoader<OptionSet> loader = ServiceLoader.load(OptionSet.class);
for (final OptionSet optionSet : loader) {
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/com/ing/data/cassandra/jdbc/CassandraResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public class CassandraResultSet extends AbstractResultSet
private boolean isClosed;
// Result set from the Cassandra driver.
private ResultSet driverResultSet;
private final List<String> driverWarnings = new ArrayList<>();

/**
* No argument constructor.
Expand Down Expand Up @@ -231,6 +232,9 @@ public class CassandraResultSet extends AbstractResultSet
this.driverResultSet = resultSet;
this.rowsIterator = resultSet.iterator();
this.isClosed = false;
if (!resultSet.getExecutionInfos().isEmpty()) {
this.driverWarnings.addAll(resultSet.getExecutionInfo().getWarnings());
}

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

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

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

for (final String warningMessage : driverWarnings) {
for (final String warningMessage : this.driverWarnings) {
final SQLWarning warning = new SQLWarning(warningMessage);
if (previousWarning == null) {
firstWarning = warning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.datastax.oss.driver.internal.core.cql.MultiPageResultSet;
import com.datastax.oss.driver.internal.core.cql.SinglePageResultSet;
import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures;
import com.ing.data.cassandra.jdbc.commands.SpecialCommandExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,8 +63,8 @@
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.NO_RESULT_SET;
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.TOO_MANY_QUERIES;
import static com.ing.data.cassandra.jdbc.utils.ErrorConstants.WAS_CLOSED_STMT;
import static com.ing.data.cassandra.jdbc.utils.SpecialCommandsUtil.containsSpecialCommands;
import static com.ing.data.cassandra.jdbc.utils.SpecialCommandsUtil.getCommandExecutor;
import static com.ing.data.cassandra.jdbc.commands.SpecialCommandsUtil.containsSpecialCommands;
import static com.ing.data.cassandra.jdbc.commands.SpecialCommandsUtil.getCommandExecutor;
import static org.apache.commons.lang3.StringUtils.countMatches;

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

// If the CQL statement is a special command, execute it using the appropriate special command executor and
// return the result. Otherwise, execute the statement through the driver.
final SpecialCommands.SpecialCommandExecutor commandExecutor = getCommandExecutor(cql);
final SpecialCommandExecutor commandExecutor = getCommandExecutor(cql);
if (commandExecutor != null) {
return commandExecutor.execute(this, cql);
}
Expand Down
187 changes: 0 additions & 187 deletions src/main/java/com/ing/data/cassandra/jdbc/SpecialCommands.java

This file was deleted.

Loading

0 comments on commit 155be2f

Please sign in to comment.