it.gotoandplay.smartfoxserver.db
Class DbManager

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.db.DbManager

public class DbManager
extends java.lang.Object

The DbManager class manages the connection to a database using either JDBC native drivers or JDBC-ODBC bridge.
Additionally it provides configurable connection pooling for optimal performance and resource usage.

Each Zone has its own DbManager which can be configured directly in the main config.xml file. More details about how to configure the database connection are found in chapter 6.3 of our documentation

Author:
(c) 2004-2007 gotoAndPlay() -- www.gotoandplay.it

Constructor Summary
DbManager(java.lang.String driverName, java.lang.String connStr, java.lang.String usrName, java.lang.String pword, java.lang.String zoneName, int maxActive, int maxIdle, java.lang.String exhaustedAction, int blockTime)
          Creates a new, pooled DbManager object
For further details check this page
 
Method Summary
 boolean executeCommand(java.lang.String cmd)
          Executes any non-SELECT SQL commands (INSERT, UPDATE, DELETE etc...)
 java.util.ArrayList executeQuery(java.lang.String cmd)
          Executes a SQL query (SELECT) and returns an ArrayList of DataRows where each column can be referenced with the field name
 java.util.ArrayList executeQuery(java.lang.String cmd, int keyType)
          Executes a SQL query (SELECT) and returns an ArrayList of DataRows where each column can be referenced by its field name or numeric index (starting from zero)
 java.sql.Connection getConnection()
          Grab a connection from the connection pool This allows the extension developer to freely instantiate a db connection and use all the objects exposed by the JDBC APIs.
 void shutDown()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbManager

public DbManager(java.lang.String driverName,
                 java.lang.String connStr,
                 java.lang.String usrName,
                 java.lang.String pword,
                 java.lang.String zoneName,
                 int maxActive,
                 int maxIdle,
                 java.lang.String exhaustedAction,
                 int blockTime)
Creates a new, pooled DbManager object
For further details check this page

Parameters:
driverName - the database driver name (must be in the classpath)
connStr - the connection string
usrName - the user name for the connection
pword - the password
zoneName - the name of the Zone which owns this object
maxActive - max. active connections in the pool
maxIdle - max. idle connections
exhaustedAction - what to do if the pool fails to retrieve a connection (grow, wait, fail)
blockTime - how much time to wait if wait is chosen for the above option
Method Detail

getConnection

public java.sql.Connection getConnection()
Grab a connection from the connection pool This allows the extension developer to freely instantiate a db connection and use all the objects exposed by the JDBC APIs.

Returns:
a connection to the db configured in the current zone
Since:
SFS 1.5.0

executeQuery

public java.util.ArrayList executeQuery(java.lang.String cmd)
Executes a SQL query (SELECT) and returns an ArrayList of DataRows where each column can be referenced with the field name

Parameters:
cmd - any valid SQL SELECT command
Returns:
an ArrayList of DataRow
See Also:
DataRow

executeQuery

public java.util.ArrayList executeQuery(java.lang.String cmd,
                                        int keyType)
Executes a SQL query (SELECT) and returns an ArrayList of DataRows where each column can be referenced by its field name or numeric index (starting from zero)

Parameters:
cmd - any valid SQL SELECT command
keyType - accepts DataRow.DATAROW_INTKEY or DataRow.DATAROW_STRINGKEY
Returns:
an ArrayList of results

executeCommand

public boolean executeCommand(java.lang.String cmd)
Executes any non-SELECT SQL commands (INSERT, UPDATE, DELETE etc...)

Parameters:
cmd - the SQL command
Returns:
true if the operation was successfull

shutDown

public void shutDown()