Skip to content

Commit

Permalink
Harmonize file creation, add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 26, 2024
1 parent 7271669 commit 6d34c4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
27 changes: 19 additions & 8 deletions src/main/java/net/ucanaccess/jdbc/DBReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ private void closeHsqlDb(Session _session, boolean _firstConnectionKeeptMirror)
hbase.delete();
} else if (!immediatelyReleaseResources || _firstConnectionKeeptMirror) {
toKeepHsql.delete();
if (!toKeepHsql.createNewFile()) {
if (toKeepHsql.createNewFile()) {
logger.log(Level.DEBUG, "Created file {0}", toKeepHsql);
} else {
logger.log(Level.WARNING, "Could not create file {0}", toKeepHsql);
}
for (File hsqlf : getHSQLDBFiles()) {
Expand Down Expand Up @@ -368,8 +370,12 @@ private String getHsqlUrl(Session _session) throws SQLException {
}
if (!inMemory && tempHsql == null) {
if (toKeepHsql != null) {
if (!toKeepHsql.exists() && !toKeepHsql.createNewFile()) {
logger.log(Level.WARNING, "Could not create file {0}", toKeepHsql);
if (!toKeepHsql.exists()) {
if (toKeepHsql.createNewFile()) {
logger.log(Level.DEBUG, "Created file {0}", toKeepHsql);
} else {
logger.log(Level.WARNING, "Could not create file {0}", toKeepHsql);
}
}
tempHsql = toKeepHsql;
} else {
Expand All @@ -378,10 +384,13 @@ private String getHsqlUrl(Session _session) throws SQLException {
hbase.mkdir();
tempHsql = new File(hbase, id);

if (!tempHsql.createNewFile()) {
logger.log(Level.WARNING, "Could not create file {0}", tempHsql);
} else {
tempHsql.delete();
if (!tempHsql.exists()) {
if (tempHsql.createNewFile()) {
logger.log(Level.DEBUG, "Created file {0}", tempHsql);
tempHsql.delete();
} else {
logger.log(Level.WARNING, "Could not create file {0}", tempHsql);
}
}
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Expand Down Expand Up @@ -446,7 +455,9 @@ private File fileLock() {
private void lockMdbFile() throws UcanaccessSQLException {
try {
File flLock = fileLock();
if (!flLock.createNewFile()) {
if (flLock.createNewFile()) {
logger.log(Level.DEBUG, "Created file {0}", flLock);
} else {
logger.log(Level.WARNING, "Could not create file {0}", flLock);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/ucanaccess/jdbc/UcanaccessDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public Connection connect(String _url, Properties _props) throws SQLException {
LOGGER.log(Level.WARNING, "{0} parameter cannot be combined with parameters {1} or {2}, {3} skipped",
keepMirror, jackcessOpener, encrypt, keepMirror);
} else {
File dbMirror =
new File(props.get(keepMirror) + fileDb.getName().toUpperCase().hashCode());
File dbMirror = new File(props.get(keepMirror));
dbRef.setToKeepHsql(dbMirror);
if (props.containsKey(readOnlyMirror)) {
dbRef.setMirrorReadOnly(Boolean.parseBoolean(props.get(readOnlyMirror)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testReloadMirror(AccessVersion _accessVersion) throws Exception {

File dbFile = createTempFileName(getClass().getSimpleName(), getFileExtension());
dbFile.deleteOnExit();
File mirrorFile = createTempFileName(getClass().getSimpleName(), "");
File mirrorFile = new File(dbFile.getAbsolutePath().substring(0, dbFile.getAbsolutePath().lastIndexOf(getFileExtension())));
mirrorFile.deleteOnExit();

// create the database
Expand Down

0 comments on commit 6d34c4d

Please sign in to comment.