Lookups and Searches
Before a client can make any changes to an object, it needs to find that object. There are three scenarios for getting a reference to a distributed component:
Looking it up by its unique identifier
Searching for it based on a set of criteria
Asking another related component for a reference to it
The last scenario is the simplest and begs the question of the other
two. Specifically, given a reference to a Customer
component, you should be able to get all of that
Customer’s Account
objects. How did you get a reference to that
Customer in the first place?
EJB uses a kind of meta-component called a home to manage operations on a component as a class, including lookups, searches, and creates. Whether you call it a home or something else, a distributed database application needs some way to get access to the business objects stored on the server. You will take advantage of the home metaphor, but you’ll put a new spin on it.
Getting a reference to an object using its unique identifier is
fairly simple. A find( )
method
in the home accepts an Identifier and an
objectID as parameters and returns a reference to
the component identified by that objectID:
public abstract Account find(Identifier id,
long oid)
throws FindException;Using the persistence library that will be
discussed in Chapter 9, you can then search the
persistence store for an object that has the specified
objectID.
Performing searches on criteria other than a unique identifier gets more complex. First, because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access