Skip to content

Commit

Permalink
Add transaction manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jacodg committed May 2, 2024
1 parent ea4bbd0 commit 4a81e33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/nl/nn/testtool/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.transaction.TransactionManager;

import io.quarkus.arc.DefaultBean;
import nl.nn.testtool.echo2.ComparePane;
Expand Down Expand Up @@ -229,6 +231,14 @@ DataSource dataSource() {
return new SimpleDriverDataSource();
}

@Bean
@Scope("prototype")
TransactionManager transactionManager(DataSource dataSource) {
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(dataSource);
return transactionManager;
}

@Bean
@Scope("prototype")
JdbcTemplate jdbcTemplate(DataSource dataSource) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/nl/nn/testtool/storage/database/DatabaseStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -57,6 +59,15 @@
/**
* @author Jaco de Groot
*/
// With transaction manager configured auto-commit is disabled and PostgreSQL will not throw the following exception
// on insert of a report: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
// Without proxyTargetClass = true the test webapp will give: Bean named 'proofOfMigrationStorage' is expected to be of
// type 'nl.nn.testtool.storage.proofofmigration.ProofOfMigrationStorage' but was actually of type 'jdk.proxy3.$Proxy26'
// It would also be possible to set auto-commit to false on Connection(Pool) or DataSource level but then still a
// transaction manger needs to be configured for JdbcTemplate to commit changes. Otherwise everything seems to be
// working fine (logging shows insert query) but no data appears in database and debug tab.
@EnableTransactionManagement(proxyTargetClass = true)
@Transactional
// @Dependent disabled for Quarkus for now because of the use of JdbcTemplate
public class DatabaseStorage implements LogStorage, CrudStorage {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand Down

0 comments on commit 4a81e33

Please sign in to comment.