com.planet_ink.coffee_mud.core.database
Class DBConnections

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.database.DBConnections

public class DBConnections
extends java.lang.Object


Field Summary
protected  java.util.Vector Connections
          the database connnections
protected  int consecutiveErrors
          the number of times the system has failed a request
protected  int consecutiveFailures
          the number of times the system has failed to get a db
protected  java.lang.String DBClass
           
protected  java.lang.String DBPass
          the odbc password
protected  java.lang.String DBService
          the odbc service
protected  java.lang.String DBUser
          the odbc login user
protected  boolean disconnected
          the disconnected flag
protected  boolean errorQueingEnabled
          Object to synchronize around on error handling
protected  boolean lockedUp
          the im in trouble flag
protected  int maxConnections
          number of connections to make
protected  boolean reuse
          whether to reuse connections
protected  boolean YOU_ARE_DONE
          set this to true once, cuz it makes it all go away.
 
Constructor Summary
DBConnections(java.lang.String NEWDBClass, java.lang.String NEWDBService, java.lang.String NEWDBUser, java.lang.String NEWDBPass, int NEWnumConnections, boolean NEWreuse, boolean DoErrorQueueing)
          Initialize this class.
 
Method Summary
 boolean amIOk()
          Return the happiness level of the connections

Usage: amIOk()
 void clearErrors()
           
 void DBDone(DBConnection D)
          Return a DBConnection object fetched with DBFetch()

Usage:
 DBConnection DBFetch()
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchAny(java.lang.String SQL, boolean prepared)
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchPrepared(java.lang.String SQL)
           
 boolean deregisterDriver()
           
 void enQueueError(java.lang.String SQLString, java.lang.String SQLError, java.lang.String tries)
          Queue up a failed write/update for later processing.
 java.lang.StringBuffer errorStatus()
          return a status string, or "" if everything is ok.
static long getLongRes(java.sql.ResultSet Results, java.lang.String Field)
          When reading a database table, this routine will read in the given Field NAME, returning the value.
static java.lang.String getRes(java.sql.ResultSet Results, int One)
          When reading a database table, this routine will read in the given One index number, returning the value.
static java.lang.String getRes(java.sql.ResultSet Results, java.lang.String Field)
          When reading a database table, this routine will read in the given Field NAME, returning the value.
static java.lang.String getResQuietly(java.sql.ResultSet Results, java.lang.String Field)
           
 void killConnections()
          Destroy all database connections, effectively shutting down this class.
 void listConnections(java.io.PrintStream out)
          list the connections

Usage: listConnections(out);
 int numConnectionsMade()
          Return the number of connections made.
 int numInUse()
           
 int queryRows(java.lang.String queryString)
          

Usage: update("UPDATE...");
 void reportError()
           
 void resetConnections()
           
 void retryQueuedErrors()
          Queue up a failed write/update for later processing.
 int update(java.lang.String updateString)
          

Usage: update("UPDATE...");
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBClass

protected java.lang.String DBClass

DBService

protected java.lang.String DBService
the odbc service


DBUser

protected java.lang.String DBUser
the odbc login user


DBPass

protected java.lang.String DBPass
the odbc password


maxConnections

protected int maxConnections
number of connections to make


disconnected

protected boolean disconnected
the disconnected flag


lockedUp

protected boolean lockedUp
the im in trouble flag


consecutiveFailures

protected int consecutiveFailures
the number of times the system has failed to get a db


consecutiveErrors

protected int consecutiveErrors
the number of times the system has failed a request


errorQueingEnabled

protected boolean errorQueingEnabled
Object to synchronize around on error handling


Connections

protected java.util.Vector Connections
the database connnections


YOU_ARE_DONE

protected boolean YOU_ARE_DONE
set this to true once, cuz it makes it all go away.


reuse

protected boolean reuse
whether to reuse connections

Constructor Detail

DBConnections

public DBConnections(java.lang.String NEWDBClass,
                     java.lang.String NEWDBService,
                     java.lang.String NEWDBUser,
                     java.lang.String NEWDBPass,
                     int NEWnumConnections,
                     boolean NEWreuse,
                     boolean DoErrorQueueing)
Initialize this class. Must be called at first, and after any killConnections() calls.

Usage: Initialize("ODBCSERVICE","USER","PASSWORD",10);

Parameters:
NEWDBClass - the odbc service
NEWDBService - the odbc service
NEWDBUser - the odbc user login
NEWDBPass - the odbc user password
NEWnumConnections - Connections to maintain
NEWreuse - Whether to reuse connections
DoErrorQueueing - whether to save errors to a file
Method Detail

update

public int update(java.lang.String updateString)


Usage: update("UPDATE...");

Parameters:
updateString - the update SQL command
Returns:
int the responseCode, or -1

numConnectionsMade

public int numConnectionsMade()
Return the number of connections made.

Usage: n=numConnectionsMade();

Returns:
numConnectionsMade The number of connections

numInUse

public int numInUse()

DBFetch

public DBConnection DBFetch()
Fetch a single, not in use DBConnection object. You can then call DBConnection.query and DBConnection.update on this object. The user must ALWAYS call DBDone when done with the object.

Usage: DB=DBFetch();

Returns:
DBConnection The DBConnection to use

DBFetchAny

public DBConnection DBFetchAny(java.lang.String SQL,
                               boolean prepared)
Fetch a single, not in use DBConnection object. You can then call DBConnection.query and DBConnection.update on this object. The user must ALWAYS call DBDone when done with the object.

Usage: DB=DBFetchPrepared();

Parameters:
SQL - The prepared statement SQL
prepared - whether the statement should be a prepared one
Returns:
DBConnection The DBConnection to use

DBFetchPrepared

public DBConnection DBFetchPrepared(java.lang.String SQL)

DBDone

public void DBDone(DBConnection D)
Return a DBConnection object fetched with DBFetch()

Usage:

Parameters:
D - The Database connection to return to the pool

getRes

public static java.lang.String getRes(java.sql.ResultSet Results,
                                      java.lang.String Field)
When reading a database table, this routine will read in the given Field NAME, returning the value. The value will be trim()ed, and will not be NULL.

Usage: str=getRes(R,"FIELD");

Parameters:
Results - The ResultSet object to use
Field - Field name to return
Returns:
String The value of the field being returned

getLongRes

public static long getLongRes(java.sql.ResultSet Results,
                              java.lang.String Field)
When reading a database table, this routine will read in the given Field NAME, returning the value. The value will be trim()ed, and will not be NULL.

Usage: str=getLongRes(R,"FIELD");

Parameters:
Results - The ResultSet object to use
Field - Field name to return
Returns:
String The value of the field being returned

getRes

public static java.lang.String getRes(java.sql.ResultSet Results,
                                      int One)
When reading a database table, this routine will read in the given One index number, returning the value. The value will be trim()ed, and will not be NULL.

Usage: str=getRes(R,1);

Parameters:
Results - The ResultSet object to use
One - Field number to return
Returns:
String The value of the field being returned

getResQuietly

public static java.lang.String getResQuietly(java.sql.ResultSet Results,
                                             java.lang.String Field)

deregisterDriver

public boolean deregisterDriver()

resetConnections

public void resetConnections()

killConnections

public void killConnections()
Destroy all database connections, effectively shutting down this class.

Usage: killConnections();


amIOk

public boolean amIOk()
Return the happiness level of the connections

Usage: amIOk()

Returns:
boolean true if ok, false if not ok

enQueueError

public void enQueueError(java.lang.String SQLString,
                         java.lang.String SQLError,
                         java.lang.String tries)
Queue up a failed write/update for later processing.

Usage: enQueueError("UPDATE SQL","error string");

Parameters:
SQLString - UPDATE style SQL statement
SQLError - The error message being reported
tries - The number of tries to redo it so far

retryQueuedErrors

public void retryQueuedErrors()
Queue up a failed write/update for later processing.

Usage: RetryQueuedErrors();


queryRows

public int queryRows(java.lang.String queryString)


Usage: update("UPDATE...");

Parameters:
queryString - the update SQL command
Returns:
int the responseCode, or -1

listConnections

public void listConnections(java.io.PrintStream out)
list the connections

Usage: listConnections(out);

Parameters:
out - place to send the list out to

reportError

public void reportError()

clearErrors

public void clearErrors()

errorStatus

public java.lang.StringBuffer errorStatus()
return a status string, or "" if everything is ok.

Usage: errorStatus();

Returns:
StringBuffer complete error status