• Save
Ajs 3 c
Upcoming SlideShare
Loading in...5
×
 

Ajs 3 c

on

  • 688 views

 

Statistics

Views

Total Views
688
Views on SlideShare
644
Embed Views
44

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 44

http://niitcourseslides.blogspot.in 42
http://niitcourseslides.blogspot.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ajs 3 c Ajs 3 c Presentation Transcript

    • CollaborateKnowledge Byte In this section, you will learn about: • EJB in J2EE Architecture • EJB Design Patterns ©NIIT Collaborate Lesson 3C / Slide 1 of 36
    • CollaborateEJB in J2EE Architecture • Enterprise JavaBeans are the server side components that are based on Java technology. • EJB enables you to inherit all the features that an enterprise component requires. • For example, you do not need to write a code to establish a database connection. • You can concentrate on writing business logic of an enterprise bean development and leaving all the middleware service requirements for application server to handle. • You can concentrate on the programming logic of an application using EJB. • Moreover, you can buy EJB components instead of building own components. ©NIIT Collaborate Lesson 3C / Slide 2 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • The various characteristics of using EJB in J2EE architecture are: • Supporting multiple clients • Improving the reliability and productivity of an application • Supporting large scale deployment of applications • Developing transactional applications • Supporting reusability • Implementing security ©NIIT Collaborate Lesson 3C / Slide 3 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Supporting Multiple Clients • An enterprise bean can service only one client request at an instance of time, as enterprise beans are single threaded. • The container creates a pool of bean instances, and selects a bean instance from the pool to service the request whenever a client sends the request. • After servicing a client request, the bean instance is returned to the pool and container can assign this instance to another client request. • In this manner, the container uses a small number of bean instances to service a large number of client requests. • The container increases the pool size when the load on the server increases, and reduces the pool size when the load on the server is reduces. ©NIIT Collaborate Lesson 3C / Slide 4 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Supporting Multiple Clients (Contd.) • The following figure shows how a container uses pool of beans to service client requests: ©NIIT Collaborate Lesson 3C / Slide 5 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Improving the Reliability and Productivity of an Application • EJB improves the productivity and reliability of an enterprise application by distributing the whole tasks into various subtasks. • Creating an enterprise bean component, assembling the components in an application, and deploying the application in an application server into different parties are the examples of subtasks. • EJB considers that each party is an expert in its task. Some of the parties involved are: • Bean Developer: Is required to concentrate on the business logic of the bean. • Application Assembler: Is responsible for assembling the enterprise beans into an application. • Bean Deployer: Is an expert of an application server environment. ©NIIT Collaborate Lesson 3C / Slide 6 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Supporting Large Scale Deployment of Applications • You can use the functionality of an existing system using the legacy integration. • For example, a client on a Web server invokes a session bean on an application server. • The session bean further invokes an entity bean that uses a database server for storing data. • This type of application requires a highly secure fault-tolerant environment. • It also has to maintain a very high level of performance and availability. ©NIIT Collaborate Lesson 3C / Slide 7 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Supporting Large Scale Deployment of Applications (Contd.): • To meet all the requirements of enterprise applications EJB provides support for: • Instance Pooling: Uses a pool of bean instances to service client requests. • Connection Pooling: Uses a pool of connections that are required by components. • Transactions: Contains a sequence of operations executed under a single process. • Location Transparency: Does not require a client to be aware of the actual location of the object. ©NIIT Collaborate Lesson 3C / Slide 8 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Developing Transactional Applications • A transaction is defined as a sequence of operations. • The transaction succeeds if all the operations in the transaction succeed and it fails if any of the operation in a transaction fails. • In EJB, a transactional application can be developed by two approaches: • Declarative: Enables you to declare the required transactional attributes, such as Required, Supports, Mandatory, and Never in the deployment descriptor file. • Programmatic: Enables you to explicitly code the transactional behavior of the bean in the bean class. ©NIIT Collaborate Lesson 3C / Slide 9 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Supporting Reusability • EJB components are not reusable by default. • However, you can make a bean reusable using following approaches: • Customization: Enables you to modify the properties of a bean according to application requirements. • Extension: Enables you to write an application specific code by extending the bean class. ©NIIT Collaborate Lesson 3C / Slide 10 of 36
    • CollaborateEJB in J2EE Architecture (Contd.) • Implementing Security • An enterprise application is susceptible to unauthorized access and attacks. • Therefore, you need to protect an enterprise application from these threats. • The EJB container provides a secure environment for enterprise beans. • Securing an application involves two steps: • Authentication: Verifies the identity of a user. • Authorization: Provides restricted access to authenticated users. ©NIIT Collaborate Lesson 3C / Slide 11 of 36
    • CollaborateEJB Design Patterns • The EJB design patterns can de defined as best practices for designing an EJB application. • It provides a reusable approach for you to design and develop an application. • The EJB design patterns enable you to design secure, reliable, and scalable applications. • The various EJB design patterns are: • Client-Side EJB Interaction Design Patterns • EJB Layer Architectural Design Patterns • Inter-Tier Data Transfer Design Patterns • Transaction and Persistence Design Patterns ©NIIT Collaborate Lesson 3C / Slide 12 of 36
    • CollaborateEJB Design Patterns (Contd.) • Client-Side EJB Interaction Design Patterns • The Client-Side EJB Interaction design patterns are used to improve the performance and maintainability of client-side applications. • The various client-side EJB interaction design patterns are: • EJB Home Factory • Business Delegate • EJB Home Factory Pattern • The EJB Home Factory design pattern is used to locate the EJBHome object in order to access the remote interface of EJB. • Locating the EJBHome object for each Web request reduces the application performance. • The better approach is to abstract the EJBHome lookup code into a reusable EJBHomeFactory that can cache EJBHome objects for the lifetime of a client application. ©NIIT Collaborate Lesson 3C / Slide 13 of 36
    • CollaborateEJB Design Patterns (Contd.) • Client-Side EJB Interaction Design Patterns (Contd.) • EJB Home Factory Pattern (Contd.) • You can implement the EJB home factory pattern in any environment, such as applets, servlets, and EJBs. • The advantages of using the EJB Home Factory design pattern are: • Providing an efficient technique for abstracting the EJB home complexity from the client in a reusable format. • Improving the performance by reducing the cost involved in locating the redundant home lookups. ©NIIT Collaborate Lesson 3C / Slide 14 of 36
    • CollaborateEJB Design Patterns (Contd.) • Client-Side EJB Interaction Design Patterns (Contd.) • Business Delegate Pattern • The Business Delegate design pattern is used to map session beans present in the session facade pattern and wrap it with multiple message-driven beans. • Business Delegate is a Java class that acts as an intermediary between client and server. • The advantages of using the Business Delegate design pattern are: • Maintaining integration between non-Java applications and EJB by wrapping the business delegate Java objects with non-Java code using Java Naming Interface (JNI). • Hiding the complexity of EJB API by encapsulating the code required to invocate the session and message facade EJB layers. ©NIIT Collaborate Lesson 3C / Slide 15 of 36
    • CollaborateEJB Design Patterns (Contd.) • EJB Layer Architectural Design Patterns • The EJB Layer Architectural design patterns are used to select a correct EJB architecture in order to improve the performance, portability, and maintainability of applications. • The EJB Layer Architectural design patterns include various architectural design patterns: • Message Facade • EJB Command • Data Transfer Object Factory • Message Facade Pattern • The Message Facade design pattern is used when an enterprise Java bean client needs to call different methods available in multiple EJBs within the context of a single use case. ©NIIT Collaborate Lesson 3C / Slide 16 of 36
    • CollaborateEJB Design Patterns (Contd.) • EJB Layer Architectural Design Patterns (Contd.) • Message Facade Pattern (Contd.) • The advantages of using the Message Facade design pattern are: • Enabling a client to continue performing other tasks without waiting for the server’s response after sending a JMS message. • Enabling a pending transaction to retrieve later from the queue, this is rolled back due to non-functioning of the EJB server. • You can use the message facade design pattern when a client wants to update the data available on the server but has no time constraints for checking the updated results. ©NIIT Collaborate Lesson 3C / Slide 17 of 36
    • CollaborateEJB Design Patterns (Contd.) • EJB Layer Architectural Design Patterns (Contd.) • EJB Command Pattern • The EJB Command design pattern is used when a client needs to execute business logic to complete a use case. • The business logic of a use case determines the logic that needs to be operated across multiple session beans and entity beans. • The advantages of using the EJB Command design pattern are: • Writing a use case as a command bean enables you to easily deploy and test the application. • Executing the command beans in an EJB server requires only a single network call to complete even a complex use case. • You can use the EJB Command design pattern to decouple the client from EJB in lightweight command beans that act as a facade for the EJB layer. ©NIIT Collaborate Lesson 3C / Slide 18 of 36
    • CollaborateEJB Design Patterns (Contd.) • EJB Layer Architectural Design Patterns (Contd.) • Data Transfer Object Factory Pattern • The Data Transfer Object (DTO) Factory design pattern is used to separate the logic associated with the DTO from other components, such as entity beans. • The DTOs have a tendency to change frequently in an application. • The DTOs are of two types, domain DTO and custom DTO. • Domain DTO changes when a domain attribute is modified, such as adding a new attribute to an entity bean. • Custom DTO transports data across a network. ©NIIT Collaborate Lesson 3C / Slide 19 of 36
    • CollaborateEJB Design Patterns (Contd.) • EJB Layer Architectural Design Patterns (Contd.) • Data Transfer Object Factory Pattern (Contd.) • The advantages of using the data transfer object factory design pattern are: • Improving the maintainability of system by separating the use case from the entity beans. • Enabling different projects to reuse the entity beans because different DTO factories can suit the requirements of different applications. • You can use the Data Transfer Object Factory design pattern to read and update the data present on the server. • You can implement Data Transfer Object Factory design pattern as a stateless session bean in a servlet or as a Java class in a session bean. ©NIIT Collaborate Lesson 3C / Slide 20 of 36
    • CollaborateEJB Design Patterns (Contd.) • Inter-Tier Data Transfer Design Patterns • The Inter-Tier Data Transfer design pattern is used to transfer data from the server to the client and vice-versa. • The Inter-Tier Data Transfer design pattern includes various design patterns: • Data Transfer Object • Domain Data Transfer Object • Custom Data Transfer Object • Data Transfer Object Pattern • A data transfer object represents a serializable Java class, which contains data contained in a bundle placed on the server. • You can use the Data Transfer Object design pattern for performing read and update operations in distributed enterprise applications. ©NIIT Collaborate Lesson 3C / Slide 21 of 36
    • CollaborateEJB Design Patterns (Contd.) • Inter-Tier Data Transfer Design Patterns (Contd.) • Data Transfer Object Pattern (Contd.) • The advantages of using the Data Transfer Object design pattern are: • Transporting data between different tiers in a J2EE system. • Performing read operations from server to client in a single network call. • Domain Data Transfer Object Pattern • The Domain Data Transfer Object design pattern provides data transfer objects to clients. • This pattern provides local access to duplicate copies of server- side domain objects. ©NIIT Collaborate Lesson 3C / Slide 22 of 36
    • CollaborateEJB Design Patterns (Contd.) • Inter-Tier Data Transfer Design Patterns (Contd.) • Domain Data Transfer Object Pattern (Contd.) • The advantages of using the Domain Data Transfer Object design pattern are: • Duplicating and sending copies of entity beans from server to a client using a single network call. • Performing syntactic validation of entity bean attributes at client-side by incorporating a valid logic in domain DTO set methods. • You can use the Domain Data Transfer Object design pattern when you want to retrieve and manipulate data from the server-side domain object model, such as an entity bean. • This pattern is also used to marshal the copies of domain model instead of domain objects. ©NIIT Collaborate Lesson 3C / Slide 23 of 36
    • CollaborateEJB Design Patterns (Contd.) • Inter-Tier Data Transfer Design Patterns (Contd.) • Custom Data Transfer Objects Pattern • The Custom Data Transfer Objects design pattern implements a use-case-driven approach, in which the DTOs are designed according to the client requirements. • The custom DTOs are immutable in contrast to domain DTOs. • The custom DTOs are used to perform read-only operations. ©NIIT Collaborate Lesson 3C / Slide 24 of 36
    • CollaborateEJB Design Patterns (Contd.) • Transaction and Persistence Design Patterns (Contd.) • The Transaction and Persistence design pattern is associated with transaction control, persistence, and performance of a system. • The Transaction and Persistence design pattern includes various design patterns: • JDBC for Reading • Data Access Command Beans • Dual Persistent Entity Bean • JDBC for Reading Pattern • The JDBC for Reading design pattern represents a static server- side data to a client in a tabular user interface. • You can use the JDBC for Reading design pattern to represent a relational database for an EJB application. ©NIIT Collaborate Lesson 3C / Slide 25 of 36
    • CollaborateEJB Design Patterns (Contd.) • Transaction and Persistence Design Patterns (Contd.) • JDBC for Reading Pattern (Contd.) • The advantages of using the JDBC for Reading design pattern are: • Retrieving the data from any number of tables required by use-case queries. • Extracting the data required by the client in a single bulk database call. • Data Access Command Beans Pattern • The Data Access Command Beans design pattern creates a data access command bean for an enterprise application. • A data access command bean is used to apply the required information and invoke the required methods for executing the bean. ©NIIT Collaborate Lesson 3C / Slide 26 of 36
    • CollaborateEJB Design Patterns (Contd.) • Transaction and Persistence Design Patterns (Contd.) • Data Access Command Beans Pattern (Contd.) • It also enables you to call the corresponding getter methods to retrieve the data from the bean. • The advantages of using the Data Access Command Beans design pattern are: • Extracting the content of persistence logic layer to data access command beans layer to reduce the efforts required in making modifications. • Providing a clean and robust persistence mechanism for EJB, servlets, and JSP. • You can use the Data Access Command Beans design pattern to retrieve a persistent data store, such as RDBMS for an enterprise bean application. ©NIIT Collaborate Lesson 3C / Slide 27 of 36
    • CollaborateEJB Design Patterns (Contd.) • Transaction and Persistence Design Patterns (Contd.) • Dual Persistent Entity Bean Pattern • The Dual Persistent Entity Bean design pattern is made to support both Container Managed Persistent (CMP) entity bean and Bean Managed Persistent (BMP) entity bean. • A dual persistent entity bean divides the entity bean logic into classes, CMP-compliant superclass and a subclass that extends ejbLoad() and ejbStore() methods. • The advantages of using the Dual Persistent Entity Bean design pattern are: • Creating portable enterprise bean applications. • Migrating BMP entity beans to CMP entity beans. • You can use the Dual Persistent Entity Bean design pattern to include entity bean components that support both Container Managed Persistent (CMP) entity bean and Bean Managed Persistent (BMP) entity bean. ©NIIT Collaborate Lesson 3C / Slide 28 of 36
    • CollaborateFrom the Expert’s Desk In this section, you will learn: • Best Practice on: • Using Design Patterns to Improve Performance • Tips and Tricks on: • Setting the Optimum Age for Stateful Session Bean • Using BMP and DAO • FAQs on Design Patterns ©NIIT Collaborate Lesson 3C / Slide 29 of 36
    • CollaborateBest PracticesUsing Design Patterns to Improve Performance • The functions of different design patterns in improving the performance of a system are: • Value list handler: Improves the performance by providing the search facility, caching the results, and providing a filterable result set. • Session facade: Improves the performance by reducing the network overhead and grouping the related updates into transactions. • Service locator: Caches the references, such as EJB references, data sources, and Java Message Service (JMS) to hold the results obtained by Java Naming and Directory Interface (JNDI) lookups. • Data transfer objects: Improves the performance by reducing the network traffic that creates a network boundary between two entity beans. ©NIIT Collaborate Lesson 3C / Slide 30 of 36
    • CollaborateTips and TricksSetting the Optimum Age for Stateful Session Bean • You can set the optimum age for a stateful session bean by using the remove() method in a bean client class. • The remove() method is used to explicitly remove the bean instance from the container when the class does not require the use of bean. • A container either passivates the bean or stores the bean in the instance cache, when a client cannot use the remove() method. • This bean instance binds up the resources with server and consumes significant amount of memory. • You need to set the bean age explicitly, as a turnaround. • Setting the bean age explicitly enables a container to remove the bean, when age of a bean expires even if the client does not call the remove() method. • You can configure the required bean timeouts by specifying the server- specific timeout properties using application servers. ©NIIT Collaborate Lesson 3C / Slide 31 of 36
    • CollaborateTips and TricksUsing BMP and DAO • The various uses of Bean Managed Persistence (BMP) entity beans or Data Access Objects (DAO) are: • Working with legacy databases or persistence storage, such as Relational Database Management System (RDBMS). • Executing complicated queries, such as bulk updates, and complex joins. • Executing the already existing complex applications. • The various situations, in which you cannot use BMP and DAO, are: • Implementing batch loading or servicing queries that return large result sets. However, you can use DAO by encapsulating JDBC. • Invoking the get and set methods of entity beans from clients. ©NIIT Collaborate Lesson 3C / Slide 32 of 36
    • CollaborateFAQs • Which patterns are used by SUN in designing the Enterprise JavaBeans model? The various design patterns used by SUN in designing the Enterprise JavaBeans model are: • Factory method: Defines an interface for creating classes in the EJB creation model. • Singleton: Provides a global access to a class by creating a single instance of the class. • Abstract factory: Creates objects using interfaces without specifying the classes. • Builder: Creates different representations by separating the composition of a complex factory from its representation. • Adapter: Converts an interface of a class into another interface. • Proxy: Provides replacement of other objects to control their access in an application. • Memento: Acquires an internal state of an object. ©NIIT Collaborate Lesson 3C / Slide 33 of 36
    • CollaborateFAQs (Contd.) • What is session facade? Session facade is a J2EE design pattern used in developing session enterprise bean applications. The session facade design pattern provides a remote reference layer, which exposes the required interfaces to be used by clients. • What are collaboration patterns? Collaboration patterns are the techniques used to collaborate teamwork among users. These patterns can be used to gather requirement inputs for a team. ©NIIT Collaborate Lesson 3C / Slide 34 of 36
    • CollaborateChallenge 1. _____is responsible for assembling the enterprise bean components into a J2EE application. 2. A _______ is a single unit of work that consists of a sequence of operations. 3. A stateless session bean exist in two states exists state and ready state. (True/False) 4. The ______ exception is thrown, when a client is not associated with a transaction, which is associated with the mandatory transaction attribute. 5. The Never transaction attribute specifies that it is not mandatory for a bean method to be part of a transaction. (True/False) ©NIIT Collaborate Lesson 3C / Slide 35 of 36
    • CollaborateSolutions to Challenge • Application Assembler • Transaction • False • TransactionRequiredException • False ©NIIT Collaborate Lesson 3C / Slide 36 of 36