Skip to content
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.

Style

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.

Commands

The only commands accepted are:

  • findBy returns only the first result
  • findAllBy returns all the results

Operators

This are the operators

  • LessThan
  • LessThanEquals
  • GreaterThan
  • GreaterThanEquals
  • Between
  • Like
  • IsNotNull
  • IsNull
  • Not
  • NotEqual
  • And
  • Or

Limitations

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

Clone this wiki locally