Skip to content

Commit

Permalink
Improved Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hudeany committed Mar 2, 2024
1 parent d23fb88 commit 229a4f8
Show file tree
Hide file tree
Showing 7 changed files with 1,694 additions and 18 deletions.
Binary file modified lib_soderer/soderer-utilities-24.1.8.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions src/de/soderer/dbimport/DbImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,6 @@ private static int connectionTest(final ConnectionTestDefinition connectionTestD
for (int i = 1; i <= connectionTestDefinition.getIterations() || connectionTestDefinition.getIterations() == 0; i++) {
connectionCheckCount++;
System.out.println("Connection test " + i + (connectionTestDefinition.getIterations() > 0 ? " / " + connectionTestDefinition.getIterations() : ""));
@SuppressWarnings("resource")
Connection testConnection = null;
try {
System.out.println(DateUtilities.formatDate(DateUtilities.YYYY_MM_DD_HHMMSS, LocalDateTime.now()) + ": Creating database connection");
Expand Down Expand Up @@ -1081,7 +1080,9 @@ private static int connectionTest(final ConnectionTestDefinition connectionTestD
if (testConnection != null) {
try {
System.out.println(DateUtilities.formatDate(DateUtilities.YYYY_MM_DD_HHMMSS, LocalDateTime.now()) + ": Closing database connection");
testConnection.close();
if (!testConnection.isClosed()) {
testConnection.close();
}
} catch (final SQLException e) {
System.out.println(DateUtilities.formatDate(DateUtilities.YYYY_MM_DD_HHMMSS, LocalDateTime.now()) + ": Error closing database connection: " + e.getMessage());
returnCode = 1;
Expand Down
11 changes: 6 additions & 5 deletions src/de/soderer/dbimport/DbImportWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ public void setLogErroneousData(final boolean logErroneousData) {
this.logErroneousData = logErroneousData;
}

@SuppressWarnings("resource")
@Override
public Boolean work() throws Exception {
dataItemsDone = 0;
Expand Down Expand Up @@ -631,9 +630,11 @@ public Boolean work() throws Exception {
DbUtilities.dropTableIfExists(connection, tempTableName);

if (connection != null) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
if (!connection.isClosed()) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
}
connection = null;
if (dbDefinition.getDbVendor() == DbVendor.Derby) {
DbUtilities.shutDownDerbyDb(dbDefinition.getDbName());
Expand Down Expand Up @@ -1187,7 +1188,7 @@ protected Closeable validateAndSetParameter(final PreparedStatement preparedStat
batchValueItem.add(data);
} else {
itemToCloseAfterwards = inputStream;
preparedStatement.setBinaryStream(columnIndex, (FileInputStream) itemToCloseAfterwards);
preparedStatement.setBinaryStream(columnIndex, inputStream);
batchValueItem.add(itemToCloseAfterwards);
}
importedDataAmount += new File(valueString).length();
Expand Down
9 changes: 5 additions & 4 deletions src/de/soderer/dbimport/DbNoSqlImportWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void setCompleteCommit(final boolean commitOnFullSuccessOnly) throws Exce
}
}

@SuppressWarnings("resource")
@Override
public Boolean work() throws Exception {
signalUnlimitedProgress();
Expand Down Expand Up @@ -214,9 +213,11 @@ public Boolean work() throws Exception {
Utilities.closeQuietly(logOutputStream);

if (connection != null) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
if (!connection.isClosed()) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
}
connection = null;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/de/soderer/dbimport/DbSqlWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void close() {
sqlScriptReader = null;
}

@SuppressWarnings("resource")
@Override
public Boolean work() throws Exception {
OutputStream logOutputStream = null;
Expand Down Expand Up @@ -199,9 +198,11 @@ public Boolean work() throws Exception {
throw e;
} finally {
if (connection != null) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
if (!connection.isClosed()) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/de/soderer/dbimport/DbStructureWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ public Boolean work() throws Exception {
setEndTime(LocalDateTime.now());
} finally {
if (connection != null) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
if (!connection.isClosed()) {
connection.rollback();
connection.setAutoCommit(previousAutoCommit);
connection.close();
}
connection = null;
if (dbDefinition.getDbVendor() == DbVendor.Derby) {
DbUtilities.shutDownDerbyDb(dbDefinition.getDbName());
Expand Down
Loading

0 comments on commit 229a4f8

Please sign in to comment.