Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JavaEE, Spring, JPA, Repositories e Specifications

JavaEE, Spring, JPA, Repositories e Specifications

JPA provavelmente é uma das especificações do JavaEE mais difundidas entre os programadores da plataforma Java. Entretanto muitos insistem em ainda utilizar o conceito de DAOs para realizar acesso a dados. Nesta palestra veremos como utilizar Domain-Driven Design para criar Repositories, e como criar Specifications para melhorar a semântica, reuso e legibilidade do nosso código. Tudo isso utilizando lambdas do Java 8.

Avatar for Edson Yanaga

Edson Yanaga

October 17, 2014
Tweet

More Decks by Edson Yanaga

Other Decks in Technology

Transcript

  1. J AVA E E , S P R I N

    G , J PA , R E P O S I T O R I E S E S P E C I F I C AT I O N S E d s o n Ya n a g a @ y a n a g a # T D C 2 0 1 4
  2. E D S O N YA N A G A

    • Bacharel em Ciência da Computação/UEM • Mestre em Engenharia Elétrica/UTFPR • Desenvolvedor Java desde 1997 • Administrador Unix desde 1999 • Líder Técnico na Produtec desde 2012 • Instrutor Líder da GlobalCode desde 2012
  3. C E R T I F I C A Ç

    Õ E S • Oracle Certified Professional, Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer • Sun Certified Enterprise Architect for the Java Platform,Enterprise Edition 5 (i) • Certified ScrumMaster • Sun Certified Developer for Java Web Services 5 • Sun Certified Specialist for NetBeans IDE • Sun Certified Web Component Developer for J2EE 1.4 • Sun Certified Programmer for Java 2 Platform 1.4
  4. S o f t w a re é A r

    t e s a n a l
  5. public class Person { private String name; private String ssn;

    private String telephone; private Date birth; }
  6. P R I M I T I V E O

    B S E S S I O N
  7. public class Person { private Name name; private Ssn ssn;

    private Telephone telephone; private Birth birth; }
  8. – D E M E T E R L A

    W “Don’t talk to strangers”
  9. CriteriaQuery query = builder.createQuery(); Root<Person> men = query.from( Person.class );

    Root<Person> women = query.from( Person.class ); Predicate menRestriction = builder.and( builder.equal( men.get( Person_.gender ), Gender.MALE ), builder.equal( men.get( Person_.relationshipStatus ), RelationshipStatus.SINGLE )); Predicate womenRestriction = builder.and( builder.equal( women.get( Person_.gender ), Gender.FEMALE ), builder.equal( women.get( Person_.relationshipStatus ), RelationshipStatus.SINGLE )); query.where( builder.and( menRestriction, womenRestriction ) );
  10. JPAQuery query = new JPAQuery(em); QPerson men = new QPerson("men");

    QPerson women = new QPerson("women"); query.from(men, women).where( men.gender.eq(Gender.MALE), men.relationshipStatus.eq(RelationshipStatus.SINGLE), women.gender.eq(Gender.FEMALE), women.relationshipStatus.eq(RelationshipStatus.SINGLE));
  11. A culpa é minha e eu a coloco em quem

    eu quiser H O M E R S I M P S O N
  12. E N TÃ O FA Ç A P O R

    V O C Ê ! D E M A G O G I A ?
  13. V O C Ê E S TÁ C E R

    T O . Não importa em que você acredita.
  14. S O F T W A R E M E

    L H O R PA R A U M M U N D O M E L H O R
  15. S O U R C E C O D E

    AVA I L A B L E O N : h t t p s : / / g i t h u b . c o m / y a n a g a / d d d - j a v a e e 7
  16. E D S O N YA N A G A

     e d s o n @ y a n a g a . c o m . b r  @ y a n a g a  w w w. y a n a g a . c o m . b r