SlideShare a Scribd company logo
1 of 59
Enterprise Guice

 Robbie Vanbrabant
Dependency



             Art by Jesse Wilson
Pure Java™
interface Hero {
}

class Batman implements Hero {
}

class GothamCity {
  GothamCity(Hero hero) {
    ...
  }
}
class GothamCity {
  @Inject GothamCity(Hero hero) {
    ...
  }
}

class HeroModule implements Module {
  public void configure(Binder binder) {
    binder.bind(Hero.class).to(Batman.class);
  }
}
Enterprise Guice
2.0
  Guice

              2.0
Warp   Persist

 Google GIN
Art by Jesse Wilson
Basics
AOP
     for
Mere Mortals
Guice Servlet
Java Virtual Machine

                    Web Container



                                            Servlet
                          Filter pipeline
HTTP Request


HTTP Request                                Servlet


HTTP Request
                                            Servlet
Java Virtual Machine

                 Web Container



                                                        Servlet
HTTP Request       GuiceFilter        Filter pipeline


HTTP Request                                            Servlet


HTTP Request
                                                        Servlet
2.0
AssistedInject
Private Modules
Modules.override(
  new ProductionModule(),
  new TestModule()
);
Grapher
Code {}
  vs
<XML/>
Properties
database.url        =   jdbc:mysql://localhost/test
database.driver     =   com.mysql.jdbc.Driver
database.user       =   test
database.password   =   test
class PropertiesModule extends AbstractModule {
  protected void configure() {
    Names.bindProperties(binder(),
        load(“database.properties”));
  }
}

class UsesDatabase {
  @Inject @Named(“database.host”)
  private String host;
}
But I Want <XML/>
Compile-time Smiling
class AppModule extends AbstractModule {
  protected void configure() {
    install(new DataModule());
    install(new WebModule());
  }
}

<beans>
    <import resource=“data-context.xml”/>
    <import resource=“web-context.xml”/>
</beans>
@Annotations
     and
Tight Coupling
Summary
Guice 1.0 March 2007

Guice 2.0 Any minute
Hibernate

   JPA

 DB4O

Neodatis
@Transactional

Dynamic Finders
Unit of Work

Session / Transaction


Session / Request
class PersistenceModule extends ServletModule {
  protected void configureServlets() {

        install(PersistenceService.usingHibernate()
                                  .across(UnitOfWork.REQUEST)
                                  .buildModule());

        bind(Configuration.class).toInstance(
            new AnnotationConfiguration()
                .addAnnotatedClass(Product.class)
                .setProperties(load(quot;hibernate.propertiesquot;))
        );

        filter(“/*”).through(PersistenceFilter.class);
    }
}

Guice.createInjector(new PersistenceModule());
# configure hibernate to use the HSQL in-memory database
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:mem
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.pool_size=1
hibernate.dialect=org.hibernate.dialect.HSQLDialect

# creates tables for us automatically
hibernate.hbm2ddl.auto=create

# let Warp Persist apply the open-session-in-view pattern
hibernate.current_session_context_class=managed

# don’t use 2nd level caching
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
public class ProductManager {
    @Inject Provider<Session> session;

    @Transactional
    public void create(Product p) {
        session.get().save(p);
    }
}
public interface ProductAccess {
  @Transactional
  @Finder(namedQuery=“all products”)
  List<Product> listAll();

    @Transactional
    @Finder(query=“from Product where pn = :name”)
    Product find(@Named(“name”) String name);
}
@Transactional(rollbackOn = IOException.class,
               exceptOn = FileNotFoundException.class)
public class ProductService {
    @Inject Provider<Session> session;

    public void process(Product p) throws IOException {
        session.get().save(p);

        // do IO stuff
    }
}
PersistenceService.usingHibernate()
                  .across(UnitOfWork.REQUEST)
                  .forAll(
                      annotatedWith(Transactional.class),
                      any())
                  .buildModule());
Multiple Modules
public class ProductManager {
    @Inject @Product
    Provider<Session> session;

    @Transactional(unit=Product.class)
    public void create(Product p) {
        session.get().save(p);
    }
}
class PersistenceModule extends ServletModule {
  protected void configureServlets() {
    HibernatePersistenceStrategy hibernate =
        HibernatePersistenceStrategy.builder()
            .annotatedWith(Product.class).build();

        // Connect to the product database
        PersistenceService.using(hibernate)
                         .across(UnitOfWork.TRANSACTION)
                         .buildModule();

        bind(Configuration.class).annotatedWith(Product.class).toInstance(
            new AnnotationConfiguration()
                .addAnnotatedClass(Product.class)
                .setProperties(load(quot;hibernate.propertiesquot;))
        );
        ...
    }
}
Google GIN
on the
Client
Google Web Toolkit
brings
  Type Safety
       to
Web Development
Miracles Happen
   Java™                JavaScript
              Miracle
Source Code               HTML
“Bunny Heaven” by Mikko Eerola
No Bytecode
    cglib
No Reflection
     MyType.class
klazz.getAnnotation(...)
   Class.forName(...)
GIN
            is
Statically Compiled Guice
Code Generator
Zero
Overhead
Guice
http://code.google.com/p/google-guice

                Warp
http://code.google.com/p/warp-persist

              Google GIN
 http://code.google.com/p/google-gin

               Robbie
     http://garbagecollected.org
Pray for Common Sense
Enterprise Guice
Enterprise Guice 20090217 Bejug

More Related Content

What's hot

Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
Igor Khotin
 

What's hot (20)

Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
 
Spring 4 - A&BP CC
Spring 4 - A&BP CCSpring 4 - A&BP CC
Spring 4 - A&BP CC
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
 
The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developers
 
React, Redux and es6/7
React, Redux and es6/7React, Redux and es6/7
React, Redux and es6/7
 
GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
Ship your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerShip your Scala code often and easy with Docker
Ship your Scala code often and easy with Docker
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Android development
Android developmentAndroid development
Android development
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
 
Improving app performance with Kotlin Coroutines
Improving app performance with Kotlin CoroutinesImproving app performance with Kotlin Coroutines
Improving app performance with Kotlin Coroutines
 
Simple REST with Dropwizard
Simple REST with DropwizardSimple REST with Dropwizard
Simple REST with Dropwizard
 

Similar to Enterprise Guice 20090217 Bejug

Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 

Similar to Enterprise Guice 20090217 Bejug (20)

Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Guice gin
Guice ginGuice gin
Guice gin
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web ToolkitJava Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
 
Servlets
ServletsServlets
Servlets
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 

Enterprise Guice 20090217 Bejug

  • 2. Dependency Art by Jesse Wilson
  • 4. interface Hero { } class Batman implements Hero { } class GothamCity { GothamCity(Hero hero) { ... } }
  • 5. class GothamCity { @Inject GothamCity(Hero hero) { ... } } class HeroModule implements Module { public void configure(Binder binder) { binder.bind(Hero.class).to(Batman.class); } }
  • 6.
  • 7.
  • 9. 2.0 Guice 2.0 Warp Persist Google GIN
  • 10. Art by Jesse Wilson
  • 12. AOP for Mere Mortals
  • 14. Java Virtual Machine Web Container Servlet Filter pipeline HTTP Request HTTP Request Servlet HTTP Request Servlet
  • 15. Java Virtual Machine Web Container Servlet HTTP Request GuiceFilter Filter pipeline HTTP Request Servlet HTTP Request Servlet
  • 18. Modules.override( new ProductionModule(), new TestModule() );
  • 20.
  • 21.
  • 22. Code {} vs <XML/>
  • 23.
  • 24. Properties database.url = jdbc:mysql://localhost/test database.driver = com.mysql.jdbc.Driver database.user = test database.password = test
  • 25. class PropertiesModule extends AbstractModule { protected void configure() { Names.bindProperties(binder(), load(“database.properties”)); } } class UsesDatabase { @Inject @Named(“database.host”) private String host; }
  • 26. But I Want <XML/>
  • 27. Compile-time Smiling class AppModule extends AbstractModule { protected void configure() { install(new DataModule()); install(new WebModule()); } } <beans> <import resource=“data-context.xml”/> <import resource=“web-context.xml”/> </beans>
  • 28. @Annotations and Tight Coupling
  • 30. Guice 1.0 March 2007 Guice 2.0 Any minute
  • 31.
  • 32.
  • 33. Hibernate JPA DB4O Neodatis
  • 35. Unit of Work Session / Transaction Session / Request
  • 36. class PersistenceModule extends ServletModule { protected void configureServlets() { install(PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .buildModule()); bind(Configuration.class).toInstance( new AnnotationConfiguration() .addAnnotatedClass(Product.class) .setProperties(load(quot;hibernate.propertiesquot;)) ); filter(“/*”).through(PersistenceFilter.class); } } Guice.createInjector(new PersistenceModule());
  • 37. # configure hibernate to use the HSQL in-memory database hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.url=jdbc:hsqldb:mem hibernate.connection.username=sa hibernate.connection.password= hibernate.connection.pool_size=1 hibernate.dialect=org.hibernate.dialect.HSQLDialect # creates tables for us automatically hibernate.hbm2ddl.auto=create # let Warp Persist apply the open-session-in-view pattern hibernate.current_session_context_class=managed # don’t use 2nd level caching hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
  • 38. public class ProductManager { @Inject Provider<Session> session; @Transactional public void create(Product p) { session.get().save(p); } }
  • 39. public interface ProductAccess { @Transactional @Finder(namedQuery=“all products”) List<Product> listAll(); @Transactional @Finder(query=“from Product where pn = :name”) Product find(@Named(“name”) String name); }
  • 40. @Transactional(rollbackOn = IOException.class, exceptOn = FileNotFoundException.class) public class ProductService { @Inject Provider<Session> session; public void process(Product p) throws IOException { session.get().save(p); // do IO stuff } }
  • 41. PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .forAll( annotatedWith(Transactional.class), any()) .buildModule());
  • 43. public class ProductManager { @Inject @Product Provider<Session> session; @Transactional(unit=Product.class) public void create(Product p) { session.get().save(p); } }
  • 44. class PersistenceModule extends ServletModule { protected void configureServlets() { HibernatePersistenceStrategy hibernate = HibernatePersistenceStrategy.builder() .annotatedWith(Product.class).build(); // Connect to the product database PersistenceService.using(hibernate) .across(UnitOfWork.TRANSACTION) .buildModule(); bind(Configuration.class).annotatedWith(Product.class).toInstance( new AnnotationConfiguration() .addAnnotatedClass(Product.class) .setProperties(load(quot;hibernate.propertiesquot;)) ); ... } }
  • 48. brings Type Safety to Web Development
  • 49. Miracles Happen Java™ JavaScript Miracle Source Code HTML
  • 50. “Bunny Heaven” by Mikko Eerola
  • 51. No Bytecode cglib
  • 52. No Reflection MyType.class klazz.getAnnotation(...) Class.forName(...)
  • 53. GIN is Statically Compiled Guice
  • 56. Guice http://code.google.com/p/google-guice Warp http://code.google.com/p/warp-persist Google GIN http://code.google.com/p/google-gin Robbie http://garbagecollected.org