package com.ag.dynamicmodule.service;

import org.mybatis.spring.SqlSessionTemplate;

import java.lang.reflect.Proxy;

/**
 * @description:  用于基本数据save构造
 * @author: WangNan
 * @create: 2019-04-10 16:20
 */
public  class BaseMapperRepository {

    private Object bean;

    private SqlSessionTemplate sqlSessionTemplate;

    private Object mapper;

    private String myBatisNameSpace;

    String getMyBatisNameSpace(){return myBatisNameSpace;}

    Object getBean(){return this.bean;}

    Object getMapper(){return this.mapper;}

    SqlSessionTemplate getSqlSessionTemplate(){return this.sqlSessionTemplate;}

    public BaseMapperRepository(Object bean, SqlSessionTemplate sqlSessionTemplate,
                                String myBatisNameSpace) {
        this.bean = bean;
        this.sqlSessionTemplate = sqlSessionTemplate;
        this.myBatisNameSpace=myBatisNameSpace;
    }

    public BaseMapperRepository(Object bean, Object mapper) {
        /**
         * 必须是mybatis动态代理对象
         */
        if (!Proxy.isProxyClass(mapper.getClass())){
            throw new RuntimeException("Constructor Fail.... The second parameter must be the interface for Mybatis dynamic Proxy");
        }
        this.bean = bean;
        this.mapper = mapper;
    }
}