org.problets.lib.comm.database
Class Database

java.lang.Object
  extended by org.problets.lib.comm.database.Database

public class Database
extends java.lang.Object

Upper class used to connect to database

Author:
Atanas Frengov

Field Summary
static java.lang.String DATABASE_NAME
           
static java.lang.String DATABASE_TRANSLATION_FILE
           
 
Constructor Summary
Database(java.lang.String databaseName)
          Constructor for the upper-level database class.
 
Method Summary
 void create(java.lang.String databaseName)
          Create a new database
 void create(java.lang.String tableName, java.util.Vector structure)
          Create a new table
 void delete(java.lang.String tableName, DatabaseRecord conditions)
          Delete data from the specified table
 void disconnectDatabase()
          A function to disocnnect from the database ( just a call to CommunicateDatabase disconnect)
 void drop(java.lang.String tableName)
          Drop a table from the current database
 java.util.Vector getFields(java.lang.String tableName)
          Get the names of each field in the specified table
 java.util.Vector getTables()
          get the table names in the current database
 void insert(java.util.HashMap translationTable)
          Update the database with what is in the translation table
static void main(java.lang.String[] args)
           
 java.sql.ResultSet select(java.lang.String tableName)
          Select all data from a specified table
 java.sql.ResultSet select(java.lang.String tableName, DatabaseRecord fields, DatabaseRecord conditions, java.lang.String operator)
          Query the database
 void update(java.lang.String tableName, DatabaseRecord newValues, DatabaseRecord conditions)
          Update selected fields in the database
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_NAME

public static final java.lang.String DATABASE_NAME
See Also:
Constant Field Values

DATABASE_TRANSLATION_FILE

public static final java.lang.String DATABASE_TRANSLATION_FILE
See Also:
Constant Field Values
Constructor Detail

Database

public Database(java.lang.String databaseName)
Constructor for the upper-level database class. All it needs to connect to the database is the name of the database All other information is as class constants and is passed to the lower-level class CommunicateDatabase

Parameters:
databaseName - the name of the database to be used for communicating
Method Detail

select

public java.sql.ResultSet select(java.lang.String tableName)
Select all data from a specified table

Parameters:
tableName - the name of the table to be used
Returns:
a result set of the selected data

select

public java.sql.ResultSet select(java.lang.String tableName,
                                 DatabaseRecord fields,
                                 DatabaseRecord conditions,
                                 java.lang.String operator)
Query the database

Parameters:
tableName - the table name to be used
fields - the fields that have to be selected
conditions - a database record of the conditions for selecting what to be displayed
operator - what operator should be used for the specified conditions
Returns:
a result set of the selected data

getTables

public java.util.Vector getTables()
get the table names in the current database

Returns:
a vector of Strings of the names of the tables in the database

getFields

public java.util.Vector getFields(java.lang.String tableName)
Get the names of each field in the specified table

Parameters:
tableName - the table to be used
Returns:
a vector with the name of each field as String

create

public void create(java.lang.String databaseName)
Create a new database

Parameters:
databaseName - the name of the new database that will be created

create

public void create(java.lang.String tableName,
                   java.util.Vector structure)
Create a new table

Parameters:
tableName - the name of the table to be inserted
structure - a vector holding the data about each field in the new table

drop

public void drop(java.lang.String tableName)
Drop a table from the current database

Parameters:
tableName - the table to be dropped

delete

public void delete(java.lang.String tableName,
                   DatabaseRecord conditions)
Delete data from the specified table

Parameters:
tableName - the table from which entries will be deleted
conditions - the conditions to be used for the deletion of certain items

insert

public void insert(java.util.HashMap translationTable)
Update the database with what is in the translation table

Parameters:
translationTable - a hash map that contains the translation done by the DataTranslator

update

public void update(java.lang.String tableName,
                   DatabaseRecord newValues,
                   DatabaseRecord conditions)
Update selected fields in the database

Parameters:
tableName - the table to be used
newValues - a database record holding the new AttributeValue pairs to change the database
conditions - a database record holding the conditions to be used for updating certain fields

disconnectDatabase

public void disconnectDatabase()
A function to disocnnect from the database ( just a call to CommunicateDatabase disconnect)


main

public static void main(java.lang.String[] args)