January 19th, 2008
Writing the session bean class Writing the session bean class To create a session bean class, 1 Create a class that implements the javax.ejb.SessionBean interface. 2 Implement one or more ejbCreate() methods. If you are creating a stateless session bean, the class implements just one parameterless ejbCreate() method. If you ve already created the remote home or local home interface for the bean, the bean must have an ejbCreate() method with the same signature for each create() method in the remote home/local home interface. 3 Define and implement the business methods you want your bean to have. If you ve already created the remote or local interface for the bean, the methods must be defined exactly as they are in the remote/local interface. JBuilder s EJB tools can start these tasks for you, including creating the home and remote interfaces. They create a class that extends the SessionBean interface and write empty implementations of the SessionBean methods. You fill in the implementations if your bean requires them. The next section explains what these methods are and how they are used. Implementing the SessionBean interface The SessionBean interface defines the methods all session beans must implement. It extends the EnterpriseBean interface. package javax.ejb; public interface SessionBean extends EnterpriseBean { void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException; void ejbRemove() throws EJBException, RemoteException; void ejbActivate() throws EJBException, RemoteException; void ejbPassivate() throws EJBException, RemoteException; } The methods of the SessionBean interface are closely associated with the life cycle of a session bean. This table explains their purpose: Method Description setSessionContext() Sets a session context. The bean s container calls this method to associate a session bean instance with its context. The session context interface provides methods to access the runtime properties of the context in which a session runs. Usually a session bean retains its context in a data field. ejbRemove() Notifies a session object that it is about to be removed. The container calls this method whenever it removes a stateful session bean as a result of the client calling a remove() method of the remote/local or remote home/local home interface. ejbActivate() Notifies a stateful session object that has been activated. ejbPassivate() Notifies a stateful session object that it is about to be deactivated by the container. The ejbActivate() and ejbPassivate() methods allow a stateful session bean to manage resources. 150 Developing Applications with Enterprise JavaBeans
We are here to provide web hosting at an affordable rate for the online Christian community. The term “Christian” is used by various groups with diverse beliefs to describe themselves. Some people, including many born-again Christians, use a fairly specific definition of “Christian”. They believe that in order to be a Christian, one must follow Jesus, and that the proof of this is found in agreeing to and following the doctrines set forth in the Bible. Others who refer to themselves as Christians require only that one believes that Jesus is the Son of God, that he died, and that he was resurrected from the dead, to claim the term Christian.Check Christian Web Hosting section.
Posted in JBuilder Blog | No Comments »
January 18th, 2008
Chapter 15 Developing session beans JBuilder s EJB tools can greatly simplify the creation of enterprise beans and their supporting interfaces. You should understand what the requirements are for these classes and interfaces, however, so you can modify the files JBuilder produces and so you understand what JBuilder is doing for you. The next few chapters can help you gain that understanding. A session bean usually exists for the lifetime of a single client session. The methods of a session bean perform a set of tasks or processes for the client that uses the bean. Session beans persist only for the life of the connection with the client. In a sense, the session bean represents the client in the EJB server. It usually provides a service to the client. Unless you need to work with persistent data that exists in a data store, you are usually working with session beans. Types of session beans There are two types of session beans: those that can maintain state information between method calls, which are called stateful beans, and those that can t, which are called stateless beans. Stateful session beans Stateful session beans are objects used by a single client and they maintain state on behalf of that client. For example, consider a shopping cart session bean. As the shopper in an online store selects items to purchase, the items are added to the shopping cart by storing the selected items in a list within the shopping cart session bean object. When the shopper is ready to purchase the items, the list is used to calculate the total cost. Stateless session bean Stateless session beans don t maintain state for any specific client. Therefore, they can be used by many clients. For example, consider a sort session bean that contains a sortList() business method. The client would invoke sortList(), passing it an unsorted list of items. sortList() would then pass back to the client a sorted list. Chapter 15: Developing session beans 149
Don’t want to have just any web hosting, but web hosting provider who will share the same beliefs? You have found them. Our Church Web Hosting company will treat in you in appropriate way, the one you are accustomed to.
Posted in JBuilder Blog | No Comments »
January 18th, 2008
148 Developing Applications with Enterprise JavaBeans
We strive to offer the highest quality service while maintaining a cheap and discount price structure. For your company, ecommerce, or personal web hosting needs, we offer the best solution.Trust us and please check quality web hosting services.
Posted in JBuilder Blog | No Comments »
January 17th, 2008
Handling relationships public PersonnelDataModule() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { try { sessionBeanConnection.setJndiName(”Personnel”); sessionBeanConnection.addCreateSessionBeanListener(new com.borland.dx.ejb.CreateSessionBeanListener() { public void creating(CreateSessionBeanEvent e) { sessionBeanConnection_creating(e); } }); personnelDataSet.setSessionBeanConnection(sessionBeanConnection); personnelDataSet.setMethodName(”Personnel”); } catch (Exception ex) { } } public static PersonnelDataModule getDataModule() { if (myDM == null) { myDM = new PersonnelDataModule(); } return myDM; } public com.borland.dx.ejb.SessionBeanConnection getSessionBeanConnection() { return sessionBeanConnection; } public com.borland.dx.ejb.EjbClientDataSet getPersonnelDataSet() { return personnelDataSet; } void sessionBeanConnection_creating(CreateSessionBeanEvent e) { } } Handling relationships The EntityBeanProvider automatically flattens relationships. For example, if you have any Employee entity bean that has a getDept() method that returns a Dept, where Dept is an entity bean remote, a DataSet is created that has all the fields in the Employee entity bean plus all the fields in the Dept entity bean (including any hidden columns containing the primary keys of each of the entity beans). Except for Dept.ejbPrimaryKey, the other Dept fields will be read-only. To resolve changes when a one-to-one relationship is involved, you must add an event listener to the EntityBeanProvider because it can t dynamically determine the home of the related entity bean. Chapter 14: Using the DataExpress for EJB components 147
Our facility is located in Orlando, Florida. Our Orlando web hosting data center gives you assurance that your website will work smoothly . Check more in Orlando Web Hosting.
Posted in JBuilder Blog | No Comments »
January 16th, 2008
Building the client side In this example, the event handler calls a findAll() method to return all the entity beans. You can call any finder you want. You could use the EntityBeanProvider’s parameterRow property to dynamically determine which finder to call and/or which parameters to pass. For resolving, the EntityBeanResolver can by default determine how to apply updates and deletes. But it can t automatically determine how to create new entity beans because there is no way it can determine which create() method to call and which parameters to pass to it. So, if you want to add a row to the data source, you must add the create event yourself and supply the necessary logic. You can use the Inspector to add the skeleton create event code to your session bean. You can see an example of a create event in the EjbDx.jpx sample project. You can also use the other events available in EntityBeanResolver to override the default behavior, if you choose. Deploy the session and entity beans to the application server. For more information about deploying your beans, see Deploying to an application server on page 112. Building the client side Now that you ve created the entity beans and the session bean that accesses them and deployed them to your target application server, you re ready to begin building the client. Follow these steps: 1 Create a data module. Choose File|New|General|Data Module. 2 From the component palette, select the EjbClientDataSet and add it to the data module. 3 From the component palette, select the SessionBeanConnection and add it to the data module. 4 In the Inspector, set the sessionBeanConnection property of the EjbClientDataSet to the name of the SessionBeanConnection component. 5 In the Inspector, specify a name for the methodName property of the EjbClientDataSet component. The methodName property determines how the methods that provide and resolve data are named. For example, if you specify a value of Employee for methodName, the session bean methods to provide and resolve data become provideEmployee() and resolveEmployee(). Later you will need to add these methods to the session bean you create. 6 In the Inspector or directly in the source code, set the jndiName property of the SessionBeanConnection component. Or you can specify the name of the remote interface of the session bean you will create instead as the value of the sessionBeanRemote property. You can also use the Inspector to add a creating event to your SessionBeanConnection. Code you add to the event handler can control the creation of the session bean after the JNDI lookup occurs. Usually you must add a creating event if you want to invoke a create() method on the home interface that requires parameters. For example, look at this code: import com.borland.dx.dataset.*; import com.borland.dx.ejb.*; public class PersonnelDataModule implements DataModule { private static PersonnelDataModule myDM; SessionBeanConnection sessionBeanConnection = new SessionBeanConnection(); EjbClientDataSet personnelDataSet = new EjbClientDataSet(); 146 Developing Applications with Enterprise JavaBeans
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 JBuilder Blog | No Comments »
January 15th, 2008
Creating the server-side session bean The resolver must call the method of an EntityBeanConnection class that resolves any updates to the entity beans. This is how resolveEmployee() should appear: public DataSetData[] resolveEmployee(DataSetData[] dataSetDataArray) { return EntityBeanConnection.saveChanges(dataSetDataArray, new DataSet[] {employeeDataSet}); } Next add these methods to the remote interface. The simplest way to do this is to use the EJB designer. In the bean representation in the EJB designer, click a new method you just added and in the method inspector that appears, select Remote or Local from the Interfaces drop-down list. Or you can use BeansExpress. With the bean source file open in the editor, click the Bean tab, click the Methods tab, and check the check boxes next to the names of the two methods you just added. You can now check your session bean s remote interface (or local interface for a 2.0 bean if that is the interface you chose to define the methods in) to verify that the two methods are now defined. If you chose to define the methods in the remote interface, this is how it would look: public interface Personnel extends EJBObject { public com.borland.dx.dataset.DataSetData[] providePersonnel(com.borland.dx.ejb.RowData[] parameterArray, com.borland.dx.ejb.RowData[] masterArray) throws RemoteException; public com.borland.dx.dataset.DataSetData[] resolvePersonnel(com.borland.dx.dataset.DataSetData[] dataSetDataArray) throws RemoteException; } Calling the finder method You must tell the EntityBeanProvider which entity beans to provide. To do this, add an event to the EntityBeanProvider: 1 While in the UI designer, select the EntityBeanProvider in the structure pane. 2 Click the Events tab of the Inspector and double-click the blank column next to the findEntityBeans event. A new event is added. Here is the resulting event: entityBeanProvider1.addEntityBeanFindListener(new com.borland.dx.ejb.EntityBeanFindListener() { public void findEntityBeans(EntityBeanFindEvent e) { entityBeanProvider1_findEntityBeans(e); } }); … void entityBeanProvider_findEntityBeans(EntityBeanFindEvent e) { } 3 To the new event handler, add a finder method to return the entity beans you want. Here the added code appears in bold: void entityBeanProvider_findEntityBeans(EntityBeanFindEvent e) { try { e.setEntityBeanCollection(employeeHome.findAll()); } catch (Exception ex) { throw new EJBException(ex); } } Chapter 14: Using the DataExpress for EJB components 145
Our unmatched NT experience allows us to provide the most reliable and affordable hosting for our customers, just check NT Web Hosting services.
Posted in JBuilder Blog | No Comments »
January 14th, 2008
Creating the server-side session bean EmployeeHome.class); entityBeanProvider.setEjbHome(employeeHome); entityBeanResolver.setEjbHome(employeeHome); } catch (Exception ex) { throw new EJBException(ex); } } Note that setSessionContext() sets the value of the ejbHome properties in the EntityBeanProvider and EntityBeanResolver components to the name of the home interface of the Employee entity bean. Adding an EJB reference or EJB local reference to the deployment descriptor You must add an EJB reference to Personnel in the deployment descriptor for the lookup to work. For an entity bean with local interfaces, you must add an EJB local reference instead. You can use the EJB DD editor: 1 In the project pane, double-click the EJB module node. For the sample project, this is the personnel module. 2 Double-click the personnel module in the project pane and click the EJB DD Editor tab. The EJB DD editor appears. 3 Expand the Personnel bean in the structure pane until you can see the EJB References node (or the EJB Local References node for an EJB 2.0 bean) in the EJB DD editor. 4 Right-click the EJB References or EJB Local References node and choose Add to add a reference to the entity bean containing the data you are interested in. A new page appears in the EJB DD editor. 5 Enter a reference name. For the sample project, the name is ejb/Employee. 6 Use the Link drop-down list to select the bean you are referring to. 7 Use the Type drop-down list to specify whether the bean you are referring to is an entity or a session bean. The rest of the data should fill in for you automatically. You can enter an optional description if you like. Adding the providing and resolving methods You must add two methods to the session bean, a provider and a resolver. The names of these methods use the value you specified as the methodName property value in the EjbClientDataSet component. So the provider for PersonnelBean becomes provideEmployee() and the resolver becomes resolveEmployee(). The provider must call the method of an EntityBeanConnection class that provides the data from an entity bean to a dataset that can be sent over the wire. This is what the provideEmployee() method must look like: public DataSetData [] provideEmployee(RowData[] parameterArray, RowData[] masterArray) { return EntityBeanConnection.provideDataSets(new StorageDataSet[] {employeeDataSet}, parameterArray, masterArray); } 144 Developing Applications with Enterprise JavaBeans
Our Colorado hosting facilities are located in Little Rock, Colorado. Colorado web hosting datacenter which we have is linked on five major US backbones which gives you assurance that your site will be online 24/7 a day. More details you can find out in Web Hosting Colorado part.
Posted in JBuilder Blog | No Comments »
January 13th, 2008
Creating the server-side session bean public void ejbActivate() throws RemoteException { } public void ejbPassivate() throws RemoteException { } public void setSessionContext(SessionContext sessionContext) throws RemoteException { this.sessionContext = sessionContext; } } Click the Design tab to display the UI designer. Adding provider and resolver components to the session bean From the EJB page of the component palette, add an EntityBeanProvider and an EntityBeanResolver to the session bean. If you are working with an 2.0 enterprise bean, add a LocalEntityBeanProvider and a LocalEntityBeanResolver instead. You must also add a dataset component to hold the data gathered from the entity beans before it is sent to the client and the data that the client sends back. From the DataExpress page of the component palette, add a TableDataSet component and rename TableDataSet to some appropriate name. This is how the top of PersonnelBean would look; the TableDataSet has been renamed to employeeDataSet: public class PersonnelBean implements SessionBean { private SessionContext sessionContext; EntityBeanProvider entityBeanProvider = new EntityBeanProvider(); EntityBeanResolver entityBeanResolver = new EntityBeanResolver(); TableDataSet employeeDataSet = new TableDataSet(); … Using the Inspector, set the provider and resolver properties of the TableDataSet to the newly added EntityBeanProvider and EntityBeanResolver components, respectively. The result is two new methods in the jbInit() method: employeeDataSet.setProvider(entityBeanProvider); employeeDataSet.setResolver(entityBeanResolver); To the members of this class, add a reference to the home interface of the entity bean that contains the data you want to access. For this example, the reference is to the home interface of the Employee entity bean as shown here in bold. public class PersonnelBean implements SessionBean { private SessionContext sessionContext; EntityBeanProvider entityBeanProvider = new EntityBeanProvider(); EntityBeanResolver entityBeanResolver = new EntityBeanResolver(); TableDataSet employeeDataSet = new TableDataSet(); EmployeeHome employeeHome; … Writing the setSessionContext() method In the session bean s sessionContext() method add a try block. Modify the method so that it looks like this: public void setSessionContext(SessionContext sessionContext) throws RemoteException { this.sessionContext = sessionContext; try { Context context = new InitialContext(); Object object = context.lookup(”java:comp/env/ejb/Employee”); employeeHome = (EmployeeHome) PortableRemoteObject.narrow(object, Chapter 14: Using the DataExpress for EJB components 143
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 JBuilder Blog | No Comments »
January 12th, 2008
Creating the entity beans Components for the server The two components on the EJB page of the component palette that are used by the session bean deployed on the server are the EntityBeanProvider and EntityBeanResolver components. EntityBeanProvider provides data from the entity beans deployed on the server, and EntityBeanResolver resolves data to those entity beans. You add these components to the session bean you create to make the session bean capable of providing from and resolving to the entity beans. If you are creating enterprise beans that run in an EJB 1.x container, you should continue using the EntityBeanProvider and EntityBeanResolver components. If your beans are going to be running in an EJB 2.0 container, you should use the LocalEntityBeanProvider and LocalEntityBeanResolver components instead. These components have an ejbLocalHome property instead of an ejbHome property. They also have an ejbLocal property, which takes the class of the entity bean s interface that implements EJBLocalObject. All the events and listeners in the EntityBeanProvider and EntityBeanResolver components have corresponding local versions in LocalEntityBeanProvider and LocalEntityBeanResolver. Components for the client Two of the components on the EJB page are used in the client side: EjbClientDataSet and SessionBeanConnection. The EjbClientDataSet provides data from and resolves changes to the session bean referenced in the SessionBeanConnection. A SessionBeanConnection holds the reference to a session bean on the server, and it contains the method names to provide datasets from and resolve datasets to that session bean. Creating the entity beans Begin by using the EJB 1.x Entity Modeler or the EJB designer to create the entity beans that access the data you are interested in. The sample project creates Employee and Department entity beans, although this chapter refers only to Employee. For information about creating EJB 1.x entity beans using the EJB 1.x Entity Bean Modeler, see Chapter 9, Creating EJB 1.x entity beans from an existing database table. For information about creating EJB 2.0 or 1.1 entity beans with the EJB designer, see Chapter 6, Creating entity beans with the EJB designer. Creating the server-side session bean Create the session bean that will live on the server. Consider using the Enterprise JavaBean 1.x wizard or the EJB designer to create a stateless session bean. Later in the next section you ll be adding EntityBeanProvider and EntityBeanResolver classes to this bean. Because these classes aren t serializable, it s easier to place them in a stateless session bean, which, for Borland application servers, is never passivated. If you require a stateful session bean for your application, you should either have the stateful session bean refer to a stateless session bean, or you must reinstantiate the EntityBeanProvider and EntityBeanResolver when the stateful session bean is activated. Here is what a resulting bean class named PersonnelBean would look like: public class PersonnelBean implements SessionBean { private SessionContext sessionContext; public void ejbCreate() { } public void ejbRemove() throws RemoteException { } 142 Developing Applications with Enterprise JavaBeans
Would you like to be a member of headache free web site owner’s community. Now you can. We focus in IX Web Hosting, go go go!
Posted in JBuilder Blog | No Comments »
January 11th, 2008
Chapter 14 Using the DataExpress for EJB components JBuilder has several components that allow you to retrieve data from entity beans into DataExpress DataSets (providing), and to save data from DataExpress DataSets back to entity beans (resolving). These DataExpress for EJB components make it easy to implement a Session Bean wrap Entity Bean or Session Facade design pattern. Using this design pattern, clients usually don t access entity beans directly, but instead they access them using session beans. The session beans, which are co-located with the entity beans, make all the calls to the entity beans within a single transaction and then return all the data at once. DataSets provide a way of transporting the data from the session bean to the client and back. Because data is sent over the wire just once to provide the data to the client, and then just once again to resolve changes to the entity beans on the server, performance improves. These components also make it easier for you to build client applications using DataExpress-aware visual components such as dbSwing or InternetBeans Express. For a full description of DataExpress, see the Developing Database Applications book. This chapter explains how to use these components to transfer data from entity beans deployed on a server to your client application and back again. The data the sample accesses is stored in an Employee data store. The sample creates an entity bean to hold Employee data. It also creates a Personnel session bean that retrieves data from Employee and then sends it to the client. The client sends the data back to the Personnel, which resolves the data to the Employee entity bean instances. Note If you are using JDK 1.4, you won t be able to view live data with the DataExpress for EJB components in the UI designer using the Borland Enterprise Server 5.2.1. The DataExpress EJB components Six of the DataExpress EJB components are on the EJB page of the component palette. You can work with these components in the UI designer, setting properties and events using the Inspector. There are additional classes that your code can call that you don t work with visually. For information about all of the classes, see the API Reference. Chapter 14: Using the DataExpress for EJB components 141
Adult web hosting has rich experience in providing unique solutions for the customer’s needs, just check frontpage web hosting services.
Posted in JBuilder Blog | No Comments »