-
Notifications
You must be signed in to change notification settings - Fork 16
Dynamic Finders
Eldelshell edited this page Apr 27, 2020
·
3 revisions
A dynamic finder is a special query used to access records in a resource (table or view) which are translated to an SQL query.
A dynamic finder must follow this style and use Camel Case to separate the different parts of the query:
- command + column + operator
- command + column + boolean operator + column + operator
- command + column + operator + boolean operator + column + operator
Some examples:
http://.../amforeas/demo1/dynamic/user/findByNameEquals?args=foo
SELECT * FROM user WHERE name = foo
http://.../amforeas/demo1/dynamic/user/findAllByNameLike?args=foo
SELECT * FROM user WHERE name LIKE foo
http://.../amforeas/demo1/dynamic/user/findByNameEqualsAndAgeEquals?args=foo&args=30
SELECT * FROM user WHERE name LIKE foo AND age = 30
http://.../amforeas/demo1/dynamic/user/findByNameLikeAndAgeGreaterThanEquals?args=foo&args=30
SELECT * FROM user WHERE name LIKE foo AND age >= 30
http://.../amforeas/demo1/dynamic/user/findAllByBirthIsNull
SELECT * FROM user WHERE birth IS NULL
Of course, the name of the columns must be the same used on the database.
The only commands accepted are:
- findBy returns only the first result
- findAllBy returns all the results
This are the operators
- LessThan
- LessThanEquals
- GreaterThan
- GreaterThanEquals
- Between
- Like
- IsNotNull
- IsNull
- Not
- NotEqual
- And
- Or
Dynamic finders (as in Grails) are limited to a maximum of two columns. So you can't issue a query like findByNameAndAgeAndCreditEquals
. So for more complex queries, you may use stored procedures or views.
For dynamic finders to work, you should use Camel Case