Enterprise JavaBeans (EJB) Server is a component transaction server. It supports the EJB server-side component model for developing and deploying distributed, enterprise-level applications in a multi-tiered environment. It provides the framework for creating, deploying, and managing middle-tier business logic.
In a three-tier environment, the client provides the user interface logic, the business rules are separated to the middle tier, and the database is the information repository. The client does not access the database directly. Instead, the client makes a call to the EJB Server on the middle tier, which then accesses the database.
The three tiers can reside on different machines or on the same machines. EJB Server is designed to reside on the same machine as the database engines it serves. Because the servers are on the same machine, EJB Server can communicate with the database using Adaptive Server’s high-speed, shared-memory JDBC driver. This approach ensures:
High-speed communication and data transfer, even for large data sets
Secure data transmission because the transfer of information from the third tier to the middle tier does not take place over the network
EJB components (or Beans) are reusable modules of code that combine related tasks (methods) into a well-defined interface. EJB components contain the methods that execute business logic and access data sources. You (or the Administrator) install the component’s executable code on EJB Server. Any number of independent Java or EJB applications (clients) can use the EJBs.
There are three types of Enterprise JavaBeans: stateful session Beans, stateless session Beans, and entity Beans. Each type of bean is a set of methods and is responsible for different tasks on behalf of the client.
All session Bean instances are transient. They maintain a one-to-one relationship with the client. They perform tasks, and can store information in the database on the client’s behalf. Stateful session Beans manage complex tasks that require the accumulation of data. Stateless session Beans manage tasks that do not store data between method calls. Entity Bean instances are persistent. They represent underlying objects, typically a particular row in a database. All three bean types work together to process a request and return information to the client.
Figure 1-1shows how the client interacts with the EJB Server and the database.
Figure 1-1: EJB Server environment
The stub and the skeleton allow EJB Server to appear to run locally on the client. Every component instance has its own stub and skeleton created specifically for it. The stub resides on the client machine and is connected over the network to the skeleton, which resides on EJB Server. The stub acts as a surrogate for the client, transmitting requests to the skeleton. The skeleton listens on an IIOP port for requests from the stub.
When the skeleton receives a request, it determines which method is required and then invokes that method. Using the Sybase high-speed JDBC driver, EJB Server sends the request to Adaptive Server. If values are returned, the skeleton sends them to the stub, which returns them to the client application.
EJB Server provides efficient management of client sessions, threads, third-tier database connections, and transaction flow, without requiring specialized knowledge on the part of the component developer. As a consequence, developers can focus on solving business problems instead of programming the application's infrastructure.
Developers use classes and interfaces from the javax.ejb packages of the JavaSoft API to create and deploy components. To implement a component, the developer must define interfaces and classes:
Remote interface – defines the Bean’s business methods and extends javax.ejb.EJBObject.
Home interface – defines the Bean’s lifecycle methods and extends javax.ejb.EJBHome.
Bean class – implements the Bean’s business methods and extends javax.ejb.EnterpriseBean.
Primary key – provides a pointer into the Adaptive Server database and must implement Serializable. Necessary for entity Beans only.
Sybase provides a graphics-based management tool, the Adaptive Server plug-in to Sybase Central, for EJB Server developers and administrators. From this graphical interface, developers can deploy components and administrators can configure the server.
For detailed information about creating and implementing EJB clients and components, see Chapter 6, “Working with EJB Packages and Components.”
For detailed information about configuring EJB Server, see Chapter 2, “Getting Started,” and Chapter 10, “Configuring EJB Server.”
EJB Server features include the following:
A scalable, multithreaded, platform-independent execution engine
Dispatch and stub/proxy support for the EJB component model
High-speed communication through Adaptive Server shared memory
Graphical administration with the Adaptive Server plug-in to Sybase Central
Easy integration with Sybase PowerJ development environment
Transparent client-session and component lifecycle management
Connection caching to allow reuse of database connections
Industry-standard naming services to resolve components using logical names rather than server addresses
Transaction management to simplify the design and implementation of an application’s transactions
Transparent thread-safety features to simplify use of shared data and resources
Result-set support to enable efficient retrieval of tabular data in client applications
Support for Enterprise JavaBeans (EJB) components developed according to version 1.1 of the Enterprise JavaBeans specification.
The following sections explain these features and describe how EJB Server works.