Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Upgrade hsqldb dependency from 2.5.0 to 2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 3, 2023
1 parent b11781f commit 464cf44
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 63 deletions.
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@
<project.build.systemJdk>11</project.build.systemJdk>
<project.build.targetJdk>11</project.build.targetJdk>

<dep.hsqldb.version>2.5.0</dep.hsqldb.version>
<dep.jackcess.version>4.0.5</dep.jackcess.version>

<dep.hsqldb.version>2.7.1</dep.hsqldb.version>
<dep.hsqldb.classifier>debug</dep.hsqldb.classifier>

<dep.slf4j.version>2.0.9</dep.slf4j.version>

<dep.junit.version>5.10.0</dep.junit.version>
Expand Down Expand Up @@ -98,6 +100,7 @@
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${dep.hsqldb.version}</version>
<classifier>${dep.hsqldb.classifier}</classifier>
</dependency>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public final class UcanaccessDriver implements Driver {
DriverManager.registerDriver(new UcanaccessDriver());
Class.forName("org.hsqldb.jdbc.JDBCDriver");

} catch (ClassNotFoundException e) {
// Set property with semicolon-separated list (including wildcards) of Java classes
// that can be used for routines based on Java static methods
System.setProperty("hsqldb.method_class_names", "net.ucanaccess.converters.*");

} catch (ClassNotFoundException _ex) {
Logger.logWarning(LoggerMessageEnum.HSQLDB_DRIVER_NOT_FOUND);
throw new RuntimeException(e.getMessage());
} catch (SQLException e) {
throw new RuntimeException(e.getMessage());
throw new RuntimeException(_ex.getMessage());
} catch (SQLException _ex) {
throw new RuntimeException(_ex.getMessage());
}
}

Expand Down Expand Up @@ -173,7 +177,11 @@ public Connection connect(String _url, Properties _props) throws SQLException {
SQLWarning sqlw = null;
if (!alreadyLoaded) {
boolean toBeLoaded = !dbRef.loadedFromKeptMirror(session);
LoadJet la = new LoadJet(dbRef.getHSQLDBConnection(session), dbRef.getDbIO());
Connection conn = dbRef.getHSQLDBConnection(session);
// from version 2.7 hsqldb translates timestamps stored without timezone in the database
// into the default timezone. MS Access however does not know timezones, therefore assume timestamps are UTC
conn.createStatement().executeQuery("SET TIME ZONE 'UTC'");
LoadJet la = new LoadJet(conn, dbRef.getDbIO());
Logger.turnOffJackcessLog();
if (_props.containsKey("sysschema")) {
boolean sysSchema = Boolean.parseBoolean(_props.getProperty("sysschema"));
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/net/ucanaccess/converters/AddFunctions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.ucanaccess.converters;

import net.ucanaccess.converters.TypesMap.AccessType;
import net.ucanaccess.ext.FunctionType;

import java.sql.Timestamp;

public final class AddFunctions {

private AddFunctions() {
}

@FunctionType(functionName = "pluto", argumentTypes = {AccessType.TEXT, AccessType.TEXT, AccessType.DATETIME}, returnType = AccessType.TEXT)
public static String example(String s1, String s2, Timestamp dt) {
return s1 + s2 + dt;
}

@FunctionType(functionName = "concat", argumentTypes = {AccessType.TEXT, AccessType.TEXT}, returnType = AccessType.TEXT)
public static String concat(String s1, String s2) {
return s1 + s2;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ucanaccess.test.integration;

import net.ucanaccess.converters.AddFunctions;
import net.ucanaccess.test.util.AccessVersion;
import net.ucanaccess.test.util.AddFunctionClass;
import net.ucanaccess.test.util.UcanaccessBaseTest;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
Expand Down Expand Up @@ -31,9 +31,9 @@ void testAddFunction(AccessVersion _accessVersion) throws Exception {
st.execute("INSERT INTO t_add_function (id) VALUES(1)");
}

ucanaccess.addFunctions(AddFunctionClass.class);
dumpQueryResult("SELECT pluto('hello',' world ', NOW()) FROM t_add_function");
checkQuery("SELECT CONCAT('Hello World, ','Ucanaccess') FROM t_add_function", "Hello World, Ucanaccess");
ucanaccess.addFunctions(AddFunctions.class);
dumpQueryResult("SELECT pluto('hello', ' world ', NOW()) FROM t_add_function");
checkQuery("SELECT CONCAT('Hello World, ', 'Ucanaccess') FROM t_add_function", "Hello World, Ucanaccess");

dropTable("t_add_function");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class CorruptedTest extends UcanaccessBaseTest {
private static final ByteArrayOutputStream ERR_CONTENT = new ByteArrayOutputStream();

@BeforeAll
static void setUpStreams() {
static void setStdErr() {
System.setErr(new PrintStream(ERR_CONTENT));
}

@AfterAll
static void cleanUpStreams() {
static void resetStdErr() {
System.setErr(System.err);
}

Expand All @@ -39,10 +39,10 @@ void testCorrupted(AccessVersion _accessVersion) throws SQLException {
getLogger().info("UcanaccessConnection: {}", ucanaccess);
String nl = System.lineSeparator();
String err =
"WARNING: integrity constraint violation: foreign key no parent; BABY_DADDYBABY table: BABY value: 34" + nl
"WARNING: integrity constraint violation: foreign key no parent ; BABY_DADDYBABY table: BABY value: 34" + nl
+ "WARNING: Detected Foreign Key constraint breach, table Baby, record Row[162:1][{ID=2,fk1=34}]: making the table Baby read-only" + nl
+ "WARNING: Detected Not Null constraint breach, table NotNull, record Row[140:0][{ID=1,notnull=<null>,vvv=gg,fk1=34}]: making the table NotNull read-only" + nl
+ "WARNING: integrity constraint violation: foreign key no parent; NOTNULL_DADDYNOTNULL table: NOTNULL value: 34" + nl
+ "WARNING: integrity constraint violation: foreign key no parent ; NOTNULL_DADDYNOTNULL table: NOTNULL value: 34" + nl
+ "WARNING: Detected Foreign Key constraint breach, table NotNull, record Row[140:3][{ID=4,notnull=t,vvv=t,fk1=2}]: making the table NotNull read-only" + nl
+ "WARNING: Detected Unique constraint breach, table UK, record Row[181:1][{ID=2,uk=1}]: making the table UK read-only";
assertEquals(err, ERR_CONTENT.toString().trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,26 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.util.Locale;
import java.util.TimeZone;

class SummerTimeLostHourTest extends UcanaccessBaseTest {
class UtcTimezoneTest extends UcanaccessBaseTest {

private static Locale prevLocale;
private static TimeZone prevTimeZone;

@BeforeAll
static void setLocalAndTimezone() {
prevLocale = Locale.getDefault();
prevTimeZone = TimeZone.getDefault();
Locale.setDefault(Locale.ITALY);
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
}

@AfterAll
static void resetLocalAndTimezone() {
Locale.setDefault(prevLocale);
TimeZone.setDefault(prevTimeZone);
}

@Override
protected String getAccessPath() {
return TEST_DB_DIR + "summerTimeLostHour.accdb"; // Access 2007
return TEST_DB_DIR + "utcTimezoneTest.accdb"; // Access 2007
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -56,9 +51,10 @@ void testForLostHour(AccessVersion _accessVersion) throws SQLException, IOExcept
*/
Connection hsqldbConn = ucanaccess.getHSQLDBConnection();
Statement hsqldbStmt = hsqldbConn.createStatement();
ResultSet rs = hsqldbStmt.executeQuery("SELECT CAST(f_datetime AS VARCHAR(26)) AS str FROM t_datetime WHERE id=1");
ResultSet rs = hsqldbStmt.executeQuery("SELECT f_datetime, CAST(f_datetime AS VARCHAR(26)) AS str FROM t_datetime WHERE id=1");
rs.next();
assertEquals("2017-03-26 02:00:00.000000", rs.getString(1));
assertEquals("2017-03-26 02:00:00.000000", rs.getString("f_datetime"));
assertEquals("2017-03-26 02:00:00.000000", rs.getString("str"));

/*
* also ensure that 02:00:00 -> 01:00:00 doesn't happen when writing back to Access
Expand Down
25 changes: 0 additions & 25 deletions src/test/java/net/ucanaccess/test/util/AddFunctionClass.java

This file was deleted.

28 changes: 13 additions & 15 deletions src/test/java/net/ucanaccess/test/util/UcanaccessBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
public abstract class UcanaccessBaseTest extends AbstractBaseTest {

protected static final String TEST_DB_DIR = "testdbs/";
private static final File TEST_TEMP_DIR = createTempDir("ucanaccess-test");
private static final File TEST_TEMP_DIR = createTempDir("ucanaccess-test");

static {
Main.setBatchMode(true);
}

private File fileAccDb;
private String password = "";
private AccessVersion accessVersion;
private File fileAccDb;
private String password = "";
private AccessVersion accessVersion;
// CHECKSTYLE:OFF
protected UcanaccessConnection ucanaccess;
// CHECKSTYLE:ON
private String user = "ucanaccess";
private Connection verifyConnection;
private Boolean ignoreCase;
private String user = "ucanaccess";
private Connection verifyConnection;
private Boolean ignoreCase;

private long inactivityTimeout = -1;
private String columnOrder;
private String append2JdbcURL = "";
private Boolean showSchema;
private long inactivityTimeout = -1;
private String columnOrder;
private String append2JdbcURL = "";
private Boolean showSchema;

protected UcanaccessBaseTest() {
}
Expand Down Expand Up @@ -378,10 +378,8 @@ protected UcanaccessConnection getUcanaccessConnection(String _dbPath) throws SQ
}

private UcanaccessConnection getUcanaccessConnection(String _urlPrefix, String _dbPath) throws SQLException {
if (_dbPath == null) {
_dbPath = getAccessTempPath();
}
String url = _urlPrefix + _dbPath;
String dbPath = Optional.ofNullable(_dbPath).orElseGet(this::getAccessTempPath);
String url = _urlPrefix + dbPath;
if (ignoreCase != null) {
url += ";ignoreCase=" + ignoreCase;
}
Expand Down

0 comments on commit 464cf44

Please sign in to comment.