Information Technology Reference
In-Depth Information
agent.setName("Tom");
agent.setPwd("***");
System.out.println ("agent = "+agent);
S
AMPLE
9. Updating an Agent.
agent = [EJB class = com.ibm.oats.test.disco.order.OATSBMPAgentJDBC,
key = fad895da00000103000000012a571211779bd88c, contents = AgentBean
=[name=Tom, pwd=***]
S
AMPLE
10. Printing the State of an Agent EJB.
final Agent
agentByPK = agentHome.findByPrimaryKey(uuid);
S
AMPLE
11. Retrieving an Agent via its Primary Key.
final Collection agentCollection = agentHome.findAll();
final Iterator agentIterator = agentCollection.iterator();
while (agentIterator.hasNext()) {
System.err.println ("agent="+agentIterator.next());
}
S
AMPLE
12. Retrieving a Collection of Agents
is not immutable, and does not even have to be set to a value, since it is not used for
identity mapping.
EJBs are updated via the component interface.
Sample 9
shows how clients update
the Agent state. The output from printing the Agent EJB is shown in
Sample 10
.
Unlike SDOs (see
Sample 3
), there is no dynamic get/set API for EJBs, other than
the standard Java Reflection API.
An EJB can always be retrieved via its
primary key
since an EJB is required to have
a unique identity with respect to its Home. In addition, EJBs can also be retrieved via
“custom queries” that may be optionally declared on the EJB's Home. Such queries
can either return a single EJB instance or multiple EJB instances that match the query
predicate.
Sample 11
shows how a single Agent is retrieved via its primary key.
Sample 12
shows how multiple Agent instances are retrieved through a custom
query that specifies “all Agents.”
Finally,
Sample 13
shows two ways to delete an Agent EJB.