grails gotchas and best practices

24
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ By Tom Henricksen

Upload: spring-by-pivotal

Post on 15-Apr-2017

404 views

Category:

Technology


2 download

TRANSCRIPT

Unless o therw ise i nd i cated, these s l i des a re © 2013 -2015 P i vo ta l So f tware, Inc . and l i censed under a Crea t i ve Com mons A t t r ibu tio n-NonCommercia l l i cense : h t tp : // crea tivecommons.o rg/ l icenses/by -nc/3 .0 /

By Tom Henricksen

Agenda

Domain-Driven Design

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Domain Validation

class User {

static

login

password

email

age

Conventions

Dependency Injection

Controllers

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Command Object

@grails.validation.Validateable

class LoginCommand {

String username

String password

static constraints = {

username(blank: false, minSize: 6)

password(blank: false, minSize: 6)

}

}

Services

Domain

Plugins

Testing

Discussion

Agenda

Grails Gotchas

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Be Careful with GStrings

// Single quotes

def s1 = ‘This is a string’

// Double quotes

def s2 = “This is also a string!”

// A Gstring at a software conference…

def g1 = “Hi, your name is ${user.name}”

String toString() { return “$description” }

Grails Gotchas

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Mapping

static mapping = {

table ‘descriptions’ {

columns {

description column ‘description’

}

}

static mapping = {

table ‘descriptions’

}

GORM Gotchas

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Dynamic Finders

class Book {

String title

Date releaseDate

Author author

}

def book = Book.findByTitle("The Stand")

book = Book.findByTitleLike ("Harry Pot%")

GORM Gotchas

// This is Helvetica: 18 pt or higher please

public class TransferServikjceImpl implements TransferService {

public TransferServiceImpl(AccountRepository ar) {

this.accountRepository = ar;

}

}

Default Values

String description

static constraints = {

description nullable: false, maxSize: 500

}

Grails Gotchas

Learn More. Stay Connected.