Skip to content

Commit

Permalink
Use TransactionManagementConfigurer
Browse files Browse the repository at this point in the history
  • Loading branch information
jacodg committed Apr 16, 2024
1 parent c77515b commit 439f36e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
30 changes: 28 additions & 2 deletions src/main/java/nl/nn/testtool/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022-2023 WeAreFrank!
Copyright 2022-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,17 @@

import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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 org.springframework.transaction.annotation.TransactionManagementConfigurer;

import io.quarkus.arc.DefaultBean;
import nl.nn.testtool.echo2.ComparePane;
Expand Down Expand Up @@ -93,7 +99,7 @@
@Singleton
@Scope("singleton")
@Configuration
public class Config {
public class Config implements TransactionManagementConfigurer {

@Bean
@Scope("prototype") // Echo2Application needs to be unique per user (not per JVM)
Expand Down Expand Up @@ -219,6 +225,26 @@ String xsltResource() {
return "ladybug/default.xslt";
}

@Bean
DataSource dataSource() {
return new SimpleDriverDataSource();
}

@Bean
@Override
public TransactionManager annotationDrivenTransactionManager() {
DataSourceTransactionManager tx = new DataSourceTransactionManager();
tx.setDataSource(dataSource());
return tx;
}

@Bean
JdbcTemplate jdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
return jdbcTemplate;
}

@Bean
@Scope("singleton")
@Lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@
// 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'
@EnableTransactionManagement(proxyTargetClass = true)
// Qualifier ladybug makes it possible to have an independent transaction manager to prevent interference with
// transactions of the application that is using Ladybug. It will prevent the following error running TestIAF Larva
// tests with Narayana: You cannot commit during a managed transaction. With propagation = Propagation.REQUIRES_NEW
// this error is also gone but then tests fail with: Commit not allowed by transaction service. To optimize performance
// and minimize locking isolation = Isolation.READ_UNCOMMITTED could be considered but will give the following error for
// Oracle running the TestIAF test matrix: READ_COMMITTED and SERIALIZABLE are the only valid transaction levels.
@Transactional("ladybug")
@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 439f36e

Please sign in to comment.