/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.core.rule;

import com.google.common.base.Preconditions;
import io.shardingsphere.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithm;
import io.shardingsphere.core.api.algorithm.masterslave.MasterSlaveLoadBalanceAlgorithmType;
import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration;
import lombok.Getter;

import java.util.Collection;

/**
 * Databases and tables master-slave rule configuration.
 * 
 * @author zhangliang
 */
@Getter
public final class MasterSlaveRule {
    
    private final String name;
    
    private final String masterDataSourceName;
    
    private final Collection<String> slaveDataSourceNames;
    
    private final MasterSlaveLoadBalanceAlgorithm loadBalanceAlgorithm;
    
    public MasterSlaveRule(final MasterSlaveRuleConfiguration config) {
        Preconditions.checkNotNull(config.getName(), "Master-slave rule name cannot be null.");
        Preconditions.checkNotNull(config.getMasterDataSourceName(), "Master data source name cannot be null.");
        Preconditions.checkNotNull(config.getSlaveDataSourceNames(), "Slave data source names cannot be null.");
        Preconditions.checkState(!config.getSlaveDataSourceNames().isEmpty(), "Slave data source names cannot be empty.");
        name = config.getName();
        masterDataSourceName = config.getMasterDataSourceName();
        slaveDataSourceNames = config.getSlaveDataSourceNames();
        loadBalanceAlgorithm = null == config.getLoadBalanceAlgorithm() ? MasterSlaveLoadBalanceAlgorithmType.getDefaultAlgorithmType().getAlgorithm() : config.getLoadBalanceAlgorithm();
    }
}

@@ -1089,16 +1089,35 @@
 ngliang%0A
+ * @author panjuan%0A
  */%0A@Get
@@ -2264,10 +2264,349 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Judge whether contain data source name.%0A     *%0A     * @param datasourceName data source name%0A     * @return contain or not.%0A     */%0A    public boolean containDataSourceName(final String datasourceName) %7B%0A        return masterDataSourceName.equals(datasourceName) %7C%7C slaveDataSourceNames.contains(datasourceName);%0A    %7D%0A
 %7D%0A

add containDataSourceName