Skip to content

Commit

Permalink
do not use try block in case we are not catching
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hoß authored and sebhoss committed Jul 11, 2022
1 parent 466e92c commit a11ac6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ public CodeBlock openConnection(final SqlConfiguration configuration) {
return configuration.createConnection()
.filter(Boolean.TRUE::equals)
.map(value -> controlFlows.tryWithResource(getConnectionInline()))
.orElseGet(controlFlows::startTryBlock);
.or(() -> configuration.catchAndRethrow()
.filter(Boolean.TRUE::equals)
.map(value -> controlFlows.startTryBlock()))
.orElseGet(() -> CodeBlock.builder().build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ String openConnectionWithoutConnectionExpectation() {
""";
}

@Override
String openConnectionWithGivenConnectionWithoutRethrowExpectation() {
return """
""";
}

@Override
String tryPrepareCallableExpectation() {
return """
Expand Down Expand Up @@ -454,6 +460,12 @@ String openConnectionWithoutConnectionExpectation() {
""";
}

@Override
String openConnectionWithGivenConnectionWithoutRethrowExpectation() {
return """
""";
}

@Override
String tryPrepareCallableExpectation() {
return """
Expand Down Expand Up @@ -782,6 +794,12 @@ String openConnectionWithoutConnectionExpectation() {
""";
}

@Override
String openConnectionWithGivenConnectionWithoutRethrowExpectation() {
return """
""";
}

@Override
String tryPrepareCallableExpectation() {
return """
Expand Down Expand Up @@ -1111,6 +1129,12 @@ String openConnectionWithoutConnectionExpectation() {
""";
}

@Override
String openConnectionWithGivenConnectionWithoutRethrowExpectation() {
return """
""";
}

@Override
String tryPrepareCallableExpectation() {
return """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ abstract class JdbcBlocksTCK {

abstract String openConnectionWithoutConnectionExpectation();

abstract String openConnectionWithGivenConnectionWithoutRethrowExpectation();

abstract String tryPrepareCallableExpectation();

abstract String createStatementExpectation();
Expand Down Expand Up @@ -202,6 +204,15 @@ final void openConnectionWithoutConnection() {
.withCreateConnection(false)).toString());
}

@Test
final void openConnectionWithGivenConnectionWithoutRethrow() {
Assertions.assertEquals(
openConnectionWithGivenConnectionWithoutRethrowExpectation(),
generator().openConnection(SqlConfiguration.copyOf(SqlConfigurations.sqlConfiguration())
.withCreateConnection(false)
.withCatchAndRethrow(false)).toString());
}

@Test
final void tryPrepareCallable() {
Assertions.assertEquals(
Expand Down

0 comments on commit a11ac6e

Please sign in to comment.