public class DbConnectionManager extends Object
This class also provides a set of utility methods that abstract out operations that may not work on all databases such as setting the max number or rows that a query should return.
ConnectionProvider
Modifier and Type | Class and Description |
---|---|
static class |
DbConnectionManager.DatabaseType
A class that identifies the type of the database that Jive is connected
to.
|
Constructor and Description |
---|
DbConnectionManager() |
Modifier and Type | Method and Description |
---|---|
static void |
closeConnection(Connection con)
Closes a database connection (returning the connection to the connection pool).
|
static void |
closeConnection(ResultSet rs,
Statement stmt,
Connection con)
Closes a result set, statement and database connection (returning the connection to
the connection pool).
|
static void |
closeConnection(Statement stmt,
Connection con)
Closes a statement and database connection (returning the connection to
the connection pool).
|
static void |
closeResultSet(ResultSet rs)
Closes a result set.
|
static void |
closeStatement(ResultSet rs,
Statement stmt)
Closes a statement and a result set.
|
static void |
closeStatement(Statement stmt)
Closes a statement.
|
static void |
closeTransactionConnection(Connection con,
boolean abortTransaction)
Closes a Connection.
|
static void |
closeTransactionConnection(PreparedStatement pstmt,
Connection con,
boolean abortTransaction)
Closes a PreparedStatement and Connection.
|
static PreparedStatement |
createScrollablePreparedStatement(Connection con,
String sql)
Creates a scroll insensitive PreparedStatement if the JDBC driver supports it, or a normal
PreparedStatement otherwise.
|
static void |
destroyConnectionProvider()
Destroys the currennt connection provider.
|
static void |
fastcloseStmt(PreparedStatement pstmt)
Closes a statement.
|
static void |
fastcloseStmt(ResultSet rs,
PreparedStatement pstmt)
Closes a statement and a result set.
|
static Connection |
getConnection()
Returns a database connection from the currently active connection
provider.
|
static ConnectionProvider |
getConnectionProvider()
Returns the current connection provider.
|
static DbConnectionManager.DatabaseType |
getDatabaseType()
Returns the database type.
|
static String |
getIdentifierQuoteString() |
static String |
getLargeTextField(ResultSet rs,
int columnIndex)
Retrives a large text column from a result set, automatically performing
streaming if the JDBC driver requires it.
|
static SchemaManager |
getSchemaManager()
Returns a SchemaManager instance, which can be used to manage the database
schema information for Openfire and plugins.
|
static String |
getTestSQL(String driver) |
static Connection |
getTransactionConnection()
Returns a Connection from the currently active connection provider that
is ready to participate in transactions (auto commit is set to false).
|
static boolean |
isBatchUpdatesSupported() |
static boolean |
isEmbeddedDB() |
static boolean |
isFetchSizeSupported() |
static boolean |
isMaxRowsSupported() |
static boolean |
isProfilingEnabled()
Returns true if connection profiling is turned on.
|
static boolean |
isPstmtFetchSizeSupported() |
static boolean |
isScrollResultsSupported() |
static boolean |
isStreamTextRequired() |
static boolean |
isSubqueriesSupported() |
static boolean |
isTransactionsSupported() |
static void |
limitRowsAndFetchSize(PreparedStatement pstmt,
int startIndex,
int numResults)
Limits the number of the results in a result set (to startIndex + numResults).
|
static void |
scrollResultSet(ResultSet rs,
int rowNumber)
Scrolls forward in a result set the specified number of rows.
|
static void |
setConnectionProvider(ConnectionProvider provider)
Sets the connection provider.
|
static void |
setFetchSize(PreparedStatement pstmt,
int fetchSize)
Sets the number of rows that the JDBC driver should buffer at a time.
|
static void |
setFetchSize(ResultSet rs,
int fetchSize)
Sets the number of rows that the JDBC driver should buffer at a time.
|
static void |
setLargeTextField(PreparedStatement pstmt,
int parameterIndex,
String value)
Sets a large text column in a result set, automatically performing
streaming if the JDBC driver requires it.
|
static void |
setMaxRows(Statement stmt,
int maxRows)
Sets the max number of rows that should be returned from executing a
statement.
|
static void |
setProfilingEnabled(boolean enable)
Turns connection profiling on or off.
|
public static Connection getConnection() throws SQLException
SQLException
- if a SQL exception occurs or no connection was found.public static Connection getTransactionConnection() throws SQLException
SQLException
- if a SQL exception occurs.public static void closeTransactionConnection(PreparedStatement pstmt, Connection con, boolean abortTransaction)
abortTransaction
.pstmt
- the prepared statement to close.con
- the connection to close.abortTransaction
- true if the transaction should be rolled back.public static void closeTransactionConnection(Connection con, boolean abortTransaction)
abortTransaction
.con
- the connection to close.abortTransaction
- true if the transaction should be rolled back.public static void closeResultSet(ResultSet rs)
public void doSomething(Connection con) { ResultSet rs = null; PreparedStatement pstmt = null; try { pstmt = con.prepareStatement("select * from blah"); rs = pstmt.executeQuery(); .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { ConnectionManager.closeResultSet(rs); ConnectionManager.closePreparedStatement(pstmt); } }
rs
- the result set to close.public static void closeStatement(Statement stmt)
public void doSomething(Connection con) { PreparedStatement pstmt = null; try { pstmt = con.prepareStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { ConnectionManager.closeStatement(pstmt); } }
stmt
- the statement.public static void closeStatement(ResultSet rs, Statement stmt)
public void doSomething(Connection con) { PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = con.prepareStatement("select * from blah"); rs = ... .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { ConnectionManager.closeStatement(rs, pstmt); } }
stmt
- the statement.public static void fastcloseStmt(PreparedStatement pstmt) throws SQLException
public void doSomething(Connection con) { PreparedStatement pstmt = null; try { pstmt = con.prepareStatement("select * from dual"); pstmt.executeUpdate(); ... ConnectionManager.fastcloseStmt(pstmt); pstmt = con.prepareStatement("select * from blah"); ... } ... }
pstmt
- the statement to close.SQLException
public static void fastcloseStmt(ResultSet rs, PreparedStatement pstmt) throws SQLException
public void doSomething(Connection con) { PreparedStatement pstmt = null; try { pstmt = con.prepareStatement("select * from blah"); rs = pstmt.executeQuery(); ... ConnectionManager.fastcloseStmt(rs, pstmt); pstmt = con.prepareStatement("select * from blah"); ... } ... }
pstmt
- the statement to close.SQLException
public static void closeConnection(ResultSet rs, Statement stmt, Connection con)
Connection con = null; PrepatedStatment pstmt = null; ResultSet rs = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement("select * from blah"); rs = psmt.executeQuery(); .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { ConnectionManager.closeConnection(rs, pstmt, con); }
rs
- the result set.stmt
- the statement.con
- the connection.public static void closeConnection(Statement stmt, Connection con)
Connection con = null; PrepatedStatment pstmt = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { DbConnectionManager.closeConnection(pstmt, con); }
stmt
- the statement.con
- the connection.public static void closeConnection(Connection con)
Connection con = null; try { con = ConnectionManager.getConnection(); .... } catch (SQLException sqle) { Log.error(sqle.getMessage(), sqle); } finally { DbConnectionManager.closeConnection(con); }
con
- the connection.public static PreparedStatement createScrollablePreparedStatement(Connection con, String sql) throws SQLException
con
- the database connection.sql
- the SQL to create the PreparedStatement with.SQLException
- if an error occurs.public static void scrollResultSet(ResultSet rs, int rowNumber) throws SQLException
rs
- the ResultSet object to scroll.rowNumber
- the row number to scroll forward to.SQLException
- if an error occurs.public static void limitRowsAndFetchSize(PreparedStatement pstmt, int startIndex, int numResults)
pstmt
- the PreparedStatementstartIndex
- the first row with interesting datanumResults
- the number of interesting resultspublic static void setFetchSize(PreparedStatement pstmt, int fetchSize)
pstmt
- the PreparedStatement to set the fetch size for.fetchSize
- the fetchSize.public static ConnectionProvider getConnectionProvider()
public static void setConnectionProvider(ConnectionProvider provider)
provider
- the ConnectionProvider that the manager should obtain
connections from.public static void destroyConnectionProvider()
getConnectionProvider()
will return null until a new
ConnectionProvider is set, or one is automatically loaded by a call to
getConnection()
.public static String getLargeTextField(ResultSet rs, int columnIndex) throws SQLException
rs
- the ResultSet to retrieve the text field from.columnIndex
- the column in the ResultSet of the text field.SQLException
- if an SQL exception occurs.public static void setLargeTextField(PreparedStatement pstmt, int parameterIndex, String value) throws SQLException
pstmt
- the PreparedStatement to set the text field in.parameterIndex
- the index corresponding to the text field.value
- the String to set.SQLException
- if an SQL exception occurs.public static void setMaxRows(Statement stmt, int maxRows)
stmt
- the Statement to set the max number of rows for.maxRows
- the max number of rows to return.public static void setFetchSize(ResultSet rs, int fetchSize)
rs
- the ResultSet to set the fetch size for.fetchSize
- the fetchSize.public static SchemaManager getSchemaManager()
public static DbConnectionManager.DatabaseType getDatabaseType()
public static boolean isProfilingEnabled()
public static void setProfilingEnabled(boolean enable)
enable
- true to enable profiling; false to disable.public static boolean isTransactionsSupported()
public static boolean isStreamTextRequired()
public static boolean isMaxRowsSupported()
public static boolean isFetchSizeSupported()
public static boolean isPstmtFetchSizeSupported()
public static boolean isSubqueriesSupported()
public static boolean isScrollResultsSupported()
public static boolean isBatchUpdatesSupported()
public static boolean isEmbeddedDB()
public static String getIdentifierQuoteString()
Copyright © 2003–2019 Ignite Realtime. All rights reserved.