package com.xt.hb.gis.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.xt.hb.gis.exception.BizException;
import com.xt.hb.gis.mappers.BaseMapper;

/**
 * 服务层共通基类
 * 
 * @author 袁晓冬
 *
 * @param <T>
 */
public abstract class BaseMapperService<T> implements BaseMapper<T> {
    /**
     * 获取数据库操作接口
     * 
     * @return
     */
    protected abstract BaseMapper<T> getMapper();

    /**
     * 获取检查过的Mapper对象
     * 
     * @return
     */
    private BaseMapper<T> getCheckedMapper() {
        BaseMapper<T> mapper = getMapper();
        if (null == mapper) { throw new BizException("mapper 不能为空！"); }
        return mapper;
    }

    @Transactional
    @Override
    public int deleteByPrimaryKey(String id) {
        return getCheckedMapper().deleteByPrimaryKey(id);
    }

    @Transactional
    @Override
    public int insert(T record) {
        return getCheckedMapper().insert(record);
    }

    @Override
    public T selectByPrimaryKey(String id) {
        return getCheckedMapper().selectByPrimaryKey(id);
    }

    @Override
    public List<T> selectAll() {
        return getCheckedMapper().selectAll();
    }

    @Transactional
    @Override
    public int updateByPrimaryKey(T record) {
        return getCheckedMapper().updateByPrimaryKey(record);
    }
}
