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

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

/**
 * Execute unit for JDBC statement.
 *
 * @author zhangliang
 * @author panjuan
 */
@Getter
public class StatementExecuteUnit implements SQLExecuteUnit {
    
    private final RouteUnit routeUnit;
    
    private final Statement statement;
    
    private final ConnectionMode connectionMode;
    
    public StatementExecuteUnit(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) {
        this.routeUnit = routeUnit;
        this.statement = statement;
        this.connectionMode = connectionMode;
    }
}

DELETE CONNECTION_FETCH_ONE_ROW_A_TIME