Grails Background

Grails provides several services, best described in the Grails documentation. This page provides a brief summary, and a demonstration.

Brief Grails Summary

From the perspective of Business Logic, key services include:

Groovy - a dynamic language, fully integrated with Java, providing simplified syntax, automatic type conversions, and many other features. Groovy makes Java look like a 4GL, and is fully supported by Automated Business Logic.

Data Access - Grails simplifies the creation of POJOs that map to a Relational Data Model - you can create a Domain Object simply by declaring the attributes.

Domain Object scaffolding - common elements such as accessors, persistence methods to create/read/update objects, toString etc are automated. Note these are added by compile time 'mix-ins', not to the source. Yet, the Grails Web Layer controllers can invoke them and compile correctly due to Groovy Dynamic binding

Gorm

From the perspective of Business Logic, Gorm is simplifying layer that reduces Hibernate configuration complexity. Since Business Logic operates underneath the Hibernate layer by plugging into Hibernate events, Gorm data updates are automatically subjected to business logic. In addition to basic Configuration described below, the following special considerations apply:

Constraints

We encourage the use of Gorm constraints to verify attribute value ranges, valid values etc. These complement Automated Business Logic well, which targets more complex multi-table derivations, and dependent domain constraints and actions. These enable you to automate not only simple Use Cases as shown below, but alsoaddresses complex logic like auditing, Bill of Materials processing, allocation, etc.

Business Logic and Grails

This page illustrates two different Grails applications: the Default, and the Full Demo. Since Business Logic operates at the Domain Class level (via the Event-based Injection Architecture), both approaches utilize the same underlying logic.

Build Grails Application

If you are new to Grails, you can watch this video to see how quickly you can define your domain objects, and generate an application. You can build Grails applications from either a command line, or from SpringSource Tool Suite, a variant of Eclipse that provides a complete IDE. Since this is convenient for building business logic, this demo uses STS to:

Building a Grails Application

The gadget spec URL could not be found

Create a project

Build the Domain Model (the default configuration builds an in-memory database, which can be subsequently re-targeted to a number of popular SQL databases).

Invoke the Wizards to build a Web Application

You can watch the following video to see how to build a Grails app. If you already know how to do that, you can proceed to the following section.

Full Grails Demo

The default application is a very fast way to get started, but the number of page transitions make the logic a bit hard to follow. So, we also provide a customized version that places everything on 1 page:

You can browse the implementation provided in the download. The core elements are illustrated below:

The conf/URLMappings.groovy specifies that the default application invokes the fulldemo.gsp page

the fulldemo page includes a familiar jsp-style construct to loop through related data to provide a table of Purchaseorders (and, not shown, a nested view of Line Items)