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 con...
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
           ...
Java Virtual Machine

                 Web Container



                                                        Servlet
HT...
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...
class PropertiesModule extends AbstractModule {
  protected void configure() {
    Names.bindProperties(binder(),
        ...
But I Want <XML/>
Compile-time Smiling
class AppModule extends AbstractModule {
  protected void configure() {
    install(new DataModule())...
@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...
# configure hibernate to use the HSQL in-memory database
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate...
public class ProductManager {
    @Inject Provider<Session> session;

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

    @Tr...
@Transactional(rollbackOn = IOException.class,
               exceptOn = FileNotFoundException.class)
public class Product...
PersistenceService.usingHibernate()
                  .across(UnitOfWork.REQUEST)
                  .forAll(
             ...
Multiple Modules
public class ProductManager {
    @Inject @Product
    Provider<Session> session;

    @Transactional(unit=Product.class)
...
class PersistenceModule extends ServletModule {
  protected void configureServlets() {
    HibernatePersistenceStrategy hi...
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

              Goo...
Pray for Common Sense
Enterprise Guice
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
Upcoming SlideShare
Loading in …5
×

Enterprise Guice 20090217 Bejug

1,778 views
1,654 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,778
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Enterprise Guice 20090217 Bejug

  1. 1. Enterprise Guice Robbie Vanbrabant
  2. 2. Dependency Art by Jesse Wilson
  3. 3. Pure Java™
  4. 4. interface Hero { } class Batman implements Hero { } class GothamCity { GothamCity(Hero hero) { ... } }
  5. 5. class GothamCity { @Inject GothamCity(Hero hero) { ... } } class HeroModule implements Module { public void configure(Binder binder) { binder.bind(Hero.class).to(Batman.class); } }
  6. 6. Enterprise Guice
  7. 7. 2.0 Guice 2.0 Warp Persist Google GIN
  8. 8. Art by Jesse Wilson
  9. 9. Basics
  10. 10. AOP for Mere Mortals
  11. 11. Guice Servlet
  12. 12. Java Virtual Machine Web Container Servlet Filter pipeline HTTP Request HTTP Request Servlet HTTP Request Servlet
  13. 13. Java Virtual Machine Web Container Servlet HTTP Request GuiceFilter Filter pipeline HTTP Request Servlet HTTP Request Servlet
  14. 14. 2.0 AssistedInject
  15. 15. Private Modules
  16. 16. Modules.override( new ProductionModule(), new TestModule() );
  17. 17. Grapher
  18. 18. Code {} vs <XML/>
  19. 19. Properties database.url = jdbc:mysql://localhost/test database.driver = com.mysql.jdbc.Driver database.user = test database.password = test
  20. 20. class PropertiesModule extends AbstractModule { protected void configure() { Names.bindProperties(binder(), load(“database.properties”)); } } class UsesDatabase { @Inject @Named(“database.host”) private String host; }
  21. 21. But I Want <XML/>
  22. 22. 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>
  23. 23. @Annotations and Tight Coupling
  24. 24. Summary
  25. 25. Guice 1.0 March 2007 Guice 2.0 Any minute
  26. 26. Hibernate JPA DB4O Neodatis
  27. 27. @Transactional Dynamic Finders
  28. 28. Unit of Work Session / Transaction Session / Request
  29. 29. 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());
  30. 30. # 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
  31. 31. public class ProductManager { @Inject Provider<Session> session; @Transactional public void create(Product p) { session.get().save(p); } }
  32. 32. 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); }
  33. 33. @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 } }
  34. 34. PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST) .forAll( annotatedWith(Transactional.class), any()) .buildModule());
  35. 35. Multiple Modules
  36. 36. public class ProductManager { @Inject @Product Provider<Session> session; @Transactional(unit=Product.class) public void create(Product p) { session.get().save(p); } }
  37. 37. 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;)) ); ... } }
  38. 38. Google GIN
  39. 39. on the Client
  40. 40. Google Web Toolkit
  41. 41. brings Type Safety to Web Development
  42. 42. Miracles Happen Java™ JavaScript Miracle Source Code HTML
  43. 43. “Bunny Heaven” by Mikko Eerola
  44. 44. No Bytecode cglib
  45. 45. No Reflection MyType.class klazz.getAnnotation(...) Class.forName(...)
  46. 46. GIN is Statically Compiled Guice
  47. 47. Code Generator
  48. 48. Zero Overhead
  49. 49. 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
  50. 50. Pray for Common Sense
  51. 51. Enterprise Guice

×