package com.interplug.qcast.config.batch; import javax.sql.DataSource; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory; import org.springframework.batch.support.DatabaseType; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.transaction.PlatformTransactionManager; /** * Spring Batch Configuration for SQL Server without sequence support */ @Configuration @EnableBatchProcessing(modular = false) public class BatchConfiguration { /** * Custom JobRepository that uses table-based ID generation instead of sequences */ @Bean @Primary public JobRepository jobRepository(DataSource dataSource, PlatformTransactionManager transactionManager) throws Exception { JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); factory.setDataSource(dataSource); factory.setTransactionManager(transactionManager); // 테이블 prefix 설정 factory.setTablePrefix("BATCH_"); // 격리 레벨 설정 factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED"); factory.setIncrementerFactory(new DefaultDataFieldMaxValueIncrementerFactory(dataSource)); // SQL Server 데이터베이스 타입 설정 //factory.setDatabaseType(DatabaseType.SQLSERVER.getProductName()); factory.setDatabaseType("sqlserver"); factory.afterPropertiesSet(); return factory.getObject(); } /** * TaskExecutor for async batch processing */ @Bean public TaskExecutor batchTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(5); executor.setMaxPoolSize(10); executor.setQueueCapacity(25); executor.setThreadNamePrefix("batch-"); executor.initialize(); return executor; } }