Skip to content

Commit

Permalink
GH 41262:[Java][FlightSQL] Implement stateless prepared statement
Browse files Browse the repository at this point in the history
Fix Derby clean up
  • Loading branch information
stevelorddremio committed Jun 3, 2024
1 parent 5a867ee commit a43c06b
Showing 1 changed file with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,36 +252,39 @@ public static boolean removeDerbyDatabaseIfExists() {
boolean wasSuccess;
final Path path = Paths.get("target" + File.separator + "derbyDB");

try (final Connection connection = DriverManager.getConnection("jdbc:derby:target/derbyDB;create=true");
Statement statement = connection.createStatement()) {

dropTable(statement, "intTable");
dropTable(statement, "foreignTable");
} catch (final SQLException e) {
LOGGER.error(format("Failed attempt to drop tables in DerbyDB: <%s>", e.getMessage()), e);
return false;
}
if (Files.exists(path)) {
try (final Connection connection = DriverManager.getConnection("jdbc:derby:target/derbyDB;create=true");
Statement statement = connection.createStatement()) {
dropTable(statement, "intTable");
dropTable(statement, "foreignTable");
} catch (final SQLException e) {
LOGGER.error(format("Failed attempt to drop tables in DerbyDB: <%s>", e.getMessage()), e);
return false;
}

try (final Stream<Path> walk = Files.walk(path)) {
/*
* Iterate over all paths to delete, mapping each path to the outcome of its own
* deletion as a boolean representing whether or not each individual operation was
* successful; then reduce all booleans into a single answer, and store that into
* `wasSuccess`, which will later be returned by this method.
* If for whatever reason the resulting `Stream<Boolean>` is empty, throw an `IOException`;
* this not expected.
*/
wasSuccess = walk.sorted(Comparator.reverseOrder()).map(Path::toFile).map(File::delete)
.reduce(Boolean::logicalAnd).orElseThrow(IOException::new);
} catch (IOException e) {
/*
* The only acceptable scenario for an `IOException` to be thrown here is if
* an attempt to delete an non-existing file takes place -- which should be
* alright, since they would be deleted anyway.
*/
if (!(wasSuccess = e instanceof NoSuchFileException)) {
LOGGER.error(format("Failed attempt to clear DerbyDB: <%s>", e.getMessage()), e);
try (final Stream<Path> walk = Files.walk(path)) {
/*
* Iterate over all paths to delete, mapping each path to the outcome of its own
* deletion as a boolean representing whether or not each individual operation was
* successful; then reduce all booleans into a single answer, and store that into
* `wasSuccess`, which will later be returned by this method.
* If for whatever reason the resulting `Stream<Boolean>` is empty, throw an `IOException`;
* this not expected.
*/
wasSuccess = walk.sorted(Comparator.reverseOrder()).map(Path::toFile).map(File::delete)
.reduce(Boolean::logicalAnd).orElseThrow(IOException::new);
} catch (IOException e) {
/*
* The only acceptable scenario for an `IOException` to be thrown here is if
* an attempt to delete an non-existing file takes place -- which should be
* alright, since they would be deleted anyway.
*/
if (!(wasSuccess = e instanceof NoSuchFileException)) {
LOGGER.error(format("Failed attempt to clear DerbyDB: <%s>", e.getMessage()), e);
}
}
} else {
return true;
}

return wasSuccess;
Expand Down

0 comments on commit a43c06b

Please sign in to comment.