diff --git a/CHANGELOG.md b/CHANGELOG.md index d1254a8..eb680d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [#55](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/55)). - Add support for the special CQL command `CONSISTENCY [level]` in `CassandraStatement` (inspired by PR [#56](https://github.com/ing-bank/cassandra-jdbc-wrapper/pull/56)). +- Add a method `setComplianceMode(String)` in `CassandraDataSource` to specify a specific compliance mode when getting + the connection from a `DataSource` (see issue [#68](https://github.com/ing-bank/cassandra-jdbc-wrapper/issues/68)). ### Changed - Update Java Driver for Apache Cassandra® to version 4.18.1. - Update Jackson dependencies to version 2.17.1. diff --git a/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java b/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java index 69c66a9..9a387b8 100644 --- a/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java +++ b/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java @@ -59,22 +59,27 @@ public class CassandraDataSource implements ConnectionPoolDataSource, DataSource * The Cassandra data source description. */ protected static final String DATA_SOURCE_DESCRIPTION = "Cassandra Data Source"; + /** * The contact points of the data source. */ protected List contactPoints; + /** * The database name. In case of Cassandra, i.e. the keyspace used as data source. */ protected String databaseName; + /** * The username used to connect to the data source. */ protected String user; + /** * The password used to connect to the data source. */ protected String password; + /** * The consistency level. *

@@ -88,6 +93,7 @@ public class CassandraDataSource implements ConnectionPoolDataSource, DataSource * The compliance mode. */ protected String complianceMode = null; + /** * The local datacenter. */ diff --git a/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java index 85b1e16..9895201 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java @@ -50,15 +50,14 @@ void givenParameters_whenConstructDataSource_returnCassandraDataSource() throws assertEquals(USER, cds.getUser()); assertEquals(PASSWORD, cds.getPassword()); - CassandraDataSource cds2 = new CassandraDataSource(Collections.singletonList(ContactPoint.of( + final CassandraDataSource ds = new CassandraDataSource(Collections.singletonList(ContactPoint.of( cassandraContainer.getContactPoint().getHostName(), cassandraContainer.getContactPoint().getPort())), KEYSPACE, USER, PASSWORD, CONSISTENCY, "datacenter1"); - cds2.setComplianceMode(COMPLIANCE_MODE); - final DataSource ds = cds2; + ds.setComplianceMode(COMPLIANCE_MODE); assertNotNull(ds); // null username and password - java.sql.Connection cnx = ds.getConnection(null, null); + CassandraConnection cnx = ds.getConnection(null, null); assertFalse(cnx.isClosed()); ds.setLoginTimeout(5); assertEquals(5, ds.getLoginTimeout()); @@ -67,8 +66,8 @@ void givenParameters_whenConstructDataSource_returnCassandraDataSource() throws cnx = ds.getConnection(); assertFalse(cnx.isClosed()); ds.setLoginTimeout(5); - assertEquals(CONSISTENCY, ((CassandraConnection) cnx).getConnectionProperties().get(TAG_CONSISTENCY_LEVEL)); - assertEquals(COMPLIANCE_MODE, ((CassandraConnection) cnx).getConnectionProperties().get(TAG_COMPLIANCE_MODE)); + assertEquals(CONSISTENCY, cnx.getConnectionProperties().get(TAG_CONSISTENCY_LEVEL)); + assertEquals(COMPLIANCE_MODE, cnx.getConnectionProperties().get(TAG_COMPLIANCE_MODE)); assertEquals(5, ds.getLoginTimeout()); } diff --git a/src/test/java/com/ing/data/cassandra/jdbc/PooledUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/PooledUnitTest.java index 468a8ef..8bef275 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/PooledUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/PooledUnitTest.java @@ -37,7 +37,6 @@ class PooledUnitTest extends UsingCassandraContainerTest { private static final String PASSWORD = "secret"; private static final String CONSISTENCY = "ONE"; private static final String LOCAL_DATACENTER = "datacenter1"; - private static final String COMPLIANCE_MODE = "Liquibase"; @Test void givenPooledDataSource_whenGetAndCloseConnection2MillionTimes_manageConnectionsProperly() throws Exception {