entity beans
play

Entity Beans Vue objet dune base de donnes (exemples: client, - PowerPoint PPT Presentation

5. Enterprise JavaBeans 5.3 Entity Beans Entity Beans Vue objet dune base de donnes (exemples: client, compte,) en gnral, une ligne d une table relationnelle (SGBD-R) ou un objet persistant (SGBD- OO) sont persistant


  1. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Beans Vue objet d’une base de données (exemples: client, compte,…) � en général, une ligne d ’une table relationnelle (SGBD-R) ou un objet persistant (SGBD- � OO) sont persistant (long-lived) � la gestion de la persistance peut être faite par le bean ( bean managed persistence ) ou � déléguée à son conteneur ( container managed persistence ) acceptent les accès multiples effectués par plusieurs clients � gestion de la concurrence � • différents niveaux d ’isolation peuvent participer à des transactions � survivent aux pannes d’un serveur EJB � les pannes sont transparentes aux clients � Le client peut soit créer un nouveau Entity Bean ou trouver un Bean existant � La "Home interface" fournit des méthodes de recherche ("finder methods") � • findByPrimaryKey – clé unique dans un home • Méthodes de recherche spécifiques à l'application Department of Informatics

  2. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Structure Department of Informatics

  3. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Structure Department of Informatics

  4. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Beans and Database Tables Order Bean Table Order ID Customer ID Product ID . . . Customer 1 2 1002 152 Key: Customer ID 1 76 9 3 2 1212 * * Order Bean 1 1 Product Invoice Table Key: Order ID Invoice ID Order ID . . . Key: Product ID Customer ID 1001 1 Product ID 1003 3 1 Invoice Key: Invoice ID Customer Table Order ID Customer ID Orders Address . . . 2 1002 76 1 Department of Informatics

  5. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: créer un objet Department of Informatics

  6. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Retrouver un objet Department of Informatics

  7. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Recherche d'objets Department of Informatics

  8. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Efficacité? Department of Informatics

  9. 5. Enterprise JavaBeans 5.3 Entity Beans Entity Bean: Réservoir (Pool) Department of Informatics

  10. 5. Enterprise JavaBeans 5.3 Entity Beans Cycle de vie des instances Department of Informatics

  11. 5. Enterprise JavaBeans 5.3 Entity Beans Cycle de vie vu du client Department of Informatics

  12. 5. Enterprise JavaBeans 5.3 Entity Beans Cycle de vie vu du client Department of Informatics

  13. 5. Enterprise JavaBeans 5.3 Entity Beans Persistence � Two kinds Bean Managed: Programmatic � Container Managed: Declarative � � Bean Managed Bean provider must write routines to access the data store � • Declares instance variables to contain the persistent data • Finder method implementation written by Bean provider Container invokes these routines at an appropriate times in � lifecycle More common when underlying data store is an application � Department of Informatics

  14. 5. Enterprise JavaBeans 5.3 Entity Beans Persistence (2) Container Managed � Allows Bean to be logically independent of data source � • e.g.: same code for relational database, IMS database, etc. Container generates code to access the data store � • Deployer maps the fields of the Bean to the columns of the database – Bean provider describes Bean’s fields and relationships to other Beans in deployment descriptor • Container may use lazy access methods and caching • Finder methods are described in the deployment descriptor – Description is in EJB QL – Implementation is generated when Bean is deployed Virtual fields are used in the Bean to contain the persistent data � • Access is via getXXX/setXXX methods. Relationship between Beans � • Similar to foreign keys in relational databases (one to one, many to one, one to many, many to many) Allows container to ensure referential integrity � • e.g.: setting a Bean in field for a one to one relationship will automically remove the Bean from a prior relationship Department of Informatics

  15. 5. Enterprise JavaBeans 5.3 Entity Beans Deployment Descriptor � Captures declarative information � Well-formed XML � Contains � Structural information • Name of Bean, class, interfaces, Bean type, persistence type, container managed fields, . . . • Not all combinations of structural information make sense � Application assembly information � Security roles, method permissions, transaction attributes, etc. Department of Informatics

  16. 5. Enterprise JavaBeans 5.3 Entity Beans Deployment Descriptor Example <!DOCTYPE ejb-jar PUBLIC "-/Sun Microsystems, Inc.//DTD EnterpriseJavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb- jar_2_0.dtd"> <ejb-jar> <enterprise-beans> <entity> <ejb-name>CabinEJB</ejb-name> <home>com.titan.CabinHomeRemote</home> <remote>com.titan.CabinRemote</remote> <local-home>com.titan.CabinHomeRemote</local-home> <local>com.titan.CabinRemote</local> <ejb-class>com.titan.CabinBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.Integer</prim-key-class> <reentrant>False</reentrant> </entity> </enterprise-beans> </ejb-jar> Department of Informatics

  17. 5. Enterprise JavaBeans 5.3 Entity Beans EJB QL A query language � Similar to a subset of SQL � Used in the deployment descriptor to describe the behavior of finder � (and other) methods for Beans with Container Managed Persistence � <query> <query-method> <method-name>findByName</method-name> <method-params> <method-param>java.lang.String<method-param> <method-params> </query-method> <ejb-ql> SELECT OBJECT(c) FROM Cruise WHERE c.name = ?1 </ejb-ql> </query> Department of Informatics

Recommend


More recommend