Simple Selection

The following examples show how to use NQ to select all objects of the specified type from a database. Store Pilots function is used to fill in the database.

SelectAllPilots

For languages with generics support (Java5-6; .NET2.0-3.0):

SimpleExamples.java: selectAllPilots
01private static void selectAllPilots() { 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 // each Pilot is included in the result 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 }

SelectAllPilotsNonGeneric

For languages without generics support (Java1.1-1.4; .NET1.0):

SimpleExamples.java: selectAllPilotsNonGeneric
01private static void selectAllPilotsNonGeneric() { 02 ObjectContainer container = database(); 03 if (container != null) { 04 try { 05 List result = container.query(new Predicate() { 06 public boolean match(Object object) { 07 // each Pilot is included in the result 08 if (object instanceof Pilot) { 09 return true; 10 } 11 return false; 12 } 13 }); 14 listResult(result); 15 } catch (Exception ex) { 16 System.out.println("System Exception: " + ex.getMessage()); 17 } finally { 18 closeDatabase(); 19 } 20 } 21 }