Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 2.0 Final
-
Fix Version/s: 2.1.0
-
Component/s: Persistence Layer
-
Labels:None
Description
A finder impl to DaoImpls that can handle majority of findAllWhere(conditions...) that is similar but more flexible than query by example that can handle:
/**
- Generic method to get a list of objects based on class and constraints as a Map of:
- <ul>
- <li>HQL property path expression 1 as String -> null | Object | Object[] | Collection
- <li>HQL property path expression 2 as String -> null | Object | Object[] | Collection
- <li>...
- </ul>
- Note that:
- <ul>
- <li>Each Map entry translate to a predicate that must be satisfied, i.e. all entries are to be 'AND'd together
- <li>if entry.value is null, the HQL criteria translates to isNull
- <li>if entry.value is Object, the HQL criteria translates to isEqualTo
- <li>if entry.value is Object[] or Collection, the HQL criteria translates to isOneOf
- <li>if entry.key starts with "!", the HQL criteria translates to isNot
- <li>if entry.key ends with "~", the HQL criteria translates to isLike
- <li>if entry.key ends with ">", the HQL criteria translates to isGreaterThan
- <li>if entry.key ends with ">=", the HQL criteria translates to isGreaterThanOrEqualTo
- <li>if entry.key ends with "<", the HQL criteria translates to isLessThan
- <li>if entry.key ends with "<=", the HQL criteria translates to isLessThanOrEqualTo
- </ul>
- Example: find all Users whose first name is Brian, last name starts with G, and age between 30 and 40
- find(User.class,
{ "firstName":"Brian", "lastName~":"G%", "age>=":30, "age<":40 }
)
- @param clazz model class to lookup
- @param Map specifying the constraints
- @return List of populated object satisfying constraints
- @see org.springframework.orm.ObjectRetrievalFailureException
*/
public List<T> find(Map<String,Object> constraints);
/**
- Extending find(Class,Map) to handle Several Constraint Sets, only one ConstraintSet need to match
- i.e. Disjunctive Normal Form
- @param clazz
- @param constraintSets
- @return List of populated object satisfying at least one of the constraintSets
*/
public List<T> find(Map<String,Object>[] constraintSets);
I believe using Compass for fancy queries is better than adding this functionality. This was added last week with
APF-267.