SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Building Grails Applications
                       with PostgreSQL
                            Brent Baxter and Ken Rimple
                          PostgreSQL East - March 25, 2010




Tuesday, March 30, 2010
About Brent and Ken
             • Brent Baxter: bbaxter@chariotsolutions.com
                   ‣ Consultant and Applications Architect
                   ‣ Grails, Java, and Spring developer
             • Ken Rimple: krimple@chariotsolutions.com
                   ‣ Head of Education Services
                   ‣ Host, Chariot TechCast:
                          http://techcast.chariotsolutions.com
                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
About Chariot Solutions

             • Java and Open Source solutions provider
             • Chariot Solutions Education Services
                   ‣ Groovy and Grails training and mentoring
             • Chariot Solutions Consulting
                   ‣ Development and consulting services
             • http://www.chariotsolutions.com
                                 PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Goals


             • Provide a basic overview of the Grails
                     framework - with a dash of Groovy
             • Review some of the features of Grails Object
                     Relational Modeling (GORM)
             • Demonstrate Grails with PostgreSQL

                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Introduction to Groovy



                                 PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Groovy

             • A dynamic language built for the Java Virtual
                     Machine
                   ‣ Compiles to native ByteCode
                   ‣ Can inherit Groovy classes from Java classes
                     (and vice versa)
                   ‣ Native access to any Java library


                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Benefits of Groovy

             • Adds "Convention over Configuration"
                   ‣ Groovy beans are VERY simple
                   ‣ Assumes methods are public, member
                     variables are private
                   ‣ Constructors not required
                   ‣ Easy collections – Use the [ ] syntax for lists
                     and maps

                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
A Sampling of Groovy APIs
             •      xml – Powerful XML                      •    builders – a set of
                    Parsing, Creation                            repetitive building tasks can
                                                                 be automated using various
             •      gsql – Simplified JDBC API                    Groovy Builders

             •      Groovy Testing– simple                  •    Swing – the Groovy
                    testing API, mocking with                    SwingBuilder makes UI
                    closures, etc...                             easy. Also Griffon is a
                                                                 Groovy-based MVC
             •      Collections – lists, maps                    framework for Swing (like
                                                                 Grails for Web)
                    and ranges




                                         PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Java Person Class
                          public class Person {
                            private String firstName;
                            private String lastName;
                            private Date birthDate;

                              public Person(String firstName,
                                    String lastName, Date birthDate) {
                                  ...
                              }

                              public void setFirstName() { ... }
                              public String getFirstName() { ... }

                              // etc...
                          }


                                          PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Groovy Person Class


                          class Person {
                            String lastName
                            String firstName
                            Date birthDate
                          }




                               PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Constructors and Lists

       // Groovy provides constructors for free
       def bob = new Person(firstName:'Bob', lastName:'Smith')
       def sue = new Person(firstName:'Sue', lastName:'Jones',
                      birthDate:new Date('8/12/1974'))




       // ArrayLists are simple
       def persons = [ new Person(firstName:‘Bob’),
                                 new Person(firstName:‘Sue’)]

       persons += new Person(firstName:‘John’)



                              PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Groovy SQL Support


                  // Using JDBC

                  def sql = Sql.newInstance(url, usr, pwd, driver)
                  sql.execute(“insert into table values ($foo, $bar)”)
                  sql.execute(“insert into table values (?,?)”, [a,b])
                  sql.eachRow(“select * from USER”) {println it.name}
                  def list = sql.rows(“select * from USER”)




                                    PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Introduction to Grails



                                PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Framework

             • A web application framework
                   ‣ Three-tiered Model View Controller (MVC)
             • Convention based
                   ‣ Sensible default configuration or use any of a
                     number of simple DSLs
             • Extendable with a rich set of plug-ins
                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Is Groovy

             • Leverages the Groovy programing language
                   ‣ Groovy Services and Beans
             • Configuration DSLs
                   ‣ Logging, data source configuration,
                     dependency resolution, ...
             • Web tier Groovy Server Pages (GSP)
                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Is Java

             • Framework backed by best of breed industry
                     standards
                   ‣ Spring, Hibernate, SiteMesh, Web Flow, etc.
             • Leverage any Java library, access from Groovy or
                     Java classes
             • Can be deployed as a Java web application
                     (WAR) to any Servlet container

                                    PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Technology Stack

                                      Grails

                                                        Standard
               SiteMesh Spring Hibernate                            Groovy
                                                        Libraries

                                    Java API

                            Java Platform (JVM)


                              PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Key Grails Components

             • Domain Class - A class representing an object in
                     your domain (database table)
             • Controller - A class that operates on URLs
                     submitted to the web site
             • View - A Groovy Server Page (GSP) designed to
                     render the content based on a specific request


                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Domain Driven Design with Grails
             • Focus on the complexities of the domain first
             • Create domain objects and their relationships
                     first
             • Dynamically 'scaffold' controllers and views for
                     each domain class, validate domain objects and
                     relationships
             • When ready, finish by generating or coding all
                     views, controllers, and tests

                                     PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Scaffolding
             • Dynamically generated views based on default
                     templates
             • No need to define a page before completing the
                     data model

                 // Domain                         // Dynamic Scaffold Controller
                 class Person {                    class PersonController {
                   String firstName                   def scaffold = true
                   String lastName                 }
                   Date birthDate
                 }



                                      PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
More than a web framework...
             • Eases development of every tier
                   ‣ Integrated Groovy build system
                   ‣ Integrated Groovy unit and integration test
                     mechanism
                   ‣ Simple ORM based on Hibernate
                   ‣ Extensible plug-in system built on Spring
                   ‣ Also simplifies Web MVC

                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Object Relational
                            Mapping (GORM)



                                 PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
GORM
             • Grails Object Relational Mapping API
                   ‣ Uses domain classes written in Groovy
                   ‣ Injects methods into domain classes for load,
                     save, update, and query data
                   ‣ Backed by Hibernate and Spring
                   ‣ Write Hibernate objects without all of the
                     messy XML!

                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
GORM Benefits

             • Write your domain classes as POGOs
             • Define validation via constraints
             • Define relationships via simple belongsTo,
                     hasMany mappings
             • Easy to test framework, can use grails console
                     or grails shell, even integration tests
             • Finders make it easy to locate data
                                     PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Grails Domain Classes

             • Created with create-domain-class
             • Simple Groovy Beans
                   ‣ Each member variable represents a column in
                     a table
                   ‣ Implied version, primary key fields
                   ‣ Can define relationships with other domains,
                     validation constraints

                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Connecting to PostgreSQL

             • Grails defines database connections for various
                     environments (Development, Test, Production)
             • Steps to configure your database
                   ‣ Install your database driver
                   ‣ Modify grails-app/config/DataSource.groovy
                   ‣ Boot grails with grails run-app


                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Defining Constraints
                                      class Customer {
                •     Checked
                      automatically        static constraints = {
                      when saved             firstName(maxLength: 15, blank: false)
                                             lastName(maxLength: 20, blank: false)
                      or when                registrationDate(nullable: false)
                      validate() is          preferredCustomer(default: true)
                      called                 awardsBalance(range: 0.0..5000.0)
                                           }
                                           String firstName
                •     Tip: scaffold        String lastName
                      configuration         Date registrationDate
                                           Boolean preferredCustomer
                      follows              BigDecimal awardsBalance
                      constraint      }
                      order for
                      field order


                                          PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Entity Relationships

             • Grails supports all Hibernate relation mappings
                   ‣ One to One
                   ‣ One to Many
                   ‣ Many to Many
                   ‣ Parent/Child (Inheritence)


                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
One to many relationship
        • Customer 'owns' accounts (cascade deletes, updates, saves)
          class Customer {
                                                            class Account {
                 String firstName
                                                                static belongsTo =
                 String lastName
                                                                       [customer:Customer]
                 ...
                                                                   String accountNumber
               static hasMany = [accounts:Account]
                                                            }
          }


              // arbitrary but working example... flush for testing only...
              def customer = new Customer(firstName: "Dude", lastName: "WheresMyCar")
              def account = new Account(accountNumber:"1234", customer:customer)
              customer.accounts = [account]
              def result = customer.save(flush:true)

              def account2 = Account.findById(account.id)
              println account2.customer

              def customer2 = Customer.findById(customer.id)
              println customer2.accounts

                                          PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Physical DB Settings - mapping
             • Changing the table, versioning on/off, column
                     mappings, indexing, multi-column-index, etc...
       class Person {
       String firstName
       String address
          static mapping = {
             table 'people'
             version false
             id column:'person_id'
             firstName column:'First_Name', index:'Name_Idx'
             address column:'Address', index:'Name_Idx, Address_Index'
          }
       }



                                    PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Stored Procedures

             • Several approaches
                   ‣ Spring's JdbcTemplate
                   ‣ Spring's StoredProcedure class
                   ‣ Spring's SqlFunction
                   ‣ Groovy SQL
             • Demonstration
                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Where to find the code


             • Hit our GitHub repository (you can just ask to
                     download the files)
             • GitHub repo for our samples
                   ‣ github.com/krimple/Grails-Demos-
                     PostgreSQL-East-2010.git



                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Groovy and Grails Resources

             • Grails Web Site
                   ‣ http://www.grails.org
             • Grails User Email List
                   ‣ http://n4.nabble.com/Grails-f1312388.html
             • Groovy Web Site
                   ‣ http://groovy.codehaus.org/

                                  PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Free InfoQ E-Book

             •      Getting Started with Grails,
                    Second Edition

                   ‣ Scott Davis

                   ‣ Jason Rudolph

             •      http://www.infoq.com/
                    minibooks/grails-getting-
                    started


                                        PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Regional User Groups

             • Philadelphia Groovy and Grails User Group
                   ‣ http://phillygroovy.org
                   ‣ Meet-up April 8 as part of Philly ETE
             • Philadelphia Spring User Group
                   ‣ http://phillyspring.ning.com/


                                   PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010
Thank you!

                          Questions ... ?


                             PostgreSQL East - March 25, 2010


Tuesday, March 30, 2010

Mais conteúdo relacionado

Mais procurados

Pgday bdr 천정대
Pgday bdr 천정대Pgday bdr 천정대
Pgday bdr 천정대PgDay.Seoul
 
Microsoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxMicrosoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxsamtakke1
 
WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewJames Bayer
 
Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Loginmoniguna
 
MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuningguest5ca94b
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PGPgDay.Seoul
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101Will Button
 
Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!PGConf APAC
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsHolly Schinsky
 
[Apache Kafka® Meetup by Confluent] Graph-based stream processing
[Apache Kafka® Meetup by Confluent] Graph-based stream processing[Apache Kafka® Meetup by Confluent] Graph-based stream processing
[Apache Kafka® Meetup by Confluent] Graph-based stream processingconfluent
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxKeepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxNeoClova
 

Mais procurados (20)

Pgday bdr 천정대
Pgday bdr 천정대Pgday bdr 천정대
Pgday bdr 천정대
 
Microsoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptxMicrosoft SQL Server Database Administration.pptx
Microsoft SQL Server Database Administration.pptx
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool Overview
 
Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Login
 
MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuning
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG[Pgday.Seoul 2018]  이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Nginx
NginxNginx
Nginx
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
[Apache Kafka® Meetup by Confluent] Graph-based stream processing
[Apache Kafka® Meetup by Confluent] Graph-based stream processing[Apache Kafka® Meetup by Confluent] Graph-based stream processing
[Apache Kafka® Meetup by Confluent] Graph-based stream processing
 
Spring boot
Spring bootSpring boot
Spring boot
 
Kotlin Coroutines - the new async
Kotlin Coroutines - the new asyncKotlin Coroutines - the new async
Kotlin Coroutines - the new async
 
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docxKeepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
Keepalived+MaxScale+MariaDB_운영매뉴얼_1.0.docx
 

Semelhante a Building Grails applications with PostgreSQL

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
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackJeremy Grelle
 
Mojo+presentation+1
Mojo+presentation+1Mojo+presentation+1
Mojo+presentation+1Craig Condon
 
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil BartlettCook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlettmfrancis
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneDeepu S Nath
 
Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Kate Marshalkina
 
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"GeeksLab Odessa
 
Dynamic poly-preso
Dynamic poly-presoDynamic poly-preso
Dynamic poly-presoScott Shaw
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLGabriele Bartolini
 
PostgreSQL is the new NoSQL - at Devoxx 2018
PostgreSQL is the new NoSQL  - at Devoxx 2018PostgreSQL is the new NoSQL  - at Devoxx 2018
PostgreSQL is the new NoSQL - at Devoxx 2018Quentin Adam
 
Integrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into GalaxyIntegrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into Galaxypjacock
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingMatt Stine
 
Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Guillaume Laforge
 
Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4John Ballinger
 
Welcome, Java 15! (Japanese)
Welcome, Java 15! (Japanese)Welcome, Java 15! (Japanese)
Welcome, Java 15! (Japanese)Logico
 
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
GSoC2014 - PGDay Ijui/RS Presentation October, 2016 GSoC2014 - PGDay Ijui/RS Presentation October, 2016
GSoC2014 - PGDay Ijui/RS Presentation October, 2016 Fabrízio Mello
 

Semelhante a Building Grails applications with PostgreSQL (20)

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
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web Stack
 
Mojo+presentation+1
Mojo+presentation+1Mojo+presentation+1
Mojo+presentation+1
 
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil BartlettCook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Oscon 2010
Oscon 2010Oscon 2010
Oscon 2010
 
Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014Drupal meets PostgreSQL for DrupalCamp MSK 2014
Drupal meets PostgreSQL for DrupalCamp MSK 2014
 
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
JS Lab`16. Сергей Селецкий: "Ретроспектива тестирования JavaScript"
 
Rejectkaigi 2010
Rejectkaigi 2010Rejectkaigi 2010
Rejectkaigi 2010
 
Dynamic poly-preso
Dynamic poly-presoDynamic poly-preso
Dynamic poly-preso
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQL
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
PostgreSQL is the new NoSQL - at Devoxx 2018
PostgreSQL is the new NoSQL  - at Devoxx 2018PostgreSQL is the new NoSQL  - at Devoxx 2018
PostgreSQL is the new NoSQL - at Devoxx 2018
 
Integrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into GalaxyIntegrating the NCBI BLAST+ suite into Galaxy
Integrating the NCBI BLAST+ suite into Galaxy
 
Postgres level up
Postgres level upPostgres level up
Postgres level up
 
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive MetaprogrammingFeelin' Groovy: An Afternoon of Reflexive Metaprogramming
Feelin' Groovy: An Afternoon of Reflexive Metaprogramming
 
Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010
 
Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4
 
Welcome, Java 15! (Japanese)
Welcome, Java 15! (Japanese)Welcome, Java 15! (Japanese)
Welcome, Java 15! (Japanese)
 
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
GSoC2014 - PGDay Ijui/RS Presentation October, 2016 GSoC2014 - PGDay Ijui/RS Presentation October, 2016
GSoC2014 - PGDay Ijui/RS Presentation October, 2016
 

Mais de Command Prompt., Inc

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsCommand Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenCommand Prompt., Inc
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy wayCommand Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Command Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Command Prompt., Inc
 

Mais de Command Prompt., Inc (20)

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
Temporal Data
Temporal DataTemporal Data
Temporal Data
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
Go replicator
Go replicatorGo replicator
Go replicator
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index Constraints
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy way
 
Bucardo
BucardoBucardo
Bucardo
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1
 

Building Grails applications with PostgreSQL

  • 1. Building Grails Applications with PostgreSQL Brent Baxter and Ken Rimple PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 2. About Brent and Ken • Brent Baxter: bbaxter@chariotsolutions.com ‣ Consultant and Applications Architect ‣ Grails, Java, and Spring developer • Ken Rimple: krimple@chariotsolutions.com ‣ Head of Education Services ‣ Host, Chariot TechCast: http://techcast.chariotsolutions.com PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 3. About Chariot Solutions • Java and Open Source solutions provider • Chariot Solutions Education Services ‣ Groovy and Grails training and mentoring • Chariot Solutions Consulting ‣ Development and consulting services • http://www.chariotsolutions.com PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 4. Goals • Provide a basic overview of the Grails framework - with a dash of Groovy • Review some of the features of Grails Object Relational Modeling (GORM) • Demonstrate Grails with PostgreSQL PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 5. Introduction to Groovy PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 6. Groovy • A dynamic language built for the Java Virtual Machine ‣ Compiles to native ByteCode ‣ Can inherit Groovy classes from Java classes (and vice versa) ‣ Native access to any Java library PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 7. Benefits of Groovy • Adds "Convention over Configuration" ‣ Groovy beans are VERY simple ‣ Assumes methods are public, member variables are private ‣ Constructors not required ‣ Easy collections – Use the [ ] syntax for lists and maps PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 8. A Sampling of Groovy APIs • xml – Powerful XML • builders – a set of Parsing, Creation repetitive building tasks can be automated using various • gsql – Simplified JDBC API Groovy Builders • Groovy Testing– simple • Swing – the Groovy testing API, mocking with SwingBuilder makes UI closures, etc... easy. Also Griffon is a Groovy-based MVC • Collections – lists, maps framework for Swing (like Grails for Web) and ranges PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 9. Java Person Class public class Person { private String firstName; private String lastName; private Date birthDate; public Person(String firstName, String lastName, Date birthDate) { ... } public void setFirstName() { ... } public String getFirstName() { ... } // etc... } PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 10. Groovy Person Class class Person { String lastName String firstName Date birthDate } PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 11. Constructors and Lists // Groovy provides constructors for free def bob = new Person(firstName:'Bob', lastName:'Smith') def sue = new Person(firstName:'Sue', lastName:'Jones', birthDate:new Date('8/12/1974')) // ArrayLists are simple def persons = [ new Person(firstName:‘Bob’), new Person(firstName:‘Sue’)] persons += new Person(firstName:‘John’) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 12. Groovy SQL Support // Using JDBC def sql = Sql.newInstance(url, usr, pwd, driver) sql.execute(“insert into table values ($foo, $bar)”) sql.execute(“insert into table values (?,?)”, [a,b]) sql.eachRow(“select * from USER”) {println it.name} def list = sql.rows(“select * from USER”) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 13. Introduction to Grails PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 14. Grails Framework • A web application framework ‣ Three-tiered Model View Controller (MVC) • Convention based ‣ Sensible default configuration or use any of a number of simple DSLs • Extendable with a rich set of plug-ins PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 15. Grails Is Groovy • Leverages the Groovy programing language ‣ Groovy Services and Beans • Configuration DSLs ‣ Logging, data source configuration, dependency resolution, ... • Web tier Groovy Server Pages (GSP) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 16. Grails Is Java • Framework backed by best of breed industry standards ‣ Spring, Hibernate, SiteMesh, Web Flow, etc. • Leverage any Java library, access from Groovy or Java classes • Can be deployed as a Java web application (WAR) to any Servlet container PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 17. Grails Technology Stack Grails Standard SiteMesh Spring Hibernate Groovy Libraries Java API Java Platform (JVM) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 18. Key Grails Components • Domain Class - A class representing an object in your domain (database table) • Controller - A class that operates on URLs submitted to the web site • View - A Groovy Server Page (GSP) designed to render the content based on a specific request PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 19. Domain Driven Design with Grails • Focus on the complexities of the domain first • Create domain objects and their relationships first • Dynamically 'scaffold' controllers and views for each domain class, validate domain objects and relationships • When ready, finish by generating or coding all views, controllers, and tests PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 20. Grails Scaffolding • Dynamically generated views based on default templates • No need to define a page before completing the data model // Domain // Dynamic Scaffold Controller class Person { class PersonController { String firstName def scaffold = true String lastName } Date birthDate } PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 21. More than a web framework... • Eases development of every tier ‣ Integrated Groovy build system ‣ Integrated Groovy unit and integration test mechanism ‣ Simple ORM based on Hibernate ‣ Extensible plug-in system built on Spring ‣ Also simplifies Web MVC PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 22. Grails Object Relational Mapping (GORM) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 23. GORM • Grails Object Relational Mapping API ‣ Uses domain classes written in Groovy ‣ Injects methods into domain classes for load, save, update, and query data ‣ Backed by Hibernate and Spring ‣ Write Hibernate objects without all of the messy XML! PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 24. GORM Benefits • Write your domain classes as POGOs • Define validation via constraints • Define relationships via simple belongsTo, hasMany mappings • Easy to test framework, can use grails console or grails shell, even integration tests • Finders make it easy to locate data PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 25. Grails Domain Classes • Created with create-domain-class • Simple Groovy Beans ‣ Each member variable represents a column in a table ‣ Implied version, primary key fields ‣ Can define relationships with other domains, validation constraints PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 26. Connecting to PostgreSQL • Grails defines database connections for various environments (Development, Test, Production) • Steps to configure your database ‣ Install your database driver ‣ Modify grails-app/config/DataSource.groovy ‣ Boot grails with grails run-app PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 27. Defining Constraints class Customer { • Checked automatically static constraints = { when saved firstName(maxLength: 15, blank: false) lastName(maxLength: 20, blank: false) or when registrationDate(nullable: false) validate() is preferredCustomer(default: true) called awardsBalance(range: 0.0..5000.0) } String firstName • Tip: scaffold String lastName configuration Date registrationDate Boolean preferredCustomer follows BigDecimal awardsBalance constraint } order for field order PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 28. Entity Relationships • Grails supports all Hibernate relation mappings ‣ One to One ‣ One to Many ‣ Many to Many ‣ Parent/Child (Inheritence) PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 29. One to many relationship • Customer 'owns' accounts (cascade deletes, updates, saves) class Customer { class Account { String firstName static belongsTo = String lastName [customer:Customer] ... String accountNumber static hasMany = [accounts:Account] } } // arbitrary but working example... flush for testing only... def customer = new Customer(firstName: "Dude", lastName: "WheresMyCar") def account = new Account(accountNumber:"1234", customer:customer) customer.accounts = [account] def result = customer.save(flush:true) def account2 = Account.findById(account.id) println account2.customer def customer2 = Customer.findById(customer.id) println customer2.accounts PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 30. Physical DB Settings - mapping • Changing the table, versioning on/off, column mappings, indexing, multi-column-index, etc... class Person { String firstName String address static mapping = {    table 'people'    version false    id column:'person_id'    firstName column:'First_Name', index:'Name_Idx'    address column:'Address', index:'Name_Idx, Address_Index' } } PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 31. Stored Procedures • Several approaches ‣ Spring's JdbcTemplate ‣ Spring's StoredProcedure class ‣ Spring's SqlFunction ‣ Groovy SQL • Demonstration PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 32. Where to find the code • Hit our GitHub repository (you can just ask to download the files) • GitHub repo for our samples ‣ github.com/krimple/Grails-Demos- PostgreSQL-East-2010.git PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 33. Groovy and Grails Resources • Grails Web Site ‣ http://www.grails.org • Grails User Email List ‣ http://n4.nabble.com/Grails-f1312388.html • Groovy Web Site ‣ http://groovy.codehaus.org/ PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 34. Free InfoQ E-Book • Getting Started with Grails, Second Edition ‣ Scott Davis ‣ Jason Rudolph • http://www.infoq.com/ minibooks/grails-getting- started PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 35. Regional User Groups • Philadelphia Groovy and Grails User Group ‣ http://phillygroovy.org ‣ Meet-up April 8 as part of Philly ETE • Philadelphia Spring User Group ‣ http://phillyspring.ning.com/ PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010
  • 36. Thank you! Questions ... ? PostgreSQL East - March 25, 2010 Tuesday, March 30, 2010