/*
 * 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.shardingproxy.runtime;

import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.api.config.RuleConfiguration;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.executor.ShardingExecuteEngine;
import io.shardingsphere.core.metadata.ShardingMetaData;
import io.shardingsphere.core.rule.DataSourceParameter;
import io.shardingsphere.core.rule.MasterSlaveRule;
import io.shardingsphere.core.rule.ShardingRule;
import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule;
import io.shardingsphere.orchestration.internal.rule.OrchestrationShardingRule;
import io.shardingsphere.shardingproxy.backend.BackendExecutorContext;
import io.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSource;
import io.shardingsphere.shardingproxy.runtime.metadata.ProxyTableMetaDataConnectionManager;
import lombok.Getter;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Sharding schema.
 *
 * @author zhangliang
 * @author zhangyonglun
 * @author panjuan
 * @author zhaojun
 * @author wangkai
 */
@Getter
public final class ShardingSchema extends LogicSchema {
    
    private final ShardingRule shardingRule;
    
    private final ShardingMetaData metaData;
    
    public ShardingSchema(final String name, final Map<String, DataSourceParameter> dataSources, final ShardingRuleConfiguration shardingRuleConfig, final boolean isUsingRegistry) {
        super(name, dataSources);
        shardingRule = getShardingRule(shardingRuleConfig, isUsingRegistry);
        metaData = getShardingMetaData(BackendExecutorContext.getInstance().getExecuteEngine());
    }
    
    private ShardingRule getShardingRule(final ShardingRuleConfiguration shardingRule, final boolean isUsingRegistry) {
        return isUsingRegistry ? new OrchestrationShardingRule(shardingRule, dataSources.keySet()) : new ShardingRule(shardingRule, dataSources.keySet());
    }
    
    private ShardingMetaData getShardingMetaData(final ShardingExecuteEngine executeEngine) {
        return new ShardingMetaData(getDataSourceURLs(dataSources), shardingRule,
                DatabaseType.MySQL, executeEngine, new ProxyTableMetaDataConnectionManager(backendDataSource), GlobalRegistry.getInstance().getMaxConnectionsSizePerQuery());
    }
    
    private Map<String, String> getDataSourceURLs(final Map<String, DataSourceParameter> dataSourceParameters) {
        Map<String, String> result = new LinkedHashMap<>(dataSourceParameters.size(), 1);
        for (Entry<String, DataSourceParameter> entry : dataSourceParameters.entrySet()) {
            result.put(entry.getKey(), entry.getValue().getUrl());
        }
        return result;
    }
}

@@ -667,129 +667,8 @@
 e;%0A%0A
-import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;%0Aimport io.shardingsphere.api.config.RuleConfiguration;%0A
 impo
@@ -993,151 +993,16 @@
 ule.
-MasterSlaveRule;%0Aimport io.shardingsphere.core.rule.ShardingRule;%0Aimport io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlave
+Sharding
 Rule
@@ -1158,94 +1158,8 @@
 xt;%0A
-import io.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSource;%0A
 impo
@@ -2246,33 +2246,36 @@
 e(shardingRule, 
-d
+getD
 ataSources.keySe
@@ -2260,32 +2260,34 @@
 , getDataSources
+()
 .keySet()) : new
@@ -2314,17 +2314,20 @@
 ngRule, 
-d
+getD
 ataSourc
@@ -2328,16 +2328,18 @@
 aSources
+()
 .keySet(
@@ -2501,17 +2501,20 @@
 rceURLs(
-d
+getD
 ataSourc
@@ -2515,16 +2515,18 @@
 aSources
+()
 ), shard
@@ -2625,17 +2625,20 @@
 Manager(
-b
+getB
 ackendDa
@@ -2645,16 +2645,18 @@
 taSource
+()
 ), Globa

modify it