/*
 * 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.jpa.nodep;

import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jpa.service.SpringEntityService;
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.processSuccess();
        try {
            commonService.processFailure();
        } catch (final Exception ex) {
            System.out.println(ex.getMessage());
            commonService.printData();
        }
    }
    
    private static CommonService getCommonService(final ConfigurableApplicationContext applicationContext) {
        return applicationContext.getBean(SpringEntityService.class);
    }
}

@@ -1435,16 +1435,125 @@
 _SLAVE;%0A
+    private static boolean IS_RANGE_SHARDING = true;%0A//    private static boolean IS_RANGE_SHARDING = false;%0A
     %0A   
@@ -1700,33 +1700,88 @@
 Context(
-getApplicationFil
+IS_RANGE_SHARDING ? getApplicationFileRange() : getApplicationFilePrecis
 e())) %7B%0A
@@ -1886,16 +1886,23 @@
 tionFile
+Precise
 () %7B%0A   
@@ -2022,16 +2022,24 @@
 atabases
+-precise
 .xml%22;%0A 
@@ -2127,24 +2127,32 @@
 rding-tables
+-precise
 .xml%22;%0A     
@@ -2264,16 +2264,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 
@@ -3229,32 +3229,38 @@
 ing-master-slave
+-range
 .xml%22;%0A         
@@ -3566,16 +3566,33 @@
 Success(
+IS_RANGE_SHARDING
 );%0A     
@@ -3768,16 +3768,33 @@
 intData(
+IS_RANGE_SHARDING
 );%0A     

update SpringNamespaceExample