This example shows how to modify the query output without effecting the objects in the database. Store Pilots function is used to fill in the database.
01private static void selectAndChangePilots() { 02
ObjectContainer container = database(); 03
if (container != null) { 04
try { 05
List<Pilot> result = container.query(new Predicate<Pilot>() { 06
public boolean match(Pilot pilot) { 07
// Add ranking to the pilots during the query. 08
// Note: pilot records in the database won't 09
// be changed!!! 10
if (pilot.getPoints() <= 5) { 11
pilot.setName(pilot.getName() + ": weak"); 12
} else if (pilot.getPoints() > 5 13
&& pilot.getPoints() <= 15) { 14
pilot.setName(pilot.getName() + ": average"); 15
} else if (pilot.getPoints() > 15) { 16
pilot.setName(pilot.getName() + ": strong"); 17
} 18
return true; 19
} 20
}); 21
listResult(result); 22
} catch (Exception ex) { 23
System.out.println("System Exception: " + ex.getMessage()); 24
} finally { 25
closeDatabase(); 26
} 27
} 28
}