Java EJB and Network Application Instances

Source: Internet
Author: User

Java EJB and Network Application Instances

Bean Instance)

A Bean Instance is the instantiation in a container. If Bean is compared to a class, bean Instance is a Java Object.

Bean-managed persistence (the Permanent BMP managed by Bean itself)

This term is used to describe how Enterprise Java Beans store their state to database tutorials or other storage mechanisms. The container will prompt the Bean to call the EjbLoad () and EjbSave () Methods of the Bean.

Container)

The container of a Bean is actually the home interfaces and remote interfaces of the bean. It should provide a set of utilities to hide bean instances, intervene in method calls, and maintain transaction integrity and general management of bean instances pools. Although the Ejb rule specifies that a container must manage more than one bean, usually each container has only one bean.

Container-managed demarcation

For an enterprise bean, whenever a commercial method is called, the container automatically starts a new transaction. After the commercial method is completed, the transaction is over. The form of the container startup transaction is determined by the bean transaction attribute, or by the commercial method itself (if any ).

Container-managed persistence (delegated permanent CMP for Container Management)

Bean developers can delegate containers to record the latest Bean status. The Bean state must be obtained by many public Fields in the Bean. Containers can ensure that these public fields are correct before any bean method is awakened. Public fields must be defined in deployment descriptor before the container classes is generated.

Entity beans

Entity beans represent identifiable perpetual objects. A typical instance is: it can represent some rows in a relational database. Of course, it can also be an archive in the archive system, or any other unique identifiable material.

Home

Every Enterprise Bean, whether Session or Entity bean, has an interface to allow the client to establish and remove a bean instance. Taking Entity as an example, home interface provides some methods to allow the client to locate a bean instance. This interface follows the rules of Java RMI interface. Each home interface inherits from a remote interface called EJBHome.

Remote

The remote interface of a bean describes a set of methods that can be called by clients in a bean instance. This interface follows the rules of Java RMI interface. Each remote interface inherits from a remote interface, that is, EJBObject.

Session beans

Session beans are created by the particle client. After a specified idle time called timeout, it will no longer exist.

Session synchronization

Session beans can be used to selectively implement the Session Synchronization interface. This allows Session beans to be notified before and after the transaction is completed. Session bean can use the beforeCompletion () method to reject the successful completion of the transaction, and can use afterCompletion () to determine whether the transaction is successful or not.

Transaction Attribute)

A transaction attribute can be used in beans and their special commercial methods. There are six possible values:

TX_NOT_SUPPORTED, TX_REQUIRED, TX_SUPPORTS,

TX_REQUIRES_NEW, TX_MANDATORY, TX_BEAN_MANAGED

File: jndi. properties

Java. naming. factory. initial = org. jnp. interfaces. NamingContextFactory
Java. naming. factory. url. pkgs = org. jboss. naming: org. jnp. interfaces
Java. naming. provider. url = localhost: 1099


File: Main. java

Import javax. naming. InitialContext;

Import bean. EmployeeServiceRemote;

Public class Main {

Public static void main (String [] a) throws Exception {

EmployeeServiceRemote service = null;

// Context compEnv = (Context) new InitialContext (). lookup ("java: comp/env ");

// Service = (HelloService) new
// InitialContext (). lookup ("java: comp/env/ejb/HelloService ");
Service = (EmployeeServiceRemote) new InitialContext (). lookup ("EmployeeBean/remote ");

Service. doAction ();

}

}


File: Employee. java

Package bean;
Import javax. persistence. Entity;
Import javax. persistence. EntityListeners;
Import javax. persistence. GeneratedValue;
Import javax. persistence. Id;
Import javax. persistence. PostRemove;

@ Entity

Public class Employee implements java. io. Serializable {
Private int id;

Private String firstName;

Private String lastName;

@ Id
@ GeneratedValue
Public int getId (){
Return id;
}


@ PostRemove
Public void postRemove ()
{
System. out. println ("@ PostRemove ");
}

Public void setId (int id ){
This. id = id;
}

Public String getFirstName (){
Return firstName;
}

Public void setFirstName (String first ){
This. firstName = first;
}

Public String getLastName (){
Return lastName;
}

Public void setLastName (String last ){
This. lastName = last;
}
}


File: EmployeeBean. java

Package bean;
Import javax. ejb. Stateless;
Import javax. jws. WebMethod;
Import javax. jws. WebService;

@ Stateless (name = "EmployeeBeanEJB ")
@ WebService (serviceName = "EmployeeBeanWebService ",
TargetNamespace = "http://www.java2s.com/ejb3/credit ")
Public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {

Public EmployeeBean (){
}

@ WebMethod (operationName = "CreditCheck ")
Public boolean validateCC (String cc ){
Return true;
}

Public void doAction (){
System. out. println ("Processing ...");

}

}


File: EmployeeServiceLocal. java

Package bean;
Import javax. ejb. Local;
Import javax. ejb. Remote;


@ Local

Public interface EmployeeServiceLocal {
Public void doAction ();
}

 

File: EmployeeServiceRemote. java

Package bean;
Import javax. ejb. Stateless;
Import javax. jws. WebService;


Public interface EmployeeServiceRemote {
Public void doAction ();


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.