Skip to content

Commit

Permalink
Fixed Connection auto-commit settings.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <[email protected]>
  • Loading branch information
Tomas-Kraus committed Sep 26, 2023
1 parent fd005d9 commit b1360ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ protected PreparedStatement prepareStatement(DbClientServiceContext serviceConte
* @return statement
*/
protected PreparedStatement prepareStatement(String stmtName, String stmt) {
return prepareStatement(connectionPool.connection(), stmtName, stmt);
Connection connection = connectionPool.connection();
try {
connection.setAutoCommit(true);
} catch (SQLException e) {
throw new DbClientException("Failed to set autocommit to true", e);
}
return prepareStatement(connection, stmtName, stmt);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package io.helidon.dbclient.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import io.helidon.dbclient.DbClientException;
import io.helidon.dbclient.DbStatement;

/**
Expand Down Expand Up @@ -44,6 +47,14 @@ protected JdbcTransactionStatement(JdbcConnectionPool connectionPool,

@Override
protected PreparedStatement prepareStatement(String stmtName, String stmt) {
return prepareStatement(transactionContext.connection(), stmtName, stmt);
Connection connection = transactionContext.connection();
try {
connection.setAutoCommit(false);
} catch (SQLException e) {
throw new DbClientException("Failed to set autocommit to false", e);
}
return prepareStatement(connection, stmtName, stmt);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static void setup(DbClient dbClient, Config config) {
}

// Add 2 endpoints:
// - HealthCheck /observe/healthNoDetails with details turned off
// - HealthCheck /observe/healthDetails with details turned on
// - HealthCheck /noDetails/health with details turned off
// - HealthCheck /details/health with details turned on
private static void routing(DbClient dbClient, Config config, HttpRouting.Builder router) {
router.addFeature(
createObserveFeature(dbClient, config, "healthNoDetails", "noDetails", false));
Expand Down

0 comments on commit b1360ab

Please sign in to comment.