Combined Result Sets

This set of examples shows how to use NQ to select objects from more than one result sets. Store Cars and Store Persons functions are used to fill in the database. 

SelectPilotsAndTrainees

Selects all pilots and trainees using Person superclass. 

MultiExamples.java: selectPilotsAndTrainees
01private static void selectPilotsAndTrainees() { 02 ObjectContainer container = database(); 03 if (container != null) { 04 try { 05 List<Person> result = container.query(new Predicate<Person>() { 06 public boolean match(Person person) { 07 // all persons 08 return true; 09 } 10 }); 11 listResult(result); 12 } catch (Exception ex) { 13 System.out.println("System Exception: " + ex.getMessage()); 14 } finally { 15 closeDatabase(); 16 } 17 } 18 }

SelectPilotsInRange

Selects all cars that have pilot field in the preselected Pilot array. 

MultiExamples.java: selectPilotsInRange
01private static void selectPilotsInRange() { 02 ObjectContainer container = database(); 03 if (container != null) { 04 try { 05 List<Car> result = container.query(new Predicate<Car>() { 06 private List<Pilot> pilots = null; 07 08 private List getPilotsList() { 09 if (pilots == null) { 10 pilots = database().query(new Predicate<Pilot>() { 11 public boolean match(Pilot pilot) { 12 return pilot.getName().startsWith("Test"); 13 } 14 }); 15 } 16 return pilots; 17 } 18 19 public boolean match(Car car) { 20 // all Cars that have pilot field in the 21 // Pilots array 22 return getPilotsList().contains(car.getPilot()); 23 } 24 }); 25 listResult(result); 26 } catch (Exception ex) { 27 System.out.println("System Exception: " + ex.getMessage()); 28 } finally { 29 closeDatabase(); 30 } 31 } 32 }