Skip to content

Commit

Permalink
Merge pull request #115 from liquibase/LB-2115
Browse files Browse the repository at this point in the history
Obtain database connection to Cassandra with username and password (LB-2115)
  • Loading branch information
suryaaki2 authored Nov 23, 2021
2 parents 2c10446 + 27033a2 commit 458c8cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,7 @@ public boolean supports(Database database) {

@Override
public boolean hasDatabaseChangeLogTable() {
boolean hasChangeLogTable;
try {
Statement statement = ((CassandraDatabase) getDatabase()).getStatement();
statement.executeQuery("select ID from " + getDatabase().getDefaultCatalogName() + ".DATABASECHANGELOG");
statement.close();
hasChangeLogTable = true;
} catch (SQLException e) {
Scope.getCurrentScope().getLog(getClass()).info("No DATABASECHANGELOG available in cassandra.");
hasChangeLogTable = false;
} catch (ClassNotFoundException e) {
e.printStackTrace();
hasChangeLogTable = false;
}

// needs to be generated up front
return hasChangeLogTable;
return ((CassandraDatabase)getDatabase()).hasDatabaseChangeLogLockTable();
}


Expand All @@ -62,7 +47,7 @@ public int getNextSequenceValue() {
}
statement.close();

} catch (SQLException | ClassNotFoundException e) {
} catch (SQLException | DatabaseException e) {
e.printStackTrace();
}
return next + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,27 @@ public String getDefaultCatalogName() {
return getKeyspace();
}

public Statement getStatement() throws ClassNotFoundException, SQLException {
String url = super.getConnection().getURL();
Class.forName("com.simba.cassandra.jdbc42.Driver");
Connection con = DriverManager.getConnection(url);
return con.createStatement();
public Statement getStatement() throws DatabaseException {
return ((JdbcConnection) super.getConnection()).createStatement();
}

public boolean hasDatabaseChangeLogLockTable() {
boolean hasChangeLogLockTable;
try {
Statement statement = getStatement();
statement.executeQuery("SELECT ID from " + getDefaultCatalogName() + ".DATABASECHANGELOGLOCK");
statement.close();
hasChangeLogLockTable = true;
} catch (SQLException e) {
Scope.getCurrentScope().getLog(getClass()).info("No DATABASECHANGELOGLOCK available in cassandra.");
hasChangeLogLockTable = false;
} catch (DatabaseException e) {
e.printStackTrace();
hasChangeLogLockTable = false;
}

// needs to be generated up front
return hasChangeLogLockTable;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,7 @@ public void releaseLock() throws LockException {

@Override
public boolean hasDatabaseChangeLogLockTable() {
boolean hasChangeLogLockTable;
try {
Statement statement = ((CassandraDatabase) database).getStatement();
statement.executeQuery("SELECT ID from " + database.getDefaultCatalogName() + ".DATABASECHANGELOGLOCK");
statement.close();
hasChangeLogLockTable = true;
} catch (SQLException e) {
Scope.getCurrentScope().getLog(getClass()).info("No DATABASECHANGELOGLOCK available in cassandra.");
hasChangeLogLockTable = false;
} catch (ClassNotFoundException e) {
e.printStackTrace();
hasChangeLogLockTable = false;
}

// needs to be generated up front
return hasChangeLogLockTable;
return ((CassandraDatabase)database).hasDatabaseChangeLogLockTable();
}

@Override
Expand Down

0 comments on commit 458c8cd

Please sign in to comment.