This page last changed on Mar 27, 2006 by joncrlsn.

Builders

Hibernate Criteria Builder

The Hibernate Criteria Builder allows you to create queries that map to the Hibernate Criteria API. There are equivalent builder nodes for most criterion within the Hibernate Expression class.

The builder can be used standalone by passing a persistent class and sessionFactory instance:

new grails.orm.HibernateCriteriaBuilder(User.class, sessionFactory).list {
 		eq("firstName", "Fred")
 }

Or an instance can be retrieved via the createCriteria method of Grails domain class instances:

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

By default the builder returns a list of results, but can be forced to retrieve a unique result using the "get" node:

def c = Account.createCriteria()
	def a = c.get {
		eq("number", 40830994)
	}

OpenRico Builder

Grails provides support for the OpenRico project. See this document for more details on how OpenRico handles response content. Using OpenRicoBuilder in controllers users can generate any response for OpenRico requests, see the example below which uses the Google API to retrieve search results and then creates an OpenRico ajax response.

def result = google.doSearch();
   new grails.util.OpenRicoBuilder(response).ajax {
	object(id:"googleAutoComplete") {
	  for (re in result.resultElements) {
		div(class:"autoCompleteResult", re.URL)
	  }
	}
  }
Document generated by Confluence on Mar 29, 2006 08:46