com.github.chengyuxing.sql.dsl.clause.condition.InCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rabbit-sql Show documentation
Show all versions of rabbit-sql Show documentation
Light wrapper of JDBC, support ddl, dml, query, plsql/procedure/function, transaction and manage sql
file.
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);
}
}