All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chengyuxing.sql.dsl.clause.condition.InCondition Maven / Gradle / Ivy

Go to download

Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql file.

There is a newer version: 9.0.2
Show newest version
package com.github.chengyuxing.sql.dsl.clause.condition;

import com.github.chengyuxing.common.tuple.Pair;
import com.github.chengyuxing.common.utils.ObjectUtil;
import com.github.chengyuxing.sql.dsl.types.StandardOperator;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;

public class InCondition extends Condition> {
    public InCondition(String column, StandardOperator operator, Collection value) {
        super(column, operator, value);
    }

    public InCondition(String column, StandardOperator operator, Collection value, String valueKey) {
        super(column, operator, value, valueKey);
    }

    public Pair> buildStatement(int index, char namedParamPrefix) {
        StringJoiner sb = new StringJoiner(", ", "(", ")");
        Map params = new HashMap<>();
        Object[] values = ObjectUtil.toArray(value);
        for (int i = 0; i < values.length; i++) {
            String key = valueKey + "__" + index + "_" + i;
            sb.add(namedParamPrefix + key);
            params.put(key, values[i]);
        }
        return Pair.of(column + operator.padWithSpace() + sb, params);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy