Select Methods Sample

A select method is a private method that can only be used internally by a CMP entity bean class, that is, it is not defined in the bean's interfaces. The method can return (local or remote) references to the entity beans or the values of an individual CMP field that match an EJB QL or WebLogic QL query. This sample shows mostly common select methods that return the values of an individual CMP fields. Because select methods can only be used internally, various business methods are defined that use these select methods.

Note. For more examples of (WebLogic) EJB QL queries that returns references entity beans, see the Finder Methods Sample. For examples of a select method that is used by various home methods, see the Home Methods Sample.

In the example, an ItemsBean_S EJB models the persistent data in a prefilled database table, representing an inventory of products. Each items has a product name, a quantity that is in stock, and a price. In addition, this EJB has an entity relationship with the ManufacturerBean_S EJB, which holds information about the various manufacturers known for these products. Each product has one manufacturer, and a manufacturer has multiple products. Various select methods are used to obtain information about the items in the database. For each select method a home method is created with a matching name that simply returns the results of the select method as a String. For more information on common uses of home methods, see the Home Methods Sample mentioned above.

Concepts Demonstrated by this Sample

Location of Sample Files

The code of the CMP entity bean is located in the selectMethods folder of the EJBs project in the SamplesApp sample application. In the file system the location is:

BEA_HOME\weblogic81\samples\workshop\SamplesApp\EJBs\selectMethods\ItemsBean_S.ejb

The web service that you run as a client application to test the EJB, and the EJB control that you use to locate and reference the EJB, are located in the selectMethods folder of the EJBs_ClientApps project in the SamplesApp sample application. In the file system the location of the web service is:

BEA_HOME\weblogic81\samples\workshop\SamplesApp\EJBs_ClientApps\selectMethods\ItemsBeanControlTest.jws

To Run the Sample

  1. Start WebLogic Server in the appropriate domain.
  1. Launch the test web service either by opening it in WebLogic Workshop and selecting the Start operation or by entering http://localhost:7001/EJBs_ClientApps/selectMethods/ItemsBeanControlTest.jws in the address bar of your browser. If WebLogic Server is running in the appropriate domain on this machine, you may click here to run the sample.
  2. Navigate to the Test Form tab of Test View, if necessary.
  3. Invoke the startTestDrive method to create a new conversational instance.
  4. Click continue this conversation.
  5. Browse through the select methods and decide which one you would like to run. Follow the instructions given for the method and observe the outcome.
  6. Repeat the last two steps for the next select method you would like to run.

Related Topics

Home Methods Sample

@ejbgen:select Annotation