@java.lang.SuppressWarnings({"rawtypes", "unchecked", "ResultOfMethodCallIgnored"})
public class DynamicFinder
extends java.lang.Object
implements FinderGrammar
Parses a dynamic finder method name into a DynamicFinderInvocation, builds the AND/OR
junction of criteria for it, and exposes the shared argument-map/fetch/sort/detached-criteria
handling used by every finder implementation. Composed (not extended) by the concrete finder
classes in this package and in grails-datamapping-rx - see FinderGrammar.
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
ARGUMENT_CACHE |
|
static java.lang.String |
ARGUMENT_FETCH |
|
static java.lang.String |
ARGUMENT_FETCH_SIZE |
|
static java.lang.String |
ARGUMENT_FLUSH_MODE |
|
static java.lang.String |
ARGUMENT_IGNORE_CASE |
|
static java.lang.String |
ARGUMENT_LOCK |
|
static java.lang.String |
ARGUMENT_MAX |
|
static java.lang.String |
ARGUMENT_OFFSET |
|
static java.lang.String |
ARGUMENT_ORDER |
|
static java.lang.String |
ARGUMENT_READ_ONLY |
|
static java.lang.String |
ARGUMENT_SORT |
|
static java.lang.String |
ARGUMENT_TIMEOUT |
|
static java.lang.String |
ORDER_ASC |
|
static java.lang.String |
ORDER_DESC |
|
protected MappingContext |
mappingContext |
|
protected java.util.regex.Pattern |
pattern |
| Constructor and description |
|---|
DynamicFinder(java.util.regex.Pattern pattern, java.lang.String[] operators, MappingContext mappingContext, boolean firstExpressionIsRequiredBoolean)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static void |
applyAdditionalCriteria(Query query, groovy.lang.Closure additionalCriteria)Applies the given additional-criteria closure to the given query by building it through a CriteriaBuilder for the query's entity/session. |
|
public static void |
applyDetachedCriteria(Query query, AbstractDetachedCriteria detachedCriteria)Applies the given detached criteria to the given query |
|
public static void |
applySortForMap(Query query, java.util.Map sortMap, boolean ignoreCase)Applies sorting logic to the given query from the given map |
|
public static MatchSpec |
buildMatchSpec(java.lang.String prefix, java.lang.String methodName, int parameterCount)Builds a match specification that can be used to establish information about a dynamic finder compilation for the purposes of compilation etc. |
|
public Query |
buildQuery(DynamicFinderInvocation invocation, Session session)Builds a query for the given invocation using this grammar's getJunction and the shared additional-criteria/detached-criteria/argument-map handling. |
|
public static void |
configureQueryWithArguments(java.lang.Class clazz, Query query, java.lang.Object[] arguments) |
|
public Criterion |
createCriterion() |
|
public DynamicFinderInvocation |
createFinderInvocation(java.lang.Class clazz, java.lang.String methodName, groovy.lang.Closure additionalCriteria, java.lang.Object[] arguments) |
|
protected MethodExpression |
findMethodExpression(java.lang.Class clazz, java.lang.String expression) |
|
protected static MethodExpression |
findMethodExpression(java.lang.String expression) |
|
public boolean |
firstExpressionIsRequiredBoolean() |
|
public java.lang.Object[] |
getArguments() |
|
public int |
getArgumentsRequired() |
|
public static jakarta.persistence.FetchType |
getFetchMode(java.lang.Object object)Retrieves the fetch mode for the specified instance; otherwise returns the default FetchMode. |
|
public Junction |
getJunction(DynamicFinderInvocation invocation) |
|
public boolean |
isMethodMatch(java.lang.String methodName)Checks whether the given method is a match |
|
public static java.lang.String |
normalizeDirection(java.lang.String direction)Trims and accepts only asc or desc, case-insensitively. |
|
public static void |
populateArgumentsForCriteria(BuildableCriteria query, java.util.Map argMap)Populates arguments for the given query form the given map |
|
public static void |
populateArgumentsForCriteria(java.lang.Class<?> targetClass, Query query, java.util.Map argMap)Populates arguments for the given query form the given map |
|
public static void |
registerNewMethodExpression(java.lang.Class methodExpression)Registers a new method expression. |
|
public void |
setArguments(java.lang.Object[] arguments) |
|
public void |
setPattern(java.lang.String pattern)Sets the pattern to use for this finder |
|
public static void |
validateSortProperty(PersistentEntity entity, java.lang.String sort)Rejects a sort key that is not shaped like a property path. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
pattern - The method-name pattern this grammar matchesoperators - The junction operators this grammar splits on (e.g. {"And", "Or"})mappingContext - The mapping context used to resolve persistent entities/propertiesfirstExpressionIsRequiredBoolean - Whether the first parsed expression is a required
boolean clause (the "find<booleanProperty>By*"/"findAll<booleanProperty>By*" forms)Applies the given additional-criteria closure to the given query by building it through a CriteriaBuilder for the query's entity/session.
query - The queryadditionalCriteria - The additional criteria closure, or null for a no-opApplies the given detached criteria to the given query
query - The querydetachedCriteria - The detached criteriaApplies sorting logic to the given query from the given map
query - The querysortMap - The sort mapignoreCase - Whether toi ignore caseBuilds a match specification that can be used to establish information about a dynamic finder compilation for the purposes of compilation etc.
prefix - The dynamic finder prefix. For example 'findBy'methodName - The full method nameparameterCount - The number of parameters Builds a query for the given invocation using this grammar's getJunction and the
shared additional-criteria/detached-criteria/argument-map handling. This is the default,
Session-based query builder used by the synchronous single-result and list finders;
CountFinder builds its own query independently of this method.
invocation - The invocationsession - The sessionRetrieves the fetch mode for the specified instance; otherwise returns the default FetchMode.
object - The object, converted to a stringChecks whether the given method is a match
methodName - The method name Trims and accepts only asc or desc, case-insensitively. Blank and
null default to asc. The exception message omits the caller-supplied
value, which usually originates from request parameters.
Like validateSortProperty(PersistentEntity, String), this is shared by every entry
point that accepts an order argument, including listOrderBy* and criteria
queries, so a direction is never silently coerced on one path and rejected on another.
direction - the caller-supplied order argumentPopulates arguments for the given query form the given map
query - The queryargMap - The query argumentsPopulates arguments for the given query form the given map
targetClass - Unused - kept for call-site/API compatibility with existing callers in
grails-data-hibernate5/7 and grails-data-mongodbquery - The queryargMap - The query argumentsRegisters a new method expression. The Class must extends from the class MethodExpression and provide a constructor that accepts a Class parameter and a String parameter.
methodExpression - A class that extends from MethodExpressionSets the pattern to use for this finder
pattern - A regular expression Rejects a sort key that is not shaped like a property path. When the entity is known and the
first segment names one of its persistent properties, every further segment must also resolve
through the mapping: associations and embedded components are traversed, and identity
properties, including the members of a composite identity, are recognised. A dotted key
whose first segment is not a persistent property is accepted on the shape check alone,
because criteria and where-query aliases such as c1.name are not persistent
properties; the underlying query implementation resolves them, or reports an unknown name,
itself. A bare name that is not a persistent property is rejected, since nothing else can be
sorted on by a single name.
This is the single check behind every entry point that accepts a caller-supplied
sort argument: list(), dynamic finders, where queries and criteria queries.
Query implementations that handle the argument themselves call it so that the same value
fails the same way everywhere.
The exception message deliberately omits the caller-supplied value: sort keys are commonly taken straight from request parameters.
entity - the entity being queried, or null when it cannot be resolvedsort - the requested sort property