This is the default query mode: the whole query result is evaluated upon query execution and object IDs list is produced as a result.
01private static void testImmediateQueries() { 02
System.out 03
.println("Testing query performance on 10000 pilot objects in Immediate mode"); 04
fillUpDB(10000); 05
Configuration configuration = Db4o.newConfiguration(); 06
configuration.queries().evaluationMode(QueryEvaluationMode.IMMEDIATE); 07
ObjectContainer container = Db4o.openFile(configuration, DB4O_FILE_NAME); 08
try { 09
QueryStats stats = new QueryStats(); 10
stats.connect(container); 11
Query query = container.query(); 12
query.constrain(Pilot.class); 13
query.descend("points").constrain(99).greater(); 14
query.execute(); 15
long executionTime = stats.executionTime(); 16
System.out.println("Query execution time: " 17
+ executionTime); 18
} finally { 19
container.close(); 20
} 21
}
Obviously object evaluation takes some time and in a case of big resultsets you will have to wait for a long time before the first result will be returned. This is especially unpleasant in a client-server setup, when query processing can block the server for seconds or even minutes.
This mode makes the whole objects result set available at once - ID list is built based on the committed state in the database. As soon as a result is delivered it won't be changed neither by changes in current transaction neither by committed changes from another transactions.
Note, that resultset contains only references to objects, you were querying for, which means that if an object field has changed by the time of the actual object retrieval from the object set - you will get the new field value:
01private static void testImmediateChanged() { 02
System.out 03
.println("Testing immediate mode with field changes"); 04
fillUpDB(10); 05
Configuration configuration = Db4o.newConfiguration(); 06
configuration.queries().evaluationMode(QueryEvaluationMode.IMMEDIATE); 07
ObjectContainer container = Db4o.openFile(configuration, DB4O_FILE_NAME); 08
try { 09
Query query1 = container.query(); 10
query1.constrain(Pilot.class); 11
query1.descend("points").constrain(5).smaller(); 12
ObjectSet result1 = query1.execute(); 13
14
// change field 15
Query query2 = container.query(); 16
query2.constrain(Pilot.class); 17
query2.descend("points").constrain(2); 18
ObjectSet result2 = query2.execute(); 19
Pilot pilot2 = (Pilot) result2.get(0); 20
pilot2.addPoints(22); 21
container.set(pilot2); 22
listResult(result1); 23
} finally { 24
container.close(); 25
} 26
}
Pros:
this mode will be slightly faster than the
others.Cons: