/*
 * 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.example.spring.namespace.mybatis.nodep;

import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.mybatis.service.SpringPojoService;
import io.shardingsphere.example.type.ShardingType;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringNamespaceExample {
    
    private static ShardingType type = ShardingType.SHARDING_DATABASES;
//    private static ShardingType type = ShardingType.SHARDING_TABLES;
//    private static ShardingType type = ShardingType.SHARDING_DATABASES_AND_TABLES;
//    private static ShardingType type = ShardingType.MASTER_SLAVE;
//    private static ShardingType type = ShardingType.SHARDING_MASTER_SLAVE;
    
    public static void main(final String[] args) {
        try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(getApplicationFile())) {
            process(applicationContext);
        }
    }
    
    private static String getApplicationFile() {
        switch (type) {
            case SHARDING_DATABASES:
                return "META-INF/application-sharding-databases.xml";
            case SHARDING_TABLES:
                return "META-INF/application-sharding-tables.xml";
            case SHARDING_DATABASES_AND_TABLES:
                return "META-INF/application-sharding-databases-tables.xml";
            case MASTER_SLAVE:
                return "META-INF/application-master-slave.xml";
            case SHARDING_MASTER_SLAVE:
                return "META-INF/application-sharding-master-slave.xml";
            default:
                throw new UnsupportedOperationException(type.name());
        }
    }
    
    private static void process(final ConfigurableApplicationContext applicationContext) {
        CommonService commonService = getCommonService(applicationContext);
        commonService.initEnvironment();
        commonService.processSuccess();
        try {
            commonService.processFailure();
        } catch (final Exception ex) {
            System.out.println(ex.getMessage());
            commonService.printData();
        } finally {
            commonService.cleanEnvironment();
        }
    }
    
    private static CommonService getCommonService(final ConfigurableApplicationContext applicationContext) {
        return applicationContext.getBean(SpringPojoService.class);
    }
}

@@ -1441,16 +1441,125 @@
 _SLAVE;%0A
+//    private static boolean IS_RANGE_SHARDING = true;%0A    private static boolean IS_RANGE_SHARDING = false;%0A
     %0A   
@@ -1706,33 +1706,88 @@
 Context(
-getApplicationFil
+IS_RANGE_SHARDING ? getApplicationFileRange() : getApplicationFilePrecis
 e())) %7B%0A
@@ -1892,16 +1892,23 @@
 tionFile
+Precise
 () %7B%0A   
@@ -2028,16 +2028,24 @@
 atabases
+-precise
 .xml%22;%0A 
@@ -2133,24 +2133,32 @@
 rding-tables
+-precise
 .xml%22;%0A     
@@ -2270,16 +2270,781 @@
 s-tables
+-precise.xml%22;%0A            case MASTER_SLAVE:%0A                return %22META-INF/application-master-slave.xml%22;%0A            case SHARDING_MASTER_SLAVE:%0A                return %22META-INF/application-sharding-master-slave-precise.xml%22;%0A            default:%0A                throw new UnsupportedOperationException(type.name());%0A        %7D%0A    %7D%0A    %0A    private static String getApplicationFileRange() %7B%0A        switch (type) %7B%0A            case SHARDING_DATABASES:%0A                return %22META-INF/application-sharding-databases-range.xml%22;%0A            case SHARDING_TABLES:%0A                return %22META-INF/application-sharding-tables-range.xml%22;%0A            case SHARDING_DATABASES_AND_TABLES:%0A                return %22META-INF/application-sharding-databases-tables-range
 .xml%22;%0A 
@@ -3235,32 +3235,38 @@
 ing-master-slave
+-range
 .xml%22;%0A         
@@ -3613,16 +3613,33 @@
 Success(
+IS_RANGE_SHARDING
 );%0A     
@@ -3815,16 +3815,33 @@
 intData(
+IS_RANGE_SHARDING
 );%0A     

update SpringNamespace