The auction house search facility is implemented as a container-managed
finder . method. It starts when
the end user types in a search string and clicks the Submit
button on the home page to locate an auction item. As shown in the diagram,
the browser passes the search string to the AuctionServlet.searchItem
method, which then passes it to the BidderBean.getMatchingItemsList method.
At this point,
BidderBean.getMatchingItemsList passes
the search string to the findAllMatchingItems
method declared in the AuctionItemHome interface.
This method is a finder method, and container implementations
vary in how they handle calls to finder methods.
BEA Weblogic
containers look in the Bean's deployment descriptor for information
on a Bean's finder methods.
In the case of the search, the deployment descriptor maps the search string
passed to AuctionItemHome.findAllMatchingItems
to the summary field in the underlying
AuctionItems database table.
This tells the Enterprise JavaBeansTM server to retrieve data for all
auction items with a summary field that contains text
that matches the search string.
This section walks through the different parts of the
finder -based search code. Chapter 3 describes how
to create a Bean-managed search to handle complex
queries and searches that span more than one Bean type (entity and
session Beans) or database tables.
AuctionServlet.searchItems
The searchItems method retrieves the text
string from the browser, creates an
HTML page to display the search results,
and passes the search string to the
BidderBean.getMatchingItemsList method.
BidderBean is a session Bean that retrieves
lists of auction items and checks the user ID and
password for end users seeking to bid on auction items.
The search results are returned to this method
in an Enumeration variable.
private void searchItems(ServletOutputStream out,
HttpServletRequest request)
throws IOException {
//Retrieve search string
String searchString=request.getParameter(
"searchString");
//Create HTML page
String text = "Click Item number for description
and to place bid.";
setTitle(out, "Search Results");
try {
addLine("<BR>"+text, out);
//Look up home interface for BidderBean
BidderHome bhome=(BidderHome) ctx.lookup(
"bidder");
//Create remote interface for BidderBean
Bidder bid=bhome.create();
//Pass search string to BidderBean method
Enumeration enum=(Enumeration)
bid.getMatchingItemsList(searchString);
if(enum != null) {
displayitems(enum, out);
addLine("", out);
}
} catch (Exception e) {
addLine("AuctionServlet Search Items error",
out);
System.out.println("AuctionServlet <newlist>:
"+e);
}
out.flush();
}
BidderBean.getMatchingItemsList
The BidderBean.getMatchingItemsList
method calls the AuctionItemHome.findAllMatchingItems
method and passes it the search string.
AuctionItemBean is an entity Bean that handles
auction item updates and retrievals.
The search results are returned to this method
in an Enumeration variable.
public Enumeration getMatchingItemsList(
String searchString)
throws RemoteException {
Enumeration enum=null;
try{
//Create Home interface for AuctionItemBean
AuctionItemHome home = (AuctionItemHome)
ctx.lookup("auctionitems");
//Pass search string to Home interface method
enum=(Enumeration)home.findAllMatchingItems(
searchString);
}catch (Exception e) {
System.out.println("getMatchingItemList: "+e);
return null;
}
return enum;
}
AuctionItemHome.findAllMatchingItems
The AuctionItemHome.findAllMatchingItems
method is not implemented in AuctionItemBean .
The AuctionItemBean finder method implementations
are defined in the AuctionItemBean deployment descriptor
when BEA Weblogic
containers are used.
When using these containers, even if the
Bean has finder method implementations, they are
ignored and the deployment descriptor settings are consulted instead.
//Declare method in Home interface
public Enumeration findAllMatchingItems(
String searchString)
throws FinderException, RemoteException;
AuctionItemBean Deployment Descriptor
When a Bean's finder method is called, the container
consults the deployment descriptor for that Bean to find out
what data the finder method needs to retrieve from
the underlying database table. The container passes this information
to the Enterprise JavaBeans server, which does the actual retrieval.
The deployment descriptor for AuctionItemBean
provides finderDescriptors for all finder
methods declared in the AuctionItemHome interface.
The finderDescriptor for the
findAllMatchingItems method maps the search string
to the summary field in the underlying
AuctionItems database table.
This tells the Enterprise JavaBeans server to retrieve the
data for all table rows with a summary field that matches
the text in the search string.
(finderDescriptors
"findAllItems()" "(= 1 1)"
"findAllNewItems(java.sql.Date newtoday)"
"(= startdate $newtoday)"
"findAllClosedItems(java.sql.Date closedtoday)"
"(= enddate $closedtoday)"
"findAllMatchingItems(String searchString)"
"(like summary $searchString)"
); end finderDescriptors
[TOP]
|