Show/Hide Toolbars

TMS Aurelius Documentation

Navigation: Data Binding - TAureliusDataset > Providing Objects

Using Criteria for Offline Fetch-On-Demand

Scroll Prev Top Next More

Another way to provide objects to TAureliusDataset is providing a TCriteria object to it. Just create a query and pass the TCriteria object using SetSourceCriteria method.

 

var

  Criteria: TCriteria;

begin

  Criteria := Manager.Find<TPerson>;

  AureliusDataset1.SetSourceCriteria(Criteria);

 

  // Or just this single line version:

  AureliusDataset1.SetSourceCriteria(Manager.Find<TPerson>);

 

In the code above, Aurelius will just execute the query specified by the TCriteria and fill the internal object list with the retrieved objects. This approach is actually not very different than providing an object list to the dataset. The real advantage of it is when you use an overloaded version of SetSourceCriteria that allows paging.

 

Office fetch-on-demand using paging

 

SetSourceCriteria method has an overloaded signature that received an integer parameter specifying a page size:

 

  AureliusDataset1.SetSourceCriteria(Manager.Find<TPerson>, 50);

 

It means that the dataset will fetch records on demand, but without needing to keep an active database connection.

When you open a dataset after specifying a page size of 50 as illustrated in the code above, only the first 50 TPerson objects will be fetched from the database, and query will be closed. Internally, TAureliusDataset uses the paging mechanism provided by Take and Skip methods. If more records are needed (a TDBGrid is scrolled down, or you call TDataset.Next method multiple times, for example), then the dataset will perform another query in the database to retrieve the next 50 TPerson objects in the query.

 

So, in summary, it's a fetch-on-demand mode where the records are fetched in batches and a new query is executed every time a new batch is needed. The advantage of this approach is that it doesn't retrieve all objects from the database at once, so it's fast to open and navigate, especially with visual controls. Another advantage (when comparing with using cursors, for example) is that it works offline - it doesn't keep an open connection to the database. One disadvantage is that it requires multiple queries to be executed on the server to retrieve all objects.

 

You don't have to destroy the TCriteria object. The dataset uses it internally to re-execute the query and retrieve a new set of objects. When all records are fetched or the dataset is closed, the TCriteria object is automatically destroyed.