/*
 * 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.dbtest.cases.authority;

import io.shardingsphere.core.constant.DatabaseType;
import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collection;
import java.util.LinkedList;

/**
 * Authority root xml entry.
 * 
 * @author panjuan
 */
@Getter
@Setter
@XmlRootElement(name = "authority")
public final class Authority {
    
    @XmlElement(name = "init-sql")
    private Collection<InitSQL> initSQLs = new LinkedList<>();
    
    @XmlElement(name = "clean-sql")
    private Collection<CleanSQL> cleanSQLs = new LinkedList<>();
    
    /**
     * Get init sqls of this data base type.
     *
     * @param databaseType data base type
     * @return init sqls of this data base type
     */
    public Collection<String> getInitSQLs(DatabaseType databaseType) {
        for (InitSQL each : initSQLs) {
            if (each.getDatabaseTypeList().contains(databaseType)) {
                return each.getAllSQLContent();
            }
        }
        return new LinkedList<>();
    }
    
    /**
     * Get clean sqls of this data base type.
     *
     * @param databaseType data base type
     * @return clean sqls of this data base type
     */
    public Collection<String> getCleanSQLs(DatabaseType databaseType) {
        for (CleanSQL each : cleanSQLs) {
            if (each.getDatabaseTypeList().contains(databaseType)) {
                return each.getAllSQLContent();
            }
        }
        return new LinkedList<>();
    }
}

@@ -1091,16 +1091,14 @@
  = %22
-init-
 sql
+set
 %22)%0A 
@@ -1123,130 +1123,22 @@
 ion%3C
-InitSQL%3E initSQLs = new LinkedList%3C%3E();%0A    %0A    @XmlElement(name = %22clean-sql%22)%0A    private Collection%3CCleanSQL%3E cleanSQL
+SQLSet%3E SQLSet
 s = 
@@ -1403,105 +1403,90 @@
     
-for (InitSQL each : initSQLs) %7B%0A            if (each.getDatabaseTypeList().contains(databaseType)
+Collection%3CString%3E result = new LinkedList%3C%3E();%0A        for (SQLSet each : SQLSets
 ) %7B%0A
@@ -1493,35 +1493,38 @@
             
-    return 
+result.addAll(
 each.getAllS
@@ -1537,68 +1537,69 @@
 ent(
-);%0A            %7D%0A        %7D%0A        return new LinkedList%3C%3E()
+SQLType.Init, databaseType));%0A        %7D%0A        return result
 ;%0A  
@@ -1851,107 +1851,90 @@
     
-for (CleanSQL each : cleanSQLs) %7B%0A            if (each.getDatabaseTypeList().contains(databaseType)
+Collection%3CString%3E result = new LinkedList%3C%3E();%0A        for (SQLSet each : SQLSets
 ) %7B%0A
@@ -1945,27 +1945,30 @@
         
-    return 
+result.addAll(
 each.get
@@ -1985,68 +1985,70 @@
 ent(
-);%0A            %7D%0A        %7D%0A        return new LinkedList%3C%3E()
+SQLType.Clean, databaseType));%0A        %7D%0A        return result
 ;%0A  

use sql set.