com.planet_ink.coffee_mud.core.database
Class DBConnection

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

public class DBConnection
extends java.lang.Object


Nested Class Summary
static class DBConnection.FetchType
           
 
Field Summary
protected  int failuresInARow
          number of failures in a row
protected  boolean inUse
          Whether this dbconnection is being used
protected  boolean isReusable
           
protected  java.lang.String lastError
          if any SQL errors occur, they are here.
protected  java.lang.String lastSQL
          for tracking the last sql statement made
protected  boolean sqlserver
           
 
Constructor Summary
DBConnection(DBConnections parent, 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, boolean useTransactions, boolean dbReuse)
          construction Usage: DBConnection("","","");
 
Method Summary
 java.lang.String catalog()
           
 void clearFailures()
          known errors should not be a reason to report a dead state Usage: clearFailures();
 void close()
          shut down this connection totally Usage: close()
protected  void closeStatements(java.lang.String Closer)
           
protected  void doneUsing(java.lang.String Closer)
          report this connection as being free Usage: doneUsing("roll back");
 java.lang.String getLastError()
          returns an error if there was one Usage: getLastError();
 long getLastQueryTime()
          Return the time, in millis, when this connection was last returned.
 java.sql.PreparedStatement getPreparedStatement()
          returns the prepared statement, if creates Usage: getPreparedStatement();
 int getRecordCount(java.sql.ResultSet R)
          Returns the number of records in the given result set.
 boolean inSQLServerCommunication()
           
 boolean inUse()
          returns whether this connection is in use Usage: inUse();
 boolean isFakeDB()
           
 boolean isProbablyDead()
          returns whether this connection is *probably* dead Usage: isProbablyDead();
 boolean isProbablyLockedUp()
          returns whether this connection is *probably* locked up Usage: isProbablyLockedUp();
 java.sql.ResultSet query(java.lang.String queryString)
          execute a query, returning the resultset Usage: R=query("SELECT STATEMENT");
 boolean ready()
          returns whether this connection is ready for use Usage: ready();
 boolean rePrepare(java.lang.String SQL)
          set up this connection for use as a prepared statement Requires an already in use connection.
 void setPreparedClobs(java.lang.String[] vals)
          Sets all the clobs in the prepared statement to the given strings
 int update(java.lang.String updateString, int retryNum)
          execute an sql update, returning the status Usage: update("UPDATE STATEMENT");
 boolean use(java.lang.String openerSQL)
          set up this connection for use Usage: use("begin transaction")
 boolean useEmpty()
          set up this connection for use Usage: useEmpty()
 boolean usePrepared(java.lang.String SQL)
          set up this connection for use as a prepared statement Usage: usePrepared("SQL String")
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inUse

protected volatile boolean inUse
Whether this dbconnection is being used


lastError

protected java.lang.String lastError
if any SQL errors occur, they are here.


failuresInARow

protected volatile int failuresInARow
number of failures in a row


sqlserver

protected volatile boolean sqlserver

isReusable

protected boolean isReusable

lastSQL

protected volatile java.lang.String lastSQL
for tracking the last sql statement made

Constructor Detail

DBConnection

public DBConnection(DBConnections parent,
                    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,
                    boolean useTransactions,
                    boolean dbReuse)
             throws java.sql.SQLException
construction Usage: DBConnection("","","");

Parameters:
parent - the parent connections object
dbClass - JDBC Class
dbService - ODBC SERVICE
dbUser - ODBC LOGIN USERNAME
dbPass - ODBC LOGIN PASSWORD
dbParms - JDBC extra arguments
dbReuse - Whether the connection can be reused.
Throws:
java.sql.SQLException - a sql error
Method Detail

catalog

public java.lang.String catalog()

isFakeDB

public boolean isFakeDB()

close

public void close()
shut down this connection totally Usage: close()


use

public boolean use(java.lang.String openerSQL)
set up this connection for use Usage: use("begin transaction")

Parameters:
openerSQL - Any SQL string you'd like to send
Returns:
boolean The connection being used

useEmpty

public boolean useEmpty()
set up this connection for use Usage: useEmpty()

Returns:
boolean The connection being used

usePrepared

public boolean usePrepared(java.lang.String SQL)
set up this connection for use as a prepared statement Usage: usePrepared("SQL String")

Parameters:
SQL - Any SQL string you'd like to use
Returns:
boolean The connection being used

rePrepare

public boolean rePrepare(java.lang.String SQL)
set up this connection for use as a prepared statement Requires an already in use connection. Usage: rePrepare("SQL String")

Parameters:
SQL - Any SQL string you'd like to use
Returns:
boolean The connection being used

closeStatements

protected void closeStatements(java.lang.String Closer)

doneUsing

protected void doneUsing(java.lang.String Closer)
report this connection as being free Usage: doneUsing("roll back");

Parameters:
Closer - Any SQL string you'd like to send

getLastQueryTime

public long getLastQueryTime()
Return the time, in millis, when this connection was last returned.

Returns:
the last time a query was made on this conn

query

public java.sql.ResultSet query(java.lang.String queryString)
                         throws java.sql.SQLException
execute a query, returning the resultset Usage: R=query("SELECT STATEMENT");

Parameters:
queryString - SQL query-style string
Returns:
ResultSet The results of the query
Throws:
java.sql.SQLException - a sql error

setPreparedClobs

public void setPreparedClobs(java.lang.String[] vals)
                      throws java.sql.SQLException
Sets all the clobs in the prepared statement to the given strings

Parameters:
vals - the strings, in order
Throws:
java.sql.SQLException - a sql error

update

public int update(java.lang.String updateString,
                  int retryNum)
           throws java.sql.SQLException
execute an sql update, returning the status Usage: update("UPDATE STATEMENT");

Parameters:
updateString - SQL update-style string
retryNum - a retry number
Returns:
int The status of the update
Throws:
java.sql.SQLException - a sql error

ready

public boolean ready()
returns whether this connection is ready for use Usage: ready();

Returns:
boolean Whether this connection is ready

inUse

public boolean inUse()
returns whether this connection is in use Usage: inUse();

Returns:
boolean Whether this connection is in use

getRecordCount

public int getRecordCount(java.sql.ResultSet R)
Returns the number of records in the given result set.

Parameters:
R - the result set
Returns:
the number of records

clearFailures

public void clearFailures()
known errors should not be a reason to report a dead state Usage: clearFailures();


inSQLServerCommunication

public boolean inSQLServerCommunication()

isProbablyDead

public boolean isProbablyDead()
returns whether this connection is *probably* dead Usage: isProbablyDead();

Returns:
boolean Whether this connection is probably dead

isProbablyLockedUp

public boolean isProbablyLockedUp()
returns whether this connection is *probably* locked up Usage: isProbablyLockedUp();

Returns:
boolean Whether this connection is locked up

getLastError

public java.lang.String getLastError()
returns an error if there was one Usage: getLastError();

Returns:
String The last error SQL string, if any

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement()
returns the prepared statement, if creates Usage: getPreparedStatement();

Returns:
PreparedStatement the prepared statement