SlideShare una empresa de Scribd logo
1 de 54
Real World Grails

From download to production
              and beyond…




                          1
Introduction
   My name is Scott Davis
       Editor in Chief of http://aboutGroovy.com
       Author
          Groovy Recipes:
          Greasing the Wheels of Java
          (Pragmatic Bookshelf)
          GIS for Web Developers
          (Pragmatic Bookshelf)
          Google Maps API
          (Pragmatic Bookshelf)
          JBoss At Work
          (O’Reilly)




© 2007, Davisworld.org                             2
Have you ever noticed that you use
                            Spring to save time,
                         Hibernate to save time,
                             Ant to save time…


                         Does it feel like you are
                          saving any time at all?


            Why doesn’t the whole come close to
               feeling like the sum of its parts?
© 2007, Davisworld.org                               3
What is Grails?

   Grails is a fully integrated modern
   Java web application in a box:




© 2007, Davisworld.org                   4
Included JARs




© 2007, Davisworld.org   5
Included Ajax Support




© 2007, Davisworld.org   6
Included Ajax Support




© 2007, Davisworld.org   7
(Almost) Included Ajax
Support

$ grails install-dojo
   -- Installs the Dojo toolkit.
   An advanced Javascript library.




© 2007, Davisworld.org               8
Act 1:
For Those in a Hurry…



                         9
Installing Grails
                   http://grails.org



!      Download/unzip grails-bin.tar.gz
       (or zip)
!      Create GRAILS_HOME
!      Add $GRAILS_HOME/bin to PATH
© 2007, Davisworld.org                    10
Your 1-Slide Guide to Grails
Type the following:
    $ grails create-app bookstore
    $ cd bookstore
    $ grails create-domain-class book
        (Add fields to
         grails-app/domain/Book.groovy)
    $ grails generate-all book
    $ grails run-app

   $ grails help -- shows all available commands

© 2007, Davisworld.org                             11
Controller
    Model




     View




  © 2007, Davisworld.org   12
Generated List




© 2007, Davisworld.org   13
Generated Show




© 2007, Davisworld.org   14
Act 2:
Tweaking the defaults…



                          15
Changing the Port
   Grails / Jetty runs on port 8080 by
   default

       Option #1: change the port at runtime

  $ grails -Dserver.port=9090 run-app

       Option #2: edit
       GRAILS_HOME/scripts/Init.groovy
       (see next page…)
© 2007, Davisworld.org                         16
© 2007, Davisworld.org   17
Changing Grails
Environments

   Dev (the default) auto-reloads
   changes to Controllers, Views, and
   even the Model
       This is helpful for rapid development
   Prod loads all items statically for
   maximum performance
© 2007, Davisworld.org                         18
Changing the Database




© 2007, Davisworld.org   19
Why does my data go
away?
   dbCreate == hibernate.hbm2ddl.auto
       Create-drop -- creates the tables on startup,
       drops them on shutdown (DEV)
       Create -- creates the tables on startup, just
       deletes the data on shutdown
       Update -- creates the tables on startup, saves
       the data between restarts (PROD, TEST)

   Remove the value to manage the schema
   manually
© 2007, Davisworld.org                             20
Changing to MySQL

1) Create the database and user
2) Copy the driver into lib
3) Adjust values in
    grails-app/conf/DevelopmentDataSource.groovy




 © 2007, Davisworld.org                        21
Create the database
$ mysql --user=root
Welcome to the MySQL monitor.

mysql> create database bookstore_dev;

mysql> grant all on bookstore_dev.* to
grails@localhost identified by 'server';

mysql> flush privileges;

Sanity check the newly created login:

$ mysql --user=grails -p
              --database=bookstore_dev
© 2007, Davisworld.org                     22
Point Grails to MySQL




© 2007, Davisworld.org   23
mysql> show tables;
 +-------------------------+
Magic Occurs
 | Tables_in_bookstore_dev |
 +-------------------------+
 | book                    |
 +-------------------------+

 mysql> desc book;
 +---------+--------------+------+-----+
 | Field   | Type         | Null | Key |
 +---------+--------------+------+-----+
 | id      | bigint(20)   | NO   | PRI |
 | version | bigint(20)   | NO   |     |
 | title   | varchar(255) | NO   |     |
 | author | varchar(255) | NO    |     |
 +---------+--------------+------+-----+
© 2007, Davisworld.org                     24
Bootstrapping Data




© 2007, Davisworld.org   25
Bootstrapping Gotcha
   If you flipped dbCreate to “update”,
   beware:
       ApplicationBootStrap gets run each time




© 2007, Davisworld.org                           26
Changing the Web server

   To run your app in Tomcat instead
   of Jetty:
$ grails war
$ cp bookstore.war /opt/tomcat/webapps/
       Gotcha: Grails WARs run in PROD by default.
       $ grails dev war
       Or run your container with
       JAVA_OPTS=-Dgrails.env=development
© 2007, Davisworld.org                               27
Changing the Home Page
The default homepage is web-app/index.gsp.
You can redirect to any page or controller:




© 2007, Davisworld.org                        28
Act 3:
Understanding Grails
       Controllers…



                       29
Generating a Controller
$ grails generate-controller




© 2007, Davisworld.org         30
The Three R’s
         Each controller method
        ends in one of three ways:

   Redirect
       Equivalent to response.sendRedirect()
          redirect(action:list,params:params)
   Return
       Calls a GSP named the same as the method
          return [ bookList: Book.list( params ) ]
   Render
       Calls a GSP of an arbitrary name
          render(view:'edit',model:[book:book])
© 2007, Davisworld.org                               31
Controller.index


Index is the default target,
                                         Params is a Map
just like index.jsp or index.html
                                         of the QueryString
                                         name/value pairs
             redirect() == response.sendRedirect()
             action:list == the list method in this controller



© 2007, Davisworld.org                                           32
Controller.list



   Implicit return
                         GORM
   statement
                         (Grails Object/Relational Mapping)
       Map of named objects
       in the Response
       (see list.gsp, next page)


© 2007, Davisworld.org                                        33
List.gsp
                         Returned from Controller




© 2007, Davisworld.org                              34
List view




© 2007, Davisworld.org   35
Convention over
Configuration
BookController
    http://localhost:9090/bookstore/book
BookController.list
    http://localhost:9090/bookstore/book/list
    Corresponding list.gsp
BookController.show(5)
    http://localhost:9090/bookstore/book/show/5


© 2007, Davisworld.org                          36
Show view




© 2007, Davisworld.org   37
Controller.show




© 2007, Davisworld.org   38
Create.gsp               Controller Method




© 2007, Davisworld.org                       39
Controller.save




In one line, Param name/value pairs from the form
are saved to a POGO (Plain Old Groovy Object).

In the next line, the POGO is saved to the
database via GORM.
© 2007, Davisworld.org                              40
Super-sneaky Grails Shell
$ grails shell
Let's get Groovy!
================
groovy> Book.list()
groovy> go
===> [Book : 5, Book : 6, Book : 7,
Book : 8, Book : 9, Book : 10]

groovy> b = Book.get(5)
groovy> b.title
groovy> go
===> Groovy Recipes
© 2007, Davisworld.org                  41
groovy> new Book(author:’foo’).save()
Auto-scaffolding
  I like generating Controllers and Views if I know
  that I am going to be tweaking them by hand.

  Otherwise, allowing Grails to auto-scaffold my
  Controllers and Views in memory reduces by code
  footprint to…




       (I don’t even bother with the Grails CLI for these…)
© 2007, Davisworld.org                                        42
Act 4:
   Understanding Grails
                 Models…
          …and Views…
          …and GORM…
(they’re all interrelated)



                             43
POGOs
   Plain Old Groovy Objects
       Fields are automatically
       private
       Getters and setters are
       automatically provided
       Use Wrappers instead of
       Primitives
          Integer, Float, Double,
          Boolean


© 2007, Davisworld.org              44
Specifying Field Order




© 2007, Davisworld.org   45
Ordered Fields in List




© 2007, Davisworld.org   46
Field Validation




© 2007, Davisworld.org   47
Create Form




© 2007, Davisworld.org   48
Validation




© 2007, Davisworld.org   49
mysql> desc book;
Schema
+------------------+--------------+
| Field            | Type         |
+------------------+--------------+
| id               | bigint(20)   |
| version          | bigint(20)   |
| title            | varchar(50) |
| pages            | int(11)      |
| category         | varchar(255) |
| isbn             | varchar(255) |
| excerpt          | text         |
| publication_date | datetime     |
| cover            | varchar(255) |
| author           | varchar(255) |
+------------------+--------------+
© 2007, Davisworld.org                50
GORM:
One-to-many




© 2007, Davisworld.org   51
One-to-Many




© 2007, Davisworld.org   52
Conclusion

   Grails is a fully integrated modern
   Java web application in a box:




© 2007, Davisworld.org                   53
Conclusion
    Thanks for your time!
        Questions?

        Email:
           scottdavis99@yahoo.com
        Download slides:
           http://www.davisworld.org/presentations



© 2007, Davisworld.org                           54

Más contenido relacionado

La actualidad más candente

Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117
exsuns
 

La actualidad más candente (20)

Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
 
Terraforming the Kubernetes Land
Terraforming the Kubernetes LandTerraforming the Kubernetes Land
Terraforming the Kubernetes Land
 
Gpars concepts explained
Gpars concepts explainedGpars concepts explained
Gpars concepts explained
 
Tiered storage intro. By Robert Hodges, Altinity CEO
Tiered storage intro. By Robert Hodges, Altinity CEOTiered storage intro. By Robert Hodges, Altinity CEO
Tiered storage intro. By Robert Hodges, Altinity CEO
 
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
 
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionGCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow Introduction
 
ClickHouse Monitoring 101: What to monitor and how
ClickHouse Monitoring 101: What to monitor and howClickHouse Monitoring 101: What to monitor and how
ClickHouse Monitoring 101: What to monitor and how
 
Creating Beautiful Dashboards with Grafana and ClickHouse
Creating Beautiful Dashboards with Grafana and ClickHouseCreating Beautiful Dashboards with Grafana and ClickHouse
Creating Beautiful Dashboards with Grafana and ClickHouse
 
How to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'rollHow to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'roll
 
Infrastructure as Code in Google Cloud
Infrastructure as Code in Google CloudInfrastructure as Code in Google Cloud
Infrastructure as Code in Google Cloud
 
Composable caching
Composable cachingComposable caching
Composable caching
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
 
Presto in Treasure Data
Presto in Treasure DataPresto in Treasure Data
Presto in Treasure Data
 
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlareClickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117
 
Altinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouse
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
Hadoop gets Groovy
Hadoop gets GroovyHadoop gets Groovy
Hadoop gets Groovy
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
 
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with ClickhouseWebinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
 

Destacado

Os Madsen Block
Os Madsen BlockOs Madsen Block
Os Madsen Block
oscon2007
 
Os Wardenupdated
Os WardenupdatedOs Wardenupdated
Os Wardenupdated
oscon2007
 
Os Peytonjones
Os PeytonjonesOs Peytonjones
Os Peytonjones
oscon2007
 
2013 1 2 hücre iskeleti- hücreler arası bağlantı
2013 1 2 hücre iskeleti- hücreler arası bağlantı2013 1 2 hücre iskeleti- hücreler arası bağlantı
2013 1 2 hücre iskeleti- hücreler arası bağlantı
Muhammed Arvasi
 

Destacado (7)

Os Madsen Block
Os Madsen BlockOs Madsen Block
Os Madsen Block
 
Os Kelly
Os KellyOs Kelly
Os Kelly
 
Os Racicot
Os RacicotOs Racicot
Os Racicot
 
Os Wardenupdated
Os WardenupdatedOs Wardenupdated
Os Wardenupdated
 
Os Capouch
Os CapouchOs Capouch
Os Capouch
 
Os Peytonjones
Os PeytonjonesOs Peytonjones
Os Peytonjones
 
2013 1 2 hücre iskeleti- hücreler arası bağlantı
2013 1 2 hücre iskeleti- hücreler arası bağlantı2013 1 2 hücre iskeleti- hücreler arası bağlantı
2013 1 2 hücre iskeleti- hücreler arası bağlantı
 

Similar a Os Davis

Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03
Kevin Juma
 
Fast web development using groovy on grails
Fast web development using groovy on grailsFast web development using groovy on grails
Fast web development using groovy on grails
Anshuman Biswal
 

Similar a Os Davis (20)

Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and Practice
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Fast web development using groovy on grails
Fast web development using groovy on grailsFast web development using groovy on grails
Fast web development using groovy on grails
 
Test complex database systems in your laptop with dbdeployer
Test complex database systems in your laptop with dbdeployerTest complex database systems in your laptop with dbdeployer
Test complex database systems in your laptop with dbdeployer
 
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
22nd Athens Big Data Meetup - 1st Talk - MLOps Workshop: The Full ML Lifecycl...
 
Groovy and Grails
Groovy and GrailsGroovy and Grails
Groovy and Grails
 
Dbdeployer
DbdeployerDbdeployer
Dbdeployer
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installer
 

Más de oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
oscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
oscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
oscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
oscon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
oscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
oscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
oscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
oscon2007
 

Más de oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Os Davis

  • 1. Real World Grails From download to production and beyond… 1
  • 2. Introduction My name is Scott Davis Editor in Chief of http://aboutGroovy.com Author Groovy Recipes: Greasing the Wheels of Java (Pragmatic Bookshelf) GIS for Web Developers (Pragmatic Bookshelf) Google Maps API (Pragmatic Bookshelf) JBoss At Work (O’Reilly) © 2007, Davisworld.org 2
  • 3. Have you ever noticed that you use Spring to save time, Hibernate to save time, Ant to save time… Does it feel like you are saving any time at all? Why doesn’t the whole come close to feeling like the sum of its parts? © 2007, Davisworld.org 3
  • 4. What is Grails? Grails is a fully integrated modern Java web application in a box: © 2007, Davisworld.org 4
  • 5. Included JARs © 2007, Davisworld.org 5
  • 6. Included Ajax Support © 2007, Davisworld.org 6
  • 7. Included Ajax Support © 2007, Davisworld.org 7
  • 8. (Almost) Included Ajax Support $ grails install-dojo -- Installs the Dojo toolkit. An advanced Javascript library. © 2007, Davisworld.org 8
  • 9. Act 1: For Those in a Hurry… 9
  • 10. Installing Grails http://grails.org ! Download/unzip grails-bin.tar.gz (or zip) ! Create GRAILS_HOME ! Add $GRAILS_HOME/bin to PATH © 2007, Davisworld.org 10
  • 11. Your 1-Slide Guide to Grails Type the following: $ grails create-app bookstore $ cd bookstore $ grails create-domain-class book (Add fields to grails-app/domain/Book.groovy) $ grails generate-all book $ grails run-app $ grails help -- shows all available commands © 2007, Davisworld.org 11
  • 12. Controller Model View © 2007, Davisworld.org 12
  • 13. Generated List © 2007, Davisworld.org 13
  • 14. Generated Show © 2007, Davisworld.org 14
  • 15. Act 2: Tweaking the defaults… 15
  • 16. Changing the Port Grails / Jetty runs on port 8080 by default Option #1: change the port at runtime $ grails -Dserver.port=9090 run-app Option #2: edit GRAILS_HOME/scripts/Init.groovy (see next page…) © 2007, Davisworld.org 16
  • 18. Changing Grails Environments Dev (the default) auto-reloads changes to Controllers, Views, and even the Model This is helpful for rapid development Prod loads all items statically for maximum performance © 2007, Davisworld.org 18
  • 19. Changing the Database © 2007, Davisworld.org 19
  • 20. Why does my data go away? dbCreate == hibernate.hbm2ddl.auto Create-drop -- creates the tables on startup, drops them on shutdown (DEV) Create -- creates the tables on startup, just deletes the data on shutdown Update -- creates the tables on startup, saves the data between restarts (PROD, TEST) Remove the value to manage the schema manually © 2007, Davisworld.org 20
  • 21. Changing to MySQL 1) Create the database and user 2) Copy the driver into lib 3) Adjust values in grails-app/conf/DevelopmentDataSource.groovy © 2007, Davisworld.org 21
  • 22. Create the database $ mysql --user=root Welcome to the MySQL monitor. mysql> create database bookstore_dev; mysql> grant all on bookstore_dev.* to grails@localhost identified by 'server'; mysql> flush privileges; Sanity check the newly created login: $ mysql --user=grails -p --database=bookstore_dev © 2007, Davisworld.org 22
  • 23. Point Grails to MySQL © 2007, Davisworld.org 23
  • 24. mysql> show tables; +-------------------------+ Magic Occurs | Tables_in_bookstore_dev | +-------------------------+ | book | +-------------------------+ mysql> desc book; +---------+--------------+------+-----+ | Field | Type | Null | Key | +---------+--------------+------+-----+ | id | bigint(20) | NO | PRI | | version | bigint(20) | NO | | | title | varchar(255) | NO | | | author | varchar(255) | NO | | +---------+--------------+------+-----+ © 2007, Davisworld.org 24
  • 25. Bootstrapping Data © 2007, Davisworld.org 25
  • 26. Bootstrapping Gotcha If you flipped dbCreate to “update”, beware: ApplicationBootStrap gets run each time © 2007, Davisworld.org 26
  • 27. Changing the Web server To run your app in Tomcat instead of Jetty: $ grails war $ cp bookstore.war /opt/tomcat/webapps/ Gotcha: Grails WARs run in PROD by default. $ grails dev war Or run your container with JAVA_OPTS=-Dgrails.env=development © 2007, Davisworld.org 27
  • 28. Changing the Home Page The default homepage is web-app/index.gsp. You can redirect to any page or controller: © 2007, Davisworld.org 28
  • 29. Act 3: Understanding Grails Controllers… 29
  • 30. Generating a Controller $ grails generate-controller © 2007, Davisworld.org 30
  • 31. The Three R’s Each controller method ends in one of three ways: Redirect Equivalent to response.sendRedirect() redirect(action:list,params:params) Return Calls a GSP named the same as the method return [ bookList: Book.list( params ) ] Render Calls a GSP of an arbitrary name render(view:'edit',model:[book:book]) © 2007, Davisworld.org 31
  • 32. Controller.index Index is the default target, Params is a Map just like index.jsp or index.html of the QueryString name/value pairs redirect() == response.sendRedirect() action:list == the list method in this controller © 2007, Davisworld.org 32
  • 33. Controller.list Implicit return GORM statement (Grails Object/Relational Mapping) Map of named objects in the Response (see list.gsp, next page) © 2007, Davisworld.org 33
  • 34. List.gsp Returned from Controller © 2007, Davisworld.org 34
  • 35. List view © 2007, Davisworld.org 35
  • 36. Convention over Configuration BookController http://localhost:9090/bookstore/book BookController.list http://localhost:9090/bookstore/book/list Corresponding list.gsp BookController.show(5) http://localhost:9090/bookstore/book/show/5 © 2007, Davisworld.org 36
  • 37. Show view © 2007, Davisworld.org 37
  • 39. Create.gsp Controller Method © 2007, Davisworld.org 39
  • 40. Controller.save In one line, Param name/value pairs from the form are saved to a POGO (Plain Old Groovy Object). In the next line, the POGO is saved to the database via GORM. © 2007, Davisworld.org 40
  • 41. Super-sneaky Grails Shell $ grails shell Let's get Groovy! ================ groovy> Book.list() groovy> go ===> [Book : 5, Book : 6, Book : 7, Book : 8, Book : 9, Book : 10] groovy> b = Book.get(5) groovy> b.title groovy> go ===> Groovy Recipes © 2007, Davisworld.org 41 groovy> new Book(author:’foo’).save()
  • 42. Auto-scaffolding I like generating Controllers and Views if I know that I am going to be tweaking them by hand. Otherwise, allowing Grails to auto-scaffold my Controllers and Views in memory reduces by code footprint to… (I don’t even bother with the Grails CLI for these…) © 2007, Davisworld.org 42
  • 43. Act 4: Understanding Grails Models… …and Views… …and GORM… (they’re all interrelated) 43
  • 44. POGOs Plain Old Groovy Objects Fields are automatically private Getters and setters are automatically provided Use Wrappers instead of Primitives Integer, Float, Double, Boolean © 2007, Davisworld.org 44
  • 45. Specifying Field Order © 2007, Davisworld.org 45
  • 46. Ordered Fields in List © 2007, Davisworld.org 46
  • 47. Field Validation © 2007, Davisworld.org 47
  • 48. Create Form © 2007, Davisworld.org 48
  • 50. mysql> desc book; Schema +------------------+--------------+ | Field | Type | +------------------+--------------+ | id | bigint(20) | | version | bigint(20) | | title | varchar(50) | | pages | int(11) | | category | varchar(255) | | isbn | varchar(255) | | excerpt | text | | publication_date | datetime | | cover | varchar(255) | | author | varchar(255) | +------------------+--------------+ © 2007, Davisworld.org 50
  • 53. Conclusion Grails is a fully integrated modern Java web application in a box: © 2007, Davisworld.org 53
  • 54. Conclusion Thanks for your time! Questions? Email: scottdavis99@yahoo.com Download slides: http://www.davisworld.org/presentations © 2007, Davisworld.org 54