Native Queries

We have checked in the SODA topic that SODA queries can work with a server without application classes deployed. So we can expect optimized Native Queries (converted to SODA under the hood) to work as well:

Client.java: getPilotsNative
01private static void getPilotsNative() throws IOException { 02 System.out.println("Retrieving Pilot objects: Native Query"); 03 ObjectContainer oc = Db4o.openClient("localhost", 0xdb40, "db4o","db4o"); 04 try { 05 List <Pilot> result = oc.query(new Predicate<Pilot>() { 06 public boolean match(Pilot pilot) { 07 return pilot.getPoints() == 5; 08 } 09 }); 10 listResult(result); 11 } finally { 12 oc.close(); 13 } 14 }

Unfortunately, if the query cannot be optimized to SODA, the server needs to instantiate the classes to run the query. This is not possible if the class is not available

This query won't work:

Client.java: getPilotsNativeUnoptimized
01private static void getPilotsNativeUnoptimized() throws IOException { 02 System.out.println("Retrieving Pilot objects: Native Query Unoptimized"); 03 ObjectContainer oc = Db4o.openClient("localhost", 0xdb40, "db4o","db4o"); 04 try { 05 List <Pilot> result = oc.query(new Predicate<Pilot>() { 06 public boolean match(Pilot pilot) { 07 return pilot.getPoints() % 2 == 0; 08 } 09 }); 10 listResult(result); 11 } finally { 12 oc.close(); 13 } 14 }