taxisrus.implementation
Class DataStoreConnection

java.lang.Object
  |
  +--taxisrus.implementation.DataStoreConnection
All Implemented Interfaces:
DataStoreInterface

public class DataStoreConnection
extends Object
implements DataStoreInterface

Author:
Team Doug Creates a connection to the database and allows information to be passed to it and received from it.

Inner Class Summary
 class DataStoreConnection.MapData
          MapData class - used for the map return.
 class DataStoreConnection.PolygonVertex
          PolygonVertex class - used for polygon return.
 
Constructor Summary
DataStoreConnection()
          Constructor - uses default (hard-coded in this file) name, password, and database driver to create a database connection object and database statement object.
DataStoreConnection(String checkusername, String checkpassword, String checkdatabase, Boolean isnew)
          Constructor - uses given username, etc to create the database connection and database statement objects.
 
Method Summary
 boolean addDenial(int cabid, Date date)
          Records a driver rejection of a customer assignment.
 void addMapData(String pictureName, int x1, int y1, int x2, int y2)
          Inserts the data for a map, including the filename and two points representing the bounds of the map.
 boolean addPolygonVertex(int polyid, int vertid, double x, double y)
          Inserts data representing a polygon's vertex, given 2 integers representing the polygon: Zone/polygon ID ( >= 0 ), the vertex identifier ( > 0 ), and 2 doubles representing an x coordinate and a y coordinate.
 boolean addRideRequest(Customer newCustomer)
          Stores a Customer object just after it has been created: it will not have a cab yet so it is a "ride request," but should still have all destination information.
 boolean cancelRideRequest(Customer theCustomer)
          Records the fact that a ride has been canceled by the given customer.
 boolean checkCabID(int driverID, int cabID)
          Given 2 integers relaying values corresponding to a driverid and a cabid that need to be checked for validity (i.e.
 boolean checkNewCustomer(String check, Statement stmt)
          Given a customer and a sql.Statement object this method will find out if that customer currently exists in the customer table.
 void dropAllTablesInDataStore()
          This method deletes all the tables from the data store.
 Vector getAllCabs()
          Returns a vector of all of the cab objects stored in the database.
 Vector getAllPolygonVertices(int zoneid)
          Given an integer representing a Zone/polygon identifier, this method returns all the polygon vertex data associated with that polygon in the form of a vector of polygon vertex objects that contain the desired data
 DataStoreConnection.MapData getMapData()
          Returns a mapData object pertaining to the *one* set of MapData held in the db.
 ManagerReport getNumDispatcherOverrides(int specificity, Date from, Date to)
          getNumDispatcherOverrides - given a String representing a dispatcher's name, this method returns an integer representing the number of dispatcher overrides present in the db corresponding to that dispatcher **NOTE** to effectively turn off the "date" arguments simply pass in 2 of the same date objects.
 ManagerReport getReport(int typeOfReport, int specificity, int timeInterval, Date from, Date to)
          Returns a Report designed for a manager of the cab company, given an enumerated type of report.
 void ourDestructor()
          Destructor - closes the connection and statement.
 String parseIntervalString(String interval)
          parseIntervalString - given one interval ResultSet return object, it'll give you back a pretty string which is useful in reports.
 void removeAllPolygonVertices()
          removeAllPolygonVertices - clears all rows in the mapdata table in the db INTERNAL
 boolean rideHasFinished(Customer theCustomer, Date timeOfFinish, double theFare, double milesTraveled)
          Stores the fact that the given customer has reached their destination, and creates and records statistics relevant to the ride.
 boolean storeCabRideAssignment(Cab theCab)
          Moves the temporary customer info in the rideRequest Table into the Customers table and logs the specific ride information into the rideLog table, given a Cab object.
 boolean updateCabRideAssignment(Cab oldCabState, Cab newCabState)
          Updates the ridelog and customer tables, given a cab object representing the previous state of a cab-ride-assignment and a cab object representing the new state of a cab-ride-assignment.
 boolean updateRideRequests(Customer oldCustomerState, Customer newCustomerState)
          Updates the information in the database, given current and previous customer information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataStoreConnection

public DataStoreConnection()
Constructor - uses default (hard-coded in this file) name, password, and database driver to create a database connection object and database statement object.

DataStoreConnection

public DataStoreConnection(String checkusername,
                           String checkpassword,
                           String checkdatabase,
                           Boolean isnew)
Constructor - uses given username, etc to create the database connection and database statement objects. If the database is new (should only be new if the tables do not exist at all!) then new, empty tables are created.
Method Detail

ourDestructor

public void ourDestructor()
Destructor - closes the connection and statement. Should be called before garbage-collecting any DataStoreConnection object.

addRideRequest

public boolean addRideRequest(Customer newCustomer)
Description copied from interface: DataStoreInterface
Stores a Customer object just after it has been created: it will not have a cab yet so it is a "ride request," but should still have all destination information.
Specified by:
addRideRequest in interface DataStoreInterface
See Also:
DataStoreInterface.addRideRequest(Customer)

storeCabRideAssignment

public boolean storeCabRideAssignment(Cab theCab)
Description copied from interface: DataStoreInterface
Moves the temporary customer info in the rideRequest Table into the Customers table and logs the specific ride information into the rideLog table, given a Cab object.
Specified by:
storeCabRideAssignment in interface DataStoreInterface
See Also:
DataStoreInterface.storeCabRideAssignment(Cab)

checkNewCustomer

public boolean checkNewCustomer(String check,
                                Statement stmt)
Given a customer and a sql.Statement object this method will find out if that customer currently exists in the customer table. INTERNAL
Returns:
boolean indicating whether or not a given customer name is in the table

cancelRideRequest

public boolean cancelRideRequest(Customer theCustomer)
Description copied from interface: DataStoreInterface
Records the fact that a ride has been canceled by the given customer. These attributes must match a customer in the database: theCustomer._last_name, theCustomer._phone, theCustomer._ETA.
Specified by:
cancelRideRequest in interface DataStoreInterface
See Also:
taxisrus.publicinterface.DataStoreInterface#cancelRideRequestCustomer(Customer)

rideHasFinished

public boolean rideHasFinished(Customer theCustomer,
                               Date timeOfFinish,
                               double theFare,
                               double milesTraveled)
Description copied from interface: DataStoreInterface
Stores the fact that the given customer has reached their destination, and creates and records statistics relevant to the ride. ASSUMPTION: rides that have not finished will have a value of 0.0 for mileage in the rideLog table in the database.
Specified by:
rideHasFinished in interface DataStoreInterface
See Also:
DataStoreInterface.rideHasFinished(Customer, Date, double, double)

getReport

public ManagerReport getReport(int typeOfReport,
                               int specificity,
                               int timeInterval,
                               Date from,
                               Date to)
Description copied from interface: DataStoreInterface
Returns a Report designed for a manager of the cab company, given an enumerated type of report. If the timeInterval is not FROM_DATE_TO_DATE, any value can go in the from and to inputs. Definition of all enumerated types can be found in the ManagerReportsPanel class.
Specified by:
getReport in interface DataStoreInterface
See Also:
DataStoreInterface.getReport(int, int, int, Date, Date)

getAllCabs

public Vector getAllCabs()
Description copied from interface: DataStoreInterface
Returns a vector of all of the cab objects stored in the database. Should be used for putting data back into the model on startup/after a crash.
Specified by:
getAllCabs in interface DataStoreInterface
See Also:
DataStoreInterface.getAllCabs()

addPolygonVertex

public boolean addPolygonVertex(int polyid,
                                int vertid,
                                double x,
                                double y)
Description copied from interface: DataStoreInterface
Inserts data representing a polygon's vertex, given 2 integers representing the polygon: Zone/polygon ID ( >= 0 ), the vertex identifier ( > 0 ), and 2 doubles representing an x coordinate and a y coordinate.
Specified by:
addPolygonVertex in interface DataStoreInterface
See Also:
taxisrus.publicinterface.DataStoreInterface#addPolygonVertex()

getAllPolygonVertices

public Vector getAllPolygonVertices(int zoneid)
Description copied from interface: DataStoreInterface
Given an integer representing a Zone/polygon identifier, this method returns all the polygon vertex data associated with that polygon in the form of a vector of polygon vertex objects that contain the desired data
Specified by:
getAllPolygonVertices in interface DataStoreInterface
See Also:
DataStoreInterface.getAllPolygonVertices(int)

removeAllPolygonVertices

public void removeAllPolygonVertices()
removeAllPolygonVertices - clears all rows in the mapdata table in the db INTERNAL
Specified by:
removeAllPolygonVertices in interface DataStoreInterface

getMapData

public DataStoreConnection.MapData getMapData()
Description copied from interface: DataStoreInterface
Returns a mapData object pertaining to the *one* set of MapData held in the db.
Specified by:
getMapData in interface DataStoreInterface
See Also:
DataStoreInterface.getMapData()

addMapData

public void addMapData(String pictureName,
                       int x1,
                       int y1,
                       int x2,
                       int y2)
Description copied from interface: DataStoreInterface
Inserts the data for a map, including the filename and two points representing the bounds of the map. Note - this method will overwrite any previous data. Only the last set of MapData stored is ever available.
Specified by:
addMapData in interface DataStoreInterface
See Also:
taxisrus.publicinterface.DataStoreInterface#addMapData()

updateRideRequests

public boolean updateRideRequests(Customer oldCustomerState,
                                  Customer newCustomerState)
Description copied from interface: DataStoreInterface
Updates the information in the database, given current and previous customer information. The oldCustomerState must have the old last name, ETA, and phone number. Should be used when the customer changes pickup/destination information, etc.
Specified by:
updateRideRequests in interface DataStoreInterface
See Also:
taxisrus.publicinterface.DataStoreInterface#updateRideRequests(Customer customer)

updateCabRideAssignment

public boolean updateCabRideAssignment(Cab oldCabState,
                                       Cab newCabState)
Description copied from interface: DataStoreInterface
Updates the ridelog and customer tables, given a cab object representing the previous state of a cab-ride-assignment and a cab object representing the new state of a cab-ride-assignment. This is used to update the information with respect to the customer, that is, the customer should be the same in both cab states (last name is the same). Other customer information can change (and will be updated), and the cabs themselves can be different. Precondition: oldCabState and newCabState contain customers. These customers correspond - that is - their *LAST NAME IS THE SAME*.
Specified by:
updateCabRideAssignment in interface DataStoreInterface
See Also:
DataStoreInterface.updateCabRideAssignment(Cab, Cab)

getNumDispatcherOverrides

public ManagerReport getNumDispatcherOverrides(int specificity,
                                               Date from,
                                               Date to)
getNumDispatcherOverrides - given a String representing a dispatcher's name, this method returns an integer representing the number of dispatcher overrides present in the db corresponding to that dispatcher **NOTE** to effectively turn off the "date" arguments simply pass in 2 of the same date objects. A typical way to do this would be to create a Date object that represents the current date and pass this in as both the "From" as well as the "To" parameters. INTERNAL
Parameters:
dispatcherName -  
Returns:
numDispatcherOverrides

parseIntervalString

public String parseIntervalString(String interval)
parseIntervalString - given one interval ResultSet return object, it'll give you back a pretty string which is useful in reports. Pretty cool, huh?
Parameters:
interval -  
Returns:
IntervalClass

dropAllTablesInDataStore

public void dropAllTablesInDataStore()
This method deletes all the tables from the data store. Use with extreme caution; it'll throw all sorts of errors if the tables aren't already there, and will cause all database stuff to fail if you try to access the deleted tables before recreating them with createAllTablesInDataStore(). INTERNAL We're leaving this public for the sake of unit testing.

checkCabID

public boolean checkCabID(int driverID,
                          int cabID)
Description copied from interface: DataStoreInterface
Given 2 integers relaying values corresponding to a driverid and a cabid that need to be checked for validity (i.e. that they exist in the db) this method returns the truth of that assumption. Also, sets the current time to the cab's shift start time. Assumption: this function is only called when a cab's shift starts.
Specified by:
checkCabID in interface DataStoreInterface
See Also:
DataStoreInterface.checkCabID(int, int)

addDenial

public boolean addDenial(int cabid,
                         Date date)
Description copied from interface: DataStoreInterface
Records a driver rejection of a customer assignment.
Specified by:
addDenial in interface DataStoreInterface
See Also:
DataStoreInterface.addDenial(int, Date)


API documentation for build 958