private String buildWhereConditionByPKs()

in core/src/main/java/org/apache/seata/core/store/db/sql/lock/AbstractLockStoreSql.java [188:234]


    private String buildWhereConditionByPKs(List<String> pkNameList, int rowSize, int maxInSize) {
        StringBuilder whereStr = new StringBuilder();
        //we must consider the situation of composite primary key
        int batchSize = rowSize % maxInSize == 0 ? rowSize / maxInSize : (rowSize / maxInSize) + 1;
        for (int batch = 0; batch < batchSize; batch++) {
            if (batch > 0) {
                whereStr.append(" or ");
            }
            if (pkNameList.size() > 1) {
                whereStr.append("(");
            }
            for (int i = 0; i < pkNameList.size(); i++) {
                if (i > 0) {
                    whereStr.append(",");
                }
                whereStr.append(pkNameList.get(i));
            }
            if (pkNameList.size() > 1) {
                whereStr.append(")");
            }
            whereStr.append(" in ( ");

            int eachSize = (batch == batchSize - 1) ? (rowSize % maxInSize == 0 ? maxInSize : rowSize % maxInSize)
                : maxInSize;
            for (int i = 0; i < eachSize; i++) {
                //each row is a bracket
                if (i > 0) {
                    whereStr.append(",");
                }
                if (pkNameList.size() > 1) {
                    whereStr.append("(");
                }
                for (int x = 0; x < pkNameList.size(); x++) {
                    if (x > 0) {
                        whereStr.append(",");
                    }
                    whereStr.append("?");
                }
                if (pkNameList.size() > 1) {
                    whereStr.append(")");
                }
            }
            whereStr.append(" )");
        }

        return whereStr.toString();
    }