/*
 * 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.core.executor;

import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.executor.sql.SQLExecuteUnit;
import io.shardingsphere.core.routing.RouteUnit;
import lombok.Getter;

import java.sql.SQLException;
import java.sql.Statement;

/**
 * Execute unit for JDBC statement.
 *
 * @author zhangliang
 * @author panjuan
 */
@Getter
public class StatementExecuteUnit implements SQLExecuteUnit {
    
    private static final Integer CONNECTION_FETCH_ONE_ROW_A_TIME = 0;
    
    private static final Integer MEMORY_FETCH_ONE_ROW_A_TIME = Integer.MIN_VALUE;
    
    private final RouteUnit routeUnit;
    
    private final Statement statement;
    
    private final ConnectionMode connectionMode;
    
    public StatementExecuteUnit(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) throws SQLException {
        this.routeUnit = routeUnit;
        this.statement = statement;
        this.connectionMode = connectionMode;
        setFetchSizeForStatement();
    }
    
    private void setFetchSizeForStatement() throws SQLException {
        if (connectionMode == ConnectionMode.MEMORY_STRICTLY) {
            statement.setFetchSize(MEMORY_FETCH_ONE_ROW_A_TIME);
        } else {
            statement.setFetchSize(CONNECTION_FETCH_ONE_ROW_A_TIME);
        }
    }
}

@@ -845,38 +845,8 @@
 r;%0A%0A
-import java.sql.SQLException;%0A
 impo
@@ -1036,170 +1036,8 @@
    %0A
-    private static final Integer CONNECTION_FETCH_ONE_ROW_A_TIME = 0;%0A    %0A    private static final Integer MEMORY_FETCH_ONE_ROW_A_TIME = Integer.MIN_VALUE;%0A    %0A
     
@@ -1296,36 +1296,16 @@
 ionMode)
- throws SQLException
  %7B%0A     
@@ -1421,346 +1421,8 @@
 de;%0A
-        setFetchSizeForStatement();%0A    %7D%0A    %0A    private void setFetchSizeForStatement() throws SQLException %7B%0A        if (connectionMode == ConnectionMode.MEMORY_STRICTLY) %7B%0A            statement.setFetchSize(MEMORY_FETCH_ONE_ROW_A_TIME);%0A        %7D else %7B%0A            statement.setFetchSize(CONNECTION_FETCH_ONE_ROW_A_TIME);%0A        %7D%0A
     

DELETE CONNECTION_FETCH_ONE_ROW_A_TIME