1 / 14

JEE Programming

INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA. Java Persistence API part 2. JEE Programming. Eriq Muhammad Adams J eriq.adams@ub.ac.id. Agenda. JPQL (Java Persistence Query Language) EAO Pattern Session Façade Pattern. JPQL (Java Persistence Query Language).

zulema
Télécharger la présentation

JEE Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Java Persistence API part 2 JEE Programming Eriq Muhammad Adams J eriq.adams@ub.ac.id

  2. Agenda • JPQL (Java Persistence Query Language) • EAO Pattern • Session Façade Pattern

  3. JPQL (Java Persistence Query Language) • Dynamic Query with JPQL • entityManager.createQuery(”select object o from Inventory o”).getResultList(); • Binding parameter : • entityManager.createQuery(”select object o from Inventory o where o.year=:year”).setParameter(”year”, year).getResultList(); • entityManager.createQuery(”select object o from Inventory o where o.year=?1”).setParameter(0, year).getResultList();

  4. JPQL (Java Persistence Query Language) (cont.) • Named Queries @Entity @NamedQueries({ @NamedQuery(name="findAllInventory", queryString="select object(o) from Inventory o"), @NamedQuery(name="findInventoryByYear", queryString="select object(o) from Inventory o where o.year=:year"), @NamedQuery(name="findInventoryByRegion", queryString="select object(o) from Inventory o where o.region=?1 ")}) public class Inventory implements Serializable{ ………

  5. JPQL (Java Persistence Query Language) (cont.) • entityManager.createNamedQuery(”findAllInventory”).getResultList(); • entityManager.createNamedQuery(”findInventoryByYear”).setParameter(”year”, year).getResultList(); • entityManager.createNamedQuery(”findInventoryByRegion”).setParameter(0, region).getResultList();

  6. JPQL (Java Persistence Query Language) (cont.) • Bulk Update and Delete Operation public intbulkDeleteEmptyInventory() { return em.createQuery("delete from Inventory o where o.quantity= 0").executeUpdate(); }

  7. JPQL (Java Persistence Query Language) (cont.) • Native SQL Query • entityManager.createNativeQuery(”select * from inventory”, entity.Inventory.class).getResultList(); • entityManager.createNativeQuery(”select * from inventory where year=?”,entity.Inventory.class ).setParameter(0, year).getResultList(); • Resultset Mapping • @SqlResultSetMapping(name = “InventoryResults", entities = @EntityResult(entityClass= Entity.Inventory.class)); • entityManager.createNativeQuery(”select * from inventory”, InventoryResults).getResultList();

  8. JPQL (Java Persistence Query Language) (cont.) • Native Named SQL Query @NamedNativeQuery( name = "findInventoryByYear", query = "SELECT * FROM inventory WHERE year = ?)", resultClass= entity.Inventory.class) @NamedNativeQuery( name = "findInventoryByYear", query = "SELECT * FROM inventory WHERE year = ?)", resultSetMapping = "InventoryResults") • entityManager.createNamedQuery(”findInventoryByYea r”).setParamater(0,year).getResultList();

  9. EAO Pattern • Stand for Entity Access Object Pattern • Separate or decouple data access with any business logic code. • It’s useful and widely used pattern because its reduce maintenance problem.

  10. EAO Pattern (cont.) • Illustration Sample Fig. taken from EJB 3 in Action, Manning

  11. Session Façade Pattern • The primary reasons the Session Façade pattern was invented was to reduce the number of remote calls for previous EJB incarnations, and this still holds true for EJB 3.

  12. Session Façade Pattern (cont.) • Illustration sample Fig. taken from EJB 3 in Action, Manning

  13. Demo • JPQL Demo in JPQLDemo.zip • EAO Pattern and Session Façade Pattern Demo in EAOSessionFacade.zip

  14. References • EJB 3 in Action, Manning • Beginning EJB 3 Application Development, Apress

More Related