Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.

[versions]
junit-jupiter = "5.11.4"
junit-jupiter = "5.13.4"
assertj = "3.27.3"
google-errorprone-core = "2.36.0"
nullaway = "0.12.4"
jspecify = "1.0.0"
hibernate-orm = "6.6.23.Final"
hibernate-orm = "6.6.25.Final"
mongo-java-driver-sync = "5.3.1"
slf4j-api = "2.0.16"
logback-classic = "1.5.16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.mongodb.hibernate.jdbc;

import static com.mongodb.hibernate.internal.MongoConstants.ID_FIELD_NAME;
import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doAndTerminateTransaction;
import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWithSpecifiedAutoCommit;
import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.doWorkWithSpecifiedAutoCommit;
import static com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.insertTestData;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
Expand All @@ -30,7 +29,6 @@

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Sorts;
import com.mongodb.hibernate.jdbc.MongoStatementIntegrationTests.SqlExecutable;
import com.mongodb.hibernate.junit.InjectMongoCollection;
import com.mongodb.hibernate.junit.MongoExtension;
import java.math.BigDecimal;
Expand All @@ -50,8 +48,13 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(MongoExtension.class)
@ParameterizedClass
@ValueSource(booleans = {true, false})
class MongoPreparedStatementIntegrationTests {

@AutoClose
Expand All @@ -63,6 +66,9 @@ class MongoPreparedStatementIntegrationTests {
@AutoClose
private Session session;

@Parameter
private boolean autoCommit;

@BeforeAll
static void beforeAll() {
sessionFactory = new Configuration().buildSessionFactory();
Expand Down Expand Up @@ -401,10 +407,6 @@ private void assertExecuteUpdate(
}

private void doWorkAwareOfAutoCommit(Work work) {
session.doWork(connection -> doAwareOfAutoCommit(connection, () -> work.execute(connection)));
}

void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException {
doWithSpecifiedAutoCommit(false, connection, () -> doAndTerminateTransaction(connection, work));
doWorkWithSpecifiedAutoCommit(autoCommit, session, work);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(MongoExtension.class)
@ParameterizedClass
@ValueSource(booleans = {true, false})
class MongoStatementIntegrationTests {

@AutoClose
Expand All @@ -54,6 +59,9 @@ class MongoStatementIntegrationTests {
@AutoClose
private Session session;

@Parameter
private boolean autoCommit;

@BeforeAll
static void beforeAll() {
sessionFactory = new Configuration().buildSessionFactory();
Expand Down Expand Up @@ -274,14 +282,20 @@ static void insertTestData(Session session, String insertMql) {
}

private void doWorkAwareOfAutoCommit(Work work) {
session.doWork(connection -> doAwareOfAutoCommit(connection, () -> work.execute(connection)));
doWorkWithSpecifiedAutoCommit(autoCommit, session, work);
}

void doAwareOfAutoCommit(Connection connection, SqlExecutable work) throws SQLException {
doWithSpecifiedAutoCommit(false, connection, () -> doAndTerminateTransaction(connection, work));
static void doWorkWithSpecifiedAutoCommit(boolean autoCommit, Session session, Work work) {
session.doWork(connection -> {
SqlExecutable executable = () -> work.execute(connection);
doWithSpecifiedAutoCommit(
autoCommit,
connection,
autoCommit ? executable : () -> doAndTerminateTransaction(connection, executable));
});
}

static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, SqlExecutable work)
private static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection, SqlExecutable work)
throws SQLException {
var originalAutoCommit = connection.getAutoCommit();
connection.setAutoCommit(autoCommit);
Expand All @@ -292,7 +306,8 @@ static void doWithSpecifiedAutoCommit(boolean autoCommit, Connection connection,
}
}

static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExecutable work) throws SQLException {
private static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExecutable work)
throws SQLException {
Throwable primaryException = null;
try {
work.execute();
Expand All @@ -311,7 +326,7 @@ static void doAndTerminateTransaction(Connection connectionNoAutoCommit, SqlExec
}
}

interface SqlExecutable {
private interface SqlExecutable {
void execute() throws SQLException;
}
}

This file was deleted.