use of com.baidu.unbiz.common.genericdao.param.LteParam in project disconf by knightliao.
the class QueryGenerator method appendMatches.
public void appendMatches(Collection<Match> matches, StringBuilder sb, List<Object> params) {
for (Match match : matches) {
Object value = match.getValue();
String column = match.getColumn();
if (value == null) {
sb.append(column).append(" is null");
} else if (value instanceof LikeParam) {
sb.append(column).append(" like ?");
params.add('%' + ((LikeParam) value).getWord() + '%');
} else if (value instanceof BetweenParam) {
BetweenParam bp = (BetweenParam) value;
Object start = bp.getStart();
Object end = bp.getEnd();
if (start == null && end == null) {
sb.append("1!=1");
} else if (start == null) {
sb.append(column).append(" <= ?");
params.add(end);
} else if (end == null) {
sb.append(column).append(" >= ?");
params.add(start);
} else {
sb.append(column).append(" between ? and ?");
params.add(start);
params.add(end);
}
} else if (value instanceof GteParam) {
sb.append(column).append(" >= ?");
params.add(((GteParam) value).getValue());
} else if (value instanceof GreaterThanParam) {
sb.append(column).append(" > ?");
params.add(((GreaterThanParam) value).getValue());
} else if (value instanceof LteParam) {
sb.append(column).append(" <= ?");
params.add(((LteParam) value).getValue());
} else if (value instanceof LessThanParam) {
sb.append(column).append(" < ?");
params.add(((LessThanParam) value).getValue());
} else if (value instanceof ExpressionParam) {
sb.append('(').append(column).append(')');
} else {
// 如果是取反的参数
boolean reverse = value instanceof NotParam;
if (reverse) {
value = ((NotParam) value).getValue();
}
if (value == null && reverse) {
sb.append(column).append(" is not null");
} else if (value instanceof Collection<?>) {
Collection<?> coll = (Collection<?>) value;
if (coll.size() == 0) {
sb.append(reverse ? "1=1" : "1!=1");
} else if (coll.size() == 1) {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(coll.iterator().next());
} else {
sb.append(column).append(reverse ? " not in " : " in");
sb.append(connectObjects(coll));
params.addAll(coll);
}
} else if (value.getClass().isArray()) {
Object[] array = (Object[]) value;
if (array.length == 0) {
sb.append(reverse ? "1=1" : "1!=1");
} else if (array.length == 1) {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(array[0]);
} else {
sb.append(column).append(reverse ? " not in " : " in");
sb.append(connectObjects(Arrays.asList(array)));
for (Object o : array) {
params.add(o);
}
}
} else {
sb.append(column).append(reverse ? "!=?" : "=?");
params.add(value);
}
}
sb.append(" and ");
}
sb.delete(sb.length() - 5, sb.length());
}
Aggregations