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 itemss, the unique ID is created by this class. This has not been perfected at this moment.

Since:
1.3
Version:
0.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 deleteValues(DCObject o)
          Deletes values from the database.
 void init()
          Starts the query queue and initializes the database connection
 void insertValues(DCObject o)
          Inserts new values.
static boolean isClosed()
           
 void runQuery(java.lang.String sQuery, RequestCollection requestors)
          Runs a query
 java.util.Collection runQueryDirect(DCObject o)
          Runs a query directly, bypassing the query queue
 java.util.Collection runQueryDirect(Query query)
          Does not put the query in a queue but executes it immediately.
 java.util.Collection runQueryDirect(java.lang.String sQuery)
          Does not put the query in a queue but executes it immediately.
 java.util.Collection runQueryDirect(java.lang.String sQuery, boolean catchErrors)
          Does not put the query in a queue but executes it immediately.
 java.sql.ResultSet runQueryDirectUnclosed(java.lang.String sQuery, boolean silent)
          Runs a query direct on the database instead of putting it in query queue.
 void searchValues(DCObject o, QueryOptions options)
          Searches for values.
 boolean uniqueValues(DCObject o, boolean bUpdateQuery)
          Checks whether the values are unique (do not exist as yet in the database).
 void updateValues(DCObject o)
          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


isClosed

public static boolean isClosed()

init

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

See Also:
DatabaseConnection, QueryQueue

runQuery

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

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

runQueryDirectUnclosed

public java.sql.ResultSet runQueryDirectUnclosed(java.lang.String sQuery,
                                                 boolean silent)
                                          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.Collection runQueryDirect(java.lang.String sQuery,
                                           boolean catchErrors)
                                    throws java.lang.Exception
Does not put the query in a queue but executes it immediately. Errors are either thrown or returned to the caller

Parameters:
sQuery - query statement
catchErrors - indicates whether errors should be caugth or passed on to the caller
Returns:
list of data crow objects (can be null or empty)
Throws:
java.lang.Exception

runQueryDirect

public java.util.Collection 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.Collection runQueryDirect(DCObject o)
Runs a query directly, bypassing the query queue

Parameters:
o - data crow object

runQueryDirect

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

Parameters:
query - Query object

searchValues

public void searchValues(DCObject o,
                         QueryOptions options)
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

updateValues

public void updateValues(DCObject o)
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

insertValues

public void insertValues(DCObject o)
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

deleteValues

public void deleteValues(DCObject o)
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

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