|
Jive Forums API (5.5.20.2-oracle) Developer Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jivesoftware.base.database.ConnectionManager
public class ConnectionManager
Central manager of database connections. All methods are static so that they can be easily accessed throughout the classes in the database package.
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.
In most cases, Jive is able to determine appropriate meta-data about what features the database and JDBC driver support. However, certain meta-data can be manually set by editing Jive properties. Generally, these values should only be set manually if you are running into specific problems with them:
ConnectionProvider
Nested Class Summary | |
---|---|
static class |
ConnectionManager.DatabaseType
A class that identifies the type of the database that Jive is connected to. |
Method Summary | |
---|---|
static void |
batchDeleteWithoutSubqueries(java.sql.Connection con,
java.lang.String sql,
long[] objectIDs)
Batch deletes a set of objects for the case when sub-selects are not supported (MySQL versions earlier than 4.1). |
static void |
close(java.sql.Statement stmt)
Closes a prepared statement. |
static void |
closeConnection(java.sql.Connection con)
Closes a database connection (returning the connection to the connection pool). |
static void |
closeConnection(java.sql.PreparedStatement pstmt,
java.sql.Connection con)
Closes a prepared statement and database connection (returning the connection to the connection pool). |
static void |
closeConnection(java.sql.ResultSet rs,
java.sql.Statement stmt,
java.sql.Connection con)
Closes a result set, prepared statement and database connection (returning the connection to the connection pool). |
static void |
closeConnection(java.sql.Statement stmt,
java.sql.Connection con)
Closes a statement and database connection (returning the connection to the connection pool). |
static void |
closeResultSet(java.sql.ResultSet rs)
Closes a result set. |
static void |
closeStatement(java.sql.Statement stmt)
Closes a prepared statement. |
static void |
closeTransactionConnection(java.sql.Connection con,
boolean abortTransaction)
Closes a transactional connection. |
static void |
closeTransactionConnection(java.sql.PreparedStatement pstmt,
java.sql.Connection con,
boolean abortTransaction)
Closes a prepated statement and transactional connection. |
static void |
closeTransactionConnection(java.sql.ResultSet rs,
java.sql.PreparedStatement pstmt,
java.sql.Connection con,
boolean abortTransaction)
|
static void |
closeTransactionConnection(java.sql.Statement stmt,
java.sql.Connection con,
boolean abortTransaction)
Closes a prepared statement and transactional connection. |
static java.sql.PreparedStatement |
createScrollablePreparedStatement(java.sql.Connection con,
java.lang.String sql)
Creates a scrollable PreparedStatement if the JDBC driver supports it, or a normal PreparedStatement otherwise. |
static java.sql.Statement |
createScrollableStatement(java.sql.Connection con)
Creates a scrollable Statement if the JDBC driver supports it, or a normal Statement otherwise. |
static void |
disablePostgresTablescan(java.sql.Connection con)
Disables table scanning in Postgres for the connection. |
static void |
enablePostgresTablescan(java.sql.Connection con)
Enables table scanning in Postgres for the connection. |
static java.lang.String |
getAltSyntaxName(java.lang.String originalName)
Returns the alternate syntax name for the given schema resource (db name, column, etc). |
static java.lang.String |
getAltSyntaxName(java.lang.String originalName,
boolean showTableName)
Returns the alternate syntax name for the given schema resource (db name, column, etc). |
static java.io.InputStream |
getBlob(java.sql.ResultSet rs,
int columnIndex)
Retrives a binary column from a result set, automatically performing streaming if the JDBC driver requires it. |
static java.sql.Connection |
getConnection()
Returns a database connection from the currently active connection provider. |
static ConnectionProvider |
getConnectionProvider()
Returns the current connection provider. |
static ConnectionManager.DatabaseType |
getDatabaseType()
Returns the database type. |
static java.util.Date |
getDateField(java.sql.ResultSet rs,
int columnIndex)
Deprecated. Use rs.setLong(long) |
static int |
getDateType()
Returns the SQL type from Types that Date information is stored in. |
static java.lang.String |
getLargeTextField(java.sql.ResultSet rs,
int columnIndex)
Retrives a large text column from a result set, automatically performing streaming if the JDBC driver requires it. |
static java.sql.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 |
isDeleteSubqueriesSupported()
|
static boolean |
isFetchSizeSupported()
|
static boolean |
isMaxRowsSupported()
|
static boolean |
isProfilingEnabled()
Returns true if connection profiling is turned on. |
static boolean |
isScrollResultsSupported()
|
static boolean |
isStreamBlobRequired()
|
static boolean |
isStreamTextRequired()
|
static boolean |
isSubqueriesSupported()
|
static boolean |
isTransactionsSupported()
|
static boolean |
isUseAltSyntaxForLongSchemaNames()
Returns true if we're using the alternate syntax for longer schema names in the database scripts (names longer than 18 characters), false otehrwise. |
static void |
scrollResultSet(java.sql.ResultSet rs,
int rowNumber)
Scrolls forward in a result set to the specified row number. |
static void |
setConnectionProvider(ConnectionProvider provider)
Sets the connection provider. |
static void |
setDateField(java.sql.PreparedStatement pstmt,
int parameterIndex,
java.util.Date value)
Deprecated. User rs.setLong(long) |
static void |
setFetchSize(java.sql.ResultSet rs,
int fetchSize)
Sets the number of rows that the JDBC driver should buffer at a time. |
static void |
setLargeTextField(java.sql.PreparedStatement pstmt,
int parameterIndex,
java.lang.String value)
Sets a large text column in a result set, automatically performing streaming if the JDBC driver requires it. |
static void |
setMaxRows(java.sql.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException
public static void closeConnection(java.sql.Statement stmt, java.sql.Connection con)
Connection con = null; Statment stmt = null; try { con = ConnectionManager.getConnection(); stmt = con.createStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.closeConnection(stmt, con); }
stmt
- the statement.con
- the connection.public static void closeConnection(java.sql.PreparedStatement pstmt, java.sql.Connection con)
Connection con = null; PrepatedStatment pstmt = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.closeConnection(pstmt, con); }
pstmt
- the prepared statement.con
- the connection.public static void closeConnection(java.sql.ResultSet rs, java.sql.Statement stmt, java.sql.Connection con)
Connection con = null; PrepatedStatment stmt = null; ResultSet rs = null; try { con = ConnectionManager.getConnection(); stmt = con.prepareStatement("select * from blah"); rs = psmt.executeQuery(); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.closeConnection(rs, stmt, con); }
rs
- the result set.stmt
- the statement.con
- the connection.public static void closeConnection(java.sql.Connection con)
Connection con = null; try { con = ConnectionManager.getConnection(); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.closeConnection(con); }
con
- the connection.public static void close(java.sql.Statement stmt)
public void doSomething(Connection con) { PreparedStatement stmt = null; try { stmt = con.prepareStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.close(stmt); } }
stmt
- the statement.public static void closeStatement(java.sql.Statement stmt)
public void doSomething(Connection con) { PreparedStatement stmt = null; try { stmt = con.prepareStatement("select * from blah"); .... } catch (SQLException sqle) { Log.error(sqle); } finally { ConnectionManager.closeStatement(stmt); } }
stmt
- the statement.public static void closeResultSet(java.sql.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); } finally { ConnectionManager.closeResultSet(rs); ConnectionManager.closeStatement(pstmt); } }
public static java.sql.Connection getTransactionConnection() throws java.sql.SQLException
java.sql.SQLException
public static void closeTransactionConnection(java.sql.Statement stmt, java.sql.Connection con, boolean abortTransaction)
abortTransaction
.
stmt
- the statement to closecon
- the connection to closeabortTransaction
- whether or not to abort the transactionpublic static void closeTransactionConnection(java.sql.PreparedStatement pstmt, java.sql.Connection con, boolean abortTransaction)
abortTransaction
.
public static void closeTransactionConnection(java.sql.ResultSet rs, java.sql.PreparedStatement pstmt, java.sql.Connection con, boolean abortTransaction)
public static void closeTransactionConnection(java.sql.Connection con, boolean abortTransaction)
abortTransaction
.
public static java.sql.Statement createScrollableStatement(java.sql.Connection con) throws java.sql.SQLException
con
- the database connection.
java.sql.SQLException
- if an error occurs.public static java.sql.PreparedStatement createScrollablePreparedStatement(java.sql.Connection con, java.lang.String sql) throws java.sql.SQLException
con
- the database connection.sql
- the SQL to create the PreparedStatement with.
java.sql.SQLException
- if an error occurs.public static void disablePostgresTablescan(java.sql.Connection con) throws java.sql.SQLException
enablePostgresTablescan(java.sql.Connection)
method mus be called before the connection
is returned to the pool. Typical code block:
Connection con = null; Pstmt pstmt = null; try { con = ConnectionManager.getConnection(); ConnectionManager.disablePostgresTablescan(con); ... } finally { ConnectionManager.enablePostgresTablescan(con); ConnectionManager.closeConnection(pstmt, con); }
con
- the connection.
java.sql.SQLException
- if an exception occurs.public static void enablePostgresTablescan(java.sql.Connection con)
Connection con = null; Pstmt pstmt = null; try { con = ConnectionManager.getConnection(); ConnectionManager.disablePostgresTablescan(con); ... } finally { ConnectionManager.enablePostgresTablescan(con); ConnectionManager.closeConnection(pstmt, con); }
con
- the connection.public static void scrollResultSet(java.sql.ResultSet rs, int rowNumber) throws java.sql.SQLException
rs
- the ResultSet object to scroll.rowNumber
- the row number to scroll forward to.
java.sql.SQLException
- if an error occurs.public static ConnectionProvider getConnectionProvider()
public static void setConnectionProvider(ConnectionProvider provider)
provider
- the ConnectionProvider that the manager should obtain
connections from.public static java.lang.String getLargeTextField(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
rs
- the ResultSet to retrieve the text field from.columnIndex
- the column in the ResultSet of the text field.
java.sql.SQLException
public static java.io.InputStream getBlob(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
rs
- the ResultSet to retrieve the blob field from.columnIndex
- the column in the ResultSet of the blob field.
java.sql.SQLException
public static void setLargeTextField(java.sql.PreparedStatement pstmt, int parameterIndex, java.lang.String value) throws java.sql.SQLException
pstmt
- the PreparedStatement to set the text field in.parameterIndex
- the index corresponding to the text field.value
- the String to set.
java.sql.SQLException
public static java.util.Date getDateField(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
Date
.
rs
- the ResultSet.columnIndex
- the column index that contains date information.
java.sql.SQLException
- if an error occurs.public static void setDateField(java.sql.PreparedStatement pstmt, int parameterIndex, java.util.Date value) throws java.sql.SQLException
Date
.
pstmt
- the PreparedStatement.parameterIndex
- the index of the parameter that will be set with date information.value
- the Date.
java.sql.SQLException
- if an error occurs.public static int getDateType()
Types
that Date information is stored in.
public static void setMaxRows(java.sql.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(java.sql.ResultSet rs, int fetchSize)
rs
- the ResultSet to set the fetch size for.fetchSize
- the fetchSize.public static void batchDeleteWithoutSubqueries(java.sql.Connection con, java.lang.String sql, long[] objectIDs) throws java.sql.SQLException
con
- the connection to use.sql
- the SQL fragment used to delete the records. It must be in the form
"DELETE FROM [table] WHERE [column] IN".objectIDs
- an array of long values to delete.
java.sql.SQLException
- if an exception occurs.public static ConnectionManager.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 isStreamBlobRequired()
public static boolean isMaxRowsSupported()
public static boolean isFetchSizeSupported()
public static boolean isSubqueriesSupported()
public static boolean isDeleteSubqueriesSupported()
public static boolean isScrollResultsSupported()
public static boolean isBatchUpdatesSupported()
public static boolean isUseAltSyntaxForLongSchemaNames()
public static java.lang.String getAltSyntaxName(java.lang.String originalName)
originalName
- the original name of the table/method, etc.
public static java.lang.String getAltSyntaxName(java.lang.String originalName, boolean showTableName)
originalName
- the original name of the table/method, etc.showTableName
- true to show the table name for a column reference, false to hide it.
This is useful when doing some SQL queries that only deal with a single table.
|
Jive Forums Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |