diff --git a/CHANGELOG.md b/CHANGELOG.md index 39ba186..09b56e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ 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 +### Changed +- Deprecate the parameter `version` (CQL version) in JDBC URL because this one is purely informational and has no + effect. This will be removed in the next release. + ## [4.10.1] - 2023-10-07 ### Changed - Update Apache Commons IO to version 2.14.0. 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 f665cf1..4a9398f 100644 --- a/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java +++ b/src/main/java/com/ing/data/cassandra/jdbc/CassandraDataSource.java @@ -84,7 +84,9 @@ public class CassandraDataSource implements ConnectionPoolDataSource, DataSource protected String password; /** * The CQL version. + * @deprecated For removal. */ + @Deprecated protected String version = null; /** * The consistency level. @@ -107,9 +109,26 @@ public class CassandraDataSource implements ConnectionPoolDataSource, DataSource * @param keyspace The keyspace. * @param user The username used to connect. * @param password The password used to connect. - * @param version The CQL version. * @param consistency The consistency level. */ + public CassandraDataSource(final String host, final int port, final String keyspace, final String user, + final String password, final String consistency) { + this(host, port, keyspace, user, password, null, consistency, null); + } + + /** + * Constructor. + * + * @param host The host name. + * @param port The port. + * @param keyspace The keyspace. + * @param user The username used to connect. + * @param password The password used to connect. + * @param version The CQL version. Deprecated, do not use anymore. + * @param consistency The consistency level. + * @deprecated For removal. Use {@link #CassandraDataSource(String, int, String, String, String, String)} instead. + */ + @Deprecated public CassandraDataSource(final String host, final int port, final String keyspace, final String user, final String password, final String version, final String consistency) { this(host, port, keyspace, user, password, version, consistency, null); @@ -123,7 +142,7 @@ public CassandraDataSource(final String host, final int port, final String keysp * @param keyspace The keyspace. * @param user The username used to connect. * @param password The password used to connect. - * @param version The CQL version. + * @param version The CQL version. Deprecated, do not use anymore. * @param consistency The consistency level. * @param localDataCenter The local datacenter. */ @@ -181,7 +200,10 @@ public void setServerName(final String serverName) { * Gets the CQL version. * * @return The CQL version. + * @deprecated For removal. */ + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public String getVersion() { return this.version; } @@ -190,7 +212,10 @@ public String getVersion() { * Sets the CQL version. * * @param version The CQL version. + * @deprecated For removal. */ + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public void setVersion(final String version) { this.version = version; } diff --git a/src/main/java/com/ing/data/cassandra/jdbc/SessionHolder.java b/src/main/java/com/ing/data/cassandra/jdbc/SessionHolder.java index dbe2e49..8090923 100644 --- a/src/main/java/com/ing/data/cassandra/jdbc/SessionHolder.java +++ b/src/main/java/com/ing/data/cassandra/jdbc/SessionHolder.java @@ -259,13 +259,13 @@ private Session createSession(final Properties properties) throws SQLException { configureSocketOptions(driverConfigLoaderBuilder, properties); // Set credentials when applicable. - if (username.length() > 0) { + if (!username.isEmpty()) { builder.withAuthCredentials(username, password); } // The DefaultLoadBalancingPolicy requires to specify a local data center. builder.withLocalDatacenter(localDatacenter); - if (loadBalancingPolicy.length() > 0) { + if (!loadBalancingPolicy.isEmpty()) { // if a custom load balancing policy has been given in the JDBC URL, parse it and add it to the cluster // builder. try { @@ -282,7 +282,7 @@ private Session createSession(final Properties properties) throws SQLException { } } - if (retryPolicy.length() > 0) { + if (!retryPolicy.isEmpty()) { // if retry policy has been given in the JDBC URL, parse it and add it to the cluster builder. try { driverConfigLoaderBuilder.withString(DefaultDriverOption.RETRY_POLICY_CLASS, retryPolicy); @@ -294,7 +294,7 @@ private Session createSession(final Properties properties) throws SQLException { } } - if (reconnectPolicy.length() > 0) { + if (!reconnectPolicy.isEmpty()) { // if reconnection policy has been given in the JDBC URL, parse it and add it to the cluster builder. try { final Map parsedPolicy = Optional.ofNullable( diff --git a/src/main/java/com/ing/data/cassandra/jdbc/utils/JdbcUrlUtil.java b/src/main/java/com/ing/data/cassandra/jdbc/utils/JdbcUrlUtil.java index c67577b..c306130 100644 --- a/src/main/java/com/ing/data/cassandra/jdbc/utils/JdbcUrlUtil.java +++ b/src/main/java/com/ing/data/cassandra/jdbc/utils/JdbcUrlUtil.java @@ -66,20 +66,29 @@ public final class JdbcUrlUtil { /** * JDBC URL parameter key for the CQL version. + * @deprecated For removal. */ + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public static final String KEY_VERSION = "version"; /** * Property name used to retrieve the active CQL version when the connection to Cassandra is established. This * property is mapped from the JDBC URL parameter {@code version} or from the default value defined in the * property {@code database.defaultCqlVersion} of the resource file 'jdbc-driver.properties'. + * @deprecated For removal, because {@link #KEY_VERSION} and {@link #TAG_CQL_VERSION} are deprecated. */ + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public static final String TAG_ACTIVE_CQL_VERSION = "activeCqlVersion"; /** * Property name used to retrieve the active CQL version when the connection to Cassandra is established. This * property is mapped from the JDBC URL parameter {@code version}. + * @deprecated For removal. */ + @Deprecated + @SuppressWarnings("DeprecatedIsStillUsed") public static final String TAG_CQL_VERSION = "cqlVersion"; /** @@ -460,7 +469,7 @@ public static Properties parseURL(final String url) throws SQLException { * Creates a "sub-name" portion of a JDBC URL from properties. * * @param props A {@link Properties} instance containing all the properties to be considered. - * @return A "sub-name" portion of a JDBC URL (for example: //myhost:9160/Test1?version=3.0.0). + * @return A "sub-name" portion of a JDBC URL (for example: //myhost:9160/Test1?localdatacenter=DC1). * @throws SQLException when something went wrong during the "sub-name" creation. * @throws SQLNonTransientConnectionException when the host name is missing. */ @@ -496,26 +505,18 @@ public static String createSubName(final Properties props) throws SQLException { } /** - * Builds the URI part containing the query parameters "consistency" and "version" from properties. + * Builds the URI part containing the query parameter "consistency" from properties. * * @param props A {@link Properties} instance containing all the properties to be considered. - * @return The URI part containing the query parameters (for example: "consistency=ONE&version=3.0.0") or - * {@code null} if neither version nor consistency are defined in the provided properties. + * @return The URI part containing the query parameter "consistency" (for example: "consistency=ONE") or + * {@code null} if consistency is not defined in the provided properties. */ static String makeQueryString(final Properties props) { final StringBuilder sb = new StringBuilder(); - final String version = props.getProperty(TAG_CQL_VERSION); final String consistency = props.getProperty(TAG_CONSISTENCY_LEVEL); if (StringUtils.isNotBlank(consistency)) { sb.append(KEY_CONSISTENCY).append("=").append(consistency); } - if (StringUtils.isNotBlank(version)) { - if (sb.length() != 0) { - sb.append("&"); - } - sb.append(KEY_VERSION).append("=").append(version); - } - if (sb.length() > 0) { return sb.toString().trim(); } else { diff --git a/src/main/resources/jdbc-driver.properties b/src/main/resources/jdbc-driver.properties index b4372f4..c1ee1eb 100644 --- a/src/main/resources/jdbc-driver.properties +++ b/src/main/resources/jdbc-driver.properties @@ -19,4 +19,5 @@ driver.name=Cassandra JDBC Driver driver.jdbcVersion=4.0 database.productName=Cassandra +# TODO: 'version' parameter is deprecated, this property has to be removed. database.defaultCqlVersion=3.0.0 diff --git a/src/test/java/com/ing/data/cassandra/jdbc/BatchStatementsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/BatchStatementsUnitTest.java index f11dd29..aa6c87a 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/BatchStatementsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/BatchStatementsUnitTest.java @@ -43,8 +43,8 @@ class BatchStatementsUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); - sqlConnection2 = newConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); + sqlConnection2 = newConnection(KEYSPACE, "localdatacenter=datacenter1"); } @AfterAll diff --git a/src/test/java/com/ing/data/cassandra/jdbc/CollectionsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/CollectionsUnitTest.java index f4ade4a..14b4019 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/CollectionsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/CollectionsUnitTest.java @@ -51,7 +51,7 @@ class CollectionsUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test 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 aeabe3c..cb09df5 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/DataSourceUnitTest.java @@ -18,7 +18,7 @@ import javax.sql.DataSource; import java.sql.SQLException; -import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CQL_VERSION; +import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CONSISTENCY_LEVEL; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -30,22 +30,20 @@ class DataSourceUnitTest extends UsingCassandraContainerTest { private static final String KEYSPACE = "test_keyspace"; private static final String USER = "testuser"; private static final String PASSWORD = "secret"; - private static final String VERSION = "3.0.0"; private static final String CONSISTENCY = "ONE"; @Test void givenParameters_whenConstructDataSource_returnCassandraDataSource() throws Exception { final CassandraDataSource cds = new CassandraDataSource( - "localhost", 9042, KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY); + "localhost", 9042, KEYSPACE, USER, PASSWORD, CONSISTENCY); assertEquals("localhost", cds.getServerName()); assertEquals(9042, cds.getPortNumber()); assertEquals(KEYSPACE, cds.getDatabaseName()); assertEquals(USER, cds.getUser()); assertEquals(PASSWORD, cds.getPassword()); - assertEquals(VERSION, cds.getVersion()); final DataSource ds = new CassandraDataSource(cassandraContainer.getContactPoint().getHostName(), - cassandraContainer.getContactPoint().getPort(), KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY); + cassandraContainer.getContactPoint().getPort(), KEYSPACE, USER, PASSWORD, CONSISTENCY); assertNotNull(ds); // null username and password @@ -58,7 +56,7 @@ void givenParameters_whenConstructDataSource_returnCassandraDataSource() throws cnx = ds.getConnection(); assertFalse(cnx.isClosed()); ds.setLoginTimeout(5); - assertEquals(VERSION, ((CassandraConnection) cnx).getConnectionProperties().get(TAG_CQL_VERSION)); + assertEquals(CONSISTENCY, ((CassandraConnection) cnx).getConnectionProperties().get(TAG_CONSISTENCY_LEVEL)); assertEquals(5, ds.getLoginTimeout()); } @@ -67,7 +65,7 @@ void givenParameters_whenConstructDataSource_returnCassandraDataSource() throws void givenCassandraDataSource_whenIsWrapperFor_returnExpectedValue() throws Exception { final DataSource ds = new CassandraDataSource( cassandraContainer.getContactPoint().getHostName(), cassandraContainer.getContactPoint().getPort(), - KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY); + KEYSPACE, USER, PASSWORD, CONSISTENCY); // Assert it is a wrapper for DataSource. assertTrue(ds.isWrapperFor(DataSource.class)); @@ -80,7 +78,7 @@ void givenCassandraDataSource_whenIsWrapperFor_returnExpectedValue() throws Exce void givenCassandraDataSource_whenUnwrap_returnUnwrappedDatasource() throws Exception { final DataSource ds = new CassandraDataSource( cassandraContainer.getContactPoint().getHostName(), cassandraContainer.getContactPoint().getPort(), - KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY); + KEYSPACE, USER, PASSWORD, CONSISTENCY); assertNotNull(ds.unwrap(DataSource.class)); } @@ -88,7 +86,7 @@ void givenCassandraDataSource_whenUnwrap_returnUnwrappedDatasource() throws Exce void givenCassandraDataSource_whenUnwrapToInvalidInterface_throwException() { final DataSource ds = new CassandraDataSource( cassandraContainer.getContactPoint().getHostName(), cassandraContainer.getContactPoint().getPort(), - KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY); + KEYSPACE, USER, PASSWORD, CONSISTENCY); assertThrows(SQLException.class, () -> ds.unwrap(this.getClass())); } } diff --git a/src/test/java/com/ing/data/cassandra/jdbc/JdbcRegressionUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/JdbcRegressionUnitTest.java index cd93aba..ed52d32 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/JdbcRegressionUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/JdbcRegressionUnitTest.java @@ -71,7 +71,7 @@ class JdbcRegressionUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); // Update cluster name according to the configured name. /* try (final Statement statement = sqlConnection.createStatement()) { diff --git a/src/test/java/com/ing/data/cassandra/jdbc/JsonSupportUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/JsonSupportUnitTest.java index 5536cdc..d8621b7 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/JsonSupportUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/JsonSupportUnitTest.java @@ -59,7 +59,7 @@ class JsonSupportUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test diff --git a/src/test/java/com/ing/data/cassandra/jdbc/MetadataResultSetsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/MetadataResultSetsUnitTest.java index f2a49db..b19ccb0 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/MetadataResultSetsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/MetadataResultSetsUnitTest.java @@ -55,7 +55,7 @@ class MetadataResultSetsUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } /* diff --git a/src/test/java/com/ing/data/cassandra/jdbc/PreparedStatementsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/PreparedStatementsUnitTest.java index 7baad38..a1b290b 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/PreparedStatementsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/PreparedStatementsUnitTest.java @@ -45,7 +45,7 @@ class PreparedStatementsUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test diff --git a/src/test/java/com/ing/data/cassandra/jdbc/ResultSetUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/ResultSetUnitTest.java index 5abcd4a..1d5e5e4 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/ResultSetUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/ResultSetUnitTest.java @@ -39,7 +39,7 @@ class ResultSetUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test diff --git a/src/test/java/com/ing/data/cassandra/jdbc/UtilsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/UtilsUnitTest.java index aec67aa..c6e1c7f 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/UtilsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/UtilsUnitTest.java @@ -43,7 +43,6 @@ import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CLOUD_SECURE_CONNECT_BUNDLE; import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CONNECTION_RETRIES; import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CONSISTENCY_LEVEL; -import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_CQL_VERSION; import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_DATABASE_NAME; import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_DEBUG; import static com.ing.data.cassandra.jdbc.utils.JdbcUrlUtil.TAG_LOAD_BALANCING_POLICY; @@ -84,12 +83,11 @@ static Stream buildUrlParsingTestCases() { put(TAG_USER, "user1"); put(TAG_PASSWORD, "password1"); }}), - Arguments.of("jdbc:cassandra://localhost:9042/Keyspace1?version=3.0.0&consistency=QUORUM", + Arguments.of("jdbc:cassandra://localhost:9042/Keyspace1?consistency=QUORUM", new HashMap() {{ put(TAG_SERVER_NAME, "localhost"); put(TAG_PORT_NUMBER, "9042"); put(TAG_DATABASE_NAME, "Keyspace1"); - put(TAG_CQL_VERSION, "3.0.0"); put(TAG_CONSISTENCY_LEVEL, "QUORUM"); }}), Arguments.of("jdbc:cassandra://localhost/Keyspace1?consistency=QUORUM", @@ -97,15 +95,13 @@ static Stream buildUrlParsingTestCases() { put(TAG_SERVER_NAME, "localhost"); put(TAG_PORT_NUMBER, "9042"); put(TAG_DATABASE_NAME, "Keyspace1"); - put(TAG_CQL_VERSION, null); put(TAG_CONSISTENCY_LEVEL, "QUORUM"); }}), - Arguments.of("jdbc:cassandra://localhost/Keyspace1?version=2.0.0", + Arguments.of("jdbc:cassandra://localhost/Keyspace1", new HashMap() {{ put(TAG_SERVER_NAME, "localhost"); put(TAG_PORT_NUMBER, "9042"); put(TAG_DATABASE_NAME, "Keyspace1"); - put(TAG_CQL_VERSION, "2.0.0"); put(TAG_CONSISTENCY_LEVEL, null); }}), Arguments.of("jdbc:cassandra://localhost", @@ -113,7 +109,6 @@ static Stream buildUrlParsingTestCases() { put(TAG_SERVER_NAME, "localhost"); put(TAG_PORT_NUMBER, "9042"); put(TAG_DATABASE_NAME, null); - put(TAG_CQL_VERSION, null); put(TAG_CONSISTENCY_LEVEL, null); }}), Arguments.of("jdbc:cassandra://localhost/Keyspace1?localdatacenter=DC1", @@ -194,7 +189,7 @@ void givenReconnectionPolicyString_whenParsePolicy_returnExpectedOptions( @Test void testCreateSubName() throws Exception { - final String jdbcUrl = "jdbc:cassandra://localhost:9042/Keyspace1?consistency=QUORUM&version=3.0.0"; + final String jdbcUrl = "jdbc:cassandra://localhost:9042/Keyspace1?consistency=QUORUM"; final Properties props = parseURL(jdbcUrl); final String result = createSubName(props); assertEquals(jdbcUrl, PROTOCOL + result); diff --git a/src/test/java/com/ing/data/cassandra/jdbc/VectorsDseContainerTest.java b/src/test/java/com/ing/data/cassandra/jdbc/VectorsDseContainerTest.java index 6bc816c..fe2f607 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/VectorsDseContainerTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/VectorsDseContainerTest.java @@ -27,7 +27,7 @@ class VectorsDseContainerTest extends UsingDseContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { initializeContainer(); - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test diff --git a/src/test/java/com/ing/data/cassandra/jdbc/VectorsUnitTest.java b/src/test/java/com/ing/data/cassandra/jdbc/VectorsUnitTest.java index 2e76e29..152c971 100644 --- a/src/test/java/com/ing/data/cassandra/jdbc/VectorsUnitTest.java +++ b/src/test/java/com/ing/data/cassandra/jdbc/VectorsUnitTest.java @@ -37,7 +37,7 @@ class VectorsUnitTest extends UsingCassandraContainerTest { @BeforeAll static void finalizeSetUpTests() throws Exception { - initConnection(KEYSPACE, "version=3.0.0", "localdatacenter=datacenter1"); + initConnection(KEYSPACE, "localdatacenter=datacenter1"); } @Test