1

I was reading grails criteria API , I find the following code in grails API here

 def c = Account.createCriteria() def results = c { projections { groupProperty("branch") } like("holderFirstName", "Fred%") and { between("balance", 500, 1000) eq("branch", "London") } maxResults(10) order("holderLastName", "desc") } 

my question is calling Account.createCriteria() will gives you grails.orm.HibernateCriteriaBuilder object but when say "c { ....}" , I know colsure is getting called but the object we have is HibernateCriteriaBuilder object not the Closure object , then how the closure is getting called .

2
  • 1
    It's unclear what you are asking when you say "then how its working". What problem are you encountering or trying to solve? Commented May 23, 2014 at 9:53
  • @JoshuaMoore I edited my question . I want to know how closure is getting called when we have HibernateCriteriaBuilder object Commented May 23, 2014 at 10:03

2 Answers 2

1

As stated in the API this wraps the Hibernate Criteria API in a builder. Builders are used in Groovy to create Domain Specific Languages (DSLs) such as the GORM DSL.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks . But the builders link you provided doesn't have full documentation
There is no such thing as full documentation for builders since it's a complex topic that isn't specific to Groovy as a language. For instance: groovy.codehaus.org/Builders is the closest to "full documentation" provided by Groovy. I recommend you do some research on the topic using Google.
0

It may be that you intended to do something like c.list { ... } instead of c { ... }? Those are fundamentally different. The former is invoking the list method and passing a Closure as an argument. The latter is attempting to invoke the "call" method and pass a Closure as an argument.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.