EJB learning notes

xiaoxiao2021-03-06  79

Wednesday, 2004-10-13

Server-side calculation (using WSAD development, debugging, and test EJB, JSP and Servlet (EJB first day))

1. Single-layer (desktop system) Answer: 1) GUI client, application, and resources all in the same machine (same layer);

2. Layer 2 (Server / Client) Answer: 1) Fat Client; 2) Application and Resources At the same layer; 3) Server-side program updates will result in all client program updates

3. Multi-layer architecture system A: 1) Multi-layer architecture system has experienced several major improvements: this improvement from single-layer (host type system) to the second layer (server / client); 2) in early ninety During the age, traditional enterprise information system providers have begun to improve the two-layer model into a more flexible three-layer and multi-layer application model to meet customer needs; 3) Multi-layer models deploy software in a set of machines, these forms the entire application . This new model uses the business logic from the system service and the user interface, placed in the intermediate layer between the two; 4) The development of new middleware services (transaction listener, message guide) gives this The new architecture system additional driving force; 5) In addition, the company's growth in the Internet and the internal network, highlights the lightweight and easy deployment of the web browser as the client. 6) Multi-layer settings simplify the development, deployment, and maintenance of enterprise applications. It enables developers to focus on commercial logic, depending on different backend services to provide client applications to meet user interaction. 7) Once the development is completed, commercial logic can be deployed in the server to meet an organizational existing needs; 8) No matter how, there is no standard component structure system exists in the intermediate layer, this forces the developer to focus on different platforms, development systems, and middleware Detail of the service. This limits the developer to deploy single-layer applications on different platforms and meet the challenges of different commercial conditions.

4. EJB is a multi-layer architecture system solution A: 1) EJB (Enterprise JavaBeans) is a server-side component architecture that is based on distributed applications written by Java; 2) Have Java and multi-layer architectures The double benefit of the system; 3) is a standard middleware; 4) Since several years ago, EJB technology has obtained full support for platform suppliers and corporate development teams. This is because the EJB component simplifies light and expands the development of commercial components. 5) By providing automatic support for system level services, the EJB server reduces the complexity of developing commercial components  These services include transaction processing, security, and database connections. This makes developer developers to concentrate on developing commercial logic. 6) The EJB architecture system is a component architecture that develops and deploys components-based commercial procedures.

5. EJB Specification Tarker Answer: 1) The goal of the EJB specification is to define a standard, different suppliers can implement these standards; 2) Because this standard defines each of the nature of the framework, apply the EJB framework The procedures are scalable, transactional, and multi-user security. Such applications are written as long as they are written, and then they can be deployed on any server platform that supports EJB.

6. EJB Environment Overview: 1) EJB Components Run in the container of the EJB server; 2) Container connectivity database or other components; 3) EJB client Access to different virtual machines in the same virtual machine Enterprise bean; 4) The EJB Home component can be seen as a factory for EJB objects; 5) Getting the EJB object from the Home component can be local or remote interface.

7. Good to EJB Answer: 1) Many websites intend to use Java, but they have not utilized EJB technology. Developers have used Servlet / JSP mode to perform transaction with JDBC's built-in submission and rollback techniques with the help of application servers. 2) When doing this, program developers face many challenges: some of the most important include concurrent processing, persistence, and transaction processing. As a result, the developer either develops the framework that is either purchased. 3) These issues have been resolved by using enterprise beans. The use of enterprise beans allows developers to focus on commercial logic and liberate them from infrastructure and middleware logic. Developers thus become more productivity and efficiency.

8. When to use EJB Answer: 1) Distributed objects When using an enterprise-level JavaBean, distributed objects are used to establish an enterprise-level system. This means that your system can be deployed in different physical machines, thereby producing many independent processes to achieve system objectives of performance, scalability, availability. 2) Self-transparent component framework For many vision users, what they pay attention is to meet the platform-independent, suppliers and application services have nothing to do. EJB architecture, this industrial standard architecture can help achieve these goals. For example: Enterprise Beans developed on WebSphere can be used for non-IBM applications. 3) Object persistence a. Object persistence means that his state (the value of variable) can be saved. In most cases, a persistent object is saved in the relational database. B. Unfortunately, the object and relational database are too different. Compared with Java, relational databases have limited modeling, such as object inheritance and packaging. In addition, the most important conversion problem is that the SQL data type and Java data types are not fully matched. All of these issues have been resolved when using the CMP entity bean. 4) Database architecture independent EJB technology enables commercial logic to clearly separate from database access. Business logic and database architecture are independent of and can be deployed in different or changing database architectures. 5) Transaction management a. Concurrent access to shared data is one of the most headaches of developers. All related issues, such as database locking, data integrity loss events can result in creating a highly complex framework to manage access to database-level shared data. B. EJB automatically handles these complex threads and concurrent shared data issues. As mentioned earlier, the EJB container provides all necessary transaction services to enterprise beans to manage the background data. 6) Intermediate Architecture a. Many companies believe that their applications, especially business rules, and database architecture are an effective asset. So they pay attention to how to protect them in the Internet. B. EJB allows a company to use the intermediate layer architecture, so the performance layer and the logical layer are separated. This separation makes the use of the second firewall possible. 7) Multiple servers' capacity and availability A. In the past few years, customers have found that the fat client is simple, but the spread is faulty, the Web-based system is strong. At the same time, software distribution issues also make the fat clients reduced. B. Seven days a week, 24 hours a day, normal running time is a business is a problem. Developers should be able to design a qualified system makes it possible. C. The customer needs a way to write business logic to meet various needs. WebSphere's EJB support provides this height scalability. It uses the following feature implementation: Object capture and sharing: WebSphere Application Server automatically centralized enterprise beans in server layer, which reduces time spending object creation and garbage collection. This makes operations in most data processes. 8) Unlighten clones support a. There are multiple Clones to handle requests so that failures do not destroy operation and reliability. Multiple clones are distributed in different nodes, and the entire machine fails without catastrophic results. B. WebSphere Application Service Network deployment supports distribution, cloning, and automatic fault tolerance. 9. J2EE and J2SE Answer: 1) J2EE represents Java 2 Enterprise Version 2) J2EE is a set of strong middleware applications developed by server-side; 3) J2EE is an extension of Java 2 standard version 4) J2EE makes all Java's enterprise API and functionality are possible and access them in an overall access. This simplifies complex issues in development, deployment, and multi-layer management.

10. J2EE platform technology Answer: 1) Component (Servlet, JSP, EJB): a. System Apply a layer of unit; b. Implemented by the application developer; c. Run in Container; D. Provide corresponding services and communication 2) Service a. Provide related functions for J2EE; b. API is implemented by J2EE platform provider; 3) Session a. Is provided by Container to collaborate components; 11. MVC architecture model A: 1) Model: Model layer, by EJB implementation; 2) Controller: Control layer, implementation by servlet; 3) View: Interface layer, implemented by JSP.

12. Facade Answer: 1) Complete commercial logic by the encapsulation, exposed objects complete task acceptance and completion response

13. J2EE Technical Answer: 1) Servlet: a. A J2EE component; b. Servlet can be considered to run the applet; c. Servlets provides a component-based, platform-independent approach to build basic web applications . 2) JSP a. A J2EE component; b. Represents the Java server-side page; c. JSP technology is the extension of servlet, which can be considered HTML JSP Tags. 3) EJB a. A J2EE component; b. Represents enterprise-class Java Bean; c. EJB defines how server-side components are written and provide standard architectural protocols between servers and components in components and manage their servers; 4 JDBC a. A J2EE service; b. JDBC represents Java Database Connectivity; C. JDBC provides unified access to large-scale relational databases, JDBC2.0 provides support for database connection pools. 5) RMI and RMI-IIOP a. A J2EE service; b. RMI represents remote method invocation; c. IIOP-Internet Inter-ORB protocol; d. RMI is a way to call remote methods Mechanism. EJB relies on RMI as a session API between the same machine or different machine assemblies; 6) JNDI A. A J2EE service; b. Represents Java Naming and Directory Interface; c. Based on EJB In the application, when the client needs to access the EJB component, JNDI is used to determine and obtain components to serve the client. 7) JMS a. A J2EE service; b. Represents Java Messaging Service; C. The JMS API provides a new, powerful tool by combining Java technology, JMS API provides a new, powerful tool to solve the problem of enterprise calculation. By defining a set of messaging concepts and programming strategies, JMS API improves programmers' productivity; d. Asynchronous communication; 8) JTA and JTS a. JTA representative Java Transaction API; b. JTS represents Java Transaction Service; c. JTA is High-level transmission API, allows applications and J2EE server management transactions; JTS indicates the specific implementation of the transaction manager. 9) Security a. J2EE Access Control includes authentication and authorization; b. Identification: Determine user identity (based on role); c. Authorization: Determine if the user has access to request resources; 10) Containers a. Each component is running within the container provided by the J2EE platform provider; b. Containers provide specific deployment and running services (life cycle, security, transaction, etc.); c. What services can be available dependent on components Types of. 11) Web and EJB container a. By calling JSP and servlets and returning results to clients, web components are provided to the client to run at runtime; b. Simple EJB container provides transactions, EJB component status management and Lookup, security, etc. Automatic support; 2004-10-14 Thursday sunny

Develop, debug, and test EJB, JSP, and Servlet (EJB the second day)

1. EJB A: 1) EJB is provided to the server side with a framework based on the component-based distributed computing; 2) EJB typically represents a business processing process, can cross the network across the network. 2. EJP Role A: The EJB specification defines six roles for EJB development and deployment. Each role undertakes different responsibilities in the EJB development process: 1) Bean provider: Code developer, he is responsible for converting business needs into physical code. He provides a must-have EJB, Class, and deployment description files. 2) Application Assembler is a bit like Bean Provider, or a senior team leader. Its responsibilities are packaged all EJB components and other application components, and the last product is an EAR file. 3) Deployer Deploying EAR files to Application Server 4) Server Provider provides EJB Server Environment 5) Container Provider provides EJB container environments, usually the same as Server Provider. 6) System administrator to ensure that the runtime environment is correct, the program function is correct.

3. The main EJB framework assembly A: Here is six major EJB framework components technology: 1) EJB Server: Provided to all EJB main services. Includes one to more EJB containers. It is often also referred to as EJS. 2) EJB Container: Provides an operational environment of the EJB instance, which is the intermediate layer of the server and EJB components. 3) EJB Component: These representative real EJB itself. There are three types of enterprise beans: (entity bean) Entity, (Session BEAN) Session and (Message Drive Bean) Message-Driven Bean. 4) EJB Interface and EJB Bean: The interface and EJB bean classes accessed by the client; 5) EJB Deployment Descriptor: Defines what services in EJBs should provide EJB in the run environment. A file outside the bean. 6) EJB Client: Access the EJB client, including servlet, other EJB or Java Application.

4. EJB Server Answer: 1) EJB Server is part of the EJB capacity in the application server; Unable to report which container is deployed in which container is deployed; 4) The EJB server is provided to all enterprise Java Bean public services. The EJB server is responsible for hiding complicated things. The EJB specification is a bit seven services that the EJB server must implement: a. Naming (JNDI) B. Transaction (JTA and JTS) c. Security () d. Persistence (JDBC) E. Contract () f. Life cycle () g. Messaging (JMS) 5) EJB container and EJB server do not clearly separate, EJB does not deal directly with the EJB server, but through the EJB container - it is more like an economist, providing the EJB server service to EJB. Therefore, in EJB, the EJB container provides these services. In addition, the specification only defines the contract of beans and containers. There is no container-server contract.

5. EJB container A: 1) The EJB container is a system, its functionality is similar to providing a running environmental management enterprise bean and the main services required to manage during operation. In addition, as a mediation of seven services provided by the EJB server, the EJB container also provides the lifecycle management of the EJB instance and EJB instance identification. 2) EJB container creates a bean instance, manages instance pool, and destroys them. The container provides a service indicated in the deployment descriptor. For example, it will start transaction or inspection. 6. Remote access ability Answer: 1) Usually, EJB is a remote, distributed object, one of the main responsibilities of the container is to provide an intermediary to access these remote objects. 2) Remote Access Makes a remote call to the network component to a local component. 3) The EJB container is available to the EJB container remote access capabilities using the Java RMI interface.

7. Main Services - Name A: 1) The client can call Enterprise Bean through a centralized namespace - Naming Server - Looking for Bean's name, this access is passed through JNDI. When the server is started, the container is responsible for registering the unique list of views on the JNDI name and binds the appropriate object type.

8. Main Services - Affairs A: 1) A business is defined as a set of tasks that must be implemented together: either do or do it together. 2) When the transaction of the bean is activated, the EJB container performs a transaction operation. EJB transaction behavior is described in the deployment descriptor, which is also called CMT (Container-Management Transactions). Because the container is managed, the container can be rewritten without clearly dividing the transaction.

9. Main services - Security Answers: 1) Provide a security domain for enterprise beans, EJB containers. The container is responsible for the security policy to be defined when deploying the Access Control List (ACL). 2) Access Access Control List is a list about users, users and groups, and their respective permissions. It ensures that users only access resources within their given permissions.

10. Main Services - Persistence Answers: 1) The container also has the responsibility to manage the persistent state of the bean, which is implemented in the database by synchronous beans in the database.

11. Main Services - Concurrent Access A: 1) Concurrent Access refers to a BEAN to be accessed by two and more client access, and the container is managed in accordance with the bean type.

12. Main Services - Life Day Answer: 1) Containers have a responsibility to control the life cycle of deployment components. When the EJB client issues a request to the container, the container is dynamically initialized, destroyed, and reuse the corresponding beans.

13. Main Services - Asynchronous Delivery: 1) The container must provide asynchronous communication, especially between the client and message drive.

14. EJB Components Answer: 1) The EJB component refers to the bean itself, which includes all classes, interfaces, and others. 2) There are three types of enterprises beans: a. Entity bean. Representing business entities or project related concepts; one enterprise bean corresponds to a table; one instance corresponds to a line in Table;. Bean instance variables correspond to Table in Table. B. Session bean corresponds to business tasks, completes a series of activities; c. Message driver beans completed certain business activities, listening to action by asynchronous communication.

15. Synchronous calls and asynchronous calls Answers: 1) Synchronous call: Wait for the next call after the object being called; 2) Asynchronous call: The call to other objects does not have to wait, call centralized processing;

16. EJB Interface and EJB Bean A: An EJB component consists of the following major elements: 1) EJB Components (Local or Far) Interface: Access to Component Methods by Component Interface; 2) EJB Home Interface: Manage Bean Life Cycle ; 3) EJB bean class: including all real business logic, providing all commercial logic implementations; 4) Primary key 17. EJB component interface A: 1) The client obtains the BEAN accessibility through the component interface. It defines a client-visible business method; 2) There must be a corresponding business method in the component interface in the bean class; 3) Message Drive Bean does not have a component interface because it will not be called by the client; 4) Client Access Components Interface, container obtains request, then transfer request to specific bean; 5) There are two types of component interfaces: local and distal ends. A specific user-specific component interface may only implement one of the types.

Java.rmi.Remote ↑ | javax.ejb.ejblocalobject javax.ejb.ejbobject (component interface) ↑ ↑ | | MyBeanLocal MyBean

2004-10-15 Friday sunny

Develop, debug and test EJB, JSP and Servlet (EJB on the third day)

1. Local and distal interface answers: 1) The remote interface is usually present in EJB, which enables the EJB client other than the container or virtual machine to access distributed objects; 2) In remote calls, method parameters and Return objects are passed through values. Two-end object serialization and network repeated delivery produce very large resource consumption, which reduces performance. But this has reached the location. 3) The local interface (Since EJB 2.0) is possible to access the EJB to clients in the same virtual machine. 4) In the local call, the method parameters are transmitted by reference, and the execution is in the same virtual machine, so there is no serialization and the network repeatedly transmits, more efficient. 5) Assume that the entity bean is only called by the session bean without being called directly by the external client, and only the local interface is provided with the local interface.

2. Business Method Definition: 1) As a member of a bean, we must define our BEAN's business method in our component interface. Because it is an interface, we only need to define this method. 2) The bean class must provide the true implementation of the definition method in the interface.

3. EJB HOME interface Answer: 1) EJB HOME interface provides an instance of creating and looking for bean, which provides EJB client with EJB capabilities. 2) The Home interface defines the lifecycle method of Bean, which provides basic management capabilities for the Bean lifecycle. 3) Message Driver Bean does not have a Home interface because he is not directly called by the client. 4) The client will never really access a bean instance, which is accessible to EJBOBJECT. 5) The EJBHOME object implements the HOME interface. At first, the EJB container initializes the EJBHOME object corresponding to the enterprise bean and registered this Home in the naming server. 6) The EJB client accesses the EJBHOME object via JNDI. 7) There are two types of components interface: local and distal ends.

Java.rmi.Remote ↑ | javax.ejb.ejblocalhome javax.ejb.ejbhome (main interface) ↑ | | MyBeanLocalHome mybeanhome4. HOME interface method: Lifecycle method A: 1) As a bean provider, we must The lifecycle method that is required to define the enterprise bean in the HOME interface. 2) CREATE method: In Home, the returned value is the component interface of the bean. Beans may have zero to multiple creation methods, depending on the type of bean: a. Sension bean without state must have only one creation method without parameters; b. There is at least one created (with or without parameters) in the SESSION bean. Method; c. Entity Beans may have zero or more creation methods. The behavior that occurs when creating methods also depends on the type of bean, for entity beans, each CREATE can be understood in the table in Table. For Session Bean, create means creating a bean instance. Finder method: Only valid for entity beans, they are looking for persistent data on behalf of entity bean representatives. The Home interface of each entity bean must have a method of instance primary keys as a parameter: FindByPrimaryKey (). The value returned by a Finder method is a collection of bean component interfaces or a (component interface).

5. EJB Bean Class A: 1) Bean Class includes all real enterprise beans business logic; 2) Bean Class does not have a direct client view, and the client directly deals the component or home interface. Therefore, local or remote views cannot be applied to build this class. 3) There are three different types of bean classes: entity beans, session beans, and messaging beans. 4) We must choose an entity bean interface to inherit, or an entity bean or a session bean and a message driver bean. 5) In addition, if we are building a message-driven bean, we must also implement the MessageListener interface (specific business logic writing).

Javax.ejb.EnterpriseBean ↑ | ˉˉˉˉˉˉˉˉˉˉˉˉ | ˉˉˉˉˉˉˉˉˉˉˉˉ | javax.ejb.entitybean javax.ejb.sessionBean javax.ejb.MeentageDriverbean ↑ ↑ myensagebean mysessionBean mymessagedriverbean ↓ javax.jms.MESSAGELISTENER

6. Implement the callback method of the bean class interface: 1) The method that must be implemented in the bean class relies on the type of interface we choose. These methods are not provided to the client control, but to the container to manage these beans. 2) These methods are called the container callback method, which is part of the BEAN and container we discussed. 3) For these methods, the container does not have any routine behavior. We must implement them in your own Bean Class. javax.ejb.EntityBean. void ejbActivate (). void ejbLoad (). void ejbPassivate (). void ejbRemove (). void ejbStore (). void setEntityContext (EntityContext ctx). void unsetEntityContext () javax.ejb.SessionBean. void ejbActivate (). void ejbPassivate (). void ejbRemove (). void setSessionContext (SessionContext ctx) javax.ejb.MessageDriverBean. void ejbRemove (). void setMessageDrivenContext (MessageDrivenContext ctx) javax.jms.MessageListener. void onMessage (Message message) 2004- 10-18 Monday sunny uses WSAD development, debugging, and test EJB, JSP and servlet (EJB fourth day)

1. Build bean class Answer: 1) Building a bean class means implementation of business logic; 2) As a provider of Bean, we must implement all necessary methods in Bean Class. There are four types of methods: a. Implement the business method declared in the component interface: It must be sure to have a method corresponding to the component interface in the bean class (name, number, number, quantity, order, throw an exception, return The type can be different; b. Implement the lifecycle method in the home interface: Bean Class must implement the lifecycle method defined in the primary interface. Unlike the component interface, the method can not be consistent: i. Create method: correspond to each CREATE method defined in the primary interface, the EJBCREATE method and the EJBPostCreate method must exist in the bean class. Before bean Class is created, the EJBCREATE method is prepared by the container call to becomes the creation of Bean. The EJBPostCreate method is called by the container after bean class. In the main interface, the CREATE method returns a component interface (ComponEt Interface), and the EJBCREATE method in the bean class returns the primary key (or a collection of primary keys). Ii. FindbyPrimaryKey: Only the entity bean is valid. The Find method in the primary interface returns a component interface (ComponEt Interface), and the Find method in the bean class returns the primary key. IV. Find method: The FINDXXX method in the primary interface corresponds to the EJBFINDXXX method in the bean class. V. Home method: The XXX method in the primary interface corresponds to the Eejbhomexxx method in Bean Class. C. Implement the callback method of the container: Bean Class must provide a container callback method defined in its superclass. D. Other methods: For example, the onMessage () method in the MessageListener interface of the Message-Driven BEAN, as well as some custom methods. 2. EJB Deployment Descriptor Answer: 1) How to run bean is managed in the interface and class we discussed previously, but in the deployment descriptor. 2) Deployment Descriptor file is an XML document that describes some structured information of the bean that makes up an application. This information includes the type of bean, constitutes an interface, and how to operate, how to operate at runtime. It describes other services such as security, transaction, naming, and containers. 3) Deployment Descriptor file is one of the components that must be packed in the JAR file of EJB.

3. EJB Client Answer: 1) According to previous mentioned, from the EJB client, all interaction objects have implemented HOME and Component interfaces. The EJBHOME interface is a true object of the Home interface for managing the lifecycle method of Beans (Create, Find, Remove). EJBOBJECT is a real object of the Component interface and is used by the client to access the BEAN's business approach. These two are generated by the container when deploying. 2) It should be remembering that we will never be derived directly from the EJB Bean instance because each thing is managed by EjBobject and EJBHOME. 3) There is a session between distributed object agents, but for EJB, it is implemented regardless of this call or a local interface.

4. Remote and local client views Answer: 1) Two different JVMs, EJBHOME and EJBOBJECT are used to respond to the call to the remote client. This achieves a location that is not related to the same JVM or the same JVM is working properly. 2) The same JVM, EJBLOCALHOME and EJBLOCALOBJECT are used to respond to client calls. This situation does not exist network transmission, faster, but no location is independent. 5. Client and EJB's interaction: 1) Look for Home objects by naming services: a. EJB Home object Binds to named servers and access through JNDI. We use the java.naming.initialContext object, provide a JNDI name to find our HOME interface. This is a logical name with our EJB. Code example: InitialContext CTX = new initialcontext (); object objhome = ctx.lookup ("ejb / itso / customer"); // Object objhome = ctx.lookup ("java: comp / env / ejb / itso / customer") CustomerHome Home = (customerHome) javax.rmi.portableremoteObject.narrow (Objhome, customerHome.class); b. JNDI name is a string that represents the name of the object of deployment. This name can be a global EJB namespace element. C. Lookup method Returns an object, you have to force forced conversion. 2) Use the Home object to create or find the EJB object a. Once you get the Home object, we can use it to determine our bean. For entity beans, we can find existing entity beans or create a new bean: Customer Customer = Home.FindByPrimaryKey (Akey); or Customer Customer = Home.create (akey); b. Key is the primary key of Bean, it can be An Integer (cannot be original data type); c. We can only call the create method; d. These methods that call home will call the corresponding EJBCREATE and EJBPOSTCREATE in the server in the server, or EJBFINDXXXX method. 3) Call the business method in the bean once we get the handle of the bean, we can perform any business approach. 4) Clear Bean We can choose to clear the bean. For entity beans, this means deleting records from the data table. There are two ways to remove beans: Home.Remove (Customer); // Call the Remove method of the home interface or Customer.Remove (); // Call the EJB object (component interface) The above method is the same, and they finally End of the EJBRemove method for the true bean instance is finally called by the container

6. A distinction and connection of remote and local interfaces: a remote interface | Local Interface Interface extends EJBObject | Interface extends EJBLocalObject Home extends EJBHome | Home extends EJBLocalHome Remote method calls | More efficient local calls Location Independent | Client and EJB in the same JVM Parms PaSSED by Value | Parms Passing by Reference Remote Exception Thrown on Methods | Regular Java Exceptions Use Narrow () To Cast | Use Regular Java Class CaST7. Local Interface Force Answer: 1) In the local interface, through the use of the mandatory conversion access EJBHOME code is greatly simplified: InitialContext CTX = new initialContext (); object objhome = ctx.lookup ("ejb / itso / customer"); customerHome Home = (Customerhome) Objhome;

8. EJB frame (remote) Time series: Remote Stub ORB TIE EJB EJB EJB Client Object Container Implementation | | | Business_meth (Param) | ------------> | | | Forward (PARM) | | -----------> | | | | - - - - - --------> | | | | | | | | | | | | ------------> | | | | | | | | | ------------> | | | | | | Callback_methos ) | | | | | ------------> | | | | | | | Invoke_Context () | | | | | <------------ | | | | | | | | | ----- --------------------> | | | | | | | | | |

------------ | | | | | | | | | | | | | | | | ------------> | | | | | | | | | | | | <------------ | | | | | | | | 9. EJB Frame (Local) Timing A: Local EJB_LOCAL EJB_LOCAL EJB Client Object Container Implementation

Business_meth (PARM) | ------------> | | ------------> | | | | | Callback_methos () | | | ------------> | | | | Invoke_Context () | | | | | | | | | | | | -------------------------> | | | | invoke_context () | | | | | POST_INVOKE () | | | Callback_method () | | ------------> | | | | | | <----------- - | | | | | |

10. EJB Type Answer: EJB ↑ | ˉˉˉˉˉˉˉˉˉˉˉˉ | Synchronous Asynchronous ↑ ↑ | ˉˉˉˉˉˉˉˉˉˉˉˉ | Message-Driven Entity Session ↑ ↑ | ˉˉˉˉˉ | | ˉˉˉˉˉ | cmp Bmp Stateless Stateful2004-10-19 Tuesday

Develop, debug, and test EJB, JSP and servlet (EJB on the fifth day)

WSAD preview

1. WS family Answer: 1) WSSD (for website developer). Used to develop Web Service, Service, JSP, Servlet, XML. WebSphere Application Server, and Basic Team Development Support 2) WSAD (for application developers). Have all WSSD features. Used for J2EE development and database applications 3) WSAD Integration Edition. By using J2EE integration framework, an enterprise integrated application is added

2. WSAD Work Table: 1) Not a tool, not a product, nor sales; 2) a portable, unified tool platform and integrated technology; 3) a foundation of an open source project; 4) Public, easy to use The interface; 5) has the same senses for all the tools.

3. WSAD Terminology A: 1) Perspective The same project provides different perspective views based on the role. Each perspective is suitable for a particular role, providing this role essential tool to complete a specific role. There are Java, Web, J2EE, servers, XML, data perspective, etc. You can specify the default perspective that starts WSAD calls by "Window-> Preferences-> Workbench-> Perspective". 2) View. A view shows specific information; one view can be displayed in a single pane, or several views can be stacked in a pane with tags; for information update to the view immediately gave storage. 3) Editor. An editor is used to edit or browse resources; the resource in the editor is only saved after the resource is available. 4) Online help. Select Help -> Help Menu "in the Help menu; press F1 key; 5) Define the path variable of the Java class. Setting an important task when setting your own workstation is to define the path variable of the added class. WSAD has created a set of path variables for a set of configurable classes. . Specific setting method "Window-> Perferences-> java-> classpath variables"

4. Java Editor Properties Answer: 1) The Java Editor on the Code Format Workbench can be configured according to your personal preference. Modify the code format steps: windows-> preferences-> java-> code formatter 2) Java editor preferences You can modify the font of the editor by "Windows-> Preferences-> Java-> Java Editor". 3) Organization Import You can specify that you want the Java editor to process the order in which the import statement is arranged, and the number before using the "*" number. 4) Reconstructing operations such as renaming classes, mobile classes, moving classes between different privately, and making a single code into a single method in different packages. Refactoring is used to describe this change. In traditional programming environments, such tasks are very time consuming and is easily erroneous. You can specify certain features of the reconstruction work by menu "Window-> Preferences-> Java-> Refactoring". 5) Select JRE to specify the WSAD JRE by "Windows-> Preferences-> Java-> Installed". 6) Automatic construction, when the source file is automatically built, it is automatically built. When you don't have a value after a large number of modifications, you want to build manually. In this case, you can execute a menu "Windows-> Preferences-> Workbench" to remove the "Automatic Resource Modification" option. WSAD is built into incremental, manual construction, and re-builds retrieves replacement increments to recompile all resources. Basic analysis of EJB project

1. EJB Modeling Answer: 1) For a real application, the example of the exact system performs behavior is described. 2) In the case of the example, use UML to depict classes and interfaces. 3) You can generate these UML graphics regardless of whether it is an EJB application. Judging whether ejb is used in the application is a more architectural behavior than the design. 4) Determine the best behavior and mode when constructing and interacting with your EJB is a design level behavior. 5) In this way, the design pattern will eventually affect how you build a program. Therefore, EJB design is affected in a set of design principles. 6) Realizing business logic is responsibility for bean developers.

2. When is the entity bean? A: 1) entity bean represents the main concepts in the business, which is usually noun in our system. The data they represent is stored in a persistent medium, such as a database. 2) There are many similarities between entity bean models and database models. In your system's design, any existing things in the database can be an entity bean. 3) According to the actual needs, we can select the entity bean type as CMP or BMP.

3. When is the stateless session bean? A: 1) The stateless session bean is pure business logic to serve your application. They can be used to control a series of steps in the use of a user, although they don't remember any status in the interaction process. 2) In any event, your system is a good candidate from a good bean method. Session Bean performs continuous behavior under the fit of entity beans to access the database directly.

4. When is a stateful session bean? A: 1) is also a BEAN type for processing a business method, but it can maintain the user's session state. 2) Because they can remember the state of the session, they can provide some additional features of stateless session beans. An example is an online shopping cart system, which saves your order information so you can continue shopping. 5. When will I use a message-driven bean? A: 1) The most important difference between the stateless bean and the message driver bean is the way they are called. In addition to this, there is no state of the pure business process, the bean and the message driver bean are the same. 2) It is worth mentioning that the message driver bean can take a message and then point to a normal stateless bean for processing. The difference is that one is synchronous call and the other is asynchronous call. This provides a complete dual service mode for your system. 6. Project Description: 1) We describe a very simple banking system outline to help you understand our EJB modeling; 2) We define some concepts about your account: customer, account, transaction; 3) Bank class definition All behaviors related to customers and accounts, such as: transfer, account. Some behaviors are synchronous calls and others are asynchronous calls. Various reports of the account are required, and when these reports are generated, the customer maintains a drawback.

7. EJB Collo A: 1) Entity Bean: The possible entity bean in our system is some nouns: customer, account, transaction. 2) No state session bean: The bank we describe performs some business processing, such as: transfer, account. Therefore, the bank is a good candidate for a session bean, which represents the services that the bank can provide. Confident "Bank" is not status because there is no need for a session in our example. 3) There is a state session bean: We believe that the process of requesting the report may be a session process. The request processing of the report will be a series of menus, which is used for a report. 4) Message Driver Bean: Does our system need messaging beans understand how to choose and provide our systematic service. The fact is that we specify certain interactions must be asynchronous. We can allow transactions to be called directly by the EJB client, or by sending messages. For the latter, we use the message to drive the bean call service.

8. Bank model A: The bank model consists of a series of entities and relationships. Customer: A customer of the bank Account: a bank account. A customer may have multiple accounts, and an account may be owned by multiple customers. An account is or a checking account or a saving account. Checking: Subcound of a bank account; Saving: Subcurity for a bank account; Transrecord: Transaction records generated during bank transactions. For example: deposit, cancel, or transfer between two accounts. A account can have multiple transaction records.

9. Model relationship A: Customer ↑ Relationship | M: M | Relationship ↓ <-----------------------> Transrecord Account 1: M ↑ ↑ <------------------------------ | Update Create | | | ˉˉˉˉˉˉˉˉ | | | | CHECKING SAVINGS10 EJB Class A: 1) Entity Bean: Customer, Account, Checking, Savings, Transrecord 2) No State Session Bean: Banking 3) State Session Bean: Reports 4) Message Drive Bean: Transfer

11. Facade A: 1) A usual practice is to use a FACADE to protect the front end of the entity bean of the data layer to control all client access. In this manner, this session bean can access multiple data source access sets into the business layer as a single entry point. This provides a clear separation for our business layer and integrated layers. 2) Because all access to entity beans must only occur at the Facade Bean, we can only use the local port interface of entity Beans. This provides a higher efficiency for the system.

Perspective of WSAD

1. J2EE Services JDBC Answer: 1) Provides connectivity to a variety of relational databases, which is independent of the specific database; 2) JDBC is a bit similar to ODBC, based on X / Open SQL call layer interface specification; 3) Via JDBC, your Java application or Java applet can dynamically call the database; 4) In JDBC2.0 we can access a connected pool of the data source through the data source object, using the connection pool with the following advantages: It improves performance. Creating a connection is a fee, and a data source object is initialized to create a connection pool. B. It simplifies the configuration of resources. The resource is only configured only from the data source object, not any position in the code.

2. Working steps for data sources: 1) When a servlet or other client wants to use a connection, it looks for a data source object from the JNDI server; 2) Servlet or client requests a connection to the data source object 3) Assume that the data source object does not have enough connections, which can request more connections to the database manager (as long as the maximum allowable connection number); 4) When the client completes the connection, it releases the connection. The data source object then returns the connection to a more connected pool.

3. XMI and DDL Answers: 1) XML Metadata Exchange Interface (XMI) is an object organization standard interface for exchange metadata information; 2) WSAD uses all local descriptors of databases, tables, and patterns using XMI format. The XMI file can be viewed and modified using the editor; 3) When you import an installable database mode, it is stored in XMI format; 4) Data Definition Language (DDL) is an associated database system for Store the format for how to create a database object. WSAD allows you to generate DDL from the XMI file. 4. Data Perspective: Data perspective is used to process databases, data tables, and SQL declarations, there are three main views in this perspective: 1) The database server view shows the activity connection to the database and allows you to create new The connection is not related to any item. The connection can be passivated, there is no database and data table display. Reconnect the connection by selecting "reconnect" of the right-click menu. 2) Data Defining View Displays the currently existing database model in WSAD, including both imported through the database server view, also created on the workbench. Database Model Storage Contains WSAD projects, projects can be a simple item, a web project with a database, or an EJB project with entity beans. The database definition view is the hierarchical view of the database object, which does not show how these definitions are stored in a real file. 3) Navigation View In this view you can see the local descriptor file representing the database object. Each file has an editor to contact it. Double-click the file to open an editor that is suitable for the object type described it describes. These object types can be a database, a pattern, or a data table.

5. Use the Database Server View: 1) You can connect to the existing database and view their objects. These objects can import WSAD and used for your system; 2) Database server view allows you to filter, display some mode or view. You can also generate DDL and XML modes using the Database Server view. 3) Key: Database server view is read-only, before you edit any database project, you must import them into the WSAD project.

6. Create a database connection: 1) You should establish a unique name for this connection. If you need to provide the USER ID and password, as well as the type of database you connect, the JDBC drive may be used. For DB2 databases, there are two types of JDBC:. Com.ibm.db2.jdbc.app.db2driver: Used to connect to a local database or definition from a local remote database; com.ibm.db2.jdbc.net.db2driver: Used to connect remote databases;

7. Import Database Answer: 1) Creating a simple server item such as ITSoProguidAbase to save database objects; 2) Import:. In the database view of the Perspective, select the database connection to import, import the folder; In the Import dialog box, click "Browse" to select the ITSOPROGUIDATABASE project, then click Finish. 3) In we introduced a database, for example name EJBBANK, expand the EJBBANK node in the data definition view, the same database object is displayed. You can now open these objects corresponding editor viewing and modify their definition. 4) In the navigation view, you can notice a series of XMI files created for the database object (XMI provides a way to allow developers working on object technology to switch programmed data over the network)

8. Generate DDL file Answer: 1) WSAD allows you to generate DDL files and XML schema files for database objects; 2) Generate a DDL file: Select a database object in the data definition view or database server view, select Right-click Shortcut Menu Generate a DDL command. 3) You can generate DDLs for the database, or model, or a single data sheet. 9. Generate XML Mode File Answer: 1) Generate an XML mode for a table, you must have imported it into a directory and located in the data definition view; 2) Generate an XML schema file: select a data table, click the right button shortcut menu "Generate the XML Mode" command.

10. Generate Database Object Answer: 1) The database creation in WSAD does not create a real database in the database system. You must export DDL and then create an object with the appropriate database tool or submit DDL in WSAD. 2) Creating steps: Create a mode (which provides logical classification for database objects). Table. View. Alias. Index. Trigger. Structure Type

11. DB2 JDBC Drive A: DB2 supports two JDBC drives: 1) com.ibm.db2.jdbc.app.db2driver: This is the JDBC type 2 drive, which uses the DB2 client installed in the machine where the application is located. When accessing the local database or access the remote database via a local DB2 client: JDBC: DB2: DatabaseName 2) com.ibm.db2.jdbc.net.db2driver: is a JDBC Type 3 drive, which makes Java Access the remote DB2 data source. Your application will install another machine session in the DB2 client. The database URL format is as follows: JDBC: DB2: // Hostname: Port / DatabaseName General DB2 JDBC server port is: 6789, you need to provide username and password, for example: con = DriverManager.getConnection ("JDBC: DB2: // localhost : 6789 / DatabaseName "," DB2Admin "," db2admin ");

2004-10-20 Wednesday sunny

Develop, debug, and test EJB, JSP, and Servlet (EJB on the sixth day)

Entity bean

1. When is the entity bean? A: 1) entity bean refers to the concept of business or designated domain, which is a typical noun in your system, poor accuracy concept, such as customer and account; 2) they usually add to the table Data in the database. Since they expressed their downturn in the database, the change of bean results also affects the database.

2. Why is the entity bean? A: Entity bean allows the object to make our data, while working on behalf of the data is superior to the data in the database, there are many good reasons: 1) Working more easier, They are reusable components in a system; 2) By using the service provided by the container, it will free us from some basic functions, including: concurrency, transaction, security, etc. By using the service provided by the container, we can focus on the establishment of mapping for BEAN and data, and provide the corresponding business approach to the beans to replace the SQL statement.

3. Why develop entity bean? A: 1) entity bean is the most complex EJB type; Session bean some ready-made things. 3) In the real world,? 4) We don't say that all entity beans must be developed before any other part in your system, but they can usually be developed and tested independently of other parts of your system. 5) A portion of the team focuses on entity bean development, and another team focuses on servlet and JSP development, which is very common. 4. Entity Bean can be spared from server closure: 1) entity bean is used to represent a persistent object, such as a customer and account. In most cases, persistent data indicating that the entity bean state is stored in a relational database. 2) The properties of the object are mapped in the records in one or more data tables. 3) Since the state is stored in a database, the status of an entity bean is longer than the request, session, and even the container's survival time. 5. Important attributes of entity beans: 1) They represent a persistent domain object; 2) They support concurrency access; 3) Examples are managed by the container (instance pool), thus providing scalable ability; 4) they can Execution in a secure, in the context of transaction management.

6. CMP entity bean Answer: 1) The task of continuous ability is delegated to the EJB container; 2) So as a bean provider, we don't have to provide any database access to our entity bean. We let the container do this for us. We must provide an abstract data-object mapping: mapping beans in the fields in the database, and abstract methods corresponding to these fields; 3) The container knows that the data should be continued because this mapping relationship is defined in DD. When deploying, the JDBC code that performs the relevant operation is automatically generated by the container; 4) When the container is truly deployed, the connected system can be automatically established to establish bindings to beans and data; 5) According to this idea, CMP is Some of the abstract classes associated with data, but there is no real implementation of any access data itself; 6) The CMP target is to make developers working with object-oriented thinking, rather than data-centered ideas. By separating another benefit of development and persistence related work, developers are disconnected to focus on business logic.

7. The EJB1.1 version is not defined in the CMP: 1) The EJB1.1 version specification declares that CMP is necessary. But many of the essence issues are not defined, such as:. Mapping in database mode;. Used to locate the definition of the discoverer of the bean; how to specify the details of the relationship between entity bean details;

8. New Features in EJB2.0 A: By providing a standard persistent model, the EJB2.0 specification implements some of the problems mentioned earlier. This long-lasting model tends to fuzzy product lines and becomes a standard for all EJB vendors. Specification provides:. A abstract persistent mode: This makes the CMP map in an abstract way is performed by all supplier tools; EJB QL: A standard search language is used to find and locate bean, although it is not true SQL. It is similar to part of the SQL language to provide a part of the SQL function. Container Controlled Relationship (CMR): The relationship between standardization beans, the associated type provided is one-to-one, one-to-many, and more. Also include a part of the abstract persistent mode.

9. Supply for CMP1.1: 1) EJB2.0 provides support for EJB1.1 versions, so the EJB developed by previous versions can be proliferated with new platforms.

10. BMP entity bean Answer: 1) In the BMP entity bean, the developer of EJB manages the persistent state of the BEAN by writing database calls or other persistent storage. 2) This will properly manage the responsibility of the BEAN's persistence status on the developer, so that you need to understand the working mode of the callback method and other lifecycle methods that are used to persist in persistence services. 3) The developer's responsibility:. When the EJBLOAD and EJBSTORE methods (the callback method of the bean) are stored and restored when the container is called. Create, find and remove beans by ejbcreate and ejbremove methods (lifecycle methods of Beans). 4) Most of the time, BMP developers use JDBC to write persistent logic directly in their way. Of course, other technologies can also be used, such as SQLJ or CICS transactions. 11. CMP or BMP? A: For BMP, developers have to do more work, why is there any candidate instead of CMP? There are many advantages in EJB2.0 in EJB2.0, but there are some things that CMP cannot be done. Some things that will affect your choice of entity bean include: 1) BMP is much more complexity and maintenance in BMP. In other aspects, select CMP can get better maintainability than BMP; 2) A container has limitations to CMP support in terms of data source type. For example, CICS does not support current CMP mapping and call modes. Therefore, it is necessary to use BMP; 3) Complicated queries that are not supported for EJB QL for CMP. For example, the EJB QL specification supports SELECT and JOIN, but does not support time comparison. 4) If the relationship between entity beans should be established, CMP may be necessary. CMR has the ability to define and manage the relationship between entity beans, and can handle some more complex relationships. In this case, BMP is difficult. 5) For CMP, the container will try to optimize SQL code, so they will be more scalability than your own BMP. BMP is not suitable for a wide range of performance-sensitive applications. Therefore, unless you have a true good reason, or use CMP!

12. Main key - Bean's identification: 1) As we need primary key to uniquely determine records in the database, we also need to use primary keys to uniquely determine our entity bean. 2) The primary key of the entity bean can be any Java original packaging class (Integer, Double) or a basic Java class (such as String). They are defined as a single field primary key, this key value must correspond to a lasting property we defined. 3) Notice the original Java property, such as INT and FLOAT, must be encapsulated into the master key. 4) A primary key can be any of our custom sequence type, one or more fields must be mapped to a persistent attribute subset. 5) The primary key is specified by the property in DD. 6) The primary key is the return type of method Createxxxx, which is also the parameter of the FindByPrimaryKey method. 7) Master key equivalent the same home interface = the same bean (you can use the ISIDENTICAL COMPONENT interface test).

13. Entity Bean Structure Answer: Javax.ejb.EnterpriseBean ↑ | javax.ejb.entityBean ↑ | | ˉˉˉˉˉˉˉˉˉˉˉ | MyentityCmpBean MyentityBmpBean (A Concrete Class) 13. Entity Bean Structure Answer: 1) Attribute Specifies the true type of entity bean. 2) The CMP must be an abstract class, but BMP must be a specific class. Because the abstract class cannot be instantiated, the container is responsible for generating a specific class containing real attributes. This is generated based on certain values ​​defined in DD when deploying.

14. EJB2.0 CMP and BMP Answer: 1) Abstract class / mode: EJB2.0 CMP is an abstract class, although they are specific classes in EJB1.x; 2) BMP is still specific; 3) Abstract class mapping defines in the deployment descriptor file in XML format; 4) The mapping in the deployment descriptor is defined as an abstract duration.

15. Agreement between bean and containers A: Understand what a Bean developer develops a feature-rich bean, which understands how the bean's callback and lifecycle method, and how the agreement between beans and containers of.

16. Example Picking: 1) Entity Bean is an enterprise bean type that generates an instance pool, and can be reused by the EJB container; 2) An instance pool is a service of the container, allowing the container to reuse the bean instance, this relative to each An instance of a bean requesting each time. This is one of the optimization operations made by the container; 3) This is suitable for an extensibility environment because the size of the pool can be increased when needed; 4) Mushing the object into the pool and activate them Understanding entity beans are a good start.

17. The status of the entity bean: 1) The entity bean has three states: no-state, pooled, and ready; 2) If the bean instance is not created, it is in the no-state state; 3) Once the entity bean is created, There is no connection with an EJBOBJECT, it is in a Pooled state; 4) After the entity bean and EJBObject contact, it enters the READY state from the Pooled state; 5) This state change is important because the change of each state triggers the container. Call the callback method for the corresponding state change. As a developer, you should understand these changes to determine the right logic for your bean's callback method.

Ejbcreate () | ˉˉˉˉˉˉˉˉˉˉˉˉ | setejbcontext () | ↓ no state --------------------> Pooled --------------- ----> Ready <------------------- ↑ <------------------ | unsetejbcontext ) | ejbPassivate () | | ________________________ | ejbRemove () | _______________ | | _______________ | bean created / Associated / disassodated end-of-life cycle with an EJB Object18 callback method A: 1) setEntityContext (): when the bean is called a container. When you first join the pool, the method should capture a reference to this bean. 2) unsentityContext (): This method is called when the bean is removed from the pool, which is usually when the server is turned off, this method should clear all resources. 3) ejbcreate (): When a client creates an instance through the Home interface. 4) EJBACTIVATE (): When the bean calls a request from the pool to a request. 5) These methods are preparations for BEAN, such as initializing non-persistent fields. 6) EJBREMOVE (): When a client calls an entity bean instance. 7) ejbpassivate (): When the bean is called in the container release back in the pool. 8) These methods are used to set all persistent fields, so the user of the next Pooled bean instance has a brand new Bean instance. Most of these methods are empty.

2004-10-21 Thursday sunny

Develop, debug, and test EJB, JSP, and Servlet (EJB 7th day) using WSAD

Entity bean

19. The life cycle of entity bean Answer: 1) We can see that the entity bean starts his lifecycle when moving into the instance pool. This occurs when the server is started. At this moment, it is an unexpected bean, which is waited to connect with an EJBOBJECT, in response to the client request. 2) Creating an entity bean: For entity beans, this is not only a new BEAN instance, but also inserting a new record in a corresponding database. This activity usually corresponds to INSERT recorded in a database data sheet. 3) Look for existing entity beans: This means looking for a state stored in the database, has not been associated with EJBOBJECT. The corresponding container method is called here, which typically corresponds to the SELECT recorded in a database data table. 4) Use entity beans: Once a bean is obtained, the container callback occurs when the customer calls the business method. Depending on the type of access, these activities usually record SELECT and UPDATE recorded in the database data sheet. 5) Remove the entity bean: For entity beans, this means that a record is deleted from the corresponding database. This activity usually corresponds to the DELETE recorded by the database data sheet. 20. The lifecycle process of creating an entity bean Answer: 1) Lifecycle method definition. The lifecycle method for creating entity beans is: EJBCREATE, EJBPOSTCREATE, and Home interfaces. You can have multiple creation methods through different signature or suffixes. The suffix can be used to distinguish between the same SIGNATURE. 2) Creating a method. The creation method in the Home interface must correspond to the EJBCREATE and EJBPOSTCREATE methods in the Bean Class. The home interface Create method returns a reference to a component interface, but the bean class's EJBCREATE method must return a primary key. The Crebcreate method of the home interface and the EJBCREATE method of Bean Class must throw CreateException. When the bean already exists, the CreateException exception subclass DUPLICATEYEXCEPTION is thrown. 3) Our responsibility will generate two results when the EJBCREATE method is called:. Bean's status must be initialized by developers, whether it is CMP or BMP. Real data must be inserted into the data source. For CMP, the container has been done for you. BMP needs developers to manually write insert logic. 4) Entity bean created lifecycle timing chart a. SetentityContext: Associate a bean and environment information, once this method is called, beans can access environment information about it. B. Create: Client call creation method Create an instance of a bean. C. Ejbcreate: Prepare to insert data to the database. D. Primary Key: EJBCREATE method Returns the primary key to the container so that it can build a new EJBOBIECT. E. NewInstance: A real EJBOBJECT instance will return to the client. F. Ejbpostcreate: We now have a primary key and an EJBObject. With EJBOBJECT, we can access the bean and the CMR field. G. Insert: Execute the INSERT operation of the database. H. Return EJBOBJECT: Returns the client EJBOBJECT, Bean is now preparing for the service client's request.

21. Lifecycle Procedure for Life Cycle when you look for an existing entity bean: Looking for an entity bean to perform a SELECT operation in the database. When we want to find an existing entity bean, we call the Find method. Entity Beans must specify a search method: FindbyPrimaryKey. After calling the FindByPrimaryKey method, return to the client an EJBOBJECT or EJBLOCALOBJECT. 1) Our responsibility. The entity bean class of the CMP type does not directly define the FindByPrimaryKey method, only in the HOME interface. The primary key and entity bean in the deployment descriptor exists, so the container can generate a way to persist Bean Class when deploying beans. For BMP, you must write SELECT logic in the EJBFindByPrimaryKey method: obtain database connections, manually write SQL statements and perform SELECT. 2) FindByPrimaryKey lifecycle timing chart a. SetentityContext: Associate a bean and environment information, once this method is called, Beans can access environment information about it. B. Find: The client calls the corresponding Find method. C. Select: Perform the SELECT operation of the database. D. Primary key: EJBFIND method returns the resulting primary key to the container to build a new EJBOBJECT. E. Return EJBOBJECT: Returns the client EJBOBJECT, Bean is now prepared for the service client's request.

22. Use a physical cycle process when using an entity bean: Once we create or find an entity bean, create an EJBOBJECT reference, EJB customers can call the business method of entity beans. Call the physical method of the entity bean and the SELECT / UPDATE in the database operation. This process is called synchronous object data to the background database. Synchronize the status data in the database and the status data in the entity bean. 1) EJBLOAD method: a. There is only one EJBLOAD method, this is a callback method; b. When data in the database is in the bean class, if necessary, it is necessary to call this method; c. This is most likely to trigger one SELECT operation; d. When the client requests to use the bean class, when activated it, EJBLOAD is triggered, then the bean class enters the Ready pool. 2) EJBStore method: a. There is only one EJBStore method, this is a callback method; b. When you synchronize the data into the database, if necessary, if necessary, this method is called; c. This is most likely to trigger a Update Operation; d. When the bean class is no longer used by the client, the container decides to move this bean class instance of this in the Ready state to the instance pool. 3) EJBLOAD A in CMP and BMP: Ejbload in CMP: Synchronize the data from the database to the Bean Class after adjusting EjbLoad. This provides the developer with a chance to handle some data layers, but very small when you really encode. B. BMP EJBLOAD: Developers must write SELECT logic directly to the Bean Class and databases directly in this method. 4) CMP and EJBStore A in BMP EJBStore: EJBLOAD calls just after the data is synchronized from the bean class to the database. This provides the developer with a chance to handle some data layers, but very small when you really encode. B. EJBStore in BMP: Developers must directly write Update logic to synchronize bean classes and databases directly in this method. 5) Lifecycle timing chart when using entity bean (the client has been referenced by the CREATE or FIND method) a. Business method: The client calls a business method through the component interface; b. Container: This action triggers the instance pool A bean instance is loaded; c. Ejbactivate: This call enables the container to activate an instance pool in an instance pool; CMP: d. Select: Synchronize the data in the database to the bean class; E. Ejbload: Just after SELECT execution BMP: d. Ejbload: e. Select: f. Business method: method of actual bean instance is called; g. Returned: The return result of the specific method. 6) Lifecycle timing chart when passivated entity bean is a. Container: Trigger a bean instance to move back to the instance pool, it will open the bean instance from the connection of EJB Object; b. Ejbpassivate: This call enables container passivation Bean Example back to the instance pool; c. EJBStore: Just called before the Update is executed; d. Update: Synchronize the data of the bean instance back to the database. No client is done directly in Bean.

23. Remove the lifecycle process of an entity bean A: Once we create or find an entity bean, create a reference for EJBObject, and the EJB client can select Remove. The Remove method for calling the bean instance and the delete operation of the underlying data structure are very similar. 1) The method of removing the entity bean is EJBREMOVE. Call this method before the EJB Object of the container is connected to the Bean Class. If an error occurs when you remove a bean, you will throw the RemoveException exception. 2) Our responsibility: CMP EJBREMOVE: EJBREMOVE method just before the database is deleted, most of the cases will not write code. BMP EJBREMOVE: You must write DELETE logic directly in this method. 3) Remove the life cycle process when an entity bean is removed (the client has been referenced by the Create or Find method): a. Remove: Client calls the REMOVE method in the component interface; b. Container: make some preparation; c DELETE: Record in the database is deleted; d. EJBREMOVE: The container moves the Bean instance into the instance pool. 24. Abstract persistent mode mapping A: Abstract duration mode allows us to designate two things: CMP (Container-Managed Persistence Data-To-Object Appings) and CMR (Container-Managed Relationships). This and a database mode are defined by: Data table, field, and data intervals. In EJB abstract persistence mode, these correspond to entity beans, CMP fields, and CMR fields.

25. Persistent Field Answer: 1) The persistence field is the defined persistence field in our entity bean, which can be original or serialized Java type. Each persistence field usually corresponds to a field in the database. 2) Unlike BMP, CMP does not actually define these fields in the bean, but defines the abstract getter / setter method of these fields. 3) Each instance bean must have a corresponding entry in the DD of EJB, and the lasting field of the bean is defined. 4) The container generates the actual SQL code based on the mapping defined in the DD when deployed. It uses the mapping in the bean class determines the actual type of the field.

26. Building an entity bean answer: When we build an entity bean, we care about: 1) bean class: It must contain the getter / setter method for lasting fields, and implement the bean callback method, component interface method, and any HOME interface Lifecycle method; 2) Home interface: Defines the lifecycle method of Bean; 3) Component Interface: Defines the BEAN's client view and the corresponding business method; 4) DD: XML format deployment descriptor file. Container // Persistence Type is CMP bean // Persistence Type BMP

2004-10-22 Friday sunny

Develop, debug, and test EJB, JSP and servlet (EJB on the eighth day) using WSAD

Session bean

1. Introduction: 1) Entity bean allows us to share data shared, which is persistent storage, usually there is a database. 2) The container manages the concurrency access of shared data in a safe manner; 3) Session bean can directly access data (not recommended to do this) to manually complete some tasks, or access data through entity beans. 2. Some concepts of session bean: 1) Session bean is a non-lasting entity bean; 2) There are two types of session beans: state and stateless; 3) Session beans can be used to coordinate entity beans work, provide access entity beans Context; 4) For example, the transfer between two bank accounts (represented by entity bean) can be implemented with a session bean. Such a transferred session bean should first find an instance of the two account entity beans, which will be reduced from an account and add it to another account.

3. Session Bean Type A: 1) There are two types of session beans: state and stateless; 2) On the structure, these bean types look the same, distinguish they are called by the way, whether in Bean and There is a session state between the client; 3) A stateful session bean characterizes a single customer's session state, which is available throughout the session; 4) The stateless session bean is not assigned to a specific client, Renal of multiple customers; 5) The main difference between the two session beans is how the container manages their life cycle; 6) The stateless session bean can be placed in the instance pool and is required to be many different clients. Reuse; 7) Instead, stateful session beans do not exist instance pools, for each bean method, the container must get the same bean class instance; 8) Different types of session beans, beans's developer responsibilities are different.

4. Status Session Bean Answer: 1) Status Session Bean does not hold a client's session state; 2) They can be placed in an instance pool, which can be reused by the container to serve multiple customers; 3) for the client They are all identical;

5. No session status Answer: 1) No status session bean saves a single method, which means that they do not have a session state; 2) After each method of stateless session beans, the container releases the bean class instance back instance The pool, this time the bean instance becomes available, so it can serve a new request; 3) Bean does not save memory for the client of the previous call method. Even if the same client calls other methods of the same EJBOBJECT, it is not guaranteed to call the same bean class instance; 4) When the same client calls another method, a different stateless session bean class instance can serve this new Request. For example, if a client calls a method A of a stateless session bean, then immediately calls the same bean method B, which can be served by different bean class instances; 5) A stateless session bean does not save a client behavior Any state, this is a key point of memory. Because one of people usually made in the development of stateless session beans is to try to save data between multiple method calls.

6. Consistent with stateless sessions: 1) All instances generated from the same HOME object are the same in the client, and the container can use any available use to meet the client's request; 2) If a client has The two different handles of the same HOME object generated, the ISIDENTICAL method of the component interface is usually returned.

7. Example Pool Answer: 1) Example Pool provides an expandable environment because the size of the pool can be increased when needed: increase the size of the container cache, increase memory or provide more machines. 2) Remember that the EJB client never processes the bean instance, which is usually processed from the container via EJBOBJECT. The container is open to the instance pool and then reuse the instance of the bean class is required when needed and the specific details of the client hide the implementation. 2004-10-25 Monday sunny

Develop, debug, and test EJB, JSP, and Servlet (EJB Ninth Day) using WSAD

8. State Session Bean Answer: 1) State Session Bean Keeps a client's session state; 2) They must be from one to one and only one client, in fact, concurrent access to the same state Session beans will cause container throw an exception; 3) A stateful session bean does not exist instance pool, because the container must keep a stateful session bean instance service in the entire session; 4) By using passivation and Activation method, the container can choose to optimize the access-state session bean.

9. Session status Answer: 1) A stateful session bean holds a session state that spans multiple methods; 2) A session state is interaction between clients and applications. This interaction usually requires access and access between session data between clients and applications when any needs. 3) An example of a session is a shopping cart that holds customers who want to buy. These data are also known as session data; 4) All methods to client calls are called by the same bean service; 5) During the session, Beans holds the session state of its service client. In some more advanced operations, there may be open resources in the state state, such as open database connections; 6) a stateful session bean session state stored in the instance field of the bean; 7) Most cases These data must be serialized. 9) The container must be assigned to each method to call an instance of the same state session bean; 10) Whenever a client calls the Create method of the Home interface, it produces a new instance; 11) You can save the data in state In the session example, these data is still valid in the next method call.

10. Identification of stateful session beans: 1) All state session bean instances created from the same HOME interface is unique to the client; 2) If one client holds two created from the same HOME interface Different stateful session bean instances, the ISIDentical method of the component interface usually returns false.

11. Passivation and Activity Answers: 1) When the entity bean is linked from an EJBOBJECT from an instance pool, an instance bean has experienced an activation process; 2) The purpose of activation is to contact the entity bean and real data. Some preparations and allow for any initialized behavior; 3) There is also a passivation and activation process, but its purpose and entity bean have slight differences; 4) When there is a status session bean stores secondary When the storage space is passivated, such a container has more resource available; 5) This is usually taken in the bean idle multiple; 6) After passivation, the memory occupied by the bean instance can be reapplying; 7) If this bean reclaims the previous client, it is activated back to the container; 8) Passivation and activation of state entity beans when necessary, to manage its resources; 9) Containers cannot passivate in one Examples in the transaction process should complete the transaction process first.

12. Serialized Answer: 1) In order to efficiently manage a large number of bean instances efficiently, it enables instance to evacuate memory and stored in persistent storage; 2) The state of the container uses object serial conversion beans is binary or binary Big Object (BLOB), then writing serialized data into a persistent storage space. As we aggregated, this process is called passivation; 3) When this bean is called again, the container creates a new instance and initializes it using the data stored in the passivation process. This process is called activation; 4) Therefore, if the session bean includes some session states that must be stored during multiple method calls, this session bean refers to a stateful session bean; 5) BEAN's provider is responsible for ensuring state data Can be passivated and activated; 6) Not all stateful session beans pass passivation end lifecycle, because the container cannot determine if the resource needs to be optimized; 7) When the client does not need Bean, they are directly removed. 13. A comparison of state and stateless session beans: When developing an enterprise-level application, many times the developer must determine what type of session bean that is adopted, which is usually not simple. Here are some of the options:

State | No status --------------------------------------------------------------------------------------------------------- ---------------------- can keep the state between multiple methods | Unable to maintain a state in multiple methods or business services services | Only for a single request, a single method call can remember the client history | ignore the client history or status

1) When deciding which type of session bean is adopted, please answer the following two questions: bean needs to know the state of the client to perform business logic? When the method is called, beans need to keep the state? 2) If the answer to the two questions above is sure, you should consider using a status session bean; 3) If the two issues are all, use stateless beans more conducive to your application. 4) In any case, please consider the following two points:. Supplementation failure (such as network or system failure, system restart), the status will be lost;. There is a status session bean is not easy to regenerate, This results in low performance in the hunt environment. 5) Only when it is absolutely necessary, it is necessary to choose a status session bean because they need more system resources; 6) If a business logic needs to use a stateful session bean, such as a shopping cart, you can consider it. They; 7) It is necessary to remember that developers must try to ensure that these beans's life cycle, such as creation, use, removal, clear instructions, such a workflow can be expressed by this bean.

14. Structure of Session Bean: 1) State and stateless bean implement the same interface: javax.ejb.sessionBean; 2) The actual type of session bean is in deployment descriptor. The content of the entry of the deployment descriptor is either Stateful, or Stateless; 3) The physical structure of state and stateless beans is almost the same.

Javax.ejb.enterpriseBean ↑ Account ↑ javax.ejb.SessionBean ↑ | ˉˉˉˉˉˉˉˉˉˉˉˉ | MyStatefulsessionBean MyStateLessSessionBean15. Tune method A: 1) Ignore the specific type of session bean, the bean class must implement the callback method (EJBACTIVATE, EJBPASSIVATE). Containers use these methods to actually manage Beans. 2) Bean must also realize the lifecycle method in the HOME interface, especially Create and Remove. These methods define basic Bean-Container protocols.

16. EJBCREATE A: 1) A session bean must have at least an ejbcreate method; 2) For stateless session beans, there is only one EJBCREATE method without parameters; 3) There is a state session bean can have multiple ejbcreate methods, Each method defines a unique way to go to the session state of the initialization session bean;

17. Bean-Container Agreement A: 1) Understanding the responsibility of the developer when implementing a meaningful session bean, and understands how the bean callback method and lifecycle method and how the bean-container protocol take effect. 2) The protocol does not rely on the type of session bean, here we describe the basic concept of the Bean-Container protocol: instance pool of stateless session beans, activation and passivation of stateful session beans

18. Status Session Bean status Answer: 1) There are two states: no state and ready pool; 2) Essentially, if the bean's instance is not created, it is in the No State state; 3) The container decides to need a stateless session bean that enters the READY state. Bean will keep this READY state until the container no longer needs it; 4) The fact that Bean in the instance pool does not contact with an EJBOBEJCT does not mean it is not a bean instance; 5) This is a ready-Waiting Steam instance, when it is in the Ready state, then if a client requires a bean service, the container will make the bean and an EJBOBJECT. 6) The client calls the CREATE and REMOVE method of the stateless session bean, but it really implemented the lifecycle method of the container. 7) Call from the client to CREATE is a way in which the container is assigned a bean instance from the pool. The creation method of the real bean instance may have already happened. 8) Clients Call the CREATE method for the Status Bean Instance Create method creates a new EJBOBJECT instance (implemented the Remote interface). A Remove call removes an EJBOBJECT instance instead of a real session bean instance. 9) The container maintains a sufficient example (not exceeding the maximum license of the container) Serves the current client. 10) The workload is not measured by the number of actual clients, as the client requires session beans when they call each method. 11) The actual stateless session bean actually needed in a pool is often much smaller than the number of actual clients.

12. Status Session Bean status Answer: 1) There are three states: no state, in use, passivated 2) If the bean instance has not yet been created, it is in No State. 3) Once the client needs to have a state session bean, it will call the CREATE method of the primary interface instance, which will move the bean into the in the USE state. 4) The beans will remain the READY state during the entire period of the client and the bean to keep the session. 5) When the bean is in use, it can be passivated in phases. 6) These state transitions are important because changes in each state will trigger the container call status to change the corresponding callback method. 7) As a developer, you must understand these conversions to apply appropriate logic on these callback methods. 13. EJBPASSIVATE A: 1) This method is called when the container determines the passivation bean. When passivation, it will serialize the state of the bean to the secondary storage space and collect it to the memory it occupied. 2) This method is just called before being serialized, which provides a chance to serve the developer to confident Beans. 3) The client cannot control the occurrence of this method, and the container uses the appropriate algorithm to determine which beans are suitable for passivation.

14. EJBACTIVATE A: 1) This method is called when a client calls bean in a passivation state. 2) The EJBActivate method just happens after the bean is retrofled, which provides any data to the developer to continue the bean operation in reinitialization.

15. Lifecycle Answer when creating / removing stateless session beans: 1) Container decides to create a bean: Containers are started or creating instances of beans when they want to assign more Beans to instance pools. Typically, an instance pool of a bean is created when the server is first started. 2) NewInstance: New instance of the BEAN Class for the container for the first time. 3) SetSessionContext: The container sets the session context of that bean. 4) EJBCREATE: Allows the initialization operation of Beans to occur. 5) EJBREMOVE: The container decides to reclaim the bean from the memory to save resources, allowing the operation of the bean resource to occur.

16. Lifecycle Answer when using stateless session beans: 1) CREATE: The client calls the CREATE method of the Home interface, which causes the container to contact an instance in the pool; 2) NewInstance: Generate EJBObject; 3) EJBOBJECT: Return EJBObject to the client; 4) Business method: The client calls the BEAN's business method by ejBobject; 5) EJBObject calls the method of bean instances in the pool. EJBOBJECT is only linked to the BEAN instance during the business method.

17. The life cycle of the state session bean Answer:. Create An Stateful Session Bean: This is a client to create a new stateful session bean by calling the behavior initiated by the Home interface. Finding an existingStateful session bean: This call will cause the client to re-contact with a client. . Using and stateful session bean: The client calls the method of existing Beans. Passivating / Activating A Stateful Session Bean: This occurs when the container determines passivation and activation session beans. Removing a stateful session bean: This is also a client initiated behavior, calling the Remove method.

18. The life cycle reply when creating status session beans: 1) CREATE: The client calls the Create method of the Home interface, which causes the container to start building a bean instance and EJBObject. 2) NewInstance: A new instance of stateful session beans is created. 3) SetSessionContext: Set the context of the container. 4) EJBCREATEXXX: The EJBCREATEXXX method corresponding to the bean instance is called, which can initialize the state of the session bean. 5) NewInstance: EJBObject is created. 6) EJBOBJECT: Returns EJBOBJECT to the client. 19. Find an existing session bean Answer: 1) A stateful session bean remains active before being removed or in the container; 2) A client may need to access a existing stateful session bean. The entity bean is positioned to locate the existing instance bean by the Finder method. An identity of a stateful session bean is not confirmed by the primary key or other unique identifier. Therefore they are not through the Finder method. The stateful session bean is associated with a client, and the client can access access to the bean class through the handle of the component interface. This handle can be serialized and used in the later time to re-find the bean. 20. Find a life cycle of the existing session bean: 1) Get Handle: The client gets the handle object to be stored (for example, HTTPSession). A new handle object is generated. 2) Getejbobject: The getejbobject method of the handle is called. 3) Finds bean: The container links EJBOBECT to the client. 4) EJBOBJECT: Returns EJBObject to the client.

21. Use a lifecycle when using a stateful session bean: 1) Business method: Client calls EJBOBJECT business method; 2) Business method: EJBObject will be transferred to the bean class.

2004-10-26 Tuesday

Develop, debug, and test EJB, JSP, and Servlet (EJB tenth day)

22. Passivation and activation of a stateful session bean Answer: 1) When the container wants to release some container resources, the state session bean will passivate; 2) When a client calls a passivated bean related operation Activation occurs at this time; 3) Passivation and activation are the operation of container management;

23. Passivation Trigger: 1) Passivation Trigger: The container determines which bean; 2) ejbpassivate: bean's EJBPassivate method is called to serialize Prepare; 3) State is Written to Secondary Storage: The state of the secondary memory, such as data or file directories; 4) Business method: Client calling bean business method; 5) State is Rebuilt from Secondary Storage: Reconstruction Bean's status; 6) EJBActivate: Call EJBActivate to reinitialize any necessary non-sequential data; 7) Business method: Execute the real business method of the bean instance.

24. Remove the lifecycle of a stateful session bean: When a bean time is explicit, the container will decide to remove the bean, whether it is in passivated or a Ready state. 1) REMOVE: The client starts a REMOVE operation, or call the EJBOBJECT REMOVE method, or call EJBHOME's RemoveHandle. The two methods produce the same result. 2) EJBREMOVE: Call the EJBREMOVE method to the BEAN a last chance to clear any open resources. 3) Timeout: A stateful session bean will remove the container when it expires. At this time, no matter whether it is Passivated or the READY state. 25. Build a session bean A: When we build a session bean, we refer to build bean class, home and component interface, and DD: 1) bean class: must include callback methods, implement component interface methods, and any Home life Cycle method, different types of callback methods are implemented in different types of session beans (exactly stateful session beans do not passivate and activate, so ejbactivated () and ejbpassivated () methods are empty implementation); 2) Home interface: Define BEAN's life Cycle method, session bean In addition to Create and Remove, there is no Find and other primary interface methods; 3) Component Interface: Defines a BEAN's client view and a corresponding business method; 4) Deployment descriptor in the XML format of DD: bean.

26. Deployment Descriptor Answer:. : This optional entry allows us to define a local reference for other EJBs;

27. Best habits for session bean design and construction: 1) Do not store session in stateless session beans: This is almost unconventional session bean definition, but it is worth repeating; 2) A method should not perform Depending on any previous client or session status; 3) Initializing the session-free session bean; 4) Use the EJBREMOVE method to clear the resource opened by any stateful session bean; 5) Do not implement EJBPassivate in the stateless session bean And EJBActivate logic, stateless session beans do not have passivation and activation, these methods are not called; 6) Do not call a session bean from multiple clients, confident that your logic is forbidden to have status session beans by two different clients Call; 7) Confidence that your bean does not enter the loop call, the re-entry of bean is disabled; 8) Abnormal processing: Appropriate exception causes Bean to exit from memory; 9) Keep the bean survival period relative to the short: Although session bean Can exist during a client session, but this session should never exist (for example, a week); 10) Try to make the client's session state limited and manageable. For example, some types of transactions. 11) If necessary, some big, long-running session beans are divided into more numbers, short-time beans to manage. 12) The session bean should be some of the coarse particle size commercial processing, such as deposits and withdrawals. Try to hide fine particle activity: Do not expose all methods of entity beans through a session bean. 13) Session Facade: EJB SESSION FACADE mode provides a stable, high-level gateway for server-side components. An EJB Session Facade hides the entity bean interface to the client. All access to entity beans must pass through session beans. 14) The entity bean in EJB2.0 defines the local interface. The session bean defines local and remote interfaces. Because all access to entity beans are methods of session beans located in the same server through and entity beans. 28. Looking for the main interface of Bean: 1) This shows how to find a primary interface of a session bean; 2) Because we use the remote interface, we need to call the Narrow method of PortableRemoteObject after the INITIALCONTEXT's Look Up method; 3) pass HOME object We can look for our remote component interface of our BEAN. InitialContext ctx = new InitialContext (); Object objHome = ctx.lookup ( "itso / BankingJNDIName"); BankingHome bankingHome = (BankingHome) javax.rmi.PortableRemoteObject.narrow (objHome, BankingHome.class);

Advanced part of the entity bean

1. Introduction: 1) CMR (EJB Container-Managed RELATIONSHIPS): Relationships is a way to define the connection between entity beans. The container has built a support for EJB relationships; 2) Genetics between EJBs: Genetics is an entity bean inheriting a capability of other beans, in IBM's products, such as Visualage for Java and WebSphere, or EJB1.1, Support for this ability; 3) EJB Customer Query Method: Query Method is any method used to locate entity beans in Home, such as FINDXXX (called Finder method) and selectxxxx (called SELECT method); 4) We talk about CMP, container basic an abstract query language - EJB QL (SQL subset) - responsible for generating actual database code; 5) The customer's Finder method is feasible for CMP and BMP, but CMP is for QL language have more advantages. 2. CMR (EJB Container-Managed Relationships) A: 1) Entity-Relational Database Model Chart is referred to as Erd, Erd defines the relationship between the intervals in the relational database, usually by the primary key declaration. 2) The foreign key in a database matches the primary key in another database, which forms a relationship. 3) The process of defining the relationship for entity beans is a bit like the relational database defined in the relational database. 4) In the entity bean, we deal with objects, not tables, and the objects contain data and methods. Therefore, the relationship definition of the example bean must exceed the data model. 5) CMR is defined as a collection and synthetic relationship between entity beans. 6) Key: Foreign key in a table is the prerequisite for entity bean relationships.

3. Relationships Answer: 1) Relationship 2) Role 3) MultiPlicity 4) NavigabiLity 4) NavigAbility

4. Diversity Answer: 1) One-on one: An example of a bean and another bean have the most a single relationship, but it is also. 2) One-to-many: An example of a bean can be associated with multiple instances of another bean, but another bean and the first bean have the most relationships. 3) Multi-to-many: one example of a bean may contact multiple instances of another bean, but also.

5. EJB Inheritance Answer: 1) Define an entity bean as a subclass of a entity bean is not something in the EJB specification, but in real applications, we need this essential characteristics to objects to objects. 2) This specification is directly implemented in WSAD and WAS. 3) Application developers provide different mapping to implement inheritance hierarchies, single-table methods, and external keys with foreign key contacts.

6. Inherited preview: WSAD supports two types of inheritance: 1) Java inheritance 2) EJB inheritance. Entity bean inherits related properties of another entity bean in the same EJB module, such as CMP fields and relationship roles, methods, and The method layer control descriptor property. Because EJB inherits almost only in the same EJB module, the subclass and the parent class are in the same module.

7. EJB inherited Features: 1) For the CMP entity bean, there is a support for a single table and root / leaf list map; 2) All CMP fields will be listed, including inheritance fields; 3) Main interface classes Cannot inherit with other primary interfaces, so we have to promote all related methods; 4) The remote interface class can inherit other far-end interfaces, which means we can directly inherit the definition in the parent bean in the child bean. Business method. We only need to improve the special business methods in the child bean; 5) The bean's bean class inherits the parent bean's bean class; 6) Key Class is shared for multiple enterprise beans in the inheritance mode. This means that KEY CLASS in the child bean is equal. 7) For entity beans for BMP type, you can use mapping mode, but you have to write JDBC access code. 8. Java inheritance A: 1) In Java inheritance, an entity bean class inherits the superclass's attributes and methods; 2) The remote interface inherits the commercial method for superclad implementation;

9. Features of Java inheritance: 1) Bean Class inherits super class A to implement interface B. The distal interface can inherit the interface B for defining a business method. 2) Subclasses from the same superclass inheritance are completely different beans, which have different mappings and their respective modes. 3) Inherited subclasses have different KEY CLASs used to characterize their. 4) If there is a state in the superclass, it is sure that the status is continuous.

10. The benefits of Java inheritance: 1) Java inheritance mode is very useful when we have a class that implements beans logic. 2) As a advantage of inheritance, it can reuse the code. 3) But this model is not helpful for database mapping, because the bottom table does not reflect inheritance.

11. Single table mapping inheritance mode Answer: 1) All classes mapped to a single table in the inheritance mode. 2) A distinguished field specifies the instance type of the subclass. 3) This distinguished field is not an attribute of any entity bean, which is only used for mapping.

12. Good Answers for a single table mapping: 1) This data table is not very specific in a single table mapping mode. The fields used to specify a bean are not necessary to closely be closely associated with other beans. 2) But this mode is easy to access the data table. 3) This mode is an actual limitation that when we create a new entity bean by inheriting an existing bean mode, we must change the definition of the table: add its unique field to beans. 4) So, single-table mapping mode is suitable for the CMP field of the parent bean than sub-beans.

13. Root / Leaf Table Map Inherited Mode A: 1) In the root / leaf map mapping mode, you create a table for each enterprise bean in the inheritance level; 2) The root table contains the proprietary fields in the parent bean. And identify fields. 3) Because some fields and sub-bean inheritance properties are related, this table also includes a status of sub-bean properties.

Wednesday, 2004-10-27 Wednesday

Develop, debug, and test EJB, JSP and Servlet (EJB 11)

14. EJB User Query Method A: 1) Query Method is used to find existing entity beans, through and persistent layers interact in the database to find records corresponding to entity beans. You can return one to more beans. These query methods are in the Home interface of the entity bean. 2) Single object query method Returns a bean type, multi-object query method returns a collection.

15. EJB QL A: 1) We only focus on the development of the Query method of the CMP entity bean mode. 2) If you use the CMP type bean, you can use the new EJB QL in your query. EJB QL Specifies a query statement by using an entity bean of the CMP type by using the property (CMP field) and the relationship (CMR field). 3) This language is similar to SQL, which is a subset of SQL. 4) EJB QL is used to define abstract persistence patterns of entity beans, rather than underlying data storage. Therefore, they are easy to apply to different containers. EJB QL Defines that in the deployment descriptor, the EJB container generates the actual SQL code based on EJB QL when the bean is deployed. 16. Compose Answer with: 1) Standard | Finder Method | SELECT Method --------------------------- ------------------------------------------------ where is it Disclaimer | Remote or local Home interface | Abstract method in Bean Class -------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------- method name | FINDXXXX ( Home interface) | EJBSELECTXXXX (Bean Class) | EJBFINDXXXX (Bean Class) | ------------------------------- ------------------------------------------------ visibility | Client visible | Located in the entity bean, it is used by other bean methods --------------------------------- ------------------------------------------ Example | Bean Example Pool Any abstract | current instance, but if it is a Home method call, | bean instance | can be any instance ------------------------- -------------------------------------------------- ---- Return Value | Main Interface: Return to a single object | Single or object collection. Object Types can be | (EJBOBJECT or EJBLOCALOBJECT) | EJBOBJECT or EJBLOCALOBJECT, CMP field | or a collection | | bean instance: primary key | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------- Abnormal | FINDEREXCEPTION or | FINDEREXCEPTION or | ObjectNotFoundException | ObjectNotFoundException

17. SELECT method A: 1) SELECT method is sometimes referred to as private Finder method, which is located only within a bean class. Combined with the new Home interface method, you can achieve a very complex operation of more than one entity bean type. 2) The SELECT method makes the BEAN Class have a private query method, so that these functions will not be exposed to the customer via the HOME interface. Message driver bean

1. Introduction A: 1) Message Driver Bean is exciting in the EJB2.0 specification; 2) They have opened a new framework area to provide comprehensive selections that were not available in J2EE. 3) Message Driver Bean is new in EJB2.0, which is also new for WebSphere5.0.

2. Non-synchronous communication Answer: 1) Non-synchronous communication is a message transmission method, further, there is no need to wait for a message transmission method. 2) Non-synchronous communication is a way in which session between different applications or applications. 3) We have seen the application client through the RMI / IIOP and EJB sessions. Ways of communication include RMI, COM / DCOM, CORBA, Web Services / SOAP, asynchronous communication 4) Asynchronous communication is a consumer (EJB client) and message consumers (EJB customers) and messages for calling EJB Drive Bean Intercompanies Transportation Mechanism, Object-Oriented Middleware (MOM), such as WebSphere MQ. 5) This, MOM intercepts all messages between generators and consumers and then processes them.

3. JMS and JMS Provider Role A: 1) JMS (Java Message Service) is an API that accesses the MOM service in Java. 2) All application servers supporting EJB2.0 specification must support asynchronous communication such sessions based on JMS programming interfaces. 3) JMS provides a public manner to Java programs (clients and J2EE applications) to create, send, receive, and read asynchronous requests as a message as JMS. 4) Just as any J2EE API, JMS is just a public, lightweight programming mode. It does not really provide runtime implementation or underlying message service, which is provided by MOM. Therefore, a new type of service must also be provided for application servers that support EJB2.0 specification: JMS message servers. 5) WAS 5.0 provides built-in JMS message servers as the foundation of WebSphere products. Built-in JMS servers are essentially a lightweight WebSphere MQ that allows inter-application exchange messages in the same server. 4. MDB Introduction A: 1) MDB is used to process asynchronous JMS messages in the J2EE application. 2) When the message is coming, they are called by the container. Therefore, they can see as another mechanism for calling EJB. 3) But different from the session and entity bean is that when the message is coming, it is a container, not a client, and there is a responsibility to call them. 4) Although MDB is sometimes referred to as there is no real customer, in fact, customer is the generator of the message. 5) MDB is very important:. They are not visible to the client, is anonymous. They are fully managed by the EJB container. They are stateless and cannot maintain any status of the client. They must implement Javax.jms.Messagelistener and Javax.ejb.MessageDriveNbean. They do not have components and home interfaces.

5. Concept of Java Message Services Answer: 1) JMS is a Java API that accesses the MOM system. 2) and JDBC are similar to database access. JMS is an access method that is unrelated to the message. 3) The MDB is actually the EJB called after the JMS message arrives. 4) Because JMS is the pillar of MDB, it is important to understand the basics of JMS. 6. P2P Answer in JMS Message Mode: 1) In the end-to-end, the message passes the queue (Queues) transfer; 2) The message is placed in a message (client) in the queue; 3) Typically The message is only handled by the consumer; 4) In this case, there is only one consumer.

7. Pub / Sub Answer in JMS Message Mode: 1) In the release-subscription mode, the message is published by the topic; 2) The message is published by the message generator; 3) Message can be subscribed to the consumer Receive; 4) In this way, a message can be received or processed by multiple consumers.

8. JMS Provider A: 1) The JMS provider is the basis of the message system, and they are some JAVA classes that implement the JMS API; 2) JMS Provider resources can be accessed through the JMS connection factories and destination objects. 3) The provider is either WebSphere built-in lightweight MQ or an external as WebSphere MQ.

9. JMS Server Answer: 1) The JMS provider's JMS function can be accessed through JMS server in the application server; 2) The JMS server is responsible for managing the following services: Queuing: Queue service when using P2P; agent : Provide service release / subscription service when using the Pub / Sub;

10. JMS Connection Factory A: 1) Connecting Factory is used to create a connection for a specified JMS queue or subject goal. Each connection plant encapsulates a configuration parameter that creates a JMS destination connection; 2) Store the details of the connection to JNDI using the application's connection code. There are two types of JMS connect factories:. QueueConnectionFactory: Encapsulates the settings of a queue-based messaging system;. TopicConnectionFactory: Encapsulates the settings for creating a topic-based message system.

11. JMS Destination Answer: 1) A JMS Destination provides a specified message end; 2) There are two types of JMS destination:. Queues: for P2P; Topics: For Pub / Sub;

Sending a message to the queue 12. The Java code A: InitialContext initCtx = new InitialContext (); QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup ( "java: com / env / jms / ItsoMDBConnectionFactoryRef"); QueueConnection conn = qcf.createQueueConnection () ; QueueSession session = conn.createQueueSession (false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) initCtx.lookup ( "java: comp / env / jms / ITSOMdbQueueRef"); QueueSender sender = session.createSender (queue); TextMessage msg = New TextMessage ("Test Message"); sender.send (); sender.close (); conn.close (); conn.close (); Description:. QueueConnection: A event for creating to the JMS message server Connections for creating quenessions. Similar to Connection objects in JDBC. In the Pub / Sub mode, TopicConnection is used; QueueSession: Use the created Sender objects and messages. You can only be used by one thread at a time. In the Pub / Sub mode, TopicSession will be used. Queuesender: Used to send a message to the queue, in the Pub / Sub mode, TopiCPublisher will be used. TEXTMESSAGE: A simple text message type. Other types are ObjectMessage, BytesMessage, StreamMessage, and MapMessage. Each Message type inherits the Message Class. In this list, a simple text message is sent to the queue, a good habit is to close these objects in time after completing the task, just as you do for the JDBC type object.

13. JMS message listener A: import javax.jms *; public class AListener implements MessageListener {public void onMessage (Message aMsg) {try {TextMessage msg = (TextMessage) aMsg; System.out.println ( "Got Message.: " msg.gettext ());} catch (exception e) {E.PrintStackTrace ();}} public void runit ()}} public void runit ()}} public void runit ()}} public void runit () {... queuereceiver rec = session.createReceiver (queue); Rec.setMessagelistener (this); Rec.close (); ...} ...} Description: All standard message listeners must implement the javax.jms.MessageListener interface, so this object can be registered as a JMS listener; in this example, We register themselves as a listener. For an MDB, the container will register this bean as a listener. When a JMS message arrives, the container triggers the OnMessage method. 14. Message Drive BEAN Structure A: Reese Reesence Message Drive Bean implements the Javax.EJB.MessageDriveNbean interface, and also implements the javax.jms.MessageListener interface.

javax.ejb.EnterpriseBean javax.jms.MessageListener ↑ ↑ | | javax.ejb.MessageDrivenBean | ↑ ______________________________________ | | MyMDB 15. no home or component interfaces A: 1) MDB does not require home or component interfaces, and because there is no direct client It depends on; 2) The home interface is used to position the bean, uniquely handling this instance is a container, and the container has sufficient ability to locate the MDB; 3) The purpose of the Component interface is to provide the client to access the business logic access port. Although MDB will implement business logic when the OnMessage method is called, Bean does not need to provide these to external clients.

16. MDB status Answ: There are two states of MDB, either do not exist, either in the Method-Ready Pool state. Message Drive Bean Method-Readey Pool is a bit like instance pool of stateless session beans. SetMessageDriverContext () No State ---------------------------> Method Ready Pool <------------- -------------- EJBREMOVE () 17. Building a message Drive Bean Answer: 1) When we build a message driver bean, we refer to build a bean class and deployment descriptor. Bean class: must include Tune method and implementation of the onMessage method; Deploy Descriptor: Descriptor of this bean XML format; What is business logic? Let the message-driven bean bear the business logic is not recommended, a good method is to delegate it to the stateless session bean. According to this idea, the stateless session bean completed the specific implementation of the business logic, the message driver bean simply plays the business logic delegation role.

18. What is a reply? A: 1) Non-synchronization messages are usually a trigger-forgotten behavior, for consumers, do not expect or need to reply; 2) Message-Consumer MDB can process messages, then act as JMS message generation; 3 This original message generator must listen to the message request sent back by the consumer, which is also a JMS message consumer. 4) This is a bit like a queue used to send, and another queue is used to respond.

EJB client

1. Client Type A: 1) Sessin Bean: A session bean can be seen as a client that it is accessible. In most, session beans and entity beans are running in the same EJB container, so the local interface can be used; 2) servlet: servlet can interact with the remote or local interface and EJB. A recommended approach is: servlet only with the session bean, the session bean is retrieved with the entity bean. Servlets can access session beans using remote or local interfaces, and recommend remote interfaces. Servlet is a typical thin client implementation. The client is HTML and JSP, and they call Serv J2EE Application Client: This is a Java application that accesss the enterprise bean, JDBC database, and Java message service queue. They run in the client machine and use JNDi life to access resources. The RMI-IIOP protocol enables the application client to access the enterprise bean reference and the CORBA service implemented using the J2EE platform.

2. MVC Design Mode Answer: 1) MODEL: Encapsped all business logic and rules. Usually implemented by JavaBean or EJB. 2) View: Use the results of the business logic to process and build a response presentation to the client. Usually implemented by JSP. 3) Controller: Manage and control interaction between all users and applications. Usually a servlet receives the user's request and transfers all the input to the actual work. Finally, call the JSP to return to the output.

3. Addition of MVC Answer: 1) It is clearly separated from the performance layer and the control layer; Safety mode; 3) It makes a development team role to be possible, page design and business logic development seamlessly; 4) When using this programming mode in web applications, it is used to transport data or objects from servlet to servlet to JSP Media is httpservletRequest or httpsession; 5) When a user requests resources to the server, the request object contains all the information sent to a web server. 4. How to access EJB? A: The steps from any type of client access EJB are: 1) Get home interface; 2) Look for or create an EJB object; 3) Call the business method of EJB instance.

5. Basic Programming Principles: 1) First, we will see that we can write a simple to find and use clients located in EJB containers; 2) Before accessing the enterprise bean in the EJB server, one client The necessary steps must be followed. These steps are: Get an initial name context: When we write an EJB client, you have a responsibility to create a JNDI's InitialContext. Remove the named service of the application server by hooking the application server. The simplest form of the initialization context is used in the use of its constructor: javax.naming.initialcontext initialcontext = new javax.naming.initialcontext ();. From the initialization context searching EJB primary interface: Use initialization context, we can get us The primary interface of the entity bean to be accessed. We can use global JNDI names or an EJB reference for a remote primary interface. For a local interface, we must use a local reference. . Use the EJB main interface: After getting the EJB main interface, we can create, find, and remove entity beans. Note Most methods will throw FindEREXCEPTION and RemoteException exception. These exceptions must be processed using TRY / CATCH. . Use the EJB reference: After obtaining the component interface, we can call the business method, of course, the REMOVE method in the EJB Object can also be called.

6. Client Access the type of entity bean Answer:

Client Server | ˉˉˉˉˉˉˉˉˉˉˉˉˉˉ | | ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ | | | ˉˉˉˉˉ | --------------- | - | ˉˉˉˉˉ | - | ---------------> | ˉˉˉˉˉˉ | | | | Servlet | --------------- | - | Network | - | ---------------> | Entity Bean | | | | | | _________ | --------------- | - | __________ | - | ---------------> | ____________ | | | | -Iiop | | | | | | | | | | | | | | | ˉˉˉˉˉˉ | | | | | -> | | - |.com | - | ------------> | Entity Bean | | | | | -> | ___________ | | | | | | | | | | | | | | | | | | | | | | | | | | | -> | ˉˉˉˉˉˉ | | | | | Servlet | --------------- | - | NETWORK | - | | Session Bean | -> | Entity Bean | | | | __________ | | | __________ | | | ____________ | -> | ____________ | | | | RMI-IIOP | | | ____________________________ | | ________________________________ |

CLIENT TYPE | YES, WHEN | NO, WHEN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------- Direct access |. Model Simple | Entity Bean There are multiple properties |. Efficiency is not important | ---------------------------------------- ---------------------------------------- access beans |. Need simple and fast development |. Requires more complex design mode |. The server's system resources are limited |. Cluster environments for multiple applications |. Access session beans with Java packuses | --------------- -------------------------------------------------- ---------------- Facade Beans |. Quarable Testability is important |. Client needs access to session bean |. Application open design |. Development time is important |. High performance | Deployment application

1. Create an application server Answer: 1) After the WebSphere application server is installed, a server has automatically created (Server1); 2) Although your program can deploy a configuked server, we still recommend that you are your own Program creates a separate server; 3) The default server is mainly running WebSphere examples and some templates;

2. Change the server's port number A: When we create an application server, we let this system define a default HTTP port number for the web container. We can change it on your own.

3. Create a JDBC Provider and Data Source Answer: Access the Database, we need to define the data source, then we can connect this database and our entity bean.

4. Configure WebSphere's JMS Provider A: We need to use built-in WebSpherer JMS Provider, MQSeries. In WebSphere.

5. Deployment Application A: Now we have created all the resources needed for this application, ready to deploy.

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

New Post(0)