Road - 6. Enterprise JavaBeans

xiaoxiao2021-03-06  115

Each EJB Session and Entity Bean Must Have The Following Classes and Interfaces: • HOME (EJBHOME) Interface • Remote (EJBOBJECT) Interface • XML Deployment Descriptor • Bean Class • Context Objects

HOME (EJBHOME) InterfaceThe Ejbhome Object Provides the lifecle Operations (Create (), Remove (), FIND ()) for an ejb.

Remote (EJBOBJECT) Interfacethe Remote (EJBObject) Interface Provides Access To The Business Methods Withnin The EJB. An EjBobject Represents A Client View of The EJB.

XML Deployment DescriptorThe deployment descriptor is an XML (Extensible Markup Language) file provided with each module and application that describes how the parts of a J2EE application should be deployed. The deployment descriptor configures specific container options in your deployment tool of choice.

.....................

Context Objects for Session and EntityFor each active EJB instance, the EJB container generates an instance context object to maintain information about the management rules and the current state of the instance.

Distinguish Between Session and Entity BeansA session bean is an EJB that is created by a client and usually exists only for the duration of a single client-server session. A session bean usually performs operations such as calculations or database access on behalf of the client. An Entity Bean Is An Object Representation of Persistent Data Maintained in a Permanent Data Store Such As a DataBase.

When to Use Entity and Session JavaBeans • Use entity beans to persist data An entity bean is a sharable enterprise data resource that can be accessed and updated by multiple users • Use stateful session beans when any one of the following conditions is true;.. Otherwise use stateless session beans:.. • The session bean must retain data in its member variables across method invocations • The state of the bean needs to be initialized when the session bean is instantiated • The session bean must retain information about the client across multiple method invocations. • The session bean is servicing an interactive client whose presence must be known to the applications server or EJB container.Stateful vs. Stateless Session BeansA stateful session bean will maintain a conversational state with a client. The state of the session is maintained for The duration of the conversation between the client and the stateful session bean.a stateless session bean will not maintain conversational state Spect INVOCATION.

Stateless session bean has more beneficial attributes • Bean pooling Any stateless session bean method instance that is not currently invoked is equally available to be called by an EJB container or application server to service the request of a client. This allows the EJB container to pool stateless bean instances and increase performance. • Scalability Because stateless session beans are able to service multiple clients, they tend to be more scalable when applications have a large number of clients. When compared to stateful session beans, stateless session beans usually require less instantiation. • Performance An EJB container will never move a stateless session bean from RAM out to a secondary storage, which it may do with a stateful session bean; therefore, stateless session beans may offer greater performance than stateful session beans.Entity bean Lifecycle States • Null The Bean Instance Doesn't EXIST. • Pooled The Bean Exists But ISN't Associated with Any Specific Entity Object. Ready The Bean Instance Has Been Assigned An Entity Object Identity.

CMP Pros • Database-independence The container, not the enterprise bean provider, maintains database access code to most popular databases. • Container-specific features Features such as full text search are available for use by the enterprise bean provider.CMP Cons • Algorithms Only container-supported algorithms persistence can be used. • Portability Portability to other EJB containers may be lost. • Access The developer has no access to the view and can not modify the actual code. • Efficiency Sometimes the generated SQL is not the most efficient with respect TO Performance.

BMP Pros • Container independent Entity bean code written for one EJB container should be easily portable to any other certified EJB container. • Standards based The standard EJB and JDBC APIs can be used for data access calls. • Datatype access The ability to access nonstandard datatypes and legacy applications is supported. • Maximum flexibility Data validation logic of any complexity is supported. • Database specific features The application is able to take advantage of nonstandard SQL features of different SQL servers. BMP Cons • Database specific Because entity bean code is database specific , if access to multiple databases is required, the enterprise bean provider will have to account for this in its data access methods. • Knowledge of SQL The enterprise bean provider must have knowledge of SQL. • Development time These beans on average take much longer time To develop-as much as find time.

转载请注明原文地址:https://www.9cbs.com/read-126114.html

New Post(0)