January 19th, 2008
The bean class must declare accessor (set and get) methods for each persistent and relationship field defined in the abstract persistence schema of the deployment descriptor. In truth, it s somewhat of a chicken-and-egg scenario, since the container tool needs both the abstract accessor methods (defined in the entity bean class) and the XML elements of the deployment descriptor to fully describe the bean s persistence schema. In this book, the entity bean class is always defined before the XML elements, because it s a more natural approach to developing entity beans. Here is a very simple definition of the CustomerBean class which is developed and packaged for deployment by the bean developer. import javax.ejb.EntityContext; public abstract class CustomerBean implements javax.ejb.EntityBean { public Integer ejbCreate(Integer id){ setId(id); return null; } public void ejbPostCreate(Integer id){ } // abstract accessor methods public abstract Integer getId(); public abstract void setId(Integer id); public abstract String getLastName(); public abstract void setLastName(String lname); public abstract String getFirstName(); public abstract void setFirstName(String fname); // standard call back methods public void setEntityContext(EntityContext ec){} public void unsetEntityContext(){} public void ejbLoad(){} public void ejbStore(){} public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} } The CustomerBean class is defined as an abstract class. This is required by CMP 2.0 to reinforce the idea that the CustomerBean is not deployed directly into the container system. Since abstract classes cannot be instantiated, the bean class must be subclassed by a persistence class generated by the deployment tool in order to be deployed. Also, the accessor methods are themselves Copyright (c) 2001 O’Reilly & Associates
Have you tried other web hosting companies and found out that their focus and your focus are in clash?Check our filemaker web hosting services.
Posted in Java Server Pages Blog | No Comments »
January 18th, 2008
The Customer Table Although CMP 2.0 is database independent, the examples through out this book assume that you are using a relational database. For a relational database we will need a CUSTOMER table from which we get our customer data. The relational database table definition in SQL is as follows: CREATE TABLE CUSTOMER ( ID INT PRIMARY KEY, LAST_NAME CHAR(20), FIRST_NAME CHAR(20) ) The CustomerBean The CustomerBean class is an abstract class that will be used by the container tool for generating concrete implementation, the persistent entity class, which will run in EJB container. The mechanism used by the container tool for generating a persistent entity class varies, but most vendors will generate a subclass of the abstract class provide by bean developer. Figure 6-4 The container tool typically extends the bean class Copyright (c) 2001 O’Reilly & Associates
Thailand is divided into 75 provinces , which are gathered into 5 groups of provinces by location. There are also 2 special governed districts: the capital Bangkok and Pattaya. However Pattaya is still part of Chonburi Province. Some Thai people still count Bangkok as one province, making Thailand a 76-province country.All our thai web hosting accounts have spam filter, virus scanner and frontpage extensions preinstalled. Check more in Thai Web Hosting section.
Posted in Java Server Pages Blog | No Comments »
January 18th, 2008
classes) when it s a good time to read and write data to the database. The persistent instances perform the reading and writing in a way that is optimized for the database being used. The persistent classes will include database access logic tailored to a particular database. For example, an EJB product might provide a container that can map an entity beans to a specific database like the Oracle relational database or the POET object database. This specificity allows the persistent classes to employ native database optimizations particular to a brand or kind of database, schema, and configuration. Persistent classes may employ other optimizations like lazy loading and optimistic locking to further improve performance. The container tool generates all the database access logic at deployment time, which it imbeds in the persistent classes. This means that the bean developers do not have to write this database access logic themselves, saving them a lot of work, and can also results in better performing entity beans because they are optimized implementations. As an entity bean developer, you will never have to deal with any database access code when working with CMP 2.0 entities. In fact, you won t have access to the persistent classes that contain that logic because they are generated by container tool automatically. In most cases, the source code is not available to the bean developer. Figures 7-2 and 7-3 show different container tools both of which are being used to map the Customer entity bean to a relational database. [Figure 7-2 need screen shot] BEA s Weblogic deployment tool [Figure 7-3 need screen shot] Sun Microsystem s J2EE RI deployment tool The Customer EJB In the following example we will develop a simple CMP 2.0 entity bean, the Customer EJB. The Customer EJB models the concept of a cruise customer or passenger, but its design and use is applicable across many commercial domains. As the chapter progresses the Customer EJB will be expanded and its complexity will increase to illustrate concepts discussed in each section. So this section serves only to introduce you to the entity bean and some basic concepts regarding its development, packaging and deployment. To simply things, we will skim over some concepts that are discussed in detail later in the chapter. Copyright (c) 2001 O’Reilly & Associates
If you are looking quality, fast, secure and reliable web hosting with PHP service at an affordable price, check php5 hosting services.
Posted in Java Server Pages Blog | No Comments »
January 17th, 2008
[FIGURE (note 7-1 and 6-1 are the same figure) ] Figure 6-1 Class Diagram of Customer and Address EJBs Abstract persistence schema The CMP 2.0 entity bean classes are defined using abstract accessor methods that represent virtual persistent and relationship fields. As already mentioned, the actual fields themselves are not declared in the entity classes. Instead, the characteristics of these fields are described in detail in the XML deployment descriptor used by the entity bean. The abstract persistence schema is the set of XML elements in the deployment descriptor that describe the relationship fields and the persistent fields. Together with the abstract programming model (the abstract accessor methods) and some help from the deployer, the container tool will have enough information to map the entity and its relationships with other entity beans in the database. Container Tools & Persistence One of the responsibilities of the vendor s container deployment tool is generating concrete implementations of the abstract entity beans. The concrete classes generated by the container tool are called persistent classes. Instances of the persistent classes will be responsible for working with the container to read and write data between the entity bean and the database at run time. Once the persistent classes are generated, they can be deployed into the EJB container. The container informs the persistent instances (instances of persistent Copyright (c) 2001 O’Reilly & Associates 4
Our company is website hosting provider which offers web hosting services for php, java, mysql, frontpage, dreamweaver and domain name registration. Check more about us on website hosting provider part.
Posted in Java Server Pages Blog | No Comments »
January 16th, 2008
unless you have a legacy EJB 1.1 system that you maintain. EJB 1.1 container- managed persistence is covered in Chapter 9. The next three chapters focus on developing entity beans that use EJB 2.0 container-managed persistence. In EJB 2.0, the data associated with an entity bean can be much more complex than was possible in EJB 1.1 or EJB 1.0. In EJB 2.0, container-managed persistence entity beans can have relationships with other entity beans, which wasn t well supported in the older version. In addition, container-managed persistence entity beans can be finer in granularity so that they can easily model things like Address, LineItem, or Cabin. This chapter develops two very simple entity beans, the Customer and Address EJBs, which will be used to explain how Enterprise JavaBeans 2.0 container- managed persistence entity beans are defined and operate at runtime. The Customer EJB has relationships with other several entities including address, phone, credit card, cruise, ship, cabin, and reservation EJBs. In the next few chapters, you ll learn how to leverage EJB 2.0 s powerful support for entity bean- to-bean relationships as well as understanding their limitations. In addition, you will learn about the Enterprise JavaBeans Query Language (EJB QL) in Chapter 8, which is used to define how the find methods and the new select methods should behave at runtime. It is common to refer to Enterprise JavaBeans 2.0 container-managed persistence as simply CMP 2.0. In the chapters that follow, we will use this abbreviation to distinguish between CMP 2.0 and CMP 1.1 (Enterprise JavaBeans 1.1 container- managed persistence). The abstract programming model In CMP 2.0, entity beans have their state managed automatically by the container. The container will take care of enrolling the entity bean in transactions and persisting its state to the database. The enterprise bean developer describes the attributes and relationships of an entity bean using virtual persistent fields and relationship fields. They are called virtual fields because the bean developer does not declare these fields explicitly; instead, abstract assessor (get and set) methods are declared in the entity bean class. The implementations of these methods are generated at deployment time by EJB vendor s container tools. So it s important to remember that the terms relationship field and persistent field are referring to the abstract accessor methods and not to actual fields declared in the classes. This use of terminology is a convention in EJB 2.0 that you should become confortable with. In Figure 6-1, the Customer EJB has four sets of accessor methods. The first two read and update the last and first names of the customer. These are examples of persistent fields; simple direct attributes of the entity bean. The other accessor methods obtain and set references to the Address EJB through its local interface, Address. This is an example of a relationship field called the addressfield. Copyright (c) 2001 O’Reilly & Associates
As web cam capabilities have been added to instant messaging text chat services such as Yahoo Messenger, AOL Instant Messenger (AIM), MSN Messenger and Skype, one-to-one live video communication over the internet has now reached millions of mainstream PC users worldwide.You can see details on web cam web hosting section.
Posted in Java Server Pages Blog | No Comments »
January 15th, 2008
Reservation EJB, and many others. Each of these business concepts represents data that needs to be tracked and possibly manipulated. Entities really represent data in the database, so changes to an entity bean result in changes to the database. There are many advantages to using entity beans instead of accessing the database directly. Utilizing entity beans to objectify data provides programmers with a simpler mechanism for accessing and changing data. It is much easier, for example, to change a customer s name by calling Customer.setName()than to execute an SQL command against the database. In addition, objectifying the data using entity beans also provides for more software reuse. Once an entity bean has been defined, its definition can be used throughout Titan s system in a consistent manner. The concept of customer, for example, is used in many areas of Titan s business, including booking, scheduling, and marketing. A Customer EJB provides Titan with one complete way of accessing customer information, and thus it ensures that access to the information is consistent and simple. Representing data as entity beans makes development easier and more cost effective. When a new EJB is created, a new record must be inserted into the database and a bean instance must be associated with that data. As the EJB is used and its state changes, these changes must be synchronized with the data in the database: entries must be inserted, updated, and removed. The process of coordinating the data represented by a bean instance with the database is called persistence. There are two basic types of entity beans, and they are distinguished by how they manage persistence. Container-managed persistence beans have their persistence automatically managed by the EJB container. The container knows how a bean instance s persistent fields and relationships map to the database and automatically takes care of inserting, updating, and deleting the data associated with entities in the database. Entity beans using bean-managed persistence do all this work explicitly: the bean developer must write the code to manipulate the database. The EJB container tells the bean instance when it is safe to insert, update, and delete its data from the database, but it provides no other help. The bean instance does all the persistence work itself. Bean-managed persistence is covered in Chapter 10. Container-managed persistence has undergone a dramatic change in EJB 2.0, which is so different that it s not backward compatible with EJB 1.1. For that reason, EJB 2.0 vendors must support both EJB 2.0 s container-managed persistence model and EJB 1.1 container-managed persistence model. The EJB 1.1 model is supported purely so that application developers can migrate their existing applications to the new EJB 2.0 platform as painlessly as possible. It s expected that all new entity beans and new applications will use the EJB 2.0 container-managed persistence and not EJB 1.1 version. Although EJB 1.1 container-managed persistence is covered in this book, it should be avoided Copyright (c) 2001 O’Reilly & Associates
MySQL web hosting will be off your worry about list if you sign up with us,just trust us and go check MySQL Web Hosting services.
Posted in Java Server Pages Blog | No Comments »
January 14th, 2008
6 EJB 2.0 CMP: Basic Persistence Overview In Chapter 4, we started developing some simple enterprise beans, skipping over a lot of the details about developing enterprise beans. In this chapter, we ll take a thorough look at the process of developing entity beans. On the surface, some of this material may look familiar, but it is much more detailed and specific to entity beans. Entity beans model business concepts that can be expressed as nouns. This is a rule of thumb rather than a requirement, but it helps in determining when a business concept is a candidate for implementation as an entity bean. In grammar school you learned that nouns are words that describe a person, place, or thing. The concepts of person and place are fairly obvious: a person EJB might represent a customer or a passenger, and a place EJB might represent a city or a port-of-call. Similarly, entity beans often represent things : real-world objects like ships, credit cards, and so on. An EJB can even represent a fairly abstract thing, such as a ticket or a reservation. Entity beans describe both the state and behavior of real-world objects and allow developers to encapsulate the data and business rules associated with specific concepts; a Customer EJB encapsulates the data and business rules associated with a customer, and so on. This makes it possible for data associated with a concept to be manipulated consistently and safely. In Titan s cruise ship business, we can identify hundreds of business concepts that are nouns and therefore could conceivably be modeled by entity beans. We ve already seen a simple Cabin EJB in Chapter 4, and we ll develop Customer and Address EJBs in this chapter. Titan could clearly make use of a Cruise EJB, a Copyright (c) 2001 O’Reilly & Associates
Adult web hosting has rich experience in providing unique solutions for the customer’s needs, just check frontpage web hosting services.
Posted in Java Server Pages Blog | No Comments »
January 13th, 2008
The Handle is less stable than the primary key because it relies on the networking configuration and naming the IP address of the EJB server and the JNDI name of the bean s home to remain stable. If the EJB server s network address changes or the name used to identify the home changes, the handle becomes useless. In addition, some vendors choose to implement a security mechanism in the handle that prevents its use outside the scope of the client application that originally requested it. How this mechanism would work is unclear, but the security limitation it implies should be considered before attempting to use a handle outside the client s scope. Exercise 5.2, The EJBObject, Handles and Primary Key EJB 2.0: The Local Client API Copyright (c) 2001 O’Reilly & Associates
Thailand is divided into 75 provinces , which are gathered into 5 groups of provinces by location. There are also 2 special governed districts: the capital Bangkok and Pattaya. However Pattaya is still part of Chonburi Province. Some Thai people still count Bangkok as one province, making Thailand a 76-province country.All our thai web hosting accounts have spam filter, virus scanner and frontpage extensions preinstalled. Check more in Thai Web Hosting section.
Posted in Java Server Pages Blog | No Comments »
January 12th, 2008
Inside the Handle Different vendors define their concrete implementations of the EJB handle differently. However, thinking about a hypothetical implementation of handles will give you a better understanding of how they work. In this example, we define the implementation of a handle for an entity bean. Our implementation encapsulates the JNDI lookup and use of the home s findByPrimaryKey() method so that any change that invalidates the key invalidates preserved handles that depend on that key. Here s the code for our hypothetical implementation of a Handle: package com.titan.cabin; import javax.naming.InitialContext; import javax.naming.Context; import javax.naming.NamingException; import javax.ejb.EJBObject; import javax.ejb.Handle; import java.rmi.RemoteException; import java.util.Properties; import javax.rmi.PortableRemoteObject public class VendorX_CabinHandle implements javax.ejb.Handle, java.io.Serializable { private Integer primary_key; private String home_name; private Properties jndi_properties; public VendorX_CabinHandle(Integer pk, String hn, Properties p) { primary_key = pk; home_name = hn; jndi_properties = p; } public EJBObject getEJBObject() throws RemoteException { try { Context ctx = new InitialContext(jndi_properties); Object ref = ctx.lookup(home_name); CabinHomeRemote home =(CabinHomeRemote) PortableRemoteObject.narrow(ref,CabinHomeRemote.class); return home.findByPrimaryKey(primary_key); } catch (javax.ejb.FinderException fe) { throw new RemoteException(”Cannot locate EJB object”,fe); } catch (javax.naming.NamingException ne) { throw new RemoteException(”Cannot locate EJB object”,ne); } } } Copyright (c) 2001 O’Reilly & Associates
The UK has been a member of the European Union since 1973. The attitude of the present government towards further integration is conservative, with the official opposition favoring a return of some powers and competencies to the UK.From our experience, we can recommend Cheap UK Web Hosting services.
Posted in Java Server Pages Blog | No Comments »
January 11th, 2008
session EJB object. Note that this process is not as fault tolerant as using the handle or primary key of an entity object. If the EJB server goes down or crashes, the stateful session bean will be lost and the handle will be useless. It s also possible for the session bean to time out, which would cause the container to remove it from service so that it is no longer available to the client. Changes to the container technology can invalidate both handles and primary keys. If you think your container technology might change, be careful to take this limitation into account. Primary keys obtain EJB objects by providing unique identification of instances in persistent data stores. A change in the persistence mechanism, however, can impact the integrity of the key. HomeHandle The javax.ejb.HomeHandle is similar in purpose to javax.ejb.Handle. Just as the Handle is used to store and retrieve references to remote EJB objects, the HomeHandle is used to store and retrieve references to remote EJB homes. In other words, the HomeHandle can be stored and later used to access an EJB home s remote reference the same way that a Handle can be serialized and later used to access an EJB object s remote reference. The following code shows how the HomeHandle can be obtained, serialized, and used. // Obtain cabin 100. Context jndiContext = getInitialContext(); Object ref = jndiContext.lookup(”CabinHome”); CabinHomeRemote home = (CabinHomeRemote) PortableRemoteObject.narrow(ref,CabinHomeRemote.class); // Serialize the HomeHandle for the cabin bean. HomeHandle homeHandle = home.getHomeHandle(); FileOutputStream fos = new FileOutputStream(”handle.ser”); ObjectOutputStream outStream = new ObjectOutputStream(fos); outStream.writeObject(homeHandle); outStream.flush(); fos.close(); homeHandle = null; // Deserialize the HomeHandle for the cabin bean. FileInputStream fis = new FileInputStream(”handle.ser”); ObjectInputStream inStream = new ObjectInputStream(fis); homeHandle = (HomeHandle)inStream.readObject(); fis.close(); EJBHome home = homeHandle.getEJBHome(); CabinHomeRemote home2 = (CabinHomeRemote) PortableRemoteObject.narrow(home,CabinHomeRemote.class); Copyright (c) 2001 O’Reilly & Associates
Have all the commercials and ads about web hosting companies given you headache? Relax now.Our recommendation is web hosting comparisons.
Posted in Java Server Pages Blog | No Comments »