Skip to content

Commit

Permalink
Merge branch 'release/next'
Browse files Browse the repository at this point in the history
  • Loading branch information
maximevw committed Oct 7, 2023
2 parents b07d136 + 0e20066 commit 5f9fda7
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 70 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ 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).

## [4.10.1] - 2023-10-07
### Changed
- Update Apache Commons IO to version 2.14.0.
- Harmonize logging.
### Fixed
- Fix multiple issues related to the method `findColumn(String)` of `CassandraResultSet` and `CassandraMetadataResultSet`:
- Fix issue [#31](https://github.com/ing-bank/cassandra-jdbc-wrapper/issues/31) to return a 1-based index value.
- Return a result even if there's no row in the result set but the column exist in the statement.
- Fix the exception thrown by the method when the given column name does not exist in the result set (was an
`IllegalArgumentException` instead of an `SQLException`.

## [4.10.0] - 2023-09-30
### Added
- Add support for new [`vector` CQL type](https://datastax-oss.atlassian.net/browse/JAVA-3060)
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw)
defined in [CEP-30](https://cwiki.apache.org/confluence/x/OQ40Dw).
Also see PR [#27](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/27).
- Implement the method `getWarnings()` in `CassandraResultSet`.
- Implement the following methods of `CassandraDatabaseMetaData`:
Expand Down Expand Up @@ -151,6 +162,7 @@ For this version, the changelog lists the main changes comparatively to the late
- Fix logs in `CassandraConnection` constructor.

[original project]: https://github.com/adejanovski/cassandra-jdbc-wrapper/
[4.10.1]: https://github.com/ing-bank/cassandra-jdbc-wrapper/compare/v4.10.0...v4.10.1
[4.10.0]: https://github.com/ing-bank/cassandra-jdbc-wrapper/compare/v4.9.1...v4.10.0
[4.9.1]: https://github.com/ing-bank/cassandra-jdbc-wrapper/compare/v4.9.0...v4.9.1
[4.9.0]: https://github.com/ing-bank/cassandra-jdbc-wrapper/compare/v4.8.0...v4.9.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ We use [SemVer](http://semver.org/) for versioning.
* Marius Jokubauskas - **[@mjok](https://github.com/mjok)**
* Sualeh Fatehi - **[@sualeh](https://github.com/sualeh)**
* Cedrick Lunven - **[@clun](https://github.com/clun)**
* Stefano Fornari - **[@stefanofornari](https://github.com/stefanofornari)**

And special thanks to the developer of the original project on which is based this one:
* Alexander Dejanovski - **[@adejanovski](https://github.com/adejanovski)**
Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.ing.data</groupId>
<artifactId>cassandra-jdbc-wrapper</artifactId>
<version>4.10.0</version>
<version>4.10.1</version>
<packaging>jar</packaging>

<name>Cassandra JDBC Wrapper</name>
Expand Down Expand Up @@ -74,6 +74,13 @@
<role>developer</role>
</roles>
</contributor>
<contributor>
<name>Stefano Fornari</name>
<url>https://github.com/stefanofornari</url>
<roles>
<role>developer</role>
</roles>
</contributor>
</contributors>

<scm>
Expand Down Expand Up @@ -101,7 +108,7 @@
<checkstyle.version>9.3</checkstyle.version>
<caffeine.version>2.9.3</caffeine.version>
<commons-collections.version>4.4</commons-collections.version>
<commons-io.version>2.13.0</commons-io.version>
<commons-io.version>2.14.0</commons-io.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<datastax.java.driver.version>4.17.0</datastax.java.driver.version>
<jackson.version>2.15.2</jackson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ public void beforeFirst() throws SQLException {

private void checkIndex(final int index) throws SQLException {
if (this.currentRow != null) {
this.wasNull = this.currentRow.isNull(index - 1);
if (this.currentRow.getColumnDefinitions() != null) {
if (index < 1 || index > this.currentRow.getColumnDefinitions().asList().size()) {
throw new SQLSyntaxErrorException(String.format(MUST_BE_POSITIVE, index) + StringUtils.SPACE
+ this.currentRow.getColumnDefinitions().asList().size());
}
}
this.wasNull = this.currentRow.isNull(index - 1);
} else if (this.driverResultSet != null) {
if (this.driverResultSet.getColumnDefinitions() != null) {
if (index < 1 || index > this.driverResultSet.getColumnDefinitions().asList().size()) {
Expand All @@ -245,10 +245,10 @@ private void checkIndex(final int index) throws SQLException {

private void checkName(final String name) throws SQLException {
if (this.currentRow != null) {
this.wasNull = this.currentRow.isNull(name);
if (!this.currentRow.getColumnDefinitions().contains(name)) {
throw new SQLSyntaxErrorException(String.format(VALID_LABELS, name));
}
this.wasNull = this.currentRow.isNull(name);
} else if (this.driverResultSet != null) {
if (this.driverResultSet.getColumnDefinitions() != null) {
if (!this.driverResultSet.getColumnDefinitions().contains(name)) {
Expand Down Expand Up @@ -282,7 +282,12 @@ public void close() throws SQLException {
public int findColumn(final String columnLabel) throws SQLException {
checkNotClosed();
checkName(columnLabel);
return this.currentRow.getColumnDefinitions().getIndexOf(columnLabel);
if (this.currentRow != null) {
return this.currentRow.getColumnDefinitions().getIndexOf(columnLabel) + 1;
} else if (this.driverResultSet != null) {
return this.driverResultSet.getColumnDefinitions().getIndexOf(columnLabel) + 1;
}
throw new SQLSyntaxErrorException(String.format(VALID_LABELS, columnLabel));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void close() {
try {
this.connection.removeStatement(this);
} catch (final Exception e) {
LOG.warn("Unable to close the prepared statement: " + e.getMessage());
LOG.warn("Unable to close the prepared statement: {}", e.getMessage());
}
}

Expand All @@ -198,7 +198,7 @@ private void doExecute() throws SQLException {
try {
resetResults();
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.trace("CQL: " + this.cql);
LOG.trace("CQL: {}", this.cql);
}
// Force paging to avoid timeout and node harm.
if (this.boundStatement.getPageSize() == 0) {
Expand Down Expand Up @@ -248,7 +248,7 @@ public int[] executeBatch() throws SQLException {
try {
final List<CompletionStage<AsyncResultSet>> futures = new ArrayList<>();
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.trace("CQL statements: " + this.batchStatements.size());
LOG.trace("CQL statements: {}", this.batchStatements.size());
}
for (final BoundStatement statement : this.batchStatements) {
for (int i = 0; i < statement.getPreparedStatement().getVariableDefinitions().size(); i++) {
Expand All @@ -258,7 +258,7 @@ public int[] executeBatch() throws SQLException {
}
}
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.trace("CQL: " + this.cql);
LOG.trace("CQL: {}", this.cql);
}
final BoundStatement boundStatement = statement.setConsistencyLevel(
this.connection.getDefaultConsistencyLevel());
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/ing/data/cassandra/jdbc/CassandraResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ public void beforeFirst() throws SQLException {

private void checkIndex(final int index) throws SQLException {
if (this.currentRow != null) {
this.wasNull = this.currentRow.isNull(index - 1);
if (index < 1 || index > this.currentRow.getColumnDefinitions().size()) {
throw new SQLSyntaxErrorException(String.format(MUST_BE_POSITIVE, index) + StringUtils.SPACE
+ this.currentRow.getColumnDefinitions().size());
}
this.wasNull = this.currentRow.isNull(index - 1);
} else if (this.driverResultSet != null) {
if (index < 1 || index > this.driverResultSet.getColumnDefinitions().size()) {
throw new SQLSyntaxErrorException(String.format(MUST_BE_POSITIVE, index) + StringUtils.SPACE
Expand All @@ -309,10 +309,10 @@ private void checkIndex(final int index) throws SQLException {

private void checkName(final String name) throws SQLException {
if (this.currentRow != null) {
this.wasNull = this.currentRow.isNull(name);
if (!this.currentRow.getColumnDefinitions().contains(name)) {
throw new SQLSyntaxErrorException(String.format(VALID_LABELS, name));
}
this.wasNull = this.currentRow.isNull(name);
} else if (this.driverResultSet != null) {
if (!this.driverResultSet.getColumnDefinitions().contains(name)) {
throw new SQLSyntaxErrorException(String.format(VALID_LABELS, name));
Expand Down Expand Up @@ -344,7 +344,12 @@ public void close() throws SQLException {
public int findColumn(final String columnLabel) throws SQLException {
checkNotClosed();
checkName(columnLabel);
return this.currentRow.getColumnDefinitions().firstIndexOf(columnLabel);
if (this.currentRow != null) {
return this.currentRow.getColumnDefinitions().firstIndexOf(columnLabel) + 1;
} else if (this.driverResultSet != null) {
return this.driverResultSet.getColumnDefinitions().firstIndexOf(columnLabel) + 1;
}
throw new SQLSyntaxErrorException(String.format(VALID_LABELS, columnLabel));
}

@Override
Expand Down Expand Up @@ -1025,7 +1030,7 @@ public Object getObject(final String columnLabel) throws SQLException {
@Override
public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException {
final int index = findColumn(columnLabel);
return getObject(index + 1, type);
return getObject(index, type);
}

@Override
Expand Down Expand Up @@ -1149,7 +1154,7 @@ public <T> T getObjectFromJson(final int columnIndex, final Class<T> type) throw
@Override
public <T> T getObjectFromJson(final String columnLabel, final Class<T> type) throws SQLException {
final int index = findColumn(columnLabel);
return getObjectFromJson(index + 1, type);
return getObjectFromJson(index, type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private void doExecute(final String cql) throws SQLException {

private com.datastax.oss.driver.api.core.cql.ResultSet executeSingleStatement(final String cql) {
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.debug("CQL: " + cql);
LOG.debug("CQL: {}", cql);
}
SimpleStatement stmt = SimpleStatement.newInstance(cql)
.setConsistencyLevel(this.connection.getDefaultConsistencyLevel())
Expand Down Expand Up @@ -407,12 +407,12 @@ public int[] executeBatch() throws SQLException {
final int[] returnCounts = new int[this.batchQueries.size()];
final List<CompletionStage<AsyncResultSet>> futures = new ArrayList<>();
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.debug("CQL statements: " + this.batchQueries.size());
LOG.debug("CQL statements: {}", this.batchQueries.size());
}

for (final String query : this.batchQueries) {
if (LOG.isTraceEnabled() || this.connection.isDebugMode()) {
LOG.debug("CQL: " + query);
LOG.debug("CQL: {}", query);
}
SimpleStatement stmt = SimpleStatement.newInstance(query)
.setConsistencyLevel(this.connection.getDefaultConsistencyLevel());
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/com/ing/data/cassandra/jdbc/ConnectionUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import static org.mockito.Mockito.when;

class ConnectionUnitTest extends UsingCassandraContainerTest {
private static final Logger log = LoggerFactory.getLogger(ConnectionUnitTest.class);
private static final Logger LOG = LoggerFactory.getLogger(ConnectionUnitTest.class);

private static final String KEYSPACE = "system";

Expand Down Expand Up @@ -427,15 +427,15 @@ void givenConnection_whenGetMetaData_getExpectedResultSet() throws Exception {
assertNotNull(sqlConnection.getMetaData());

final DatabaseMetaData dbMetadata = sqlConnection.getMetaData();
log.debug("====================================================");
log.debug("Connection Metadata");
log.debug("====================================================");
log.debug("Driver name: {}", dbMetadata.getDriverName());
log.debug("Driver version: {}", dbMetadata.getDriverVersion());
log.debug("DB name: {}", dbMetadata.getDatabaseProductName());
log.debug("DB version: {}", dbMetadata.getDatabaseProductVersion());
log.debug("JDBC version: {}.{}", dbMetadata.getJDBCMajorVersion(), dbMetadata.getJDBCMinorVersion());
log.debug("====================================================");
LOG.debug("====================================================");
LOG.debug("Connection Metadata");
LOG.debug("====================================================");
LOG.debug("Driver name: {}", dbMetadata.getDriverName());
LOG.debug("Driver version: {}", dbMetadata.getDriverVersion());
LOG.debug("DB name: {}", dbMetadata.getDatabaseProductName());
LOG.debug("DB version: {}", dbMetadata.getDatabaseProductVersion());
LOG.debug("JDBC version: {}.{}", dbMetadata.getJDBCMajorVersion(), dbMetadata.getJDBCMinorVersion());
LOG.debug("====================================================");

assertEquals("Cassandra JDBC Driver", dbMetadata.getDriverName());
assertNotEquals(0, dbMetadata.getDriverMajorVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@TestMethodOrder(org.junit.jupiter.api.MethodOrderer.OrderAnnotation.class)
class DbaasAstraIntegrationTest {

private static final Logger log = LoggerFactory.getLogger(DbaasAstraIntegrationTest.class);
private static final Logger LOG = LoggerFactory.getLogger(DbaasAstraIntegrationTest.class);
private static final String ASTRA_DB_TOKEN_ENV_VARIABLE = "ASTRA_DB_APPLICATION_TOKEN";
private static final String ASTRA_DB_TOKEN_PATTERN = "Astra.*";
private static final String DATABASE_NAME = "test_cassandra_jdbc";
Expand All @@ -51,13 +51,13 @@ class DbaasAstraIntegrationTest {
@BeforeAll
static void setupAstra() throws Exception {
if (System.getenv(ASTRA_DB_TOKEN_ENV_VARIABLE) != null) {
log.debug("ASTRA_DB_APPLICATION_TOKEN is provided, AstraDB tests are executed.");
LOG.debug("ASTRA_DB_APPLICATION_TOKEN is provided, AstraDB tests are executed.");

/*
* Devops API Client (create database, resume, delete)
*/
final AstraDbClient astraDbClient = new AstraDbClient(TestUtils.getAstraToken());
log.debug("Connected the DBaaS API.");
LOG.debug("Connected the DBaaS API.");

/*
* Set up a Database in Astra: create if not exist, resume if needed.
Expand All @@ -67,7 +67,7 @@ static void setupAstra() throws Exception {
String dbId = TestUtils.setupVectorDatabase(DATABASE_NAME, KEYSPACE_NAME);
Assertions.assertTrue(astraDbClient.findById(dbId).isPresent());
Assertions.assertEquals(DatabaseStatusType.ACTIVE, astraDbClient.findById(dbId).get().getStatus());
log.debug("Database ready.");
LOG.debug("Database ready.");

/*
* Download cloud secure bundle to connect to the database.
Expand All @@ -77,7 +77,7 @@ static void setupAstra() throws Exception {
astraDbClient
.database(dbId)
.downloadDefaultSecureConnectBundle("/tmp/" + DATABASE_NAME + "_scb.zip");
log.debug("Connection bundle downloaded.");
LOG.debug("Connection bundle downloaded.");

/*
* Building jdbcUrl and sqlConnection.
Expand All @@ -90,7 +90,7 @@ static void setupAstra() throws Exception {
"&consistency=" + "LOCAL_QUORUM" +
"&secureconnectbundle=/tmp/" + DATABASE_NAME + "_scb.zip");
} else {
log.debug("ASTRA_DB_APPLICATION_TOKEN is not defined, skipping AstraDB tests.");
LOG.debug("ASTRA_DB_APPLICATION_TOKEN is not defined, skipping AstraDB tests.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
* <a href="https://github.com/adejanovski/cassandra-jdbc-wrapper/">original project from GitHub</a>.
*/
class JdbcRegressionUnitTest extends UsingCassandraContainerTest {
private static final Logger log = LoggerFactory.getLogger(JdbcRegressionUnitTest.class);

private static final String KEYSPACE = "test_keyspace3";
private static final String TABLE = "regressions_test";
Expand Down
Loading

0 comments on commit 5f9fda7

Please sign in to comment.