The Main Routine
The next code is the main routine for the tutorial. The line numbers correspond to the comments that follow the code.
#include <rw/db/db.h> //1
#include "rentrep.h" //2
#include "tututil.h" //3
#include "vidrep.h" //4
#include "purchrep.h" //5
#include "video.h" //6
#include "purchase.h" //7
int main(int argc, char** argv) //8
{
associateStreams("t4in.dat", "t4out.txt", "t4err.txt"); //9
RWDBManager::setErrorHandler (outputStatus); //10
RWCString serverType, serverName, userName,
password, databaseName, pstring; //11
initializeDatabaseArguments(argc, argv, serverType,
serverName, userName, password,
databaseName, pstring); //12
RWDBDatabase aDB = RWDBManager::database
(serverType, serverName, userName, password,
databaseName, pstring); //13
VVVideoRepository videoStock(aDB, videoTableName); //14
VVPurchaseRepository
purchaseTransactions(aDB, purchaseTableName); //15
VVPurchase aPurchase; //16
VVVideo aVideo; //17
while (aPurchase.read(inStream)) { //18
aVideo.read(inStream); //19
purchaseTransactions.insert(aPurchase); //20
if (videoStock.exists(aVideo.id())) { //21
videoStock.updateStock (aVideo.id(), aVideo.quantity()); //22
outStream << aVideo.quantity()
<< " copies of " << aVideo.title()
<< " added to existing stock." << endl; //23
}
else {
videoStock.insert(aVideo); //24
outStream << aVideo.quantity()
<< " copies of " << aVideo.title()
<< " added." << endl; //25
}
}
closeStreams("t4in.dat", "t4out.txt", "t4err.txt");
return 0;
} //26