/*
 * 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.env.authority.sql;

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

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;

/**
 * Authority SQL set xml entry.
 *
 * @author panjuan
 */
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
public final class SQLSet {
    
    @XmlAttribute(name = "db-types")
    private String dbTypes;
    
    @XmlAttribute(name = "sql-type")
    private SQLType sqlType;
    
    @XmlElement(name = "sql")
    private Collection<SQL> SQLs = new LinkedList<>();
    
    private Collection<DatabaseType> getDatabaseTypeList() {
        if (null == dbTypes) {
            return Arrays.asList(DatabaseType.MySQL, DatabaseType.Oracle, DatabaseType.H2, DatabaseType.PostgreSQL, DatabaseType.SQLServer);
        }
        Collection<DatabaseType> result = new LinkedList<>();
        for (String each : dbTypes.split(",")) {
            result.add(DatabaseType.valueOf(each));
        }
        return result;
    }
    
    /**
     * Get all sqls content.
     *
     * @return sqls content
     */
    public Collection<String> getAllSQLContent(final SQLType sqlType, final DatabaseType databaseType ) {
        Collection<String> result = new LinkedList<>();
        if (this.sqlType != sqlType || !getDatabaseTypeList().contains(databaseType)) {
            return result;
        }
        for (SQL each : SQLs) {
            result.add(each.getContent());
        }
        return result;
    }
}

@@ -932,16 +932,68 @@
 lement;%0A
+import javax.xml.bind.annotation.XmlElementWrapper;%0A
 import j
@@ -1066,16 +1066,39 @@
 kedList;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1459,24 +1459,302 @@
 t%3C%3E();%0A    %0A
+    @XmlElementWrapper(name = %22user-create%22)%0A    @XmlElement(name = %22sql%22)%0A    private List%3CString%3E useCreateSQLs = new LinkedList%3C%3E();%0A    %0A    @XmlElementWrapper(name = %22user-drop%22)%0A    @XmlElement(name = %22sql%22)%0A    private List%3CString%3E useDropSQLs = new LinkedList%3C%3E();%0A    %0A
     private 
@@ -2214,28 +2214,32 @@
 Get all 
-sqls content
+create user sqls
 .%0A     *
@@ -2251,125 +2251,211 @@
  * @
-return sqls content%0A     */%0A    public Collection%3CString%3E getAllSQLContent(final SQLType sqlType, final DatabaseType 
+param databaseType data base type.%0A     * @return create user sqls%0A     */%0A    public Collection%3CString%3E getCreateUserSQLs(final DatabaseType databaseType ) %7B%0A        if (!getDatabaseTypeList().contains(
 data
@@ -2454,33 +2454,33 @@
 ins(databaseType
- 
+)
 ) %7B%0A        Coll
@@ -2479,35 +2479,18 @@
     
-Collection%3CString%3E result =
+    return
  new
@@ -2518,197 +2518,364 @@
     
-if (this.sqlType != sqlType %7C%7C !getDatabaseTypeList().contains(
+%7D%0A        return getUseCreateSQLs();%0A    %7D%0A    %0A    /**%0A     * Get all drop user sqls.%0A     *%0A     * @param databaseType 
 data
+ 
 base
-Type)) %7B%0A   
+ type.%0A
      
-    
+* @
 return 
+c
 re
-sult;%0A        %7D%0A        for (SQL each : SQLs) %7B%0A            result.add(each.getContent()
+ate user sqls%0A     */%0A    public Collection%3CString%3E getDropUserSQLs(final DatabaseType databaseType ) %7B%0A        if (!getDatabaseTypeList().contains(databaseType)) %7B%0A            return new LinkedList%3C%3E(
 );%0A 
@@ -2890,32 +2890,42 @@
 %0A        return 
-result
+getUseDropSQLs()
 ;%0A    %7D%0A%7D%0A

use @XmlElementWrapper.