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.

  • Project Creation - Grails advocates "Convention over Configuration" to simplify web application development, starting with Project Creation
  • 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 - Grails Object Relational Mapping simplifies reading/writing to SQL databases via a Hibernate / JPA layer by reducing configuration.
      • In particular, Gorm provides important constraint services.   
  • Client Generators - Grails generates CRUD (Create, Read, Update and Delete) pages / code from Domain Objects
  • Web Layer - Grails provides a thin model/view/controller client web framework.  Gorm provides the model, and this layer provides controller logic and views (Groovy Server Pages - html markup)
  • Web Services - facilities to build web APIs, via Rest and SOAP services

Special topics are described in the sub-sections below.

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:
TBD

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 also addresses 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.

Domain Objects

Domain Objects are specified in the standard Grails fashion:



Business Logic

Business Logic is specified declaratively, as shown below.  Note:



Default Grails Demonstration

You can build a default CRUD (Create, Read, Update and Delete) application by
  • Defining Domain Objects - specify the attribute of Domain Objects.  These are mapped automatically to database tables, and provide API CRUD services.  Our sample objects are shown at right.

  • UI Wizards - you can run Grails Wizards to build CRUD Web Apps

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:
  1. Building a Grails Application

    The gadget spec URL could not be found
    Create a project

  2. 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).

  3. 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)


Comments