transaction 오류 수정

This commit is contained in:
daekuk1
2026-01-27 11:03:20 +09:00
parent 75fb8234f6
commit 181400c628
3 changed files with 42 additions and 6 deletions
@@ -16,6 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonth; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonth;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonthService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonthService;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDayService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDayService;
@@ -35,6 +38,7 @@ public class DailyToMonthlyAggregationJob implements Job {
private ApiStatsDayService apiStatsDayService; private ApiStatsDayService apiStatsDayService;
private ApiStatsMonthService apiStatsMonthService; private ApiStatsMonthService apiStatsMonthService;
private DailyToMonthlyAggregationJob self;
@Autowired @Autowired
public void setApiStatsDayService(ApiStatsDayService apiStatsDayService) { public void setApiStatsDayService(ApiStatsDayService apiStatsDayService) {
@@ -46,14 +50,22 @@ public class DailyToMonthlyAggregationJob implements Job {
this.apiStatsMonthService = apiStatsMonthService; this.apiStatsMonthService = apiStatsMonthService;
} }
@Autowired
public void setSelf(DailyToMonthlyAggregationJob self) {
this.self = self;
}
@Override @Override
@Transactional
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
DataSourceType dataType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.APIGW);
DataSourceContextHolder.setDataSourceType(dataType);
try { try {
YearMonth targetMonth = YearMonth.now().minusMonths(1); YearMonth targetMonth = YearMonth.now().minusMonths(1);
executeManual(targetMonth); self.executeManual(targetMonth);
} catch (Exception e) { } catch (Exception e) {
throw new JobExecutionException(e); throw new JobExecutionException(e);
} finally {
DataSourceContextHolder.clearDataSourceType();
} }
} }
@@ -15,6 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDay; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDay;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDayService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsDayService;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsHourService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsHourService;
@@ -34,6 +37,7 @@ public class HourlyToDailyAggregationJob implements Job {
private ApiStatsHourService apiStatsHourService; private ApiStatsHourService apiStatsHourService;
private ApiStatsDayService apiStatsDayService; private ApiStatsDayService apiStatsDayService;
private HourlyToDailyAggregationJob self;
@Autowired @Autowired
public void setApiStatsHourService(ApiStatsHourService apiStatsHourService) { public void setApiStatsHourService(ApiStatsHourService apiStatsHourService) {
@@ -45,14 +49,22 @@ public class HourlyToDailyAggregationJob implements Job {
this.apiStatsDayService = apiStatsDayService; this.apiStatsDayService = apiStatsDayService;
} }
@Autowired
public void setSelf(HourlyToDailyAggregationJob self) {
this.self = self;
}
@Override @Override
@Transactional
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
DataSourceType dataType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.APIGW);
DataSourceContextHolder.setDataSourceType(dataType);
try { try {
LocalDate targetDate = LocalDate.now().minusDays(1); LocalDate targetDate = LocalDate.now().minusDays(1);
executeManual(targetDate); self.executeManual(targetDate);
} catch (Exception e) { } catch (Exception e) {
throw new JobExecutionException(e); throw new JobExecutionException(e);
} finally {
DataSourceContextHolder.clearDataSourceType();
} }
} }
@@ -14,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsYear; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsYear;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsYearService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsYearService;
import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonthService; import com.eactive.eai.rms.data.entity.onl.kjb.statistics.ApiStatsMonthService;
@@ -33,6 +36,7 @@ public class MonthlyToYearlyAggregationJob implements Job {
private ApiStatsMonthService apiStatsMonthService; private ApiStatsMonthService apiStatsMonthService;
private ApiStatsYearService apiStatsYearService; private ApiStatsYearService apiStatsYearService;
private MonthlyToYearlyAggregationJob self;
@Autowired @Autowired
public void setApiStatsMonthService(ApiStatsMonthService apiStatsMonthService) { public void setApiStatsMonthService(ApiStatsMonthService apiStatsMonthService) {
@@ -44,14 +48,22 @@ public class MonthlyToYearlyAggregationJob implements Job {
this.apiStatsYearService = apiStatsYearService; this.apiStatsYearService = apiStatsYearService;
} }
@Autowired
public void setSelf(MonthlyToYearlyAggregationJob self) {
this.self = self;
}
@Override @Override
@Transactional
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
DataSourceType dataType = DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.APIGW);
DataSourceContextHolder.setDataSourceType(dataType);
try { try {
Year targetYear = Year.now().minusYears(1); Year targetYear = Year.now().minusYears(1);
executeManual(targetYear); self.executeManual(targetYear);
} catch (Exception e) { } catch (Exception e) {
throw new JobExecutionException(e); throw new JobExecutionException(e);
} finally {
DataSourceContextHolder.clearDataSourceType();
} }
} }