1 package com.ydmes.service.impl.log;
2
3 import com.ydmes.domain.entity.log.BarTraceBackLog;
4 import org.springframework.beans.BeansException;
5 import org.springframework.context.ApplicationContext;
6 import org.springframework.context.ApplicationContextAware;
7 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
8 import org.springframework.stereotype.Component;
9 import org.springframework.transaction.TransactionDefinition;
10 import org.springframework.transaction.TransactionStatus;
11 import org.springframework.transaction.support.DefaultTransactionDefinition;
12
13 import java.util.List;
14
15 @Component
16 public class BarTraceBackLogBatchServiceImpl implements ApplicationContextAware {
17 private static ApplicationContext applicationContext;
18
19 public void batchInsertBarTraceBackLogs(List<BarTraceBackLog> barTraceBackLogs) {
20 DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
21 definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
22 definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
23
24 DataSourceTransactionManager transactionManager = (DataSourceTransactionManager)
25 applicationContext.getBean("shardingTransactitonManager");
26 TransactionStatus transactionStatus = transactionManager.getTransaction(definition);
27
28 for (BarTraceBackLog barTraceBackLog : barTraceBackLogs) {
29 //UserDao有create方法,单条插入
30 applicationContext.getBean(BarTraceBackLogServiceImpl.class).insertSelective(barTraceBackLog);
31 }
32 transactionManager.commit(transactionStatus);
33 }
34
35
36 @Override
37 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
38 this.applicationContext = applicationContext;
39 }
40 }