Skip to content
Merged
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
608 changes: 608 additions & 0 deletions articles/NOTIFICATION_SYSTEM_UPDATE.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/main/java/org/ohdsi/webapi/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public interface Constants {
Float DEFAULT_THRESHOLD = 0.01f;

ImmutableList<String> ALLOWED_JOB_EXECUTION_PARAMETERS = ImmutableList.of(
"jobName",
"jobAuthor",
"cohort_definition_id",
Params.JOB_NAME,
Params.JOB_AUTHOR,
Params.COHORT_DEFINITION_ID,
"cohortId",
"cohortDefinitionIds",
"source_id",
"source_key",
Params.SOURCE_ID,
Params.SOURCE_KEY,
"scriptType",
"analysis_id",
Params.ANALYSIS_ID,
"concept_set_id",
"estimation_analysis_id",
"prediction_analysis_id"
Params.PATHWAY_ANALYSIS_ID,
Params.COHORT_CHARACTERIZATION_ID
);

String SESSION_ID = "sid";
Expand Down
63 changes: 37 additions & 26 deletions src/main/java/org/ohdsi/webapi/JobConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@

import org.apache.commons.lang3.StringUtils;
import org.ohdsi.webapi.audittrail.listeners.AuditTrailJobListener;
import org.ohdsi.webapi.common.generation.AutoremoveJobListener;
import org.ohdsi.webapi.common.generation.CancelJobListener;
import org.ohdsi.webapi.job.JdbcSearchableJobExecutionDao;
import org.ohdsi.webapi.job.JobTemplate;
import org.ohdsi.webapi.job.SearchableJobExecutionDao;
import org.ohdsi.webapi.security.authz.AuthorizationService;
import org.ohdsi.webapi.service.JobService;
import org.ohdsi.webapi.util.ManagedThreadPoolTaskExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.ohdsi.webapi.batch.JdbcSearchableJobExecutionDao;
import org.ohdsi.webapi.batch.SearchableJobExecutionDao;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.JobExplorerFactoryBean;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.TaskExecutorJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
Expand All @@ -37,6 +34,12 @@

/**
* Spring Batch 5.x configuration for Java 21 / Spring Boot 3.2
*
* IMPORTANT: Spring Batch and JPA share the same DataSource, so they MUST use
* the same PlatformTransactionManager (the primary JpaTransactionManager).
* Using a separate DataSourceTransactionManager for batch would cause
* "Already value [ConnectionHolder] bound to thread" errors whenever a
* batch step touches JPA repositories.
*/
@Configuration
@Lazy(false)
Expand Down Expand Up @@ -77,25 +80,32 @@ private void init() {
log.info("Batch table prefix: {}", this.tablePrefix);
}

// Spring Batch transaction manager (separate from JPA)
@Bean("batchTransactionManager")
public DataSourceTransactionManager batchTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}

// JobRepository configuration for Spring Batch 5
// Uses the primary JpaTransactionManager (shared DataSource rule)
@Bean
public JobRepository jobRepository(DataSource dataSource,
@Qualifier("batchTransactionManager") DataSourceTransactionManager batchTransactionManager) throws Exception {
PlatformTransactionManager transactionManager) throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(batchTransactionManager);
factory.setTransactionManager(transactionManager);
factory.setTablePrefix(this.tablePrefix);
factory.setIsolationLevelForCreate(isolationLevelForCreate);
factory.afterPropertiesSet();
return factory.getObject();
}

// JobExplorer configuration for Spring Batch 5 - CRITICAL: Must use same table prefix as JobRepository
@Bean
public JobExplorer jobExplorer(DataSource dataSource,
PlatformTransactionManager transactionManager) throws Exception {
JobExplorerFactoryBean factory = new JobExplorerFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.setTablePrefix(this.tablePrefix);
factory.afterPropertiesSet();
return factory.getObject();
}

@Bean
public TaskExecutor batchTaskExecutor() {
ManagedThreadPoolTaskExecutor taskExecutor = new ManagedThreadPoolTaskExecutor();
Expand Down Expand Up @@ -127,33 +137,34 @@ public JobLauncher asyncJobLauncher(JobRepository jobRepository, @Qualifier("bat

@Bean
public JobTemplate jobTemplate(JobLauncher jobLauncher, JobRepository jobRepository, AuthorizationService authorizationService,
@Qualifier("batchTransactionManager") PlatformTransactionManager batchTransactionManager) {
return new JobTemplate(jobLauncher, jobRepository, authorizationService, batchTransactionManager);
PlatformTransactionManager transactionManager) {
return new JobTemplate(jobLauncher, jobRepository, authorizationService, transactionManager);
}

/**
* TransactionTemplate for batch tasklets using batchTransactionManager.
* This ensures tasklets use the same transaction manager as the Spring Batch step,
* preventing conflicts when creating nested transactions.
* TransactionTemplate for batch tasklets.
* Uses the same JpaTransactionManager as the step transaction,
* so nested PROPAGATION_REQUIRED calls participate in the existing transaction.
*/
@Bean("batchTransactionTemplate")
public TransactionTemplate batchTransactionTemplate(
@Qualifier("batchTransactionManager") PlatformTransactionManager batchTransactionManager) {
PlatformTransactionManager transactionManager) {
TransactionTemplate template = new TransactionTemplate();
template.setTransactionManager(batchTransactionManager);
template.setTransactionManager(transactionManager);
return template;
}

/**
* TransactionTemplate with PROPAGATION_REQUIRES_NEW for batch tasklets.
* Used when tasklets need to commit data immediately (e.g., cache updates)
* independent of the step's transaction.
* Used when tasklets need to commit data immediately (e.g., status updates)
* independent of the step's transaction. JpaTransactionManager properly
* suspends the outer transaction (including its ConnectionHolder).
*/
@Bean("batchTransactionTemplateRequiresNew")
public TransactionTemplate batchTransactionTemplateRequiresNew(
@Qualifier("batchTransactionManager") PlatformTransactionManager batchTransactionManager) {
PlatformTransactionManager transactionManager) {
TransactionTemplate template = new TransactionTemplate();
template.setTransactionManager(batchTransactionManager);
template.setTransactionManager(transactionManager);
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return template;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ohdsi/webapi/JobInvalidator.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.ohdsi.webapi;

import org.ohdsi.webapi.job.SearchableJobExecutionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.ohdsi.webapi.batch.SearchableJobExecutionDao;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package org.ohdsi.webapi.check.checker.cohort;

import org.ohdsi.analysis.estimation.comparativecohortanalysis.design.CohortMethodAnalysis;
import org.ohdsi.analysis.estimation.comparativecohortanalysis.design.ComparativeCohortAnalysis;
import org.ohdsi.webapi.check.builder.DuplicateValidatorBuilder;
import org.ohdsi.webapi.check.builder.IterableForEachValidatorBuilder;
import org.ohdsi.webapi.check.builder.NotNullNotEmptyValidatorBuilder;
import org.ohdsi.webapi.check.builder.ValidatorGroupBuilder;
import org.ohdsi.webapi.check.checker.BaseChecker;
import org.ohdsi.webapi.check.checker.tag.helper.TagHelper;
import org.ohdsi.webapi.cohortdefinition.dto.CohortDTO;
import org.ohdsi.webapi.service.dto.CommonEntityExtDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@Component
Expand Down
Loading
Loading