Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Easy Grails with IntelliJ IDEA - 2. Chaining Queries

DZone's Guide to

Easy Grails with IntelliJ IDEA - 2. Chaining Queries

·
Free Resource

As promised in the previous post, let’s continue with Grails support in  IntelliJ IDEA 8. Today we’ll see how the powerful IntelliJ IDEA‘s code completion applies to the Grails applications.

Suppose you have a Grails application, where you create a domain class, using the New context menu command:

[img_assist|nid=6866|title=|desc=|link=none|align=left|width=640|height=245]

 

 

 

 

Declare some fields that will be mapped to a datasource:

[img_assist|nid=6867|title=|desc=|link=none|align=left|width=640|height=307]

 

 

 

 

 

 

 

Next, use the scaffolding to create, for example, a test class, and start typing a query:

 [img_assist|nid=6871|title=|desc=|link=none|align=left|width=622|height=640]

 

 

 

 

 

 

 

 

 

 

This is where code completion comes to help. Press Ctrl+Space. The suggestion list shows all the fields declared in your domain class. Let’s select the findByName option:

[img_assist|nid=6868|title=|desc=|link=none|align=left|width=640|height=624]

 

 

 

 

 

 

 

 

 

 

 

After that, press Ctrl+Space once more – now the suggestion list shows combined queries:

[img_assist|nid=6870|title=|desc=|link=none|align=left|width=586|height=640]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

With each invocation of code completion, IntelliJ IDEA suggests the appropriate combined queries. Thus, you can go through all the fields of your domain class, and easily create queries of any level of complexity.

Enjoy!

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}