net.sf.jabb.util.db
Class ConnectionUtility

java.lang.Object
  extended by net.sf.jabb.util.db.ConnectionUtility

public class ConnectionUtility
extends Object

数据库连接工具,它提供有关数据库连接获取、关闭的方法。 它用到commons-logging来记录执行情况。

Author:
Zhengmao HU (James)

Field Summary
protected static Properties configuration
           
protected static HashMap<String,DataSourceProvider> dataSourceProviders
           
protected static HashMap<String,DataSource> dataSources
           
protected static Object dataSourcesStructureLock
           
static String DELIMITORS
           
static String PROVIDER_PROPERTY_NAME
           
static String ROOT_CONFIGURATION_FILE
           
 
Constructor Summary
ConnectionUtility()
           
 
Method Summary
static void closeConnection(Connection conn)
          Closes database Connection.
static void closeConnection(Connection conn, Statement st)
          Close database connection and statement.
static void closeConnection(Connection conn, Statement st, ResultSet... rss)
           
static void closeConnection(Connection conn, Statement st, ResultSet rs)
           
static void closeConnection(Connection conn, Statement st, ResultSet rs1, ResultSet rs2)
           
static void closeConnection(Connection conn, Statement st, ResultSet rs1, ResultSet rs2, ResultSet rs3)
           
static void closeConnection(Connection conn, Statement st1, Statement st2)
           
static void closeConnection(Connection conn, Statement st1, Statement st2, ResultSet... rss)
           
static void closeConnection(Connection conn, Statement st1, Statement st2, ResultSet rs)
           
static void closeConnection(Connection conn, Statement st1, Statement st2, ResultSet rs1, ResultSet rs2)
           
static void closeConnection(Connection conn, Statement st1, Statement st2, ResultSet rs1, ResultSet rs2, ResultSet rs3)
           
static void closeResultSet(ResultSet rs)
          Closes database ResultSet No exception will be thrown even if occurred during closing, instead, the exception will be logged at warning level.
static void closeStatement(Statement st)
          Closes database Statement.
protected static DataSource createDataSource(String source)
          为指定的逻辑数据库源创建DataSource。
static int getBatchUpdateCount(int[] batchExecuteResult)
          获得Statement.executeBatch()所修改的总记录数。
static Connection getConnection(String source)
          从指定的逻辑数据库源中获取数据库连接。
static DataSource getDataSource(String source)
          为指定的逻辑数据库源获取实际可用的DataSource。
protected static void readConfiguration()
          读取配置信息
protected static void setupDataSourceProviders()
          根据配置信息,初始化DataSourceProvider。
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_CONFIGURATION_FILE

public static final String ROOT_CONFIGURATION_FILE
See Also:
Constant Field Values

PROVIDER_PROPERTY_NAME

public static final String PROVIDER_PROPERTY_NAME
See Also:
Constant Field Values

DELIMITORS

public static final String DELIMITORS
See Also:
Constant Field Values

configuration

protected static Properties configuration

dataSources

protected static HashMap<String,DataSource> dataSources

dataSourcesStructureLock

protected static Object dataSourcesStructureLock

dataSourceProviders

protected static HashMap<String,DataSourceProvider> dataSourceProviders
Constructor Detail

ConnectionUtility

public ConnectionUtility()
Method Detail

readConfiguration

protected static void readConfiguration()
读取配置信息


setupDataSourceProviders

protected static void setupDataSourceProviders()
根据配置信息,初始化DataSourceProvider。


getConnection

public static Connection getConnection(String source)
                                throws SQLException
从指定的逻辑数据库源中获取数据库连接。

Parameters:
source -
Returns:
the database connection
Throws:
SQLException

getDataSource

public static DataSource getDataSource(String source)
为指定的逻辑数据库源获取实际可用的DataSource。

Parameters:
source -
Returns:
the DataSource for that name

createDataSource

protected static DataSource createDataSource(String source)
为指定的逻辑数据库源创建DataSource。

Parameters:
source - 配置信息
Returns:
the DataSource created

getBatchUpdateCount

public static int getBatchUpdateCount(int[] batchExecuteResult)
获得Statement.executeBatch()所修改的总记录数。

Parameters:
batchExecuteResult - Statement.executeBatch()所返回的数组
Returns:
0或正数,表示总记录数;-2表示未知;其余表示executeBatch()执行出错;

closeConnection

public static void closeConnection(Connection conn)
Closes database Connection. No exception will be thrown even if occurred during closing, instead, the exception will be logged at warning level.

Parameters:
conn - database connection that need to be closed

closeStatement

public static void closeStatement(Statement st)
Closes database Statement. No exception will be thrown even if occurred during closing, instead, the exception will be logged at warning level.

Parameters:
st - the Statement that need to be closed

closeResultSet

public static void closeResultSet(ResultSet rs)
Closes database ResultSet No exception will be thrown even if occurred during closing, instead, the exception will be logged at warning level.

Parameters:
rs - the ResultSet that need to be closed

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st)
Close database connection and statement. No exception will be thrown even if occurred during closing, instead, the exception will be logged at warning level.

Parameters:
conn -
st -

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st1,
                                   Statement st2)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st,
                                   ResultSet rs)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st1,
                                   Statement st2,
                                   ResultSet rs)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st,
                                   ResultSet rs1,
                                   ResultSet rs2)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st1,
                                   Statement st2,
                                   ResultSet rs1,
                                   ResultSet rs2)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st,
                                   ResultSet rs1,
                                   ResultSet rs2,
                                   ResultSet rs3)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st1,
                                   Statement st2,
                                   ResultSet rs1,
                                   ResultSet rs2,
                                   ResultSet rs3)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st,
                                   ResultSet... rss)

closeConnection

public static void closeConnection(Connection conn,
                                   Statement st1,
                                   Statement st2,
                                   ResultSet... rss)


Copyright © 2012. All Rights Reserved.