Skip to content

Commit

Permalink
Upgrade hsqldb from 2.5.2 to 2.7.1 (#3400)
Browse files Browse the repository at this point in the history
* Bump hsqldb from 2.5.2 to 2.7.1

Bumps hsqldb from 2.5.2 to 2.7.1.

---
updated-dependencies:
- dependency-name: org.hsqldb:hsqldb
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Ignore HSQLDB tests for Java version < 11 as it requires Java 11 .

* Remove unused HSQLDB imports from groovy tests.

* Replaces HSQLDB by H2 so we can still test cdi on java 8 as hsqldb now requires java 11.

* Makes sure that we do not touch HSQLDB classes below  Java 11

* When having drivers with compiled only for java 11, this method may fail for java 8. Adds a fallback loading strategy.

* Remove hsqldb from tests on java below 11.

* Replaces hsqldb for h2.

* Replaces hsqldb by h2 for command line test execution - refactors changelog files and fixes small issues.

* Fix Sonar warning.

* Encapsulates Java 11 verification.

* Adds user message advising that the driver they are trying to use is not compatible with the java version it's being executed.

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: filipe <filipelautert@gmail.com>
  • Loading branch information
dependabot[bot] and filipelautert authored Oct 31, 2022
1 parent 9949ca0 commit 1fb44ca
Show file tree
Hide file tree
Showing 52 changed files with 171 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import liquibase.integration.cdi.annotations.LiquibaseType;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.ResourceAccessor;
import org.hsqldb.jdbc.JDBCDataSource;
import org.h2.jdbcx.JdbcDataSource;

import javax.enterprise.inject.Produces;
import javax.sql.DataSource;
import java.sql.SQLException;

/**
* A Test CDI Producer used for testing CDILiquibase
Expand All @@ -28,11 +27,11 @@ public CDILiquibaseConfig createConfig() {

@Produces
@LiquibaseType
public DataSource createDataSource() throws SQLException {
JDBCDataSource ds = new JDBCDataSource();
ds.setDatabase("jdbc:hsqldb:mem:test");
public DataSource createDataSource() {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setUser("sa");
ds.setPassword("");
ds.setPassword("sa");
return ds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ protected void enableMonitoring() {
return;
}

if (SystemUtil.getJavaMajorVersion() < 11) {
if (!SystemUtil.isAtLeastJava11()) {
Scope.getCurrentScope().getUI().sendMessage("Performance monitoring requires Java 11 or greater. Version " + SystemUtil.getJavaVersion() + " is not supported.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import liquibase.resource.Resource;
import liquibase.resource.ResourceAccessor;
import liquibase.util.StringUtil;
import liquibase.util.SystemUtil;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -270,6 +271,9 @@ private Driver loadDriver(String driverClass) {
Driver driverObject;
try {
driverObject = (Driver) Class.forName(driverClass, true, Scope.getCurrentScope().getClassLoader()).getConstructor().newInstance();
} catch (java.lang.UnsupportedClassVersionError e) {
throw new UnexpectedLiquibaseException(String.format("Your database driver %s is not compatible with Java version %s. " +
"You will need to either upgrade your Java version or install a different driver jar file.", driverClass, SystemUtil.getJavaVersion()), e);
} catch (Exception e) {
throw new RuntimeException("Cannot find database driver: " + e.getMessage());
}
Expand Down
4 changes: 4 additions & 0 deletions liquibase-core/src/main/java/liquibase/util/SystemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public static int getJavaMajorVersion() {
}
return majorVersion;
}

public static boolean isAtLeastJava11() {
return getJavaMajorVersion() >= 11;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package liquibase.resource

import liquibase.util.StreamUtil
import liquibase.util.StringUtil
import org.hsqldb.types.Charset
import spock.lang.IgnoreIf
import spock.lang.Requires
import spock.lang.Specification
import spock.lang.Unroll

Expand Down
2 changes: 1 addition & 1 deletion liquibase-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<deploy.url>https://maven.pkg.github.com/liquibase</deploy.url>

<h2.version>2.1.214</h2.version>
<hsqldb.version>2.5.2</hsqldb.version>
<hsqldb.version>2.7.1</hsqldb.version>
<postgresql.version>42.5.0</postgresql.version>
<mssql.version>11.2.1.jre8</mssql.version>
<mysql.version>8.0.21</mysql.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class TestFilter {
System.out.println(" " + excludeKey + ": " + excludeString);
} else {
//hard code default until we support more
includeString = "db:hsqldb";
includeString = "db:h2";
}

instance = new TestFilter(includeString, excludeString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ protected Driver getDriver(String url) throws SQLException {
try {
Scope.getCurrentScope().getLog(getClass()).fine("Loading driver for " + url);
String driverJar = getDriverJar();
Driver driver;

if (driverJar == null) {
Scope.getCurrentScope().getLog(getClass()).fine("Using driver from standard classloader");
driver = DriverManager.getDriver(url);
return this.getDriverFromUrl(url);
} else {
Scope.getCurrentScope().getLog(getClass()).fine("Using driver from " + driverJar);
Path driverPath = DownloadUtil.downloadMavenArtifact(driverJar);
Expand All @@ -172,16 +170,24 @@ protected Driver getDriver(String url) throws SQLException {
final Method getDriverMethod = isolatedDriverManager.getMethod("getDriver", String.class);

final Driver driverClass = (Driver) getDriverMethod.invoke(null, url);
driver = (Driver) Class.forName(driverClass.getClass().getName(), true, isolatedClassloader).newInstance();
return (Driver) Class.forName(driverClass.getClass().getName(), true, isolatedClassloader).newInstance();
}
return driver;
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new UnexpectedLiquibaseException(e);
}
}

private Driver getDriverFromUrl(String url) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Scope.getCurrentScope().getLog(getClass()).fine("Using driver from standard classloader");
try {
return DriverManager.getDriver(url);
} catch (SQLException e) {
Scope.getCurrentScope().getLog(getClass()).fine(String.format("Error '%s' while loading driver for url '%s', last try.", e.getMessage(), url));
String driverClass = DatabaseFactory.getInstance().findDefaultDriver(url);
return (Driver) Class.forName(driverClass).newInstance();
}
}

/**
* Opens a connection with valid permissions for the {@link #setup()} logic.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import liquibase.servicelocator.ServiceLocator;
import liquibase.util.CollectionUtil;
import liquibase.util.StringUtil;
import liquibase.util.SystemUtil;
import org.junit.Assume;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
Expand Down Expand Up @@ -70,6 +71,10 @@ public static List<String> getEnabledTestSystems(String configuredTestSystems, S
List<String> skippedTestSystemsList = CollectionUtil.createIfNull(StringUtil.splitAndTrim(skippedTestSystems, ","));
returnList = returnList.stream().filter(ts -> !skippedTestSystemsList.contains(ts)).collect(Collectors.toList());
}

if (!SystemUtil.isAtLeastJava11()) {
returnList = returnList.stream().filter(ts -> !"hsqldb".equals(ts)).collect(Collectors.toList());
}
return returnList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public abstract class AbstractIntegrationTest {
private String defaultSchemaName;

protected AbstractIntegrationTest(String changelogDir, Database dbms) throws Exception {
this.testSystem = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem(dbms.getShortName());
if (dbms != null) {
this.testSystem = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem(dbms.getShortName());
}

this.completeChangeLog = "changelogs/" + changelogDir + "/complete/root.changelog.xml";
this.rollbackChangeLog = "changelogs/" + changelogDir + "/rollback/rollbackable.changelog.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.dbtest.AbstractIntegrationTest;
import liquibase.util.SystemUtil;
import org.junit.Assume;

import java.sql.SQLSyntaxErrorException;

Expand All @@ -11,12 +13,13 @@ public class HsqlIntegrationTest extends AbstractIntegrationTest {
public static final String OBJECT_ALREADY_EXISTS = "42504";

public HsqlIntegrationTest() throws Exception {
super("hsqldb", DatabaseFactory.getInstance().getDatabase("hsqldb"));
super("hsqldb", DatabaseFactory.getInstance().getDatabase(SystemUtil.isAtLeastJava11() ? "hsqldb": "none"));
}


@Override
public void setUp() throws Exception {
Assume.assumeTrue(SystemUtil.isAtLeastJava11()) ; // Since HSQLDB 2.7.1 it requires java 11
super.setUp();
try {
// Create schemas for tests testRerunDiffChangeLogAltSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@

<changeSet id="30" author="nvoxland">
<createTable tableName="pkTest">
<column name="id" type="int"/>
<column name="id" type="int">
<constraints nullable="false" />
</column>
<column name="value" type="varchar(50)"/>
</createTable>
</changeSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Optional Args:
url : { it.altUrl },
username : { it.altUsername },
password : { it.altPassword },
changesetIdentifier: "changelogs/hsqldb/complete/rollback.tag.changelog.xml::1::nvoxland",
changelogFile : "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changesetIdentifier: "changelogs/h2/complete/rollback.tag.changelog.xml::1::nvoxland",
changelogFile : "changelogs/h2/complete/rollback.tag.changelog.xml"
]

expectedResults = [
Expand All @@ -46,15 +46,15 @@ Optional Args:

run "Run without changelogFile should throw an exception", {
arguments = [
changesetIdentifier: "changelogs/hsqldb/complete/rollback.tag.changelog.xml::1::nvoxland",
changesetIdentifier: "changelogs/h2/complete/rollback.tag.changelog.xml::1::nvoxland",
]

expectedException = CommandValidationException.class
}

run "Run without changesetIdentifier should throw an exception", {
arguments = [
changelogFile : "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile : "changelogs/h2/complete/rollback.tag.changelog.xml"
]

expectedException = CommandValidationException.class
Expand All @@ -63,7 +63,7 @@ Optional Args:
run "Run without URL should throw an exception", {
arguments = [
url: "",
changelogFile : "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile : "changelogs/h2/complete/rollback.tag.changelog.xml"
]

expectedException = CommandValidationException.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Optional Args:
url : { it.altUrl },
username : { it.altUsername },
password : { it.altPassword },
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]

setup {
Expand Down Expand Up @@ -79,7 +79,7 @@ Optional Args:
run "Run without URL should throw an exception", {
arguments = [
url: "",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]

expectedException = CommandValidationException.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Optional Args:
url : { it.url },
username: { it.username },
password: { it.password },
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]

setup {
Expand Down Expand Up @@ -85,7 +85,7 @@ Optional Args:
url : { it.url },
username: { it.username },
password: { it.password },
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]

setup {
Expand Down Expand Up @@ -135,7 +135,7 @@ Optional Args:
run "Run without URL should throw an exception", {
arguments = [
url: "",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]

expectedException = CommandValidationException.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Optional Args:
username: { it.username },
password: { it.password },
tag : "version_2.0",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml"
]


Expand Down Expand Up @@ -89,7 +89,7 @@ Optional Args:

run "Run without a tag should throw an exception", {
arguments = [
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
tag : ""
]
expectedException = CommandValidationException.class
Expand All @@ -105,7 +105,7 @@ Optional Args:
run "Run without a URL should throw an exception", {
arguments = [
url : "",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
tag : "version_2.0"
]
expectedException = CommandValidationException.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Optional Args:
username: { it.username },
password: { it.password },
tag : "version_2.0",
"changelogFile": "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
"changelogFile": "changelogs/h2/complete/rollback.tag.changelog.xml"
]

setup {
Expand Down Expand Up @@ -88,7 +88,7 @@ Optional Args:
username: { it.username },
password: { it.password },
tag : "version_2.0",
"changelogFile": "changelogs/hsqldb/complete/rollback.tag.changelog.xml"
"changelogFile": "changelogs/h2/complete/rollback.tag.changelog.xml"
]

setup {
Expand Down Expand Up @@ -151,15 +151,15 @@ Optional Args:

run "Run without a tag should throw an exception", {
arguments = [
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
]
expectedException = CommandValidationException.class
}

run "Run without a URL should throw an exception", {
arguments = [
url : "",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
tag : "version_2.0"
]
expectedException = CommandValidationException.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Optional Args:
username: { it.username },
password: { it.password },
outputDirectory: "target/test-classes",
changelogFile : "changelogs/hsqldb/complete/simple.changelog.xml",
changelogFile : "changelogs/h2/complete/simple.changelog.xml",
]

expectedResults = [
Expand All @@ -45,7 +45,7 @@ Optional Args:

run "Run without an outputDirectory should throw an exception", {
arguments = [
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
outputDirectory: ""
]
expectedException = CommandValidationException.class
Expand All @@ -61,7 +61,7 @@ Optional Args:
run "Run without a URL should throw an exception", {
arguments = [
url : "",
changelogFile: "changelogs/hsqldb/complete/rollback.tag.changelog.xml",
changelogFile: "changelogs/h2/complete/rollback.tag.changelog.xml",
outputDirectory: "version_2.0"
]
expectedException = CommandValidationException.class
Expand Down
Loading

0 comments on commit 1fb44ca

Please sign in to comment.