/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

package org.apache.shardingsphere.core.optimizer;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.core.keygen.GeneratedKey;
import org.apache.shardingsphere.core.optimizer.insert.InsertOptimizeEngine;
import org.apache.shardingsphere.core.optimizer.query.QueryOptimizeEngine;
import org.apache.shardingsphere.core.parsing.parser.sql.SQLStatement;
import org.apache.shardingsphere.core.parsing.parser.sql.dml.DMLStatement;
import org.apache.shardingsphere.core.parsing.parser.sql.dml.insert.InsertStatement;
import org.apache.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement;
import org.apache.shardingsphere.core.rule.ShardingRule;

import java.util.List;

/**
 * Optimize engine factory.
 *
 * @author zhangliang
 * @author maxiaoguang
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class OptimizeEngineFactory {
    
    /**
     * Create optimize engine instance.
     * 
     * @param shardingRule sharding rule
     * @param sqlStatement SQL statement
     * @param parameters parameters
     * @param generatedKey generated key
     * @return optimize engine instance
     */
    public static OptimizeEngine newInstance(final ShardingRule shardingRule, final SQLStatement sqlStatement, final List<Object> parameters, final GeneratedKey generatedKey) {
        if (sqlStatement instanceof InsertStatement) {
            return new InsertOptimizeEngine(shardingRule, (InsertStatement) sqlStatement, parameters, generatedKey);
        }
        if (sqlStatement instanceof SelectStatement || sqlStatement instanceof DMLStatement) {
            return new QueryOptimizeEngine(sqlStatement.getRouteConditions().getOrCondition(), parameters);
        }
        // TODO do with DDL and DAL
        return new QueryOptimizeEngine(sqlStatement.getRouteConditions().getOrCondition(), parameters);
    }
}

@@ -966,16 +966,287 @@
 tedKey;%0A
+import org.apache.shardingsphere.core.optimizer.engine.encrypt.EncryptDefaultOptimizeEngine;%0Aimport org.apache.shardingsphere.core.optimizer.engine.encrypt.EncryptInsertOptimizeEngine;%0Aimport org.apache.shardingsphere.core.optimizer.engine.encrypt.EncryptOptimizeEngine;%0A
 import o
@@ -1306,32 +1306,32 @@
 OptimizeEngine;%0A
-
 import org.apach
@@ -1697,32 +1697,88 @@
 electStatement;%0A
+import org.apache.shardingsphere.core.rule.EncryptRule;%0A
 import org.apach
@@ -2895,16 +2895,16 @@
 and DAL%0A
-
         
@@ -3005,10 +3005,520 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * %0A     * %0A     * @param encryptRule%0A     * @param sqlStatement%0A     * @param parameters%0A     * @return%0A     */%0A    public static EncryptOptimizeEngine newInstance(final EncryptRule encryptRule, final SQLStatement sqlStatement, final List%3CObject%3E parameters) %7B%0A        if (sqlStatement instanceof InsertStatement) %7B%0A            return new EncryptInsertOptimizeEngine(encryptRule, (InsertStatement) sqlStatement, parameters);%0A        %7D%0A        return new EncryptDefaultOptimizeEngine();%0A    %7D%0A
 %7D%0A

add newInstance()