|
Contact Search
Listing 4. The findContact() method uses db4o's query() method to fetch a contact using the native query defined in Listing 3. public ContactDetail findContact(
String criterion, String searchVal)
{
// reset iterator and current contact
results = null;
currentContact = new ContactDetail();
// If there's nothing in the search value,
// just exit
if(searchVal.equals("")) return details;
// Set search criterion
cdQuery.setSearchCriterion(criterion);
cdQuery.setSearchString(searchVal);
// Fetch the results
results = addressbook.query(cdQuery);
if(results.hasNext())
currentContact = (ContactDetail) (results.next());
return details;
}
|