/*
 * 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.core.rule.DataSourceParameter;
import io.shardingsphere.shardingproxy.backend.jdbc.datasource.JDBCBackendDataSource;
import lombok.Getter;

import java.util.Map;

/**
 * Logic schema.
 *
 * @author panjuan
 */
@Getter
public class LogicSchema {
    
    private final String name;
    
    private final Map<String, DataSourceParameter> dataSources;
    
    private final JDBCBackendDataSource backendDataSource;
    
    public LogicSchema(final String name, final Map<String, DataSourceParameter> dataSources) {
        this.name = name;
        // TODO :jiaqi only use JDBC need connect db via JDBC, netty style should use SQL packet to get metadata
        this.dataSources = dataSources;
        backendDataSource = new JDBCBackendDataSource(dataSources);
    }
}

@@ -663,16 +663,61 @@
 ntime;%0A%0A
+import com.google.common.eventbus.Subscribe;%0A
 import i
@@ -764,16 +764,101 @@
 ameter;%0A
+import io.shardingsphere.orchestration.internal.event.config.DataSourceChangedEvent;%0A
 import i
@@ -935,16 +935,81 @@
 Source;%0A
+import io.shardingsphere.shardingproxy.util.DataSourceConverter;%0A
 import l
@@ -1250,22 +1250,16 @@
 private 
-final 
 JDBCBack
@@ -1567,24 +1567,24 @@
 ataSources;%0A
-
         back
@@ -1645,10 +1645,631 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Renew data source configuration.%0A     *%0A     * @param dataSourceEvent data source event.%0A     */%0A    @Subscribe%0A    public void renew(final DataSourceChangedEvent dataSourceEvent) %7B%0A        if (!name.equals(dataSourceEvent.getSchemaName())) %7B%0A            return;%0A        %7D%0A        backendDataSource.close();%0A        logicSchemas.put(dataSourceEvent.getSchemaName(), new ShardingSchema(dataSourceEvent.getSchemaName(),%0A                DataSourceConverter.getDataSourceParameterMap(dataSourceEvent.getDataSourceConfigurations()), logicSchema.getShardingRule(), logicSchema.getMasterSlaveRule()));%0A    %7D%0A
 %7D%0A

delete final