play with play!
TRANSCRIPT
Play with Play!
Anton Naumovemail: [email protected]
linkedin: http://ua.linkedin.com/in/antonnaumov
Monday, May 21, 12
Who am I?
Java Engineer
11+ years in Java development
Photographer
Sci-Fi addicted
Monday, May 21, 12
RIA Frameworks
?Monday, May 21, 12
RIA Frameworks
Ruby -> Rails
Monday, May 21, 12
RIA Frameworks
Python -> Django
Monday, May 21, 12
RIA Frameworks
Scala -> Play!
Monday, May 21, 12
RIA Frameworks
PHP -> PHP
Monday, May 21, 12
Java ->
RIA Frameworks
Monday, May 21, 12
Java ->
RIA Frameworks
?
Monday, May 21, 12
Java -> JSF?
RIA Frameworks
Monday, May 21, 12
GWT?Java ->JSF?
RIA Frameworks
Monday, May 21, 12
GWT?
Java ->JSF?
RIA Frameworks
Play!
Monday, May 21, 12
Play! Features
Monday, May 21, 12
Play! FeaturesNO compiling, NO redeployment
Monday, May 21, 12
Play! FeaturesNO compiling, NO redeployment
MVC out of the box
Monday, May 21, 12
Play! FeaturesNO compiling, NO redeployment
MVC out of the box
Unit & Functional test infrastructure
Monday, May 21, 12
Play! FeaturesNO compiling, NO redeployment
MVC out of the box
Unit & Functional test infrastructure
Dependency management
Monday, May 21, 12
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
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
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
Play! Anatomy
Monday, May 21, 12
What You Save Is What You Get
Monday, May 21, 12
What You Save Is What You Get
Eclipse Java Compiler
Monday, May 21, 12
What You Save Is What You Get
Eclipse Java Compiler
Custom ClassLoader
Monday, May 21, 12
What You Save Is What You Get
Eclipse Java Compiler
Custom ClassLoader
Javassist
Monday, May 21, 12
What You Save Is What You Get
Eclipse Java Compiler
Custom ClassLoader
Javassist
Netty
Monday, May 21, 12
Modelpackage models;
import play.db.jpa.Model;
import javax.persistence.Entity;
@Entitypublic class User extends Model { @Required public String firstName;}
Monday, May 21, 12
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
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
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
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
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
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
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
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
ControllerBinding
Monday, May 21, 12
ControllerBinding
public static void show(Long[] id) {...}
Monday, May 21, 12
ControllerBinding
public static void show(Long[] id) {...}
public static void show(List<Long> id) {...}
Monday, May 21, 12
ControllerBinding
Monday, May 21, 12
ControllerBindingpublic static void update(@As("dd/MM/yyyy") Date updatedAt) {...}
Monday, May 21, 12
ControllerBindingpublic static void update(@As("dd/MM/yyyy") Date updatedAt) {...}
public static void update(@As(",") List<String> items) {...}
Monday, May 21, 12
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
ControllerWorkflow
Monday, May 21, 12
ControllerWorkflow
@Before(only={"login","logout"}) static void doSomething() {
... }
Monday, May 21, 12
ControllerWorkflow
@Before(only={"login","logout"}) static void doSomething() {
... }
@Afterstatic void log() { Logger.info("Action executed ...");}
Monday, May 21, 12
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
ControllerWorkflow
Monday, May 21, 12
ControllerWorkflow
@Catch(value = Throwable.class, priority = 1) public static void logThrowable(Throwable t) {... }
Monday, May 21, 12
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
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
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
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
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
Dependency Management
Monday, May 21, 12
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
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
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
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
Configuration
Monday, May 21, 12
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
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
Modules
Monday, May 21, 12
ModulesCRUD
Monday, May 21, 12
ModulesCRUD
required: -‐ play -‐> crud
Monday, May 21, 12
ModulesCRUD
* /admin module:crudrequired: -‐ play -‐> crud
Monday, May 21, 12
ModulesCRUD
package controllers;
public class Users extends CURD {}
* /admin module:crudrequired: -‐ play -‐> crud
Monday, May 21, 12
ModulesSecure
Monday, May 21, 12
ModulesSecure
required: -‐ play -‐> secure
Monday, May 21, 12
ModulesSecure
* / module:securerequired: -‐ play -‐> secure
Monday, May 21, 12
ModulesSecure
package controllers;import play.mvc.With;
@With(Secure.class)public class Users extends CURD {}
* / module:securerequired: -‐ play -‐> secure
Monday, May 21, 12
Custom Module
Modules
Monday, May 21, 12
Custom Module
Routing
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
ZIP packaging
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
ZIP packaging
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
ZIP packaging
NO configuration
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
ZIP packaging
NO configuration
NO tests
Modules
Monday, May 21, 12
Custom Module
Routing
MVC classes
Dependencies
ZIP packaging
NO configuration
NO tests
NO dependencies
Modules
Monday, May 21, 12
Let it Play!
Monday, May 21, 12
Clouds
Heroku
CloudBees
PlayApp
Google AppEngine
Monday, May 21, 12
Disadvantages
Monday, May 21, 12
Disadvantages
Custom Modules management
Monday, May 21, 12
Disadvantages
Custom Modules management
Precompiling requirements
Monday, May 21, 12
Disadvantages
Custom Modules management
Precompiling requirements
Cloud deployment limitations
Monday, May 21, 12
Disadvantages
Custom Modules management
Precompiling requirements
Cloud deployment limitations
Configuration management limitations
Monday, May 21, 12
Disadvantages
Custom Modules management
Precompiling requirements
Cloud deployment limitations
Configuration management limitations
Technology stack limitations
Monday, May 21, 12
Disadvantages
Custom Modules management
Precompiling requirements
Cloud deployment limitations
Configuration management limitations
Technology stack limitations
Lack of documentation
Monday, May 21, 12
Alternatives
Monday, May 21, 12
Alternatives
Pure JPA 2.0
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Spring 3.1
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Spring 3.1
Spring Security
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Spring 3.1
Spring Security
Maven
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Spring 3.1
Spring Security
Maven
TestNG
Monday, May 21, 12
Alternatives
Pure JPA 2.0
NamedQueries
Spring 3.1
Spring Security
Maven
TestNG
DBUnit
Monday, May 21, 12
Take Away
Monday, May 21, 12
Thanks!
Anton Naumovemail: [email protected]
linkedin: http://ua.linkedin.com/in/antonnaumov
Monday, May 21, 12