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

entity beans
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Department of Informatics

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
  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-2
SLIDE 2

Department of Informatics

Entity Bean: Structure

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-3
SLIDE 3

Department of Informatics

Entity Bean: Structure

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-4
SLIDE 4

Department of Informatics

Entity Beans and Database Tables

Customer

Key: Customer ID

Product Key: Product ID Order Bean

Key: Order ID Customer ID Product ID

Invoice

Key: Invoice ID Order ID

* 1 1 1 1

Order Bean Table

. . . 1 1001 3 1003 Order ID Invoice ID

. . .

9 76 1 1212 2 3

Product ID Customer ID Order ID

Invoice Table

Address . . .

2 1002 1 76

Orders Customer ID

Customer Table

2 1002 152

  • 5. Enterprise JavaBeans

5.3 Entity Beans

*

slide-5
SLIDE 5

Department of Informatics

Entity Bean: créer un objet

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-6
SLIDE 6

Department of Informatics

Entity Bean: Retrouver un objet

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-7
SLIDE 7

Department of Informatics

Entity Bean: Recherche d'objets

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-8
SLIDE 8

Department of Informatics

Entity Bean: Efficacité?

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-9
SLIDE 9

Department of Informatics

Entity Bean: Réservoir (Pool)

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-10
SLIDE 10

Department of Informatics

Cycle de vie des instances

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-11
SLIDE 11

Department of Informatics

Cycle de vie vu du client

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-12
SLIDE 12

Department of Informatics

Cycle de vie vu du client

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-13
SLIDE 13

Department of Informatics

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
  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-14
SLIDE 14

Department of Informatics

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

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-15
SLIDE 15

Department of Informatics

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.

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-16
SLIDE 16

Department of Informatics

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>

  • 5. Enterprise JavaBeans

5.3 Entity Beans

slide-17
SLIDE 17

Department of Informatics

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>

  • 5. Enterprise JavaBeans

5.3 Entity Beans