Skip to content

Swapped in the new ING JDBC wrapper and the DataStax OSS Driver #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.datastax.jdbc</groupId>
<artifactId>CassandraJDBC42</artifactId>
<version>4.2</version>
<groupId>com.ing.data</groupId>
<artifactId>cassandra-jdbc-wrapper</artifactId>
<version>4.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/CassandraJDBC42.jar</systemPath>
<systemPath>${basedir}/lib/cassandra-jdbc-wrapper-4.9.1-bundle.jar</systemPath>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-parent</artifactId>
<version>4.17.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package liquibase.ext.cassandra.database;

import com.simba.cassandra.cassandra.core.CDBJDBCConnection;
import com.simba.cassandra.jdbc.jdbc42.S42Connection;
import com.ing.data.cassandra.jdbc.CassandraConnection;
import liquibase.Scope;
import liquibase.database.AbstractJdbcDatabase;
import liquibase.database.DatabaseConnection;
Expand All @@ -13,14 +12,16 @@

/**
* Cassandra 1.2.0 NoSQL database support.
* Javadocs for ING Cassandra JDBC Wrapper: https://javadoc.io/doc/com.ing.data/cassandra-jdbc-wrapper/latest/index.html
*
* Javadocs for DataStax OSS Driver: https://javadoc.io/doc/com.datastax.oss/java-driver-core/latest/index.html
* Jar file for DataStax OSS Driver: https://search.maven.org/search?q=com.DataStax.oss
*/
public class CassandraDatabase extends AbstractJdbcDatabase {
public static final String PRODUCT_NAME = "Cassandra";
public static final String SHORT_PRODUCT_NAME = "cassandra";
public static final Integer DEFAULT_PORT = 9160;
public static final String DEFAULT_DRIVER = "com.simba.cassandra.jdbc42.Driver";
public static final String NO_JDBC_VERSION_DRIVER = "com.simba.cassandra.jdbc.Driver";

public static final String DEFAULT_DRIVER = "com.ing.data.cassandra.jdbc.CassandraDriver";
private String keyspace;

@Override
Expand Down Expand Up @@ -67,12 +68,7 @@ public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws D
@Override
public String getDefaultDriver(String url) {
if (String.valueOf(url).startsWith("jdbc:cassandra:")) {
try {
Class.forName(DEFAULT_DRIVER);
return DEFAULT_DRIVER;
} catch (ClassNotFoundException e) {
return NO_JDBC_VERSION_DRIVER;
}
return DEFAULT_DRIVER;
}
return null;
}
Expand Down Expand Up @@ -115,10 +111,7 @@ public String getCurrentDateTimeFunction() {
public String getKeyspace() {
if (keyspace == null) {
try {
if (this.getConnection() instanceof JdbcConnection) {
keyspace = ((CDBJDBCConnection) ((S42Connection) ((JdbcConnection) (this).getConnection())
.getUnderlyingConnection()).getConnection()).getSession().getLoggedKeyspace();
}
keyspace = ((CassandraConnection) (this).getConnection()).getSession().getKeyspace().toString();
} catch (Exception e) {
Scope.getCurrentScope().getLog(CassandraDatabase.class)
.severe("Could not get keyspace from connection", e);
Expand Down
50 changes: 50 additions & 0 deletions test.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CREATE KEYSPACE betterbotz
WITH REPLICATION = {
'class' : 'SimpleStrategy',
'replication_factor' : 1
};
USE betterbotz;
DROP TABLE IF EXISTS authors;
CREATE TABLE authors (
id int,
first_name varchar,
last_name varchar,
email varchar,
birthdate date,
added timestamp,
PRIMARY KEY (id)
);

INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(1,'Eileen','Lubowitz','[email protected]','1991-03-04','2004-05-30 02:08:25');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(2,'Tamia','Mayert','[email protected]','2016-03-27','2014-03-21 02:52:00');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(3,'Cyril','Funk','[email protected]','1988-04-21','2011-06-24 18:17:48');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(4,'Nicolas','Buckridge','[email protected]','2017-02-03','2019-04-22 02:04:41');
INSERT INTO authors(id, first_name, last_name, email, birthdate, added) VALUES
(5,'Jayden','Walter','[email protected]','2010-02-27','1990-02-04 02:32:00');


DROP TABLE IF EXISTS posts;
CREATE TABLE posts (
id int,
author_id int,
title varchar,
description varchar,
content text,
inserted_date date,
PRIMARY KEY (id)
);

INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(1,1,'temporibus','voluptatum','Fugit non et doloribus repudiandae.','2015-11-18');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(2,2,'ea','aut','Tempora molestias maiores provident molestiae sint possimus quasi.','1975-06-08');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(3,3,'illum','rerum','Delectus recusandae sit officiis dolor.','1975-02-25');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(4,4,'itaque','deleniti','Magni nam optio id recusandae.','2010-07-28');
INSERT INTO posts(id, author_id, title, description, content, inserted_date) VALUES
(5,5,'ad','similique','Rerum tempore quis ut nesciunt qui excepturi est.','2006-10-09');