SODA query API gives you a possibility to sort any field in ascending or descending order and combine sorting of different fields. For example, let's retrieve the objects of the Pilot class saved before, sorting "points" field in descending order and "name" field in ascending.
01public static void getObjectsSODA() { 02
03
ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 04
try { 05
Query query = container.query(); 06
query.constrain(Pilot.class); 07
query.descend("name").orderAscending(); 08
query.descend("points").orderDescending(); 09
long t1 = System.currentTimeMillis(); 10
ObjectSet result = query.execute(); 11
long t2 = System.currentTimeMillis(); 12
long diff = t2 - t1; 13
System.out.println("Time to query and sort with SODA: " 14
+ diff + " ms."); 15
listResult(result); 16
} finally { 17
container.close(); 18
} 19
}
Obvious disadvantages of this method:
The valuable advantage of this method is its high performance.