src.server
Class DB

java.lang.Object
  extended bysrc.server.DB

public class DB
extends java.lang.Object

An abstraction layer between the server and the database. It supplies easier methods for simple DB operations and the possibility to perform custom queries if needed.

Version:
$Revision: 1.1.1.1 $ $Date: 2005/08/09 21:00:21 $

Constructor Summary
DB(java.lang.String tableName)
          Constructor for DB.
 
Method Summary
static void createConnection()
          Creates the database connection and does all the preparation for the database class.
 java.util.Vector customQuery(java.lang.String sqlQuery)
          Performs a custom query on the table and returns the result.
 void customQueryUpdate(java.lang.String sqlQuery)
          Executes an updating procedure (ie. a procedure not returning data.
 void delete(java.lang.String sqlConditions)
          Deletes matching rows from the table.
 java.lang.String escape(java.lang.String query)
          Escapes syntax characters from sql values so that the values don't mess up the queries.
 java.lang.Object getSingleValue(java.lang.String column, java.lang.String sqlConditions)
          Get a single column/row value
 void insert(java.util.Map values)
          Inserts certain values into the table.
 java.util.Vector select(java.util.Set fields, java.lang.String sqlConditions)
          Selects certain fields from the table that match certain conditions.
 void update(java.util.Map values, java.lang.String sqlConditions)
          Updates matching rows with the specified values.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DB

public DB(java.lang.String tableName)
Constructor for DB.

Parameters:
tableName - The name of the table to perform operations on.
Method Detail

select

public java.util.Vector select(java.util.Set fields,
                               java.lang.String sqlConditions)
Selects certain fields from the table that match certain conditions.

Parameters:
fields - The fields that should be selected.
sqlConditions - The conditions that should be met by a row to be selected.
Returns:
The selected rows, the Vector contains one HashMap for each row.

insert

public void insert(java.util.Map values)
Inserts certain values into the table.

Parameters:
values - The values to insert (field as key, value as value).

update

public void update(java.util.Map values,
                   java.lang.String sqlConditions)
Updates matching rows with the specified values.

Parameters:
values - The values to update to (field as key, value as value).
sqlConditions - The condition that should be met by a row for it to be updated.

delete

public void delete(java.lang.String sqlConditions)
Deletes matching rows from the table.

Parameters:
sqlConditions - The condition that should be met by a row for it to be deleted.

customQuery

public java.util.Vector customQuery(java.lang.String sqlQuery)
Performs a custom query on the table and returns the result.

Parameters:
sqlQuery - The query to perform.
Returns:
The result (if rows are returned then each row is represented by a Map inside the Vector).

customQueryUpdate

public void customQueryUpdate(java.lang.String sqlQuery)
Executes an updating procedure (ie. a procedure not returning data.

Parameters:
sqlQuery - The query to execute.

getSingleValue

public java.lang.Object getSingleValue(java.lang.String column,
                                       java.lang.String sqlConditions)
Get a single column/row value


createConnection

public static void createConnection()
Creates the database connection and does all the preparation for the database class.


escape

public java.lang.String escape(java.lang.String query)
Escapes syntax characters from sql values so that the values don't mess up the queries. For instance ' is turned into \' .

Parameters:
query - The value to escape.
Returns:
The safe (escaped) value.