babase.ranker
Class Database

java.lang.Object
  extended by babase.ranker.Database

public class Database
extends java.lang.Object

Class dealing with everything related to the Database including creating and maintaing connections as well as common tasks associated with the ranking of individuals.

Author:
tjb13

Constructor Summary
Database(Controller c)
          Creates a database object with a connection to the controller.
 
Method Summary
 boolean checkConnection()
          Returns the current connection status.
 void connect(java.lang.String user, java.lang.String pass, java.lang.String db)
          Connects to a database using login credentials supplied to login manager.
 void createRankMatrix(Cage cage)
          Retrieves all the necessary information from the database's actor_actees table in order to construct a rank matrix from the result set and produce a ranking matrix to be displayed in the ranker GUI from the dyadic agonistic interacitons that took place amongst them.
 void disconnect()
          Disconnects from the database
 java.lang.String getDB()
          Returns the database string
 java.sql.ResultSetMetaData getMetaData()
          Returns the result set meta data of a given successful query.
 Ranking getRankings()
          Get rankings for a given cage of individuals from the ranks table in the database.
 java.lang.String getRankQuery(java.lang.String rnktype)
          Get the correct query for a given ranktype specified in the chooser.
 java.sql.ResultSet getResultSet()
          Returns the result set of a given successful query.
 void query(java.lang.String q)
          Querys the database with a given query q.
 void queryNoResults(java.lang.String q)
          Querys the database without giving any results.
 java.lang.String quote(java.lang.String original)
          Puts single quotes around a string.
 boolean rankingExists()
          Checks to see whether a current ranking exists for the chosen group, date, and ranktype specified in the chooser.
 void setCage(Cage c)
          Changes the cage associated with this database.
 void update(java.lang.String q)
          Updates the database with a given update.
 void writeRanking()
          Writes a ranking to the database's ranks rable using the ranking information contained within the Cage object deleting a current ranking if it exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database(Controller c)
Creates a database object with a connection to the controller.

Parameters:
c -
Method Detail

setCage

public void setCage(Cage c)
Changes the cage associated with this database.

Parameters:
c - a Cage

connect

public void connect(java.lang.String user,
                    java.lang.String pass,
                    java.lang.String db)
             throws java.sql.SQLException
Connects to a database using login credentials supplied to login manager.

Parameters:
user - a username
pass - a password
db - a database
Throws:
java.sql.SQLException - if it cannot connect

getDB

public java.lang.String getDB()
Returns the database string

Returns:
a string

disconnect

public void disconnect()
                throws java.sql.SQLException
Disconnects from the database

Throws:
java.sql.SQLException - if it cannot disconnect

checkConnection

public boolean checkConnection()
Returns the current connection status.

Returns:
a boolean connection status

query

public void query(java.lang.String q)
           throws java.sql.SQLException
Querys the database with a given query q.

Parameters:
q - a query
Throws:
java.sql.SQLException

queryNoResults

public void queryNoResults(java.lang.String q)
                    throws java.sql.SQLException
Querys the database without giving any results.

Parameters:
q - a query
Throws:
java.sql.SQLException

update

public void update(java.lang.String q)
            throws java.sql.SQLException
Updates the database with a given update.

Parameters:
q - is a update to be performed
Throws:
java.sql.SQLException

getResultSet

public java.sql.ResultSet getResultSet()
Returns the result set of a given successful query.

Returns:
a result set

getMetaData

public java.sql.ResultSetMetaData getMetaData()
Returns the result set meta data of a given successful query.

Returns:
result set meta data

getRankQuery

public java.lang.String getRankQuery(java.lang.String rnktype)
                              throws java.sql.SQLException
Get the correct query for a given ranktype specified in the chooser.

Parameters:
rnktype - a rank type
Returns:
a query for this rank type
Throws:
java.sql.SQLException

writeRanking

public void writeRanking()
Writes a ranking to the database's ranks rable using the ranking information contained within the Cage object deleting a current ranking if it exists.


getRankings

public Ranking getRankings()
                    throws java.sql.SQLException
Get rankings for a given cage of individuals from the ranks table in the database.

Returns:
a ranking
Throws:
java.sql.SQLException

rankingExists

public boolean rankingExists()
                      throws java.sql.SQLException
Checks to see whether a current ranking exists for the chosen group, date, and ranktype specified in the chooser.

Returns:
a existing ranking boolean
Throws:
java.sql.SQLException

quote

public java.lang.String quote(java.lang.String original)
Puts single quotes around a string.

Parameters:
original - a string without quotes
Returns:
a string with quotes

createRankMatrix

public void createRankMatrix(Cage cage)
                      throws java.sql.SQLException
Retrieves all the necessary information from the database's actor_actees table in order to construct a rank matrix from the result set and produce a ranking matrix to be displayed in the ranker GUI from the dyadic agonistic interacitons that took place amongst them.

Parameters:
cage - a Cage
Throws:
java.sql.SQLException