BatchPreparedStatementUnit.java 1.8 KB
Newer Older
T
terrymanu 已提交
1
/*
T
terrymanu 已提交
2
 * Copyright 2016-2018 shardingsphere.io.
3 4 5 6
 * <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
T
terrymanu 已提交
7
 *
T
terrymanu 已提交
8
 *     http://www.apache.org/licenses/LICENSE-2.0
T
terrymanu 已提交
9
 *
10 11 12 13 14 15 16 17
 * 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>
 */

18
package io.shardingsphere.core.executor.type.batch;
19

20 21
import io.shardingsphere.core.executor.BaseStatementUnit;
import io.shardingsphere.core.routing.SQLExecutionUnit;
22
import lombok.AccessLevel;
23
import lombok.Getter;
24
import lombok.RequiredArgsConstructor;
25 26

import java.sql.PreparedStatement;
27
import java.util.LinkedHashMap;
T
terrymanu 已提交
28
import java.util.Map;
29 30

/**
T
terrymanu 已提交
31
 * PreparedStatement add batch execute unit.
32 33 34
 * 
 * @author zhangliang
 */
35 36
@RequiredArgsConstructor
@Getter
T
terrymanu 已提交
37
public final class BatchPreparedStatementUnit implements BaseStatementUnit {
38 39
    
    private final SQLExecutionUnit sqlExecutionUnit;
40
    
T
terrymanu 已提交
41
    private final PreparedStatement statement;
42
    
43
    private final Map<Integer, Integer> jdbcAndActualAddBatchCallTimesMap = new LinkedHashMap<>();
44
    
45
    @Getter(AccessLevel.NONE)
T
terrymanu 已提交
46
    private int actualCallAddBatchTimes;
47 48
    
    /**
T
terrymanu 已提交
49
     * Map times of use JDBC API call addBatch and times of actual call addBatch after route.
50
     * 
T
terrymanu 已提交
51
     * @param jdbcAddBatchTimes times of use JDBC API call addBatch
52
     */
T
terrymanu 已提交
53 54
    public void mapAddBatchCount(final int jdbcAddBatchTimes) {
        jdbcAndActualAddBatchCallTimesMap.put(jdbcAddBatchTimes, actualCallAddBatchTimes++);
55
    }
56
}