org.apache.lucene.store.jdbc.datasource
Class DataSourceUtils

java.lang.Object
  extended by org.apache.lucene.store.jdbc.datasource.DataSourceUtils

public abstract class DataSourceUtils
extends Object

A set of Jdbc DataSource utilities.

Author:
kimchy

Constructor Summary
DataSourceUtils()
           
 
Method Summary
static void closeResultSet(ResultSet rs)
          Close the given JDBC ResultSet and ignore any thrown exception.
static void closeStatement(Statement stmt)
          Close the given JDBC Statement and ignore any thrown exception.
static void commitConnectionIfPossible(Connection con)
          Commits the connection only if the connection is controlled by us.
static boolean controlConnection(Connection connection)
          Returns true if the connection was created by the TransactionAwareDataSourceProxy and it controls the connection (i.e. it is the most outer connection created).
static int getColumnIndexFromColumnName(ResultSetMetaData metaData, String columnName)
          Returns the column index for the guven column name.
static Connection getConnection(DataSource dataSource)
          Returns a jdbc connection, and in case of failure, wraps the sql exception with a Jdbc device exception.
static Connection getTargetConnection(Connection conn)
           
static void releaseConnection(Connection con)
          Close the given JDBC connection and ignore any thrown exception.
static void rollbackConnectionIfPossible(Connection con)
          Tollbacks the connection only if the connection is controlled by us.
static void safeCommitConnectionIfPossible(Connection con)
          Same as commitConnectionIfPossible(java.sql.Connection), only does not throw an exception
static void safeRollbackConnectionIfPossible(Connection con)
          Same as rollbackConnectionIfPossible(java.sql.Connection), only does not throw an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceUtils

public DataSourceUtils()
Method Detail

controlConnection

public static boolean controlConnection(Connection connection)
Returns true if the connection was created by the TransactionAwareDataSourceProxy and it controls the connection (i.e. it is the most outer connection created).


getConnection

public static Connection getConnection(DataSource dataSource)
                                throws JdbcStoreException
Returns a jdbc connection, and in case of failure, wraps the sql exception with a Jdbc device exception.

Throws:
JdbcStoreException

releaseConnection

public static void releaseConnection(Connection con)
Close the given JDBC connection and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

Will only close the connection under two conditions: If the connection was not created by the TransactionAwareDataSourceProxy, or if it was created by TransactionAwareDataSourceProxy, and the connection controls the connection (i.e. it is the most outer connection created).


commitConnectionIfPossible

public static void commitConnectionIfPossible(Connection con)
                                       throws JdbcStoreException
Commits the connection only if the connection is controlled by us. The connection is controlled if it is the TransactionAwareDataSourceProxy and it is the most outer connection in the tree of connections the TransactionAwareDataSourceProxy returned.

Throws:
JdbcStoreException

safeCommitConnectionIfPossible

public static void safeCommitConnectionIfPossible(Connection con)
Same as commitConnectionIfPossible(java.sql.Connection), only does not throw an exception


rollbackConnectionIfPossible

public static void rollbackConnectionIfPossible(Connection con)
                                         throws JdbcStoreException
Tollbacks the connection only if the connection is controlled by us. The connection is controlled if it is the TransactionAwareDataSourceProxy and it is the most outer connection in the tree of connections the TransactionAwareDataSourceProxy returned.

Throws:
JdbcStoreException

safeRollbackConnectionIfPossible

public static void safeRollbackConnectionIfPossible(Connection con)
Same as rollbackConnectionIfPossible(java.sql.Connection), only does not throw an exception.


closeStatement

public static void closeStatement(Statement stmt)
Close the given JDBC Statement and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

Parameters:
stmt - the JDBC Statement to close

closeResultSet

public static void closeResultSet(ResultSet rs)
Close the given JDBC ResultSet and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.

Parameters:
rs - the JDBC ResultSet to close

getColumnIndexFromColumnName

public static int getColumnIndexFromColumnName(ResultSetMetaData metaData,
                                               String columnName)
                                        throws SQLException
Returns the column index for the guven column name. Note that if there are two columns with the same name, the first onde index will be returned.

-1 is returned if none is found.

Throws:
SQLException

getTargetConnection

public static Connection getTargetConnection(Connection conn)


Copyright (c) 2004-2009 The Compass Project.