VVContactRepository::reader
Line //2 above invokes the reader() member function of VVContactRepository. The definition of the function called on //2 is shown below. This function actually creates the query and submits it to the database. It then returns an RWDBReader instance that can be used to get results back from the server.
 
RWDBReader
VVContactRepository::reader(const RWDBCriterion& criterion) //1
{
RWDBSelector s = aDB_.selector(criterion); //2
s.distinct(); //3
s << table_; //4
s.orderBy(nameColumn_); //5
return s.reader(); //6
}
 
//1 This line defines the reader() member function for the class VVContactRepository. It accepts one argument: a criterion to be used in determining which records to return from the customer table.
//2 s is an instance of RWDBSelector, an encapsulation of an SQL SELECT expression. It is produced and therefore associated with an instance of RWDBDatabase. This particular instance of RWDBDatabase, aDB_, was saved by the VVContactRepository constructor. In RWDBSelector’s constructor, it uses one argument. This argument represents the predicate to be used in the WHERE clause of the select expression. In this case, the RWDBCriterion passed in eventually translates into a predicate that is functionally equivalent to:
 
customer.ID = rentals.customerID AND rentals.dueDate < '6/2/2000'
//3 This line adds an additional requirement that all results must be distinct; in other words, no duplicates should be returned. This is added because only a single row is required for each contact selected even if the contact has more than one rental transactions past due. This is functionally equivalent to: SELECT DISTINCT ...
//4 An RWDBSelector instance can select a variable number of columns or expressions. To reflect this indeterminate number of arguments, operator<<() was chosen to specify the SELECT clause. Instances of RWDBColumn can be shifted into the selector. In this case, all the columns are selected by shifting an RWDBTable instance into the selector. Here table_ is the RWDBTable instance associated with the customer table saved by the VVContactRepository constructor. This is equivalent to an SQL SELECT * expression.
//5 To sort the mailing labels in alphabetical order, the selector is instructed to orderBy() the column in which the customer's name is stored. This column was stored by the constructor in the nameColumn_ variable. This is equivalent to the SQL ORDER BY NAME.
//6 Fetching an instance of RWDBReader from a selector submits the query to the database. The selector has sufficient information to generate the appropriate SQL statement. The reader created here by the RWDBSelector instance is returned immediately by this member function.