Groovy Multiline Strings + HQL = Bliss.

In the home screen / dashboard for the Broadchoice Workspace, the second folder ("Spaces") in the tree on the left shows which workspaces Jack Conner participates in.

The data access method that generates this list shows one of my favorite things about combining Groovy and Hibernate: using Groovy multiline strings to create and run an HQL query.

In Groovy, triple-quotes indicates a string that spans multiple lines, solving one of my least favorite things about Java / C# / many other languages: writing well-formatted SQL was a pain. ColdFusion handles this wonderfully with the CFQuery tag. Groovy can be almost as pretty.

Here's what the underlying method for that list looks like: very familiar for ColdFusion folks, especially for Transfer users:


List findUsersJoinedSpaces(User user)
{
    return getHibernateTemplate().find (
        """
            select
                membership.space
            from
                SpaceMembership as membership
            where
                membership.user = ?
        """,
        user
    )
}

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
denny's Gravatar Amazing, that I would end up here, looking for groovy multi-line string stuff. Small world.

What's even more amazing? How freaking well it works. Nifty way to automatically escape quotes and apostrophes in text, as well. I'm really digging Groovy.
# Posted By denny | 1/29/09 6:12 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002. Contact Blog Owner