SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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...Altinity Ltd
 
Terraforming the Kubernetes Land
Terraforming the Kubernetes LandTerraforming the Kubernetes Land
Terraforming the Kubernetes LandRadek Simko
 
Gpars concepts explained
Gpars concepts explainedGpars concepts explained
Gpars concepts explainedVaclav Pech
 
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 CEOAltinity Ltd
 
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...Altinity Ltd
 
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionGCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow IntroductionSimon Su
 
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 howAltinity Ltd
 
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 ClickHouseAltinity Ltd
 
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'rollPGConf APAC
 
Infrastructure as Code in Google Cloud
Infrastructure as Code in Google CloudInfrastructure as Code in Google Cloud
Infrastructure as Code in Google CloudRadek Simko
 
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)Jonathan Katz
 
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 CloudFlareAltinity Ltd
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117exsuns
 
Altinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Ltd
 
Docker in Action
Docker in ActionDocker in Action
Docker in ActionSimon Su
 
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)Altinity Ltd
 
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 ClickhouseAltinity Ltd
 

Was ist angesagt? (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
 

Andere mochten auch

Os Madsen Block
Os Madsen BlockOs Madsen Block
Os Madsen Blockoscon2007
 
Os Wardenupdated
Os WardenupdatedOs Wardenupdated
Os Wardenupdatedoscon2007
 
Os Peytonjones
Os PeytonjonesOs Peytonjones
Os Peytonjonesoscon2007
 
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
 

Andere mochten auch (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ı
 

Ähnlich wie Os Davis

Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03Groovygrailsnetbeans 12517452668498-phpapp03
Groovygrailsnetbeans 12517452668498-phpapp03Kevin Juma
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfigVijay Shukla
 
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 LaforgeGR8Conf
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfigVijay Shukla
 
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 LaneAndres Almiray
 
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 applicationsIndicThreads
 
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 LaforgeGuillaume Laforge
 
Golang Project Layout and Practice
Golang Project Layout and PracticeGolang Project Layout and Practice
Golang Project Layout and PracticeBo-Yi Wu
 
[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 OverviewLeo Lorieri
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionSchalk Cronjé
 
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, HerokuRedis Labs
 
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 grailsAnshuman Biswal
 
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 dbdeployerGiuseppe Maxia
 
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...Athens Big Data
 
Groovy and Grails
Groovy and GrailsGroovy and Grails
Groovy and GrailsGiltTech
 
Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installerGiuseppe Maxia
 

Ähnlich wie 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
 

Mehr von oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifmoscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Moleoscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashearsoscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Mythsoscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillipsoscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdatedoscon2007
 

Mehr von 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
 

Kürzlich hochgeladen

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 

Kürzlich hochgeladen (20)

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 

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