EJB substantive problem

zhaozj2021-02-16  48

EJB, is an abbreviation of enterprise java bean, I want to talk to you some substantial problems ================ Why use EJB? =========== ====== EJB's largest tempting is that she separates the app and server, and we need to deal with complex resources on the servers. What database, what process, thread, what safety privileges, In the socket, you will see the ghosts. We only need to be implemented in our business logic. ========== EJB essence? ========== EJB actually It is a set of specifications in Sun's J2EE, and specifies a series of APIs to convert EJB concepts into EJB products. EjB is beans, beans is the concept, that is, there is a to accommodate her, let her can The place where it is, it is to have a container. EjB must survive in the EJB container. This container is powerful! She first wants to pack your bean, EJB customer programs actually lead the EJB you wrote directly, they There is a relationship between the Home / Remote interface. It is responsible for all of your bean to eat Lhasa sleep, such as the sustainable, security, transaction management ... =========== == EJB server product ============= Various web server developers basically bundled EJB containers in their web server, or called EJB servers. The simplest is also the most fundamental J2EE develops a J2EE of the environmental band, which has built a good operating environment with J2EE's HTTP server and servlet engine. Due to its simple configuration, powerful, so become my favorite. Different like BEA WebLogical is a product that is recommended. Its web server feature is quite powerful. It is an ideal web server that has been built in today's website. It has also joined the ranks of EJB. It has a good performance in EJB. IASE's IAS is one more The powerful web server is also embedded in the EJB container, plus the seamless combination of JBuilder's JBuilder, which makes it popular. There is also a good WebSphere, but Apache has been equipped with EJB containers. I am not clear. In addition, I recommend an ejboss, a completely free EJB server, and the original code is open. ======================== How does the EJB container pack your bean. =========================

This year doesn't have a good thing in the sky, EJB is no exception, you want EJB containers to manage your ejb's eating and drink Lhasa sleep, what ?! With XML descriptor, you tell EJB containers through an XML file BEAN's related configuration information, such as the HOME interface of my EJB and the REMOTE interface, such as my EJB alias (actually a JNDI name), such as whether my EJB is an entity type EJB or dialog EJB, such as telling containers to manage my entity EJB in my entity EJB, ... In short, you have to talk to our EJB Big Pipe ---- EJB container put all the content clearly. This is left Look at the EJB container !!! Do you have a total of 3 files, bean definitions, home interface definitions, ROMOTE interface definitions, when you deploy them (1). First, according to Home and Remote interface Generate their implementation code, we may wish to call Home_Impl and Remote_Impl, (2). Then, use RMIC to generate home_impl and remote_impl's Stub and Skeleton files, 2x2 a total of 4 files. (Stub and Skeleton See the concept of RMI) This, finally, on the server, there is a total of bean home_impl remote_impl home_stub home_skeleton limited_stub Remote_skeleton 7 files to work. (3). Generate the library table of the database corresponding to the entity EJB (4). Register your EJB to JNDI Service =================================================== ============== In addition to writing beans, write interface files, and do you want home and transote two interfaces. ============== ================================================== Stir, these two interfaces can be merged into an interface. In fact, their roles are just an interface. In order to make the people sun dry? I still have to be dismantled? I think, as Sun said, in order to Some container-related operations and customer business methods are separated. What do you mean? Have it, home is used to standardize the container-related method, Remote is responsible for customizing business methods, and our bean is the final logic implementator. Still Understand? It doesn't matter, I am talking about, for example: I imagine it into a bean, home interface is the order of our family, R The Emote interface is the command of our unit. Our family's order determines how I eat and drink Lhasa sleep, the command of the leader determines how I do some real work, please note that I use "decision" this word, I don't have Say our family, but said our family's order, this command's meaning is the interface, not a class, and my bean is a class! Also, the bean class does not implement Remote and HOME interface, remember! Remember! = ======== EJB classification ====

===== EJB is divided into entity (Entity) EJB and dialogue (session) EJB, >>>>>> EjB: >>>>> Dialog EJB <<<<<<< conversation EJB is not at all The database is deal, why, because he does not need serialization at all! He is only responsible for completing some logic operations, such as what is written. In order to be with the entity EJB, he also gave birth to two sons, a. Stateful (sessionful To the conversation EJB, he likes the session object in the servlet, you can save the user's session related information, and he is only used by a user, not shared with others, I manage his call, but this "conversation" Turning out, this is enough, it is not as good as it is called him session! B. No status (sessionless) dialogue EJB This stuff is the easiest EJB, he can be shared by multiple users, pay attention! I am talking about sharing! Is the sharing of the instance! ============================================== a bean management continuous Entity EJB (BMP) small example ====================================== said for a long time, Everyone is probably being consumed by my consumption, good, let us analyze a bean management sustainable entity EJB (BMP). ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----- Take a look at the Remote Interface ------------------------------ Public Interface Account Extends EJBOBJECT {// must be from EJBOBJECT // inherit these are business methods, but here we wrote, must implement public void deposit (double amt) throws RemoteException in the BEAN; public double withdraw (double amt) throws AccountException, RemoteException; public double getBalance () throws RemoteException Public string getownername () throws remoteException; public void setownername (String name) throws RemoteException;} ---------------------------------------------------------------------------------------------------------------------------- - Take a look at the Home interface --------------------------------- public interface accounthome extends ejbhome {// This statement CREATE Function, because it is BMP, so you must implement a corresponding function called EJBCREATE (String Accountid, String OwnerName) throws CreateException, RemoteException;

// Press the primary key query // Since it is BMP, a corresponding function of EJBFindByPrimaryKey must be implemented in the bean, the corresponding function public acid, refount findByPrimaryKey (AccountPk key) ", RemoteException; //, according to the Name field query // because it is BMP, so You must implement a corresponding function called EJBFindBYOWNERNAME in Bean (String Name), RemoteException;} ------------------------------------------------------------------------------------------------ - See bean ----------------------------------- public class accountbean imports entitybean {// three public Fields, the three fields of the corresponding library table in the corresponding library table PUBLIC STRING ACVOUNTID PUBLIC STRING OWNERNAME; public double balance; // -------------------------------------------------------------------------------------------------------------------------------------------- instance mapping to public databases AccountPK ejbCreate (String accountID, String ownerName) throws CreateException, RemoteException {PreparedStatement pstmt = null; Connection conn = null; try {this.ownerName = ownerName; this.balance = 0; conn = getConnection () PSTMT = conn.preparestatement ("INSERT INTO Accounts (ID, Ownername, Balance) VALUES (?,?,?)"); PSTMT.SetString (1, AccountID); Pstmt.setString (2, OwnerName); PStmt.setdouble (3, balance); // Look here, see here! PSTMT.executeUpdate (); return new accountpk (accountid);} catch (exception e) {throw new createException (e.tostring ());} finally {Try {PSTMT . close (); conn.close ();} catch (exception e) {}}}} // ------------------------------------------------------------------------------------------------------------------------------------------------------ Find work public AccountPK ejbFindByOwnerName (String name) throws FinderException, RemoteException {PreparedStatement pstmt = null; Connection conn = null; try {conn = getConnection (); pstmt = conn.prepareStatement ( "select id from accounts where ownerName =?") PSTMT.SetString (1, name); // Look! Look, according to the name ... ResultSet RS = PSTMT.ExecuteQuery (); rs.next (); string id = rs.getstring ("id" PSTMT.Close ();

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

New Post(0)