Skip to content

Commit

Permalink
add Like support
Browse files Browse the repository at this point in the history
  • Loading branch information
xlorne committed Oct 22, 2024
1 parent a419e72 commit bd6b10a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ private void buildSQL(Filter filter, StringBuilder hql) {
params.add("%" + filter.getValue()[0] + "%");
paramIndex++;
}
if (filter.isLeftLike()) {
hql.append(filter.getKey()).append(" LIKE ?").append(paramIndex);
params.add("%" + filter.getValue()[0]);
paramIndex++;
}
if (filter.isRightLike()) {
hql.append(filter.getKey()).append(" LIKE ?").append(paramIndex);
params.add(filter.getValue()[0] + "%");
paramIndex++;
}
if (filter.isIn()) {
hql.append(filter.getKey()).append(" IN (").append("?").append(paramIndex).append(")");
params.add(Arrays.asList(filter.getValue()));
Expand Down Expand Up @@ -140,4 +150,4 @@ private void buildSQL(Filter filter, StringBuilder hql) {
public Object[] getParams() {
return params.toArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public boolean isLike() {
return relation == Relation.LIKE;
}

public boolean isLeftLike() {
return relation == Relation.LEFT_LIKE;
}

public boolean isRightLike() {
return relation == Relation.RIGHT_LIKE;
}

public boolean isBetween() {
return relation == Relation.BETWEEN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public enum Relation {

EQUAL,
LIKE,
LEFT_LIKE,
RIGHT_LIKE,
BETWEEN,
IN,
GREATER_THAN,
Expand Down

0 comments on commit bd6b10a

Please sign in to comment.