A method expression is made up of the prefixes: findBy, findAllBy, countBy
followed by the expression that combines a query upon one or more properties:
If a conditional keyword is not passed, we assume you want equality. Remember that!
IMPORTANT: The ? means that you can concatenate the same pattern over and over again.
The available conditionals in ColdBox are:
LessThanEquals
- Less than or equal to passed value
LessThan
- Less than to passed value
GreaterThanEquals
- Greater than or equal to passed value
GreaterThan
- Greater than to passed value
Like
- Equivalent to the SQL like expression
NotEqual
- Not equal to the passed value
isNull
- The property must be null
isNotNull
- The property must not be null
NotBetween
- The property value must not be between two values
Between
- The property value must be between two values
NotInList
- The property value must not be in the passed in simple list or array
inList
- The property value must be in the passed in simple list or array
The only valid operators are:
And
Or
If you pass a structure as the last argument to your dynamic finder/counter call, we will consider that by convention to be your query options.
The valid query options are:
ignorecase
: Ignores the case of sort order when you set it to true.
maxResults
: Specifies the maximum number of objects to be retrieved.
offset
: Specifies the start index of the resultset from where it has to start the retrieval.
cacheable
: Whether the result of this query is to be cached in the secondary cache. Default is false.
cachename
: Name of the cache in secondary cache.
timeout
: Specifies the timeout value (in seconds) for the query
datasource
: The datasource to use, it defaults to the application
sortBy
: The HQL to sort the query by
autoCast
: No more casting, let us do auto casting for you
asStream
: Want a stream back instead of the results, no problem!
Here is a more descriptive key set with the types and defaults
The ORM module supports the concept of dynamic finders and counters for ColdFusion ORM entities. A dynamic finder/counter looks like a real method but it is a virtual method that is intercepted by via onMissingMethod
. This is a great way for you to do finders and counters using a programmatic and visual representation of what HQL to run.
This feature works on the Base ORM Service, Virtual Entity Services and also Active Entity services. The most semantic and clear representations occur in the Virtual Entity Service and Active Entity as you don't have to pass an entity name around.
Another important aspect of the dynamic finders is that we will AUTO CAST all the values for you. So you don't have to mess with the right Java type, we will do it for you.
We have also enabled the ability to return a stream of objects if you are using the findAll
semantics via cbStreams.
We have three types of dynamic finders and counters:
findBy
: Find ONE entity according to method signature, if more than one record is found an exception is thrown
findAllBy
: Find ALL entities according to method signature
countBy
: Give you a count of entities according to method signature
Let's say you have the following entity:
Then we could do the following:
You can also use the virtual entity service instead of active entity.
If you just use a vanilla Base ORM Service, then the first argument must be the entityName
: