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.List<DBConnection> 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.util.Map<java.lang.String,java.lang.String> dbParms
          the jdbc args
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 shutdown
          set this to true once, cuz it makes it all go away.
protected  boolean transact
          whether to reuse connections
 
Constructor Summary
DBConnections(java.lang.String dbClass, java.lang.String dbService, java.lang.String dbUser, java.lang.String dbPass, java.util.Map<java.lang.String,java.lang.String> dbParms, int numConnections, boolean reuse, boolean transact, 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, DBConnection.FetchType type)
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchEmpty()
           
 DBConnection DBFetchPrepared(java.lang.String SQL)
           
 DBConnection DBFetchTest()
          Fetch a single, not in use DBConnection object.
 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)
           
 boolean isFakeDB()
           
 void killConnections()
          Destroy all database connections, effectively shutting down this class.
 void listConnections(java.io.PrintStream out)
          list the connections Usage: listConnections(out);
 int numAvailable()
           
 int numConnectionsMade()
          Return the number of connections made.
 int numInUse()
           
 int pingAllConnections(java.lang.String querySql, long usageTimeoutMillis)
          Pings all connections not currently in use.
 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[] updateStrings)
          Usage: update("UPDATE...");
 int updateWithClobs(java.util.List<DBConnector.DBPreparedBatchEntry> entries)
          Usage: updateWithClobs("UPDATE...");
 int updateWithClobs(java.lang.String[] updateStrings, java.lang.String[][][] values)
          Usage: updateWithClobs("UPDATE...");
 int updateWithClobs(java.lang.String updateString, java.lang.String[][] values)
          Usage: updateWithClobs("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


dbParms

protected java.util.Map<java.lang.String,java.lang.String> dbParms
the jdbc args


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.List<DBConnection> connections
the database connnections


shutdown

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


reuse

protected boolean reuse
whether to reuse connections


transact

protected boolean transact
whether to reuse connections

Constructor Detail

DBConnections

public DBConnections(java.lang.String dbClass,
                     java.lang.String dbService,
                     java.lang.String dbUser,
                     java.lang.String dbPass,
                     java.util.Map<java.lang.String,java.lang.String> dbParms,
                     int numConnections,
                     boolean reuse,
                     boolean transact,
                     boolean doErrorQueueing)
Initialize this class. Must be called at first, and after any killConnections() calls. Usage: Initialize("ODBCSERVICE","USER","PASSWORD",10);

Parameters:
dbClass - the odbc service
dbService - the odbc service
dbUser - the odbc user login
dbPass - the odbc user password
dbParms - extra jdbc parameters
numConnections - Connections to maintain
reuse - Whether to reuse connections
doErrorQueueing - whether to save errors to a file
Method Detail

update

public int update(java.lang.String[] updateStrings)
Usage: update("UPDATE...");

Parameters:
updateStrings - the update SQL commands
Returns:
int the responseCode, or -1

updateWithClobs

public int updateWithClobs(java.util.List<DBConnector.DBPreparedBatchEntry> entries)
Usage: updateWithClobs("UPDATE...");

Parameters:
entries - the update SQL commands
Returns:
int the responseCode, or -1

updateWithClobs

public int updateWithClobs(java.lang.String[] updateStrings,
                           java.lang.String[][][] values)
Usage: updateWithClobs("UPDATE...");

Parameters:
updateStrings - the update SQL commands
values - the update SQL command values
Returns:
int the responseCode, or -1

updateWithClobs

public int updateWithClobs(java.lang.String updateString,
                           java.lang.String[][] values)
Usage: updateWithClobs("UPDATE...");

Parameters:
updateString - the update SQL commands
values - the update SQL values
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()

numAvailable

public int numAvailable()

pingAllConnections

public int pingAllConnections(java.lang.String querySql,
                              long usageTimeoutMillis)
Pings all connections not currently in use.

Parameters:
querySql - the query to use as a ping
usageTimeoutMillis - the idle time to use to decide which connections to ping.
Returns:
the number of connections actually pinged

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

DBFetchTest

public DBConnection DBFetchTest()
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. This is different than DBFetch because it ensures limited connection attempts. Usage: DB=DBFetchTest();

Returns:
DBConnection The DBConnection to use

DBFetchAny

public DBConnection DBFetchAny(java.lang.String SQL,
                               DBConnection.FetchType type)
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
type - the type of fetching to do
Returns:
DBConnection The DBConnection to use

isFakeDB

public boolean isFakeDB()

DBFetchPrepared

public DBConnection DBFetchPrepared(java.lang.String SQL)

DBFetchEmpty

public DBConnection DBFetchEmpty()

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