zoukankan      html  css  js  c++  java
  • sharding JDBC 不支持批量导入解决方法

    package com.ydmes.service.impl.log;

    import com.ydmes.domain.entity.log.BarTraceBackLog;
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import org.springframework.stereotype.Component;
    import org.springframework.transaction.TransactionDefinition;
    import org.springframework.transaction.TransactionStatus;
    import org.springframework.transaction.support.DefaultTransactionDefinition;

    import java.util.List;

    @Component
    public class BarTraceBackLogBatchServiceImpl implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public void batchInsertBarTraceBackLogs(List<BarTraceBackLog> barTraceBackLogs) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);

    DataSourceTransactionManager transactionManager = (DataSourceTransactionManager)
    applicationContext.getBean("shardingTransactitonManager");
    TransactionStatus transactionStatus = transactionManager.getTransaction(definition);

    for (BarTraceBackLog barTraceBackLog : barTraceBackLogs) {
    //UserDao有create方法,单条插入
    applicationContext.getBean(BarTraceBackLogServiceImpl.class).insertSelective(barTraceBackLog);
    }
    transactionManager.commit(transactionStatus);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    }
    }

  • 相关阅读:
    Asp.Net服务器Cassini
    Vista系统Administrator帐户的激活与禁用
    SqlServer中的Top * With Ties
    SqlServer建远程服务连接
    SqlServer2005安装成功后补加Sa用户
    列出某个表中所有的列名
    水晶报表周期性打开报表失败
    Asp.net中文cookie的乱码问题
    HTML数据库编程、JavaScript数据库编程
    试图索引的限制
  • 原文地址:https://www.cnblogs.com/xyj179/p/11454562.html
Copyright © 2011-2022 走看看