// Path: tsharding-client/src/main/java/com/mogujie/trade/db/DataSourceType.java
// public enum DataSourceType {
//     master, slave
// }
// 
// Path: tsharding-client/src/main/java/com/mogujie/trade/db/ReadWriteSplittingContext.java
// public class ReadWriteSplittingContext {
// 
//     private static final ThreadLocal<DataSourceType> curDataSourceType = new ThreadLocal<DataSourceType>();
// 
//     public static void set(DataSourceType dataSourceType) {
//         curDataSourceType.set(dataSourceType);
//     }
// 
//     public static void setMaster() {
//         curDataSourceType.set(DataSourceType.master);
//     }
// 
//     public static void clear() {
//         curDataSourceType.remove();
//     }
// 
//     public static boolean isMaster() {
//         return DataSourceType.master == curDataSourceType.get();
//     }
// 
// }


import com.mogujie.trade.db.DataSourceType;
import com.mogujie.trade.db.ReadWriteSplitting;
import com.mogujie.trade.db.ReadWriteSplittingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
package com.mogujie.trade.tsharding.route.orm.base;



/**
 * 读写分离的上下文初始化和清空
 *
 * @author qigong
 */
public class ReadWriteSplittingContextInitializer {

    private final static Logger logger = LoggerFactory.getLogger(ReadWriteSplittingContextInitializer.class);

    private final static  String[] DEFAULT_WRITE_METHOD_NAMES = {"update", "save", "insert", "delete", "add",
            "batchInsert", "batchUpdate", "batchSave", "batchAdd"};

    private final static Map<Method, DataSourceType> cache = new ConcurrentHashMap<>();

    public static void initReadWriteSplittingContext(Method method) {
        // 忽略object的方法，只关注Mapper的方法
        if (method.getDeclaringClass() != Object.class) {
        }
        DataSourceType dataSourceType = getDataSourceType(method);
        logger.debug("ReadWriteSplitting {} using dataSource of  {}", method, dataSourceType);

// Path: tsharding-client/src/main/java/com/mogujie/trade/db/DataSourceType.java
// public enum DataSourceType {
//     master, slave
// }
// 
// Path: tsharding-client/src/main/java/com/mogujie/trade/db/ReadWriteSplittingContext.java
// public class ReadWriteSplittingContext {
// 
//     private static final ThreadLocal<DataSourceType> curDataSourceType = new ThreadLocal<DataSourceType>();
// 
//     public static void set(DataSourceType dataSourceType) {
//         curDataSourceType.set(dataSourceType);
//     }
// 
//     public static void setMaster() {
//         curDataSourceType.set(DataSourceType.master);
//     }
// 
//     public static void clear() {
//         curDataSourceType.remove();
//     }
// 
//     public static boolean isMaster() {
//         return DataSourceType.master == curDataSourceType.get();
//     }
// 
// }


// Path: tsharding-client/src/main/java/com/mogujie/trade/tsharding/route/orm/base/ReadWriteSplittingContextInitializer.java
import com.mogujie.trade.db.DataSourceType;
import com.mogujie.trade.db.ReadWriteSplitting;
import com.mogujie.trade.db.ReadWriteSplittingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

package com.mogujie.trade.tsharding.route.orm.base;



/**
 * 读写分离的上下文初始化和清空
 *
 * @author qigong
 */
public class ReadWriteSplittingContextInitializer {

    private final static Logger logger = LoggerFactory.getLogger(ReadWriteSplittingContextInitializer.class);

    private final static  String[] DEFAULT_WRITE_METHOD_NAMES = {"update", "save", "insert", "delete", "add",
            "batchInsert", "batchUpdate", "batchSave", "batchAdd"};

    private final static Map<Method, DataSourceType> cache = new ConcurrentHashMap<>();

    public static void initReadWriteSplittingContext(Method method) {
        // 忽略object的方法，只关注Mapper的方法
        if (method.getDeclaringClass() != Object.class) {
        }
        DataSourceType dataSourceType = getDataSourceType(method);
        logger.debug("ReadWriteSplitting {} using dataSource of  {}", method, dataSourceType);

        ReadWriteSplittingContext.set(dataSourceType);