QBE

If we have a prototype and want to find out if there is an object in the database with the same field values, we can simply use QBE:

EqualityExample.java: retrieveEqual
01private static void retrieveEqual() { 02 ObjectContainer container = database(); 03 if (container != null) { 04 try { 05 ObjectSet result = container.get(new Pilot("Kimi Raikkonnen", 100)); 06 if (result.size() > 0){ 07 System.out.println("Found equal object: " + result.next().toString()); 08 } else { 09 System.out.println("No equal object exist in the database"); 10 } 11 } catch (Exception ex) { 12 System.out.println("System Exception: " + ex.getMessage()); 13 } finally { 14 closeDatabase(); 15 } 16 } 17 }

This method allows to combine retrieval and comparing in one operation.