/*
 * 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;

import io.shardingsphere.dbtest.cases.authority.Authority;

import javax.sql.DataSource;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;

/**
 * Authority environment manager.
 *
 * @author panjuan
 */
public final class AuthorityEnvironmentManager {
    
    private final Authority authority;
    
    private final DataSource dataSource;
    
    public AuthorityEnvironmentManager(final String path, final DataSource dataSource) throws IOException, JAXBException {
        try (FileReader reader = new FileReader(path)) {
            authority = (Authority) JAXBContext.newInstance(Authority.class).createUnmarshaller().unmarshal(reader);
        }
       this.dataSource = dataSource;
    }
    
    /**
     * Initialize data.
     * 
     * @throws SQLException SQL exception
     * @throws ParseException parse exception
     */
    public void initialize() throws SQLException, ParseException {
    
    
    }
}

@@ -658,24 +658,77 @@
 authority;%0A%0A
+import io.shardingsphere.core.constant.DatabaseType;%0A
 import io.sh
@@ -923,32 +923,60 @@
 io.IOException;%0A
+import java.sql.Connection;%0A
 import java.sql.
@@ -1005,23 +1005,19 @@
 ava.
-text.ParseExcep
+util.Collec
 tion
@@ -1223,24 +1223,74 @@
 ource;%0A    %0A
+    private final DatabaseType databaseType;%0A    %0A
     public A
@@ -1362,16 +1362,49 @@
 taSource
+, final DatabaseType databaseType
 ) throws
@@ -1624,16 +1624,17 @@
 %0A       
+ 
 this.dat
@@ -1651,24 +1651,66 @@
 dataSource;%0A
+        this.databaseType = databaseType;%0A
     %7D%0A    %0A 
@@ -1750,161 +1750,860 @@
    *
- %0A     * @throws SQLException SQL exception%0A     * @throws ParseException parse exception%0A     */%0A    public void initialize() throws SQLException, Parse
+%0A     */%0A    public void initialize() %7B%0A        Collection%3CString%3E initSQLs = authority.getInitSQLs(databaseType);%0A        if (initSQLs.isEmpty()) %7B%0A            return;%0A        %7D%0A        try (Connection connection = dataSource.getConnection()) %7B%0A            for (String each : initSQLs) %7B%0A                connection.createStatement().execute(each);%0A            %7D%0A        %7D catch (final SQLException ignored) %7B%0A        %7D%0A    %7D%0A    %0A    /**%0A     * Clean data.%0A     *%0A     */%0A    public void clean() %7B%0A        Collection%3CString%3E cleanSQLs = authority.getCleanSQLs(databaseType);%0A        if (cleanSQLs.isEmpty()) %7B%0A            return;%0A        %7D%0A        try (Connection connection = dataSource.getConnection()) %7B%0A            for (String each : cleanSQLs) %7B%0A                connection.createStatement().execute(each);%0A            %7D%0A        %7D catch (final SQL
 Exce
@@ -2607,28 +2607,37 @@
 xception
+ ignored)
  %7B%0A    
-%0A
     
+%7D
 %0A    %7D%0A%7D

add initialize clean.