com.planet_ink.coffee_mud.core.database
Class DBConnector

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

public class DBConnector
extends java.lang.Object


Nested Class Summary
static class DBConnector.DBPreparedBatchEntry
           
 
Constructor Summary
DBConnector()
           
DBConnector(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, int dbPingIntMins, boolean reuse, boolean transact, boolean doErrorQueueing, boolean retryErrorQueue)
           
 
Method Summary
 boolean amIOk()
          Return the happiness level of the connections Usage: amIOk()
 void DBDone(DBConnection D)
          Return a DBConnection object fetched with DBFetch() Usage:
 DBConnection DBFetch()
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchEmpty()
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchPrepared(java.lang.String SQL)
          Fetch a single, not in use DBConnection object.
 DBConnection DBFetchTest()
          Fetch a single, not in use DBConnection object for testing only.
 boolean deregisterDriver()
           
 void enQueueError(java.lang.String SQLString, java.lang.String SQLError, java.lang.String count)
          Queue up a failed write/update for later processing.
 java.lang.StringBuffer errorStatus()
          return a status string, or "" if everything is ok.
 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.
 int getRecordCount(DBConnection D, java.sql.ResultSet R)
           
 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.
 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.
 java.lang.String getResQuietly(java.sql.ResultSet Results, java.lang.String Field)
           
 java.lang.String injectionClean(java.lang.String s)
           
 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 numConnectionsMade()
           
 int numDBConnectionsInUse()
           
 int pingAllConnections(java.lang.String querySql)
          Pings all connections
 int pingAllConnections(java.lang.String querySql, long overridePingIntMillis)
          Pings all connections
 int queryRows(java.lang.String queryString)
           
 void reconnect()
           
 void retryQueuedErrors()
          Queue up a failed write/update for later processing.
 java.lang.String service()
           
 int update(java.lang.String updateString)
           
 int update(java.lang.String[] updateStrings)
           
 int updateWithClobs(DBConnector.DBPreparedBatchEntry entry)
           
 int updateWithClobs(java.util.List<DBConnector.DBPreparedBatchEntry> entries)
           
 int updateWithClobs(java.lang.String[] updateStrings, java.lang.String[][][] values)
           
 int updateWithClobs(java.lang.String updateString, java.lang.String... values)
           
 int updateWithClobs(java.lang.String updateString, java.lang.String[][] values)
           
 boolean useBulkInserts()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBConnector

public DBConnector()

DBConnector

public DBConnector(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,
                   int dbPingIntMins,
                   boolean reuse,
                   boolean transact,
                   boolean doErrorQueueing,
                   boolean retryErrorQueue)
Method Detail

reconnect

public void reconnect()

service

public java.lang.String service()

useBulkInserts

public boolean useBulkInserts()

getRecordCount

public int getRecordCount(DBConnection D,
                          java.sql.ResultSet R)

deregisterDriver

public boolean deregisterDriver()

isFakeDB

public boolean isFakeDB()

update

public int update(java.lang.String[] updateStrings)

update

public int update(java.lang.String updateString)

updateWithClobs

public int updateWithClobs(java.lang.String[] updateStrings,
                           java.lang.String[][][] values)

updateWithClobs

public int updateWithClobs(java.util.List<DBConnector.DBPreparedBatchEntry> entries)

updateWithClobs

public int updateWithClobs(DBConnector.DBPreparedBatchEntry entry)

updateWithClobs

public int updateWithClobs(java.lang.String updateString,
                           java.lang.String... values)

updateWithClobs

public int updateWithClobs(java.lang.String updateString,
                           java.lang.String[][] values)

queryRows

public int queryRows(java.lang.String queryString)

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 for testing only. 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

DBFetchEmpty

public DBConnection DBFetchEmpty()
Fetch a single, not in use DBConnection object. Must be rePrepared afterwards 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=DBFetchEmpty();

Returns:
DBConnection The DBConnection to use

numConnectionsMade

public int numConnectionsMade()

numDBConnectionsInUse

public int numDBConnectionsInUse()

DBFetchPrepared

public DBConnection DBFetchPrepared(java.lang.String SQL)
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
Returns:
DBConnection The DBConnection to use

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 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=getLongRes(R,"FIELD");

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

getResQuietly

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

injectionClean

public java.lang.String injectionClean(java.lang.String s)

getLongRes

public 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 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

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

pingAllConnections

public int pingAllConnections(java.lang.String querySql)
Pings all connections

Parameters:
querySql - the query to ping with
Returns:
the number of pings done

pingAllConnections

public int pingAllConnections(java.lang.String querySql,
                              long overridePingIntMillis)
Pings all connections

Parameters:
querySql - the query to ping with
overridePingIntMillis - the age of a connection before a ping is necessary
Returns:
the number of pings done

enQueueError

public void enQueueError(java.lang.String SQLString,
                         java.lang.String SQLError,
                         java.lang.String count)
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
count - The number of tries so far

retryQueuedErrors

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


listConnections

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

Parameters:
out - place to send the list out to

errorStatus

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

Returns:
StringBuffer complete error status