package quant.rich.emoney.service.postgre;

import java.util.Collection;

import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import quant.rich.emoney.config.PostgreMybatisConfig;

/**
 * 使用 PostgreSQL 存储数据的 ServiceImpl，重写了部分使用 Transactional 的方法
 */
public abstract class PostgreServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {

    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER, rollbackFor = Exception.class)
    @Override
    public boolean saveBatch(Collection<T> entityList) {
        return super.saveBatch(entityList);
    }

    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER, rollbackFor = Exception.class)
    @Override
    public boolean saveBatch(Collection<T> entityList, int batchSize) {
        return super.saveBatch(entityList, batchSize);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER, rollbackFor = Exception.class)
    public boolean saveOrUpdateBatch(Collection<T> entityList) {
        return super.saveOrUpdateBatch(entityList);
    }
    
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER, rollbackFor = Exception.class)
    @Override
    public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
        return super.saveOrUpdateBatch(entityList, batchSize);
    }
    
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    @Override
    public boolean updateBatchById(Collection<T> entityList, int batchSize) {
        return super.updateBatchById(entityList, batchSize);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeByIds(Collection<?> list) {
        return super.removeByIds(list);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeByIds(Collection<?> list, boolean useFill) {
        return super.removeByIds(list, useFill);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeBatchByIds(Collection<?> list) {
        return super.removeBatchByIds(list, DEFAULT_BATCH_SIZE);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeBatchByIds(Collection<?> list, int batchSize) {
        return super.removeBatchByIds(list, batchSize);
    }

    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
        return super.removeBatchByIds(list, batchSize, useFill);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean removeBatchByIds(Collection<?> list, boolean useFill) {
        return super.removeBatchByIds(list, useFill);
    }
    
    @Override
    @Transactional(transactionManager = PostgreMybatisConfig.POSTGRE_TRANSACTION_MANAGER,rollbackFor = Exception.class)
    public boolean updateBatchById(Collection<T> entityList) {
        return super.updateBatchById(entityList);
    }
    
    
}
