From 233164fb549e198a9a6b7ecfab6727d046de34b6 Mon Sep 17 00:00:00 2001 From: Joern Muehlencord Date: Mon, 28 Oct 2019 14:51:59 +0100 Subject: [PATCH] added UUID support --- .../shared/db/CommonAbstractController.java | 20 +++++++++++++++++-- .../shared/db/ControllerException.java | 14 ++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java b/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java index 671d1c1..78ecd2c 100644 --- a/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java +++ b/db/src/main/java/de/muehlencord/shared/db/CommonAbstractController.java @@ -23,6 +23,7 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.UUID; import javax.ejb.Lock; import javax.ejb.LockType; import javax.ejb.TransactionAttribute; @@ -505,9 +506,24 @@ public abstract class CommonAbstractController { break; case NOT_EQUAL: predicate = cb.notEqual(booleanPath, searchValue); - break; + break; default: - throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue); + throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue); + } + returnCondition = addFilterCondition(cb, returnCondition, predicate); + } else if (currentFilter.getSearchValue() instanceof UUID) { + UUID searchValue = (UUID) currentFilter.getSearchValue(); + Path booleanPath = root.get(currentFilter.getFieldName()); + Predicate predicate; + switch (currentFilter.getComparator()) { + case EQUAL: + predicate = cb.equal(booleanPath, searchValue); + break; + case NOT_EQUAL: + predicate = cb.notEqual(booleanPath, searchValue); + break; + default: + throw new ControllerException(ControllerException.INTERNAL_ERROR, currentFilter.getComparator() + "not support for searchValue " + searchValue); } returnCondition = addFilterCondition(cb, returnCondition, predicate); } else { diff --git a/db/src/main/java/de/muehlencord/shared/db/ControllerException.java b/db/src/main/java/de/muehlencord/shared/db/ControllerException.java index 2dc8947..684914e 100644 --- a/db/src/main/java/de/muehlencord/shared/db/ControllerException.java +++ b/db/src/main/java/de/muehlencord/shared/db/ControllerException.java @@ -32,16 +32,15 @@ public class ControllerException extends Exception { public static final int CAUSE_CANNOT_PERSIST = 3; public static final int CAUSE_TOO_MANY_ROWS = 4; public static final int CAUSE_CANNOT_DELETE = 5; + public static final int INVALID_FILTER = 6; private final int causeCode; /** - * Creates a new instance of ControllerException without detail - * message. + * Creates a new instance of ControllerException without detail message. * * @param cause the reason code - * @param message the detail message. The detail message is saved for later - * retrieval by the {@link #getMessage()} method. + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. */ public ControllerException(int cause, String message) { super(message); @@ -51,11 +50,9 @@ public class ControllerException extends Exception { /** * * @param causeCode the reason code - * @param message the detail message. The detail message is saved for later - * retrieval by the {@link #getMessage()} method. + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. * - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A {@code null} value is permitted, and + * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value is permitted, and * indicates that the cause is nonexistent or unknown.) */ public ControllerException(int causeCode, String message, Throwable cause) { @@ -65,6 +62,7 @@ public class ControllerException extends Exception { /** * returns the cause code + * * @return the cause code */ public int getCauseCode() {