Skip to content

Commit

Permalink
Enum search support has added to BaseDao for query(__q) searches
Browse files Browse the repository at this point in the history
  • Loading branch information
recep committed Aug 24, 2016
1 parent 206b2a9 commit 10d88dd
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

<packaging>pom</packaging>
<name>Robe Project</name>
Expand Down
2 changes: 1 addition & 1 deletion robe-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-assets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>

Expand Down
2 changes: 1 addition & 1 deletion robe-convert/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>

Expand Down
2 changes: 1 addition & 1 deletion robe-crud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
55 changes: 31 additions & 24 deletions robe-hibernate/src/main/java/io/robe/hibernate/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,15 @@ private List<String> addRemoteMatchCriterias(SearchFrom from, String searchQ) {
for (String target : from.target()) {
if (field.getName().equals(target)) {
if (field.getAnnotation(SearchIgnore.class) == null) {
fieldLikes[i++] = Restrictions.ilike(field.getName(), searchQ, MatchMode.ANYWHERE);
if (SearchableEnum.class.isAssignableFrom(field.getType())) {
try {
Enum anEnum = Enum.valueOf((Class<? extends Enum>) field.getType(), searchQ);
fieldLikes[i++] = Restrictions.eq(field.getName(), anEnum);
} catch (IllegalArgumentException e) {
continue;
}
} else
fieldLikes[i++] = Restrictions.ilike(field.getName(), searchQ, MatchMode.ANYWHERE);
}
}
}
Expand Down Expand Up @@ -438,38 +446,37 @@ public Conjunction addFilterCriterias(Field[] fields, String filterParam) {
String filterTarget = StringsOperations.unCapitalizeFirstChar(params[0].replace(field.getName(), ""));
for (String target : searchFrom.target()) {
if (filterTarget.equals(target)) {
Field filterField = null;
try {
filterField = searchFrom.entity().getDeclaredField(filterTarget);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
Criteria criteria = currentSession().createCriteria(searchFrom.entity());
Field filterField = searchFrom.entity().getDeclaredField(filterTarget);
Criteria criteria = currentSession().createCriteria(searchFrom.entity());

if (searchFrom.localId().isEmpty())
params[0] = field.getName();
else
params[0] = searchFrom.localId();

if (params[1].equals("=")) {
if (searchFrom.localId().isEmpty())
params[0] = field.getName();
else
params[0] = searchFrom.localId();

if (SearchableEnum.class.isAssignableFrom(filterField.getType())) {
Enum anEnum = Enum.valueOf((Class<? extends Enum>) filterField.getType(), params[2]);
criteria.add(Restrictions.eq(filterTarget, anEnum));
} else
} else if (params[1].equals("=")) {
criteria.add(Restrictions.eq(filterTarget, params[2]));
} else if (params[1].equals("~="))
criteria.add(Restrictions.ilike(filterTarget, params[2], MatchMode.ANYWHERE));

criteria.setProjection(Projections.property(searchFrom.id()));
List list = criteria.list();
if (!list.isEmpty()) {
value = Optional.fromNullable(list);
params[1] = "|=";
break fieldsLoop;
}
value = Optional.of("");

} else if (params[1].equals("~="))
criteria.add(Restrictions.ilike(filterTarget, params[2], MatchMode.ANYWHERE));

criteria.setProjection(Projections.property(searchFrom.id()));
List list = criteria.list();
if (!list.isEmpty()) {
value = Optional.fromNullable(list);
params[1] = "|=";
break fieldsLoop;
} catch (NoSuchFieldException e) {
continue;
} catch (IllegalArgumentException e) {
continue;
}
value = Optional.of("");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion robe-mail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-quartz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion robe-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.robe</groupId>
<artifactId>robe-parent</artifactId>
<version>0.5.0.0-1034</version>
<version>0.5.0.0-1035</version>

</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit 10d88dd

Please sign in to comment.