onlineTests
Class LoadDataModel

java.lang.Object
  extended byonlineTests.LoadDataModel

public class LoadDataModel
extends java.lang.Object

This class stores actual data and privides methods for reading, adding, deleting and updating it into a relational database

Author:
Silvia Kopcheva *
See Also:
User, Utils, DBConnections

Field Summary
protected  java.sql.Connection con
          Connection to HSQLDB DataBase
protected static java.lang.String DEFAULT_URL
          Represents url for HSQLDB DataBase connection
protected static java.lang.String DRIVER
          Represents driver for HSQLDB DataBase connection
private  java.lang.Integer lastID
          ID of the last user added to DataBase
protected  java.lang.String SQLQuery
          SQL Query
protected  java.util.Vector values
          Holds actual data in this model
 
Constructor Summary
LoadDataModel()
          Constructs an empty LoadData model.
 
Method Summary
 boolean addRow(java.lang.String table, java.util.Vector newValue)
          Adds a row to the LoadData model.
 int addUser(java.lang.String name, java.lang.String pass)
          Adds record to Users table.
 boolean deleteRow(java.lang.String table, int row)
          Deletes specified row from the model.
 boolean deleteRow(java.lang.String table, java.util.Vector rowToDelete)
          Deletes specified row from the model.
protected  void freeConnection(java.sql.Connection con)
          Returns a connection to the Connection Pool.
 java.util.Vector getColumns(java.lang.String table)
          Gets column names for choosen table as a Vector
 java.lang.Integer getLastID()
          Gets userID for the last added user in Users table.
 java.util.Vector getRow(int row)
          Returns an entire row from the model as a Vector.
 int getRowCount()
          Gets the row count of current data, stored in this model.
 java.util.Vector getValues()
          Gets the vector which contains all the rows in the model.
 boolean loadData(java.lang.String sql)
          Loads the model with actual data.
 boolean updateRow(java.lang.String table, java.util.Vector oldValue, java.util.Vector newValue)
          Updates an entire row in the model with new values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRIVER

protected static final java.lang.String DRIVER
Represents driver for HSQLDB DataBase connection

See Also:
Constant Field Values

DEFAULT_URL

protected static final java.lang.String DEFAULT_URL
Represents url for HSQLDB DataBase connection

See Also:
Constant Field Values

con

protected java.sql.Connection con
Connection to HSQLDB DataBase


values

protected java.util.Vector values
Holds actual data in this model


SQLQuery

protected java.lang.String SQLQuery
SQL Query


lastID

private java.lang.Integer lastID
ID of the last user added to DataBase

Constructor Detail

LoadDataModel

public LoadDataModel()
Constructs an empty LoadData model.

Method Detail

getValues

public java.util.Vector getValues()
Gets the vector which contains all the rows in the model.

Returns:
Vector actual data, stored in this model

freeConnection

protected void freeConnection(java.sql.Connection con)
Returns a connection to the Connection Pool.

Parameters:
con - connection to be returned.

loadData

public boolean loadData(java.lang.String sql)
                 throws java.sql.SQLException
Loads the model with actual data. The data is selected by an SQL query

Parameters:
sql - SQL Query to be executed
Returns:
true if operation is completed, false - otherwise
Throws:
java.sql.SQLException

getRowCount

public int getRowCount()
Gets the row count of current data, stored in this model.

Returns:
int actual row count

getRow

public java.util.Vector getRow(int row)
Returns an entire row from the model as a Vector.

Parameters:
row - row number as int
Returns:
int actual row count

addRow

public boolean addRow(java.lang.String table,
                      java.util.Vector newValue)
               throws java.sql.SQLException
Adds a row to the LoadData model. It is added at the end of the model as a last row. Be careful not to add row with the same primary key as another existing row, or you'll get an exception.

Parameters:
table - table name for adding row to
newValue - the row to be added az Vector
Returns:
true if operation is completed, false - otherwise
Throws:
java.sql.SQLException

getColumns

public java.util.Vector getColumns(java.lang.String table)
                            throws java.sql.SQLException
Gets column names for choosen table as a Vector

Parameters:
table - table name for getting column names from
Returns:
Vector column names as vector
Throws:
java.sql.SQLException

addUser

public int addUser(java.lang.String name,
                   java.lang.String pass)
Adds record to Users table. New User is added as last row in the table

Parameters:
name - user name
pass - user password
Returns:
int status. It will be 0 if adding succeed, 1 if user with this name exists in Users table, and 2 if there's an exception.

getLastID

public java.lang.Integer getLastID()
Gets userID for the last added user in Users table.

Returns:
Integer id. The id of the last added user to Users table.

updateRow

public boolean updateRow(java.lang.String table,
                         java.util.Vector oldValue,
                         java.util.Vector newValue)
                  throws java.sql.SQLException
Updates an entire row in the model with new values. Be careful not to change the values of the primary key attributes, because an exception may occur.

Parameters:
table - the table to update row in
oldValue - the old row
newValue - the new value ot the row
Throws:
java.sql.SQLException

deleteRow

public boolean deleteRow(java.lang.String table,
                         int row)
                  throws java.sql.SQLException
Deletes specified row from the model. Be sure that the data in the row uniquely identifies it, or another row may be deleted instead of the one you want to delete.

Parameters:
table - table to delete row from
row - nomber of row to be deleted
Throws:
java.sql.SQLException

deleteRow

public boolean deleteRow(java.lang.String table,
                         java.util.Vector rowToDelete)
                  throws java.sql.SQLException
Deletes specified row from the model. Be sure that the data in the row uniquely identifies it, or another row may be deleted instead of the one you want to delete.

Parameters:
table - table to delete row from
rowToDelete - the row to be deleted from table as vector
Throws:
java.sql.SQLException