Top Banner
Play with Play! Anton Naumov email: [email protected] linkedin: http://ua.linkedin.com/in/antonnaumov Monday, May 21, 12
98

Play with play!

Apr 07, 2017

Download

Technology

Anton Naumov
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Play with play!

Play with Play!

Anton Naumovemail: [email protected]

linkedin: http://ua.linkedin.com/in/antonnaumov

Monday, May 21, 12

Page 2: Play with play!

Who am I?

Java Engineer

11+ years in Java development

Photographer

Sci-Fi addicted

Monday, May 21, 12

Page 3: Play with play!

RIA Frameworks

?Monday, May 21, 12

Page 4: Play with play!

RIA Frameworks

Ruby -> Rails

Monday, May 21, 12

Page 5: Play with play!

RIA Frameworks

Python -> Django

Monday, May 21, 12

Page 6: Play with play!

RIA Frameworks

Scala -> Play!

Monday, May 21, 12

Page 7: Play with play!

RIA Frameworks

PHP -> PHP

Monday, May 21, 12

Page 8: Play with play!

Java ->

RIA Frameworks

Monday, May 21, 12

Page 9: Play with play!

Java ->

RIA Frameworks

?

Monday, May 21, 12

Page 10: Play with play!

Java -> JSF?

RIA Frameworks

Monday, May 21, 12

Page 11: Play with play!

GWT?Java ->JSF?

RIA Frameworks

Monday, May 21, 12

Page 12: Play with play!

GWT?

Java ->JSF?

RIA Frameworks

Play!

Monday, May 21, 12

Page 13: Play with play!

Play! Features

Monday, May 21, 12

Page 14: Play with play!

Play! FeaturesNO compiling, NO redeployment

Monday, May 21, 12

Page 15: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Monday, May 21, 12

Page 16: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Unit & Functional test infrastructure

Monday, May 21, 12

Page 17: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Unit & Functional test infrastructure

Dependency management

Monday, May 21, 12

Page 18: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Unit & Functional test infrastructure

Dependency management

Simple text and YAML configuration

Monday, May 21, 12

Page 19: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Unit & Functional test infrastructure

Dependency management

Simple text and YAML configuration

Modules

Monday, May 21, 12

Page 20: Play with play!

Play! FeaturesNO compiling, NO redeployment

MVC out of the box

Unit & Functional test infrastructure

Dependency management

Simple text and YAML configuration

Modules

Cloud hosting supportMonday, May 21, 12

Page 21: Play with play!

Play! Anatomy

Monday, May 21, 12

Page 22: Play with play!

What You Save Is What You Get

Monday, May 21, 12

Page 23: Play with play!

What You Save Is What You Get

Eclipse Java Compiler

Monday, May 21, 12

Page 24: Play with play!

What You Save Is What You Get

Eclipse Java Compiler

Custom ClassLoader

Monday, May 21, 12

Page 25: Play with play!

What You Save Is What You Get

Eclipse Java Compiler

Custom ClassLoader

Javassist

Monday, May 21, 12

Page 26: Play with play!

What You Save Is What You Get

Eclipse Java Compiler

Custom ClassLoader

Javassist

Netty

Monday, May 21, 12

Page 27: Play with play!

Modelpackage  models;

import  play.db.jpa.Model;

import  javax.persistence.Entity;

@Entitypublic  class  User  extends  Model  {        @Required        public  String  firstName;}

Monday, May 21, 12

Page 28: Play with play!

Model

JPA 2.0

package  models;

import  play.db.jpa.Model;

import  javax.persistence.Entity;

@Entitypublic  class  User  extends  Model  {        @Required        public  String  firstName;}

Monday, May 21, 12

Page 29: Play with play!

Model

JPA 2.0

play.db.jpa.Model

package  models;

import  play.db.jpa.Model;

import  javax.persistence.Entity;

@Entitypublic  class  User  extends  Model  {        @Required        public  String  firstName;}

Monday, May 21, 12

Page 30: Play with play!

Model

JPA 2.0

play.db.jpa.Model

Public fields

package  models;

import  play.db.jpa.Model;

import  javax.persistence.Entity;

@Entitypublic  class  User  extends  Model  {        @Required        public  String  firstName;}

Monday, May 21, 12

Page 31: Play with play!

ModelSimplified Queries

JPQL Queries

User.find("byEmailAndPassword",                         "[email protected]",  "s3cr#t");

User.find("SELECT  u  FROM  User  u  WHERE  u.email  LIKE  ?1",                                                      "vpupkin%");

Monday, May 21, 12

Page 32: Play with play!

Controllerpackage  controllers;

import  play.*;import  play.mvc.*;import  java.util.*;import  models.*;

public  class  Application  extends  Controller  {

       public  static  void  index()  {                render();        }

}

Monday, May 21, 12

Page 33: Play with play!

Controller

public static methods

package  controllers;

import  play.*;import  play.mvc.*;import  java.util.*;import  models.*;

public  class  Application  extends  Controller  {

       public  static  void  index()  {                render();        }

}

Monday, May 21, 12

Page 34: Play with play!

Controller

public static methods

play.mvc.Controller

package  controllers;

import  play.*;import  play.mvc.*;import  java.util.*;import  models.*;

public  class  Application  extends  Controller  {

       public  static  void  index()  {                render();        }

}

Monday, May 21, 12

Page 35: Play with play!

Controller

public static methods

play.mvc.Controller

render method

package  controllers;

import  play.*;import  play.mvc.*;import  java.util.*;import  models.*;

public  class  Application  extends  Controller  {

       public  static  void  index()  {                render();        }

}

Monday, May 21, 12

Page 36: Play with play!

ControllerBinding

Monday, May 21, 12

Page 37: Play with play!

ControllerBinding

public  static  void  show(Long[]  id)  {...}

Monday, May 21, 12

Page 38: Play with play!

ControllerBinding

public  static  void  show(Long[]  id)  {...}

public  static  void  show(List<Long>  id)  {...}

Monday, May 21, 12

Page 39: Play with play!

ControllerBinding

Monday, May 21, 12

Page 40: Play with play!

ControllerBindingpublic  static  void  update(@As("dd/MM/yyyy")  Date  updatedAt)  {...}

Monday, May 21, 12

Page 41: Play with play!

ControllerBindingpublic  static  void  update(@As("dd/MM/yyyy")  Date  updatedAt)  {...}

public  static  void  update(@As(",")  List<String>  items)  {...}

Monday, May 21, 12

Page 42: Play with play!

ControllerBindingpublic  static  void  update(@As("dd/MM/yyyy")  Date  updatedAt)  {...}

public  static  void  update(@As(",")  List<String>  items)  {...}

public  static  void  anyAction(@As(binder=Binder.class)  String  name)  {...}

Monday, May 21, 12

Page 43: Play with play!

ControllerWorkflow

Monday, May 21, 12

Page 44: Play with play!

ControllerWorkflow

 @Before(only={"login","logout"})  static  void  doSomething()  {

...  }

Monday, May 21, 12

Page 45: Play with play!

ControllerWorkflow

 @Before(only={"login","logout"})  static  void  doSomething()  {

...  }

@Afterstatic  void  log()  {        Logger.info("Action  executed  ...");}

Monday, May 21, 12

Page 46: Play with play!

ControllerWorkflow

 @Before(only={"login","logout"})  static  void  doSomething()  {

...  }

@Afterstatic  void  log()  {        Logger.info("Action  executed  ...");}

@Finallystatic  void  log()  {        Logger.info("Response  contains  :  "  +  response.out);}

Monday, May 21, 12

Page 47: Play with play!

ControllerWorkflow

Monday, May 21, 12

Page 48: Play with play!

ControllerWorkflow

 @Catch(value  =  Throwable.class,  priority  =  1)  public  static  void  logThrowable(Throwable  t)  {...  }

Monday, May 21, 12

Page 49: Play with play!

ControllerWorkflow

 @Catch(value  =  Throwable.class,  priority  =  1)  public  static  void  logThrowable(Throwable  t)  {...  }

@With(Secure.class)public  class  Admin  extends  Controller  {...}

Monday, May 21, 12

Page 50: Play with play!

View

Groovy

...                <title>#{get  'title'  /}</title>...                #{get  'moreStyles'  /}...                <script  src="@{'/public/javascripts/jquery-­‐1.6.4.min.js'}"  type="text/javascript"  charset="${_response_encoding}"></script>                #{get  'moreScripts'  /}        </head>        <body>                #{doLayout  /}        </body>...

Monday, May 21, 12

Page 51: Play with play!

TestingUnit Tests

import  play.test.*;import  org.junit.*;  public  class  UsersTest  extends  UnitTest  {        @Test        public  void  aTest()  {...        }        @Test        public  void  testUsers()  {...        }}

Monday, May 21, 12

Page 52: Play with play!

TestingFunctional Tests

import  play.test.*;import  play.mvc.*;import  play.mvc.Http.*;import  org.junit.*;  public  class  ApplicationTest  extends  FunctionalTest  {                  @Test        public  void  testTheHomePage()  {                Response  response  =  GET("/");                assertStatus(200,  response);        }

}

Monday, May 21, 12

Page 53: Play with play!

TestingSelenium

#{selenium  'Test  security'}        clearSession()        open('/admin')        assertTextPresent('Login')        type('login',  'admin')        type('password',  'secret')        clickAndWait('signin')          assertText('success',  'Welcom  admin!')#{/selenium}

Monday, May 21, 12

Page 54: Play with play!

Dependency Management

Monday, May 21, 12

Page 55: Play with play!

Dependency Management

YAML

#  Application  dependenciesrequire:        -­‐  play  1.2.4        -­‐  play  -­‐>  crud        -­‐  play  -­‐>  secure

repositories:        -­‐  jboss:                type:              iBiblio                artifact:  "http://repository.jboss.org/nexus/content/groups/public-­‐jboss/"                contains:                        -­‐  org.drools  -­‐>  *

Monday, May 21, 12

Page 56: Play with play!

Dependency Management

YAML

Ant Ivy

#  Application  dependenciesrequire:        -­‐  play  1.2.4        -­‐  play  -­‐>  crud        -­‐  play  -­‐>  secure

repositories:        -­‐  jboss:                type:              iBiblio                artifact:  "http://repository.jboss.org/nexus/content/groups/public-­‐jboss/"                contains:                        -­‐  org.drools  -­‐>  *

Monday, May 21, 12

Page 57: Play with play!

Dependency Management

YAML

Ant Ivy

Repositories

#  Application  dependenciesrequire:        -­‐  play  1.2.4        -­‐  play  -­‐>  crud        -­‐  play  -­‐>  secure

repositories:        -­‐  jboss:                type:              iBiblio                artifact:  "http://repository.jboss.org/nexus/content/groups/public-­‐jboss/"                contains:                        -­‐  org.drools  -­‐>  *

Monday, May 21, 12

Page 58: Play with play!

Dependency Management

YAML

Ant Ivy

Repositories

Deps & Sync

#  Application  dependenciesrequire:        -­‐  play  1.2.4        -­‐  play  -­‐>  crud        -­‐  play  -­‐>  secure

repositories:        -­‐  jboss:                type:              iBiblio                artifact:  "http://repository.jboss.org/nexus/content/groups/public-­‐jboss/"                contains:                        -­‐  org.drools  -­‐>  *

Monday, May 21, 12

Page 59: Play with play!

Configuration

Monday, May 21, 12

Page 60: Play with play!

Configuration

Application

application.mode=dev%prod.application.mode=prod  jpda.port=8000java.source=1.6

db=mem%prod.db=postgres://user:pwd@host/database%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0

Monday, May 21, 12

Page 61: Play with play!

Configuration

Application

Routing

GET    /                                            Application.indexGET    /favicon.ico                      404GET    /public/                              staticDir:public*        /admin                                  module:crud*        /                                            module:secure*        /{controller}/{action}  {controller}.{action}

Monday, May 21, 12

Page 62: Play with play!

Modules

Monday, May 21, 12

Page 63: Play with play!

ModulesCRUD

Monday, May 21, 12

Page 64: Play with play!

ModulesCRUD

required:        -­‐  play  -­‐>  crud

Monday, May 21, 12

Page 65: Play with play!

ModulesCRUD

*        /admin        module:crudrequired:        -­‐  play  -­‐>  crud

Monday, May 21, 12

Page 66: Play with play!

ModulesCRUD

package  controllers;

public  class  Users  extends  CURD  {}

*        /admin        module:crudrequired:        -­‐  play  -­‐>  crud

Monday, May 21, 12

Page 67: Play with play!

ModulesSecure

Monday, May 21, 12

Page 68: Play with play!

ModulesSecure

required:        -­‐  play  -­‐>  secure

Monday, May 21, 12

Page 69: Play with play!

ModulesSecure

*        /      module:securerequired:        -­‐  play  -­‐>  secure

Monday, May 21, 12

Page 70: Play with play!

ModulesSecure

package  controllers;import  play.mvc.With;

@With(Secure.class)public  class  Users  extends  CURD  {}

*        /      module:securerequired:        -­‐  play  -­‐>  secure

Monday, May 21, 12

Page 71: Play with play!

Custom Module

Modules

Monday, May 21, 12

Page 72: Play with play!

Custom Module

Routing

Modules

Monday, May 21, 12

Page 73: Play with play!

Custom Module

Routing

MVC classes

Modules

Monday, May 21, 12

Page 74: Play with play!

Custom Module

Routing

MVC classes

Dependencies

Modules

Monday, May 21, 12

Page 75: Play with play!

Custom Module

Routing

MVC classes

Dependencies

ZIP packaging

Modules

Monday, May 21, 12

Page 76: Play with play!

Custom Module

Routing

MVC classes

Dependencies

ZIP packaging

Modules

Monday, May 21, 12

Page 77: Play with play!

Custom Module

Routing

MVC classes

Dependencies

ZIP packaging

NO configuration

Modules

Monday, May 21, 12

Page 78: Play with play!

Custom Module

Routing

MVC classes

Dependencies

ZIP packaging

NO configuration

NO tests

Modules

Monday, May 21, 12

Page 79: Play with play!

Custom Module

Routing

MVC classes

Dependencies

ZIP packaging

NO configuration

NO tests

NO dependencies

Modules

Monday, May 21, 12

Page 80: Play with play!

Let it Play!

Monday, May 21, 12

Page 81: Play with play!

Clouds

Heroku

CloudBees

PlayApp

Google AppEngine

Monday, May 21, 12

Page 82: Play with play!

Disadvantages

Monday, May 21, 12

Page 83: Play with play!

Disadvantages

Custom Modules management

Monday, May 21, 12

Page 84: Play with play!

Disadvantages

Custom Modules management

Precompiling requirements

Monday, May 21, 12

Page 85: Play with play!

Disadvantages

Custom Modules management

Precompiling requirements

Cloud deployment limitations

Monday, May 21, 12

Page 86: Play with play!

Disadvantages

Custom Modules management

Precompiling requirements

Cloud deployment limitations

Configuration management limitations

Monday, May 21, 12

Page 87: Play with play!

Disadvantages

Custom Modules management

Precompiling requirements

Cloud deployment limitations

Configuration management limitations

Technology stack limitations

Monday, May 21, 12

Page 88: Play with play!

Disadvantages

Custom Modules management

Precompiling requirements

Cloud deployment limitations

Configuration management limitations

Technology stack limitations

Lack of documentation

Monday, May 21, 12

Page 89: Play with play!

Alternatives

Monday, May 21, 12

Page 90: Play with play!

Alternatives

Pure JPA 2.0

Monday, May 21, 12

Page 91: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Monday, May 21, 12

Page 92: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Spring 3.1

Monday, May 21, 12

Page 93: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Spring 3.1

Spring Security

Monday, May 21, 12

Page 94: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Spring 3.1

Spring Security

Maven

Monday, May 21, 12

Page 95: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Spring 3.1

Spring Security

Maven

TestNG

Monday, May 21, 12

Page 96: Play with play!

Alternatives

Pure JPA 2.0

NamedQueries

Spring 3.1

Spring Security

Maven

TestNG

DBUnit

Monday, May 21, 12

Page 97: Play with play!

Take Away

Monday, May 21, 12

Page 98: Play with play!

Thanks!

Anton Naumovemail: [email protected]

linkedin: http://ua.linkedin.com/in/antonnaumov

Monday, May 21, 12