net.sf.dc.db
Class Database

java.lang.Object
  extended bynet.sf.dc.db.Database

public class Database
extends java.lang.Object

Holder of the Database connection and information. Starts the QueryQueue and handles update, insert and select statements. On the first start, the Database will be created (if the database is empty; the tables do not exist). If this fails, a message is shown to the user. For new records, the unique ID is created by this class. This has not been perfected at this moment.

Since:
1.3
Version:
DC0.50
Author:
Robert-Jan van der Waals

Constructor Summary
Database()
          Initializes the Database, creates a new database if necessary
 
Method Summary
static void close()
          Closes the database connection
 void deleteCollection(DCCollection collection, RequestorCollection requestors)
          Deletes a collection of data crow objects from the database
 void deleteValues(DCObject o, RequestorCollection requestors)
          Deletes values from the database.
 void init()
          Starts the query queue and initializes the database connection
 void insertCollection(DCCollection collection, RequestorCollection requestors)
          Inserts a collection of data crow objects into the database
 void insertValues(DCObject o, RequestorCollection requestors)
          Inserts new values.
 void runQuery(java.lang.String sQuery, RequestorCollection requestors)
          Runs a query
 java.util.LinkedList runQueryDirect(DCObject o)
          Runs a query directly, bypassing the query queue
 java.util.LinkedList runQueryDirect(Query query)
          Does not put the query in a queue but executes it immediately.
 java.util.LinkedList runQueryDirect(java.lang.String sQuery)
          Does not put the query in a queue but executes it immediately.
 java.sql.ResultSet runQueryDirectUnclosed(java.lang.String sQuery)
          Runs a query direct on the database instead of putting it in query queue.
 void searchValues(DCObject o, QueryOptions options, RequestorCollection requestors)
          Searches for values.
 boolean uniqueValues(DCObject o, boolean bUpdateQuery)
          Checks whether the values are unique (do not exist as yet in the database).
 void updateCollection(DCCollection collection, RequestorCollection requestors)
          Updates a collection of data crow objects
 void updateValues(DCObject o, RequestorCollection requestors)
          Updates values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database()
Initializes the Database, creates a new database if necessary

Method Detail

close

public static void close()
Closes the database connection


init

public void init()
Starts the query queue and initializes the database connection

See Also:
DatabaseConnection, QueryQueue

insertCollection

public void insertCollection(DCCollection collection,
                             RequestorCollection requestors)
Inserts a collection of data crow objects into the database

Parameters:
collection - data crow object collection
requestors - requests to be executed after insert

updateCollection

public void updateCollection(DCCollection collection,
                             RequestorCollection requestors)
Updates a collection of data crow objects

Parameters:
collection - data crow object collection
requestors - requests to be executed after update

deleteCollection

public void deleteCollection(DCCollection collection,
                             RequestorCollection requestors)
Deletes a collection of data crow objects from the database

Parameters:
collection - data crow object collection
requestors - requests to be executed after delete

runQuery

public void runQuery(java.lang.String sQuery,
                     RequestorCollection requestors)
Runs a query

Parameters:
sQuery - query statement (string)
requestors - requests to the UI

runQueryDirectUnclosed

public java.sql.ResultSet runQueryDirectUnclosed(java.lang.String sQuery)
                                          throws java.lang.Exception
Runs a query direct on the database instead of putting it in query queue. It returns an unclosed result set.

Parameters:
sQuery - query to be executed
Throws:
java.lang.Exception

runQueryDirect

public java.util.LinkedList runQueryDirect(java.lang.String sQuery)
Does not put the query in a queue but executes it immediately. Errors are returned to the caller (not thrown)

Parameters:
sQuery - query statement
Returns:
list of data crow objects (can be null or empty)

runQueryDirect

public java.util.LinkedList runQueryDirect(DCObject o)
Runs a query directly, bypassing the query queue


runQueryDirect

public java.util.LinkedList runQueryDirect(Query query)
Does not put the query in a queue but executes it immediately. Errors are returned to the caller (not thrown)


searchValues

public void searchValues(DCObject o,
                         QueryOptions options,
                         RequestorCollection requestors)
Searches for values. The query is put in the query queue. The results are past to the caller by using the RequestorCollection

Parameters:
o - the object which is used as the condition
options - query options
requestors - requestors for the result of the query (UI)

updateValues

public void updateValues(DCObject o,
                         RequestorCollection requestors)
Updates values. The query is put in the query queue. Actions are past to the caller by using the RequestorCollection

Parameters:
o - the object to be updated
requestors - requestors which depend on the outcome of the query

insertValues

public void insertValues(DCObject o,
                         RequestorCollection requestors)
Inserts new values. The query is put in the query queue. Actions are past to the caller by using the RequestorCollection

Parameters:
o - the object to be inserted
requestors - requestors which depend on the outcome of the query

deleteValues

public void deleteValues(DCObject o,
                         RequestorCollection requestors)
Deletes values from the database. The query is put in the query queue. Actions are past to the caller by using the RequestorCollection

Parameters:
o - the object to be deleted
requestors - requestors which depend on the outcome of the query

uniqueValues

public boolean uniqueValues(DCObject o,
                            boolean bUpdateQuery)
Checks whether the values are unique (do not exist as yet in the database). Updates and inserts are checked differently

Parameters:
o - object to be checked
bUpdateQuery - specifies whether this is an update or an insert