diff --git a/src/main/java/liquibase/ext/cassandra/changelog/CassandraChangeLogHistoryService.java b/src/main/java/liquibase/ext/cassandra/changelog/CassandraChangeLogHistoryService.java index 03e2e0ca..ee384358 100644 --- a/src/main/java/liquibase/ext/cassandra/changelog/CassandraChangeLogHistoryService.java +++ b/src/main/java/liquibase/ext/cassandra/changelog/CassandraChangeLogHistoryService.java @@ -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(); } @@ -62,7 +47,7 @@ public int getNextSequenceValue() { } statement.close(); - } catch (SQLException | ClassNotFoundException e) { + } catch (SQLException | DatabaseException e) { e.printStackTrace(); } return next + 1; diff --git a/src/main/java/liquibase/ext/cassandra/database/CassandraDatabase.java b/src/main/java/liquibase/ext/cassandra/database/CassandraDatabase.java index b9a9dfc6..3094c0fd 100644 --- a/src/main/java/liquibase/ext/cassandra/database/CassandraDatabase.java +++ b/src/main/java/liquibase/ext/cassandra/database/CassandraDatabase.java @@ -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 diff --git a/src/main/java/liquibase/ext/cassandra/lockservice/LockServiceCassandra.java b/src/main/java/liquibase/ext/cassandra/lockservice/LockServiceCassandra.java index 37f306e3..9953fb34 100644 --- a/src/main/java/liquibase/ext/cassandra/lockservice/LockServiceCassandra.java +++ b/src/main/java/liquibase/ext/cassandra/lockservice/LockServiceCassandra.java @@ -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