Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

DBInterface.H

Go to the documentation of this file.
00001 /*************************************
00002  *File: DBInterface.H
00003  *Author: relminya
00004  *Date:   3.15.2005
00005  *
00006  *Description: This file is the gateway
00007  * to all the data held in the database,
00008  * be it ranking info or map info.
00009  * As of 3.15.2005 it only describes
00010  * the methods that other components will
00011  * be dependent on. 
00012  **************************************/
00013 
00014 #ifndef DBInterface_h
00015 #define DBInterface_h
00016 
00017 #include <iostream>
00018 #include <string>
00019 #include <vector>
00020 #include <pqxx/pqxx> //PostgreSQL C++ interface, compiles.
00021 
00022 #include "BQStructs.H"
00023 #include "strlib.H"
00024 
00025 using namespace std;
00026 using namespace pqxx;
00027 
00028 const std::string Connection="host=dbwebu.cs.brown.edu dbname=bikequestri2 user=relminya password=coemouri";
00029 
00030 
00032 class DBInterface {
00033   
00034    //default constructor, destructor
00035 
00036 private:
00037   pqxx::result executeTransaction(pqxx::connection* c, std::string sql);
00038   pqxx::result executeNonTransaction(pqxx::connection* c, std::string sql);
00039   pqxx::connection* getConnection();
00040   pqxx::connection* makeConnection();
00041   void tryDisconnect(pqxx::connection* c);
00042   vector<seg_t*>* processRDQUANTTuple (pqxx::result& R);
00043   void addQUALResults(std::vector<seg_t*>* segvector, pqxx::connection* c);
00044 
00045 public:
00046 
00047   //EMPTY CONSTRUCTOR AND DESTRUCTOR SINCE THERE ARE NO MEMBER FUNCTIONS.
00048   DBInterface ();
00049   ~DBInterface ();
00050 
00051   /**************************************
00052    *Method: getSegment
00053    *Parameters: string routeid
00054    *Returns: STL vector of streetSeg(s)
00055    *Author: relminya
00056    *Date:   3.15.2005
00057    *
00058    *
00059    *Description: Converts routeid into an int
00060    * and then queries database for tuples 
00061    * with said routeid. Returns vector although
00062    * we will always have only one segment. This
00063    * is for continuity with the other methods and 
00064    * the helper methods.
00065    *
00066    *Error Codes: Returns Empty Vector if things go wrong.
00067    */
00069   vector<seg_t*>* getSegment(std::string routeid);
00070  
00071   /**************************************
00072    *Method: getStreetsAt
00073    *Parameters: intersection i
00074    *Returns: STL vector of streetSeg(s)
00075    *Author: relminya
00076    *Date:   3.15.2005
00077    *
00078    *
00079    *Description: Queries the database for
00080    * all streets that either start or end
00081    * with intersection i. Returns an STL
00082    * vector of all queried matches, each match
00083    * will be a filled streetSeg struct. Using
00084    * STL vector because of ease of interface,
00085    * the fact that this doesnt have to be sorted,
00086    * and because insertion and removal at the end
00087    * (the only type used in this case) is constant
00088    * time, it becomes the most efficient thing to use.
00089    *
00090    *Error Codes:  Returns Empty Vector if things go wrong.
00091    * 
00092    **************************************/
00094   vector<seg_t*>* getStreetsAt( isect_t* i );
00095   
00096   /**************************************
00097    *Method: getPath
00098    *Parameters: intersection from, intersection to
00099    *Returns: STL vector of streetSeg(s) 
00100    *Author: relminya
00101    *Date:   3.15.2005
00102    *
00103    *
00104    *Description: Returns an STL vector of street
00105    * segments that make up a single street.
00106    * For example, Thayer St. between Meeting and Waterman
00107    * is made up of Thayer betw. Meeting->Euclid, Euclid->Angell
00108    * Angell->Waterman (pardon me if wrong :-p). In the DB
00109    * it is very useful to keep road sections this small, but for 
00110    * the use of AI, UI, this should be one road section, 
00111    * and this  method helps in the detection of this. 
00112    * Could ostensibly return a queue, because order is important 
00113    * here, but consistency is also an issue with 
00114    * the interface, and vector is as good a choice. 
00115    *
00116    *Error Codes: returns NULL if record doesnt exist
00117    *
00118    **************************************/
00119   //* Returns an STL vector of street segments that make up a single street. For example, Thayer St. between Meeting and Waterman is made up of Thayer between Meeting and Euclid, Euclid and Angell, Angell and Waterman. In the DB, it is very useful to keep road sections this small, but for the use of the AI and the UI, this should be one road section, and this method helps in the detection of this. Could ostensibly return a queue, because order is important here, but consistency is also an issue with the interface, and vector is as good a choice. 
00120 
00121   vector<seg_t*>* getPath( isect_t* from, 
00122                            isect_t* to);
00123 
00124   //* Arc version of the STL-based getPath(...)
00125   vector<segComps_t*>* getPathArcs( isect_t* from,
00126                                     isect_t* to );
00127   /**************************************
00128    *Method: getMatches
00129    *Parameters: string streetName: name of street
00130    *            string town: town name
00131    *            string state: two letter state code
00132    *            string zip: five digit zip
00133    *            double address: number on street
00134    *Returns: STL vector of streetSegs
00135    *Author: relminya
00136    *Date:   3.15.2005
00137    *
00138    *
00139    *Description: Given user entered streetName, etc
00140    * return all streetSegs that match the general description
00141    * of the road given by the parameters. What elements
00142    * are required of the parameters is dictated by the UI's
00143    * form checking. If the number of matches exceeds what
00144    * is easily displayable by UI this interface will return
00145    * an error, and the user will be forced to reenter search 
00146    * terms. 
00147    * 
00148    *
00149    *Error Codes: returns NULL if record doesnt exist
00150    *
00151    **************************************/
00153 
00154   vector<seg_t*>* getMatches ( std::vector<string> streetName,
00155                               string town,
00156                               string state,
00157                               string zip,
00158                               double address );
00159   
00160   /**************************************
00161    *Method: addQuantRanking
00162    *Parameters: seg_t where: which segment has been clicked
00163    *            double x_val: votes average
00164    *            int numX_val: quantity of votes
00165    *
00166    *Returns: int
00167    *Author: relminya
00168    *Date:   3.24.2005
00169    *
00170    *
00171    *Description: given a streetSeg, and updated
00172    * rankings information we will do a SQL insert
00173    * or update to make the database reflect the
00174    * new information on the road. Returns an int for 
00175    * error codes. Not per user of course as there
00176    * are no users in BQ v1. Since there are many
00177    * rankings per segment, the mechanism to addRanking
00178    * is as follows: a call to getRanking is done
00179    * to recieve existing data on the road (the number
00180    * of votes for shoulder, and the average of it, etc)
00181    * With the current information, the rankings code
00182    * will average the new information, add a vote to the
00183    * total, and call addRanking() with the newly
00184    * calculated information.
00185    *
00186    *Error Codes: 1 if operation successful
00187    *             -1 if seg_t doesnt exist
00188    *             -2 if record is locked
00189    *             -3 if range for input numbers is not w/in BQ admissible range
00190    *             -4 other reason
00191    *
00192    **************************************/
00193 
00195   int addQuantRanking ( seg_t* where,
00196                         double shoulder_val,
00197                         int numShoulder_val,
00198                         double traffic_val,
00199                         int numTraffic_val,
00200                         double condition_val,
00201                         int numCondition_val,
00202                         double steepness_val,
00203                         int numSteepness_val );
00204   
00205   /**************************************
00206    *Method: addQualRanking
00207    *Parameters: seg_t where: which segment has been clicked
00208    *            string comment:
00209    *            int commenttype: based on enum in BQStructs, what type? 
00210    *
00211    *Returns: int
00212    *Author: relminya
00213    *Date:   3.24.2005
00214    *
00215    *Description: Interface to add qualitative comments to
00216    * bikequest database. Based on the enumeration
00217    * in BQStructs, the caller will give what type of 
00218    * comment it is. This method, in addition to adding
00219    * this to the database, will concatenate the current date
00220    * to the comment. 
00221    *
00222    *Error Codes: 1 if operation successful
00223    *             -1 if seg_t doesnt exist
00224    *             -2 if record is locked
00225    *             -3 if incorrect commenttype
00226    *             -4 other
00227    **************************************/
00228 
00230   int addQualRanking ( seg_t* where,
00231                        string comment,
00232                        int commenttype,
00233                        string author);
00234   
00235   /**************************************
00236    *Method: getRanking
00237    *Parameters: intersection from, intersection to
00238    *Returns: streetSeg
00239    *Author: relminya
00240    *Date:   3.15.2005
00241    *
00242    *
00243    *Description: Given a street segment that starts
00244    * with from, and ends with to, query the database
00245    * for a row which meets the from, to criteria. 
00246    * Also fills out a streetSeg struct with the information
00247    * returned. The data that is needed out of the street
00248    * segment is its ranking information. The qualitative
00249    * information from tables is parsed here, and put into
00250    * a multimap for ease of information retrieval. 
00251    *
00252    *Error Codes: returns NULL if record doesnt exist.
00253    **************************************/
00255   seg_t* getRanking ( isect_t* from,
00256                       isect_t* to );
00257   
00258   /**************************************
00259    *Method: getArcs 
00260    *Parameters: pathDesc fullpath
00261    *Returns: String
00262    *Author: relminya
00263    *Date:   3.21.2005
00264    *
00265    *
00266    *Description: Given a full path description
00267    * we will traverse the linked list of street segments
00268    * and return a string of comma separated values 
00269    * that are the exact point to point geometry of the streets
00270    * in the path. Used by mapvis. Mapvis will parse the numbers
00271    * sent back and convert the stateplane coordinates to 
00272    * their own xy coordinate plane. 
00273    *
00274    *Error Codes: returns NULL if all segs arent found.
00275    *             returns String with names of unfound segs if some are found.
00276    **************************************/
00278   vector<segComps_t*>* getArcs (  );
00279   
00280   
00281   
00282 }; 
00283   
00284 #endif

Generated on Mon May 16 11:08:35 2005 for BikeQuest by  doxygen 1.4.0