Ontimize 5.2072EN

com.ontimize.db
Class DatabaseConnectionManager

java.lang.Object
  extended bycom.ontimize.db.DatabaseConnectionManager
Direct Known Subclasses:
MSAccessConnectionManager

public class DatabaseConnectionManager
extends java.lang.Object

Allows to create and manage a database connection pool. Parameters of 'database.properties' are parsed here.

Author:
Imatia Innovation
See Also:
DatabaseConnectionManager(boolean, boolean, URL, URL, boolean)

Nested Class Summary
protected  class DatabaseConnectionManager.CheckConnectionThread
           
protected  class DatabaseConnectionManager.ReleaseThread
           
protected  class DatabaseConnectionManager.ReserveCancellationThread
           
 
Field Summary
static boolean AUTOCOMMIT_ON_UNLOCK
           
static java.lang.String AUTONUMERICAL_PROPERTIES
           
static java.lang.String CHECK_CYCLE
           
protected  DatabaseConnectionManager.CheckConnectionThread checkConnectionThread
           
protected  int checkupCicle
           
static java.lang.String CONNECTION_INFO
           
protected  java.util.Vector connections
           
static java.lang.String CREATE_INITIAL_CONNECTIONS
           
static java.lang.String DATABASE
           
protected  java.lang.String databaseId
           
protected  java.lang.Object dataSource
           
protected  java.lang.String dataSourceName
           
static java.lang.String DATASOURCENAME
           
static boolean DEBUG
           
static java.lang.String defaultPasswordValue
           
static java.lang.String defaultUserValue
           
protected  java.lang.String driver
           
static java.lang.String DRIVER
           
static java.lang.String E64PASSWORD
           
static java.lang.String EPASSWORD
           
protected  boolean forceDisconnection
           
static java.lang.String INCREASE_CONNECTIONS
           
protected  int increment
           
static java.lang.String LOCKED_TIMEOUT
           
protected  java.util.Vector lockTime
           
protected  long lockTimeout
           
protected  int maximum
           
static java.lang.String MAXIMUM_CONNECTIONS
           
protected  double maxlocktime
           
protected  int maxReserveTime
           
protected  int minimum
           
static java.lang.String MINIMUM_CONNECTIONS
           
static int offset
           
static java.lang.String offsetString
           
protected  java.lang.String password
           
static java.lang.String PASSWORD
           
static java.lang.String RELEASE_CYCLE
           
protected  long releaseCicleThread
           
protected  DatabaseConnectionManager.ReleaseThread releaseThread
           
protected  DatabaseConnectionManager.ReserveCancellationThread reserveCancellationThread
           
protected  int reserveCicle
           
static java.lang.String TEST_TABLE
           
protected  java.lang.String testTable
           
protected  long timeout
           
static java.lang.String TIMEOUT
           
static java.lang.String UPDATE_CYCLE
           
protected  long updateCicleThread
           
static java.lang.String URL
           
protected  java.lang.String urlDB
           
protected  boolean useJ2EEConnection
           
static java.lang.String USEJ2EECONNECTIONS
           
protected  java.lang.String user
           
static java.lang.String USER
           
 
Constructor Summary
DatabaseConnectionManager(boolean statisticViewer, boolean connectionsInfoToFile, java.net.URL urlPropDB, java.net.URL urlAutonumerical)
          Class constructor.
DatabaseConnectionManager(boolean statisticViewer, boolean connectionsInfoToFile, java.net.URL urlPropDB, java.net.URL urlAutonumerical, boolean createInitialConnections)
          Constructor that gets parameters related to database.
DatabaseConnectionManager(java.util.Hashtable parameters)
           
DatabaseConnectionManager(java.net.URL urlDBProp, java.net.URL urlAutonumerical, int minConnections, int maxConnections, int connectionIncrement, long timeoutBlockConnection, long timeoutConnection, boolean statisticViewer)
           
 
Method Summary
 void activeForceDisconnection()
          Close all the connections.
 void closeConnections()
           
 void closeLockedConnections()
           
 java.sql.Connection createConnection()
           
protected  OntimizeConnection createConnection(java.lang.String driver, java.lang.String uRLBD, java.lang.String user, java.lang.String password)
           
protected  java.lang.Object createDataSource(java.lang.String dataSourceName, java.util.Properties prop)
           
 void deactivateForceDisconnection()
           
protected  void finalize()
           
 Autonumerical getAutonumerialReference()
           
 Autonumerical getAutonumerical()
           
 int getAutonumericalValue()
           
 int getAutonumericalValue(java.lang.String table)
           
 double getAverageLockTime()
           
 java.lang.String getDatabase()
           
 int getLockedOntimizeConnectionNumber()
           
 double getMaximumLockTime()
           
 OntimizeConnection getOntimizeConnection()
          Returns an available connection and locks it.
 OntimizeConnection getOntimizeConnection(int id)
          Search an unlocked connection reserved with the specified id.
 int getOntimizeConnectionNumber()
           
 long getUpdateCicleTime()
           
 boolean isForceDisconnectionEnabled()
           
 void setAutonumerical(Autonumerical auto)
           
 void setAutonumerical(java.lang.String oPropAutonumerical)
           
 void setAutonumerical(java.net.URL oURLAutonumerical)
           
 void setCheckupCicle(int checkupCicle)
           
 void setDatabaseId(java.lang.String databaseId)
           
 void setDriver(java.lang.String driver)
           
 void setIncrementConnections(int increment)
           
 void setLockTimeout(long lockTimeout)
           
 void setMaximumConnections(int maximum)
           
 void setMinimumConnections(int minimum)
           
 void setPassword(java.lang.String password)
           
 void setReleaseCicle(long releaseCicle)
           
 void setSaveConnectionsInfo(boolean connectionInfo)
           
 void setTestTable(java.lang.String testTable)
           
 void setTimeout(long timeout)
           
 void setUpdateCicle(long updateCicle)
           
 void setUrlDB(java.lang.String urlDB)
           
 void setUser(java.lang.String user)
           
 java.lang.String toString()
           
 void unLock(OntimizeConnection ontimizeConnection)
          Unlock the connection
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultUserValue

public static java.lang.String defaultUserValue

defaultPasswordValue

public static java.lang.String defaultPasswordValue

TIMEOUT

public static final java.lang.String TIMEOUT
See Also:
Constant Field Values

LOCKED_TIMEOUT

public static final java.lang.String LOCKED_TIMEOUT
See Also:
Constant Field Values

INCREASE_CONNECTIONS

public static final java.lang.String INCREASE_CONNECTIONS
See Also:
Constant Field Values

MAXIMUM_CONNECTIONS

public static final java.lang.String MAXIMUM_CONNECTIONS
See Also:
Constant Field Values

MINIMUM_CONNECTIONS

public static final java.lang.String MINIMUM_CONNECTIONS
See Also:
Constant Field Values

EPASSWORD

public static final java.lang.String EPASSWORD
See Also:
Constant Field Values

E64PASSWORD

public static final java.lang.String E64PASSWORD
See Also:
Constant Field Values

PASSWORD

public static final java.lang.String PASSWORD
See Also:
Constant Field Values

USER

public static final java.lang.String USER
See Also:
Constant Field Values

TEST_TABLE

public static final java.lang.String TEST_TABLE
See Also:
Constant Field Values

CHECK_CYCLE

public static final java.lang.String CHECK_CYCLE
See Also:
Constant Field Values

RELEASE_CYCLE

public static final java.lang.String RELEASE_CYCLE
See Also:
Constant Field Values

UPDATE_CYCLE

public static final java.lang.String UPDATE_CYCLE
See Also:
Constant Field Values

URL

public static final java.lang.String URL
See Also:
Constant Field Values

DRIVER

public static final java.lang.String DRIVER
See Also:
Constant Field Values

DATABASE

public static final java.lang.String DATABASE
See Also:
Constant Field Values

USEJ2EECONNECTIONS

public static final java.lang.String USEJ2EECONNECTIONS
See Also:
Constant Field Values

DATASOURCENAME

public static final java.lang.String DATASOURCENAME
See Also:
Constant Field Values

CONNECTION_INFO

public static final java.lang.String CONNECTION_INFO
See Also:
Constant Field Values

CREATE_INITIAL_CONNECTIONS

public static final java.lang.String CREATE_INITIAL_CONNECTIONS
See Also:
Constant Field Values

AUTONUMERICAL_PROPERTIES

public static final java.lang.String AUTONUMERICAL_PROPERTIES
See Also:
Constant Field Values

DEBUG

public static boolean DEBUG

AUTOCOMMIT_ON_UNLOCK

public static final boolean AUTOCOMMIT_ON_UNLOCK
See Also:
Constant Field Values

minimum

protected int minimum

maximum

protected int maximum

increment

protected int increment

lockTimeout

protected long lockTimeout

timeout

protected long timeout

offset

public static int offset

offsetString

public static java.lang.String offsetString

reserveCancellationThread

protected DatabaseConnectionManager.ReserveCancellationThread reserveCancellationThread

checkConnectionThread

protected DatabaseConnectionManager.CheckConnectionThread checkConnectionThread

maxReserveTime

protected int maxReserveTime

reserveCicle

protected int reserveCicle

checkupCicle

protected int checkupCicle

testTable

protected java.lang.String testTable

useJ2EEConnection

protected boolean useJ2EEConnection

dataSourceName

protected java.lang.String dataSourceName

dataSource

protected java.lang.Object dataSource

connections

protected java.util.Vector connections

driver

protected java.lang.String driver

urlDB

protected java.lang.String urlDB

databaseId

protected java.lang.String databaseId

user

protected java.lang.String user

password

protected java.lang.String password

releaseThread

protected DatabaseConnectionManager.ReleaseThread releaseThread

releaseCicleThread

protected long releaseCicleThread

updateCicleThread

protected long updateCicleThread

lockTime

protected java.util.Vector lockTime

maxlocktime

protected double maxlocktime

forceDisconnection

protected boolean forceDisconnection
Constructor Detail

DatabaseConnectionManager

public DatabaseConnectionManager(java.net.URL urlDBProp,
                                 java.net.URL urlAutonumerical,
                                 int minConnections,
                                 int maxConnections,
                                 int connectionIncrement,
                                 long timeoutBlockConnection,
                                 long timeoutConnection,
                                 boolean statisticViewer)
                          throws java.lang.Exception
Parameters:
urlDBProp - URI of the database properties file path
One of the parameters of this file is 'usej2eeconnections' with values 'yes' or 'no' (default value is 'no') to indicate is j2ee connections are used (DataSource). When 'usej2eeconnections'='yes' the file must contains the DataSource name ('datasourcename').
urlAutonumerical -
minConnections -
maxConnections -
connectionIncrement -
timeoutBlockConnection -
timeoutConnection -
statisticViewer -
Throws:
java.lang.Exception

DatabaseConnectionManager

public DatabaseConnectionManager(boolean statisticViewer,
                                 boolean connectionsInfoToFile,
                                 java.net.URL urlPropDB,
                                 java.net.URL urlAutonumerical)
Class constructor.

Parameters:
statisticViewer - condition to show the statisticViewer
connectionsInfoToFile - conditions to write connections info to file
urlPropDB - URL to database properties (Relative to classpath):
urlAutonumerical - URL to autonumerical properties

DatabaseConnectionManager

public DatabaseConnectionManager(boolean statisticViewer,
                                 boolean connectionsInfoToFile,
                                 java.net.URL urlPropDB,
                                 java.net.URL urlAutonumerical,
                                 boolean createInitialConnections)
Constructor that gets parameters related to database. Typically this parameters are specified in database.properties.

Parameters:
statisticViewer - Not used
connectionsInfoToFile - Indicates whether information of connections is written to a file
urlPropDB - complete path to database.properties file
urlAutonumerical - complete path to autonumerical.properties file
createInitialConnections - Indicates whether connections are created on startup

Parameters for database.properties

attribute values default required meaning
URL yes The URL where database is stored. For example, with HSQLD engine: jdbc:hsqldb:db/myDatabase
Driver yes Driver for database. For example, with jdbc connection in HSQLD engine: org.hsqldb.jdbcDriver
Database default/Postgres/SQLServer/Oracle/HSQLDB/Access default no Indicates the handler used to manage operations with database. There are many available handlers.
User yes User to connect with database
Password yes Password to connect with database. When password in database.properties is stored encrypted, parameter Password must be replaced by this one.
E64Password no This parameter is used instead of Password when user wants to store database password encrypted in database.properties.
TestTable no (but strongly recommended) This parameter checks automatically that connection with database is OK and try to reconnect (transparently for user) when an communication error is produced among server and database.
CheckCycle 20000 ms no Timer for thread where Ontimize connection pool checks database connections
ReleaseCycle 5000 ms no Timer for thread where Ontimize connection pool checks to release blocked connections.
UpdateCycle 500 ms no Time between captures of the Server Monitor where info of conections is showed
MinimumConnections 0 yes Minimum connection number that the connection pool will open in the start up
MaximumConnections 10 no Maximum connection number the the connection pool will handle
IncreaseConnections 5 no Connection number to be open when all the connections are being used.
LockedTimeout Long.MAX_VALUE no Max time the connection can be blocked.
Timeout Long.MAX_VALUE no Max time of inactivity to close a connection.
usej2eeconnections yes/no no no Indicates when application is using J2EE DataSource for connections
datasourcename no (required when usej2eeconnections is set to 'yes' The name of datasource. It is the name used to do 'lookup' operation from context.

DatabaseConnectionManager

public DatabaseConnectionManager(java.util.Hashtable parameters)
                          throws java.lang.Exception
Method Detail

getOntimizeConnection

public OntimizeConnection getOntimizeConnection()
                                         throws java.lang.Exception
Returns an available connection and locks it. Ontimize tries to return a non-locked and non-reserved connection. When it is not possible, the oldest connection non-locked and reserved is returned. When neither non-locked nor non-reserved connections are available, Ontimize tries to increase the number connections, if it is not possible returns null.

Returns:
a connection available or null
Throws:
java.lang.Exception - when Exception occurs

getOntimizeConnection

public OntimizeConnection getOntimizeConnection(int id)
                                         throws java.lang.Exception
Search an unlocked connection reserved with the specified id. If the connection does not exist then uses the getConnection method

Parameters:
id - Reservation identifier
Returns:
Throws:
java.lang.Exception

createConnection

protected OntimizeConnection createConnection(java.lang.String driver,
                                              java.lang.String uRLBD,
                                              java.lang.String user,
                                              java.lang.String password)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

createConnection

public java.sql.Connection createConnection()
                                     throws java.sql.SQLException
Throws:
java.sql.SQLException

unLock

public void unLock(OntimizeConnection ontimizeConnection)
Unlock the connection

Parameters:
ontimizeConnection - Connection to unlock

setAutonumerical

public void setAutonumerical(java.net.URL oURLAutonumerical)

setAutonumerical

public void setAutonumerical(java.lang.String oPropAutonumerical)

setAutonumerical

public void setAutonumerical(Autonumerical auto)

getAutonumericalValue

public int getAutonumericalValue()

getAutonumerical

public Autonumerical getAutonumerical()

getAutonumericalValue

public int getAutonumericalValue(java.lang.String table)

closeConnections

public void closeConnections()

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

getOntimizeConnectionNumber

public int getOntimizeConnectionNumber()

getLockedOntimizeConnectionNumber

public int getLockedOntimizeConnectionNumber()

closeLockedConnections

public void closeLockedConnections()

getAverageLockTime

public double getAverageLockTime()

getMaximumLockTime

public double getMaximumLockTime()

getUpdateCicleTime

public long getUpdateCicleTime()

activeForceDisconnection

public void activeForceDisconnection()
                              throws java.lang.Exception
Close all the connections. This method can only be used when the JEE connections mode is not enabled.

Throws:
java.lang.Exception

deactivateForceDisconnection

public void deactivateForceDisconnection()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

isForceDisconnectionEnabled

public boolean isForceDisconnectionEnabled()

getAutonumerialReference

public Autonumerical getAutonumerialReference()

createDataSource

protected java.lang.Object createDataSource(java.lang.String dataSourceName,
                                            java.util.Properties prop)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

getDatabase

public java.lang.String getDatabase()

toString

public java.lang.String toString()

setDriver

public void setDriver(java.lang.String driver)

setUrlDB

public void setUrlDB(java.lang.String urlDB)

setUser

public void setUser(java.lang.String user)

setPassword

public void setPassword(java.lang.String password)

setMinimumConnections

public void setMinimumConnections(int minimum)

setMaximumConnections

public void setMaximumConnections(int maximum)

setIncrementConnections

public void setIncrementConnections(int increment)

setDatabaseId

public void setDatabaseId(java.lang.String databaseId)

setLockTimeout

public void setLockTimeout(long lockTimeout)

setTimeout

public void setTimeout(long timeout)

setCheckupCicle

public void setCheckupCicle(int checkupCicle)

setReleaseCicle

public void setReleaseCicle(long releaseCicle)

setUpdateCicle

public void setUpdateCicle(long updateCicle)

setTestTable

public void setTestTable(java.lang.String testTable)

setSaveConnectionsInfo

public void setSaveConnectionsInfo(boolean connectionInfo)

Ontimize