Commit 6bf8f78b authored by michael.simon's avatar michael.simon
Browse files

extend dao search routine

finds now lowercase also
can now do "or" operations over multiple fields
parent 4e2e0a90
......@@ -33,7 +33,9 @@ import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GenericSortOrder;
import edu.kit.scc.webreg.dao.ops.AndPredicate;
import edu.kit.scc.webreg.dao.ops.MultipathOrPredicate;
import edu.kit.scc.webreg.dao.ops.OrPredicate;
import edu.kit.scc.webreg.dao.ops.PathObjectValue;
import edu.kit.scc.webreg.ds.DefaultDatasource;
import edu.kit.scc.webreg.entity.BaseEntity;
......@@ -197,7 +199,16 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
}
protected Predicate predicateFromObject(CriteriaBuilder builder, Root<T> root, String path, Object o) {
if (o instanceof OrPredicate) {
if (o instanceof MultipathOrPredicate) {
MultipathOrPredicate p = (MultipathOrPredicate) o;
List<Predicate> pList = new ArrayList<Predicate>();
for (Object object : p.getOperandList()) {
PathObjectValue pov = (PathObjectValue) object;
pList.add(predicateFromObject(builder, root, pov.getPath(), pov.getValue()));
}
return builder.or(pList.toArray(new Predicate[pList.size()]));
}
else if (o instanceof OrPredicate) {
OrPredicate p = (OrPredicate) o;
List<Predicate> pList = new ArrayList<Predicate>();
for (Object object : p.getOperandList()) {
......@@ -214,7 +225,10 @@ public abstract class JpaBaseDao<T extends BaseEntity<PK>, PK extends Serializab
return builder.and(pList.toArray(new Predicate[pList.size()]));
}
else if (o instanceof String) {
return builder.like(this.<String>resolvePath(root, path), "%" + o + "%");
String s = (String) o;
return builder.like(
builder.lower(this.<String>resolvePath(root, path)),
"%" + s.toLowerCase() + "%");
}
else {
return builder.equal(resolvePath(root, path), o);
......
package edu.kit.scc.webreg.dao.ops;
public class MultipathOrPredicate extends DaoPredicate {
private static final long serialVersionUID = 1L;
public MultipathOrPredicate(PathObjectValue... objects) {
super((Object []) objects);
}
}
package edu.kit.scc.webreg.dao.ops;
public class PathObjectValue {
private String path;
private Object value;
public PathObjectValue(String path, Object value) {
super();
this.path = path;
this.value = value;
}
public String getPath() {
return path;
}
public Object getValue() {
return value;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment