xmlBlaster 2.2.0 client API

org.xmlBlaster.util.queue.jdbc
Class JdbcConnectionPool

java.lang.Object
  extended by org.xmlBlaster.util.queue.jdbc.JdbcConnectionPool
All Implemented Interfaces:
I_Timeout, I_StorageProblemNotifier

public class JdbcConnectionPool
extends java.lang.Object
implements I_Timeout, I_StorageProblemNotifier

A Pool of connections to the database to be used for a persistent queue. To keep genericity, queries and update strings are read from properties.

See Also:
The queue.jdbc.commontable requirement

Constructor Summary
JdbcConnectionPool()
          The default constructor currently does nothing.
 
Method Summary
 java.sql.Connection createNewConnection(boolean doLog)
          Independend of pool.
 void discardConnection(java.sql.Connection conn)
          Discards the passed connection from the pool and instead adds a new fresh connection to the pool.
 void disconnect()
          Closes all connections to the Database.
 void dumpMetaData()
           
 void finalize()
           
 java.lang.String getColNamePrefix()
           
 java.sql.Connection getConnection()
          Returns a free connection.
 Global getGlobal()
          Returns the global object associated with this pool.
static java.lang.String getIsolationLevel(java.sql.Connection conn)
           
 java.util.Hashtable<java.lang.String,java.lang.String> getMapping()
          The mapping is taken out of the xmlBlaster.properties file.
 java.util.Properties getPluginProperties()
          returns the plugin properties, i.e.
 int getProp(java.lang.String key, int def)
           
 java.lang.String getProp(java.lang.String key, java.lang.String def)
           
 int getQueryTimeout()
           
 int getStatus()
          returns true if the connection is temporarly lost (and the pool is polling for new connections)
 int getTableAllocationIncrement()
           
 java.lang.String getTableNamePrefix()
           
 java.lang.String getUrl()
           
 java.lang.String getUserName()
           
 void initialize(Global glob, java.util.Properties pluginProperties)
          Is called after the instance is created.
 boolean isBatchModeEnabled()
          The batch mode means that insertions in the database are made in batch mode, i.e.
 boolean isCascadeDeleteSuppported()
           
 boolean isDbAdmin()
           
 boolean isInitialized()
          returns true if the pool already is initialized, false otherwise.
 boolean isNestedBracketsSuppported()
           
static java.lang.String isolationToString(int isolation)
           
static void main(java.lang.String[] args)
           
 void registerManager(java.lang.Object manager)
           
 boolean registerStorageProblemListener(I_StorageProblemListener storageProblemListener)
          Sets the connection listener.
 void releaseConnection(java.sql.Connection conn, boolean success)
          Used to give back a connection to the pool.
 void setDatabaseLost()
          informs this pool that the connection to the DB has been lost
 void shutdown()
           
 void timeout(java.lang.Object userData)
          Invoked by the timer when a check for reconnection is wanted again
 void unregisterManager(java.lang.Object manager)
           
 boolean unRegisterStorageProblemListener(I_StorageProblemListener storageProblemListener)
          Unregisters the storageProblemListener.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcConnectionPool

public JdbcConnectionPool()
The default constructor currently does nothing. Initialization is done in the initialize() method.

Method Detail

getPluginProperties

public java.util.Properties getPluginProperties()
returns the plugin properties, i.e. the specific properties passed to the jdbc queue plugin. These are commonly used by the jdbc manager.


timeout

public void timeout(java.lang.Object userData)
Invoked by the timer when a check for reconnection is wanted again

Specified by:
timeout in interface I_Timeout
Parameters:
userData - You get bounced back your userData which you passed with Timeout.addTimeoutListener()
See Also:
I_Timeout.timeout(Object)

registerStorageProblemListener

public boolean registerStorageProblemListener(I_StorageProblemListener storageProblemListener)
Sets the connection listener. Only one is allowed at a time. So if there is already a connection listener, it will be overwritten (and the old one will not get anyu notification anymore).

Specified by:
registerStorageProblemListener in interface I_StorageProblemNotifier

unRegisterStorageProblemListener

public boolean unRegisterStorageProblemListener(I_StorageProblemListener storageProblemListener)
Unregisters the storageProblemListener. If no one has been defined, or if the one you want to unregister is different from the one you have registered, nothing is done and 'false' is returned.

Specified by:
unRegisterStorageProblemListener in interface I_StorageProblemNotifier

getGlobal

public Global getGlobal()
Returns the global object associated with this pool.


isInitialized

public boolean isInitialized()
returns true if the pool already is initialized, false otherwise.


discardConnection

public void discardConnection(java.sql.Connection conn)
                       throws XmlBlasterException
Discards the passed connection from the pool and instead adds a new fresh connection to the pool. This method is to be invoked when an exception occured and it can be supposed that the connection is not good anymore.

Parameters:
conn -
Throws:
XmlBlasterException

isolationToString

public static java.lang.String isolationToString(int isolation)

getIsolationLevel

public static java.lang.String getIsolationLevel(java.sql.Connection conn)

createNewConnection

public java.sql.Connection createNewConnection(boolean doLog)
                                        throws java.sql.SQLException
Independend of pool.

Parameters:
doLog -
Returns:
Throws:
java.sql.SQLException

getProp

public java.lang.String getProp(java.lang.String key,
                                java.lang.String def)

getProp

public int getProp(java.lang.String key,
                   int def)

initialize

public void initialize(Global glob,
                       java.util.Properties pluginProperties)
                throws java.lang.ClassNotFoundException,
                       java.sql.SQLException,
                       XmlBlasterException
Is called after the instance is created. It reads the needed properties, sets the driver and then connects to the database as many times as specified in the properties.

Note that prefix is the string which identifies a certain database. It is called prefix because it is the prefix in the xmlBlaster.properties for the properties bound to the database.
A pool instance is created for every such database. For example if you want the history queue (the queue which stores the published messages) on a different database than the callback queues, then you could define different databases.

  • prefix.driverName DEFAULTS TO "org.postgresql.Driver"
  • prefix.connectionPoolSize "DEFAULTS TO 2"
  • prefix.url DEFAULTS TO "jdbc:postgresql://localhost/test"
  • prefix.user DEFAULTS TO "postgres"
  • prefix.password DEFAULTS TO ""
  • Throws:
    java.lang.ClassNotFoundException
    java.sql.SQLException
    XmlBlasterException

    getTableNamePrefix

    public java.lang.String getTableNamePrefix()
    Returns:
    the prefix for the name of the tables to associate to the queues

    getUserName

    public java.lang.String getUserName()

    getColNamePrefix

    public java.lang.String getColNamePrefix()
    Returns:
    the prefix for the name of the columns in each DB table

    getTableAllocationIncrement

    public int getTableAllocationIncrement()
    Returns:
    the number of tables to add each time no free tables are available when creating a new queue.

    getMapping

    public java.util.Hashtable<java.lang.String,java.lang.String> getMapping()
    The mapping is taken out of the xmlBlaster.properties file. It is an Hashtable where the keys are the logical names used for a type in the JdbcQueuePlugin and the values are the real names to be used in the database used (which may be vendor specific).


    disconnect

    public void disconnect()
    Closes all connections to the Database. It should not throw any exception. Exceptions coming from the backend or the communication layer are catched and logged. When this occurs, the affected connections are set to null.


    finalize

    public void finalize()
    Overrides:
    finalize in class java.lang.Object

    getStatus

    public final int getStatus()
    returns true if the connection is temporarly lost (and the pool is polling for new connections)


    setDatabaseLost

    public final void setDatabaseLost()
    informs this pool that the connection to the DB has been lost


    getConnection

    public java.sql.Connection getConnection()
                                      throws XmlBlasterException
    Returns a free connection. If no connection is currently available it waits no more than what specified in the configuration. If after that time still no connection is available it throws an XmlBlasterException. It also throws an XmlBlasterException if the number of threads which are waiting is already too high (also configurable).

    Throws:
    XmlBlasterException

    releaseConnection

    public void releaseConnection(java.sql.Connection conn,
                                  boolean success)
                           throws XmlBlasterException
    Used to give back a connection to the pool. If the pool is already full it will throw an exception. If the success flag is true, it well release the connection back to the pool, otherwise it will throw away the current connection and add to the pool a new one.

    Throws:
    XmlBlasterException

    dumpMetaData

    public void dumpMetaData()

    isDbAdmin

    public boolean isDbAdmin()

    getQueryTimeout

    public int getQueryTimeout()

    main

    public static void main(java.lang.String[] args)

    shutdown

    public void shutdown()

    registerManager

    public void registerManager(java.lang.Object manager)

    unregisterManager

    public void unregisterManager(java.lang.Object manager)

    isBatchModeEnabled

    public boolean isBatchModeEnabled()
    The batch mode means that insertions in the database are made in batch mode, i.e. several entries in one sweep. This can increase perfomance significantly on some DBs.

    Returns:
    true if batch mode has been enabled, false otherwise (defaults to true).

    isCascadeDeleteSuppported

    public boolean isCascadeDeleteSuppported()
    Returns:
    true if 'cascadeDeleteSupported' has been set to true

    isNestedBracketsSuppported

    public boolean isNestedBracketsSuppported()
    Returns:
    true if 'nestedBracketsSupported' has been set to true

    getUrl

    public java.lang.String getUrl()
    Returns:
    the url

    xmlBlaster 2.2.0 client API

    Copyright © 1999-2014 The xmlBlaster.org contributers.