Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

37
GRAILS Ezgi AYVAZOGLU pril 2014 - IZMIR

description

Introduction to Grails , Groovs vs Java, Grails vs Rails

Transcript of Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Page 1: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

GRAILS

Ezgi AYVAZOGLUApril 2014 - IZMIR

Page 2: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Content

What is Grails? Why full stack? What is Groovy? Grails vs Rails Groovy vs Java Testing in Grails Examples

Page 3: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails ( on Rails) is an Open Source, full stack, web application framework for the Java Virtual

Machine.

It uses the Groovy programming language which is an

agile, object oriented & dynamic programming language

for the Java Virtual Machine.

What is Grails?

Page 4: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

What is Grails?

Rapid Web Application Development Framework

For the JVM,

Inspired by Ruby on Rails, Django and others.

Page 5: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

What is Grails?

Convention over Configuration (CoC),

Don’t Repeat Yourself (DRY).

"every distinct concept and/or piece of data should live in one, and only one, place. redundancy is bad. normalization is good."

Page 6: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails Architecture

Page 7: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

How Grails is full stack framework?-1

Normally when you build applications, you need…

Database management (ORM) Presentation (User Interface) Service Layer Configuration

Grails will provide you functionality to all those areas so you don't need to look for a set of frameworks, just use one.

Page 8: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails attempts to solve as many pieces of the web development puzzle through the core technology and its associated plug-ins.

An easy to use Object Relational Mapping (ORM) layer built on Hibernate,

An expressive view technology called Groovy Server Pages (GSP),

A controller layer built on Spring MVC,

How Grails is full stack framework?-2

Page 9: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

A controller layer built on Spring MVC?

Basic controller logic,

Data binding and validation,

Runtime configurations,

Transactions.

Page 10: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

A command line scripting environment built on the Groovy-powered Gant,

An embedded Tomcat container which is configured for on the fly reloading,

Dependency injection with the inbuilt Spring container,

How Grails is full stack framework?-3

Page 11: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Support for internationalization (i18n) built on Spring's core MessageSource concept,

A transactional service layer built on Spring's transaction abstraction.

How Grails is full stack framework?-4

Page 12: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

All of these are made easy to usethrough the power ofthe Groovy languageand the extensive use

ofDomain SpecificLanguages (DSLs)

Why full stack?

Page 13: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Groovy

Page 14: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

What is Groovy?

Groovy is an object-oriented programming language for the Java platform.

It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk.

It can be used as a scripting language for the Java Platform, is dynamically compiled to Java Virtual Machine (JVM).

Page 15: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails vs Rails

Page 16: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails vs Rails - 1

Groovy vs Ruby API documentation better than Rails Solid frameworks underneath, such as

spring, hibernate Both has a active community, Rails more

popular, and more jobs, more books.

Page 17: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Grails vs Rails - 2

DB Migrations GORM vs Active Record REST Faster than Rails, but used lot of

memory, cheaper hosting Rails mature than Grails Rails release/update more often

Page 18: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Groovy vs Java

Page 19: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Default imports

java.io.* java.lang.* java.math.BigDecimal java.math.BigInteger java.net.* java.util.* groovy.lang.* groovy.util.*

Groovy vs Java -1

Page 20: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Groovy vs Java - 2

Closures Native syntax for lists and maps GroovyMarkup and GPath support Native support for regular expressions

Polymorphic iteration and powerful switch statement

Dynamic and static typing is supported - so you can omit the type declarations on methods, fields and variables

def clos = { println "hello!" } clos() //prints "hello!"

Page 21: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

In Java: for (int i=0; i < len; i++) {...}

In Groovy for (i in 0..len-1) {...} or for (i in 0..<len) {...} or len.times {...}.

Groovy vs Java - 3

Page 22: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Semicolons are optional. Use them if you like (though you must use them to put several statements on one line).

The return keyword is optional. You can use the this keyword inside static methods (which refers to this class).

Methods and classes are public by default. Protected in Groovy has the same meaning as protected in Java.

Groovy vs Java - 4

Page 23: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Groovy vs Java - 5

Page 24: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Testing

Page 25: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Testing

IntegrationTo execute the JUnit integration tests you can run:

grails test-app integration:integration

UnitThe following command will run all test types in the

unit phase:grails test-app unit:

Page 26: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Testing - Spock

Spock is a testing and specification framework for Java and Groovy applications.

What makes it stand out from the crowd is its beautiful and highly expressive specification language.

This plug-in brings the power of Spock to Grails.

grails test-app :spock

Page 27: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

To run the all of the spock tests in the functional phase you would run.

grails test-app functional:spock More than one pattern can be specified.grails test-app unit:spock integration:spock Test and type/phase targetting can be applied at

the same time:grails test-app integration: unit: some.org.**.*(This would run all tests in the integration and unit

phases that are in the package some.org or a subpackage.)

Testing - Spock

Page 28: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Tools

IDE: GGTS, Eclipse 3.5、 NetBeans 6.8、IDEA 9、 Spring STS 2.3.0

Editor: E-Texteditor、 Textmate、 GEdit Build:Maven、 Ant、 Ivy WebContainer: Tomcat、 Jetty Database: HSQL、MySQL GRAG

Page 29: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

GGTS

The Groovy/Grails Tool Suite provides the best Eclipse-powered development environment for building Groovy and Grails applications.

GGTS provides support for the latest versions of Groovy and Grails, and comes on top of the latest Eclipse releases.

Page 30: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

GGTS

Page 31: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Demo

Grails gTunes:1) grails create-app gTunes2) grails create-controller store3) edit StoreController.groovy4) write -> controller.index()assert 'Welcome to the gTunes store!'==

response.text5) grails run-app

Page 32: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Demo

http://localhost:8080/gTunes/

Page 33: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Examples

http://www.nowtv.com/ https://wwws.citruslane.com/#index http://www.vodafone.co.uk/ http://grails.org/ http://uros.com/ … Twitter in 60 minutes! http://www.youtube.com/watch?

v=pmT1zg8Cie4

Page 34: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Summary

=+

+

Page 35: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Summary

Grails is built on proven & solid OSS bricks Spring: IoC, DI, Spring MVC, transactions… Hibernate: ORM, querying mechanism Groovy: for everything that matters SiteMesh: page layout and composition Quartz: for job scheduling AJAX: integration with different libraries Jetty & HSQLDB: for fast development

cycles

Page 36: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Has it got to be complex?

But it’s slow to start with Seting up the project takes time

It gets complicated pretty rapidly Dive into Spring & Hibernate to

wireeverything together

There are so many layers DAOs, DTOs, more abstraction

layers Too many configuration files

Often too much XML for everything

Struts / Spring / Hibernate is okay…

Page 37: Introduction to Grails (Groovy vs Java and Grails vs Rails are included)

Thank You

Any question

Ezgi AYVAZOGLU