public class LibraryConnection extends Object
Modifier and Type | Class and Description |
---|---|
static class |
LibraryConnection.TransactionStateListener
TransactionStateListener is an abstract inner class used to provide
a way of alerting custom listeners to the changes in Transaction
state.
|
Modifier and Type | Field and Description |
---|---|
protected Connection |
m_Connection
The database connection.
|
protected String |
m_ConnectionPoolName
The name of this ConnectionPool to which this LibraryConnection belongs.
|
protected long |
m_Id
An identifer, accessible using
getId . |
protected int |
m_LibraryQueryStatementCount
The number of LibraryQueryStatements current in the
m_LibraryQueryStatements map (not the same as the map's size)
|
protected HashMap |
m_LibraryQueryStatements
LibraryQueryStatements previously prepared in this LibraryConnection,
hashed by statement name.
|
protected HashMap |
m_PreparedStatements
PreparedStatements previously prepared in this LibraryConnection,
hashed by statement name.
|
protected S_LibraryService |
m_Service
The S_LibraryService that contains this LibraryConnection.
|
protected String |
m_SessionLanguage
The current Connection's language
|
protected long |
m_StatementAccessSequence
The sequence number marking the last time a cached statement has been used.
|
protected long |
m_StatementAccessSequenceAtPreviousPurge
The sequence number the last time a purge was attempted.
|
protected int |
m_StatementCacheSizeTrigger
The number of statements that need to be cached before a purge
is triggered.
|
protected int |
m_StatementCacheTarget
The target maximum number of statements we wish to keep cached.
|
protected int |
m_StatementResetLimit
Access limit at which the saved statements will be closed and
re-opened.
|
protected boolean |
m_StatementResetRequested
An indication that a reset of all cached statements has been requested.
|
protected long |
m_StatementValidityRsn
The resolution sequence number at which the validity of the
cached PreparedStatements and LibraryQueryStatements was last confirmed.
|
protected oracle.ifs.server.LibraryConnection.TransactionStateManager |
m_TransactionStateManager
The internal TransactionStateManager.
|
Modifier | Constructor and Description |
---|---|
protected |
LibraryConnection(long id,
S_LibraryService service,
String connectionPoolName,
DataSource dataSource,
PrintStream jdbcLogStream,
int defaultRowPrefetch,
int statementResetLimit,
int stmtCacheTarget,
int stmtCacheTrigger)
Constructs a LibraryConnection.
|
Modifier and Type | Method and Description |
---|---|
LibraryQueryStatement |
acquireLibraryQueryStatement(String key)
Acquires an instance of the specified LibraryQueryStatement from the
LibraryQueryStatement cache.
|
void |
addPreparedStatement(String key,
PreparedStatement stmt)
Caches the specified PreparedStatement.
|
void |
addTransactionStateListener(LibraryConnection.TransactionStateListener listener)
Adds a TransactionStateListener.
|
protected void |
alterSessionLanguage(String language)
alterSessionLanguage
|
protected void |
alterSessionSqlTrace(boolean enabled)
alter the SQL_TRACE parameter for the database session
|
protected int |
closeLibraryQueryStatements(int closeCount,
int sizeest,
long seqTarget)
Close least recently used LibraryQueryStatements.
|
protected int |
closePreparedStatements(int closeCount,
int sizeest,
long seqTarget)
Close least recently used PreparedStatements.
|
protected void |
commit()
Commits the database Connection represented by this LibraryConnection.
|
protected void |
dispose()
Shuts down this LibraryConnection.
|
protected void |
disposeCachedStatements()
Close all cached statements, and clear the caches.
|
protected String |
fetchSessionLanguage()
fetchSessionLanguage
|
protected void |
finalize()
Finalizes this LibraryConnection.
|
PreparedStatement |
findPreparedStatement(String key)
Finds the specified PreparedStatement in the PreparedStatement cache.
|
Connection |
getConnection()
Gets the database Connection represented by this LibraryConnection.
|
String |
getConnectionPoolName()
Gets the name of the ConnectionPool to which this LibraryConnection
belongs.
|
protected long |
getId()
Gets the identifier of this LibraryConnection.
|
protected S_LibraryService |
getService()
Gets the S_LibraryService to which this LibraryConnection belongs.
|
String |
getSessionLanguage()
get current language of the database session
|
protected long |
getStatementValidityRsn()
Gets the current StatementValidity resolution sequence number (RSN)
of this LibraryConnection.
|
protected int |
handleResetOfCachedStatements()
Dispose of any cached statements if a reset has been
indicated.
|
protected boolean |
isDisposed()
Return true if this LibraryConnection has been disposed.
|
protected boolean |
isValid()
Detects whether the connection is still valid, by checking
the encapsulated database connection.
|
protected int |
purge()
Purges statement caches if needed.
|
void |
releaseLibraryQueryStatement(LibraryQueryStatement lstmt)
Places the specified LibraryQueryStatement in the LibraryQueryStatement
cache.
|
protected void |
resetCachedStatements()
Prevent any statements currently cached from being re-used.
|
protected void |
rollback()
Rolls-back the database Connection represented by this LibraryConnection.
|
protected void |
rollback(String savepoint)
Rolls-back the database Connection represented by this LibraryConnection
to the specified savepoint.
|
protected void |
rollbackOrDispose()
Rolls-back the database Connection represented by this LibraryConnection.
|
protected void |
rollbackOrDispose(String savepoint)
Rolls-back the database Connection represented by this LibraryConnection
to the specified savepoint.
|
protected void |
setSavepoint(String savepoint)
Sets a savepoint in the database Connection represented by this
LibraryConnection.
|
String |
setSessionLanguage(String language)
set current language of the database session if
different from the current setting.
|
protected void |
verifyConnectionValidity()
Verify validity of database connection by trying simple
query.
|
protected void |
verifyNotDisposed()
Verify that this LibraryConnection is still valid
(i.e. is not disposed).
|
protected long m_Id
getId
.protected Connection m_Connection
protected String m_SessionLanguage
protected S_LibraryService m_Service
protected String m_ConnectionPoolName
protected HashMap m_PreparedStatements
protected HashMap m_LibraryQueryStatements
protected int m_LibraryQueryStatementCount
protected int m_StatementResetLimit
protected boolean m_StatementResetRequested
protected long m_StatementValidityRsn
protected long m_StatementAccessSequence
protected long m_StatementAccessSequenceAtPreviousPurge
protected int m_StatementCacheTarget
protected int m_StatementCacheSizeTrigger
protected oracle.ifs.server.LibraryConnection.TransactionStateManager m_TransactionStateManager
protected LibraryConnection(long id, S_LibraryService service, String connectionPoolName, DataSource dataSource, PrintStream jdbcLogStream, int defaultRowPrefetch, int statementResetLimit, int stmtCacheTarget, int stmtCacheTrigger) throws IfsException
id
- an identifierservice
- the S_LibraryService creating the
LibraryConnectionconnectionPoolName
- the name of the ConnectionPool to which
this LibraryConnection belongsdataSource
- data source for database connectionsjdbcLogStream
- a PrintStream to which the JDBC log will be
sent, or null to disable loggingdefaultRowPrefetch
- the default number of prefetched rows;
ignored if 0 or if driverName
does not create an OracleConnectionstmtCacheTarget
- the desired number of cached statementsstmtCacheTrigger
- the number of caches statements before
triggering a purgeIfsException
- (IFS-10600) if the operation failsprotected final long getId() throws IfsException
IfsException
- if the operation failsprotected final long getStatementValidityRsn()
public void addTransactionStateListener(LibraryConnection.TransactionStateListener listener)
listener
- the TransactionStateListener to addpublic final Connection getConnection() throws IfsException
IfsException
- (IFS-10602) if the operation failsprotected final S_LibraryService getService() throws IfsException
IfsException
- if the operation failspublic final String getConnectionPoolName() throws IfsException
IfsException
- if the operation failspublic final String getSessionLanguage() throws IfsException
IfsException
- if the operation failspublic final String setSessionLanguage(String language) throws IfsException
language
- the desired language nameIfsException
- if the operation failspublic final void addPreparedStatement(String key, PreparedStatement stmt)
key
- the key by which the PreparedStatement is to be
identifiedstmt
- the PreparedStatementpublic final PreparedStatement findPreparedStatement(String key)
key
- the PreparedStatement keypublic final LibraryQueryStatement acquireLibraryQueryStatement(String key)
Unlike the PreparedStatement cache, whose statements can only be used transiently by a session, statements in the LibraryQueryStatement cache can be acquired by a session and used for as long as necessary, even after the session releases this LibraryConnection. This can be used, for example, to provide cursor support. For a given statement key, this cache may contain multiple (identical) LibraryQueryStatements, allowing several sessions to concurrently acquire identical statements.
This method acquires a LibraryQueryStatement. To release it for use
by other sessions, invoke releaseLibraryQueryStatement
.
key
- the LibraryQueryStatement keypublic final void releaseLibraryQueryStatement(LibraryQueryStatement lstmt)
This method is used both to release a previously acquired statement for use by other sessions, and to add new statement to the cache. For each statement key, the cache may contain more than one LibraryQueryStatement instance (all identical). The maximum number of copies is set by the LibraryQueryStatement constructor.
lstmt
- the LibraryQueryStatementprotected final String fetchSessionLanguage() throws IfsException
IfsException
protected final void alterSessionLanguage(String language) throws IfsException
language
- the new language setting for the database session.IfsException
- (IFS-10609) if the operation failsprotected final void alterSessionSqlTrace(boolean enabled) throws IfsException
enabled
- true if SQL tracing is to be enabled; false if
it is to be disabledIfsException
- (IFS-10612) if the operation failsprotected final void setSavepoint(String savepoint) throws IfsException
savepoint
- the savepoint nameIfsException
- (IFS-10603) if the operation failsprotected final void commit() throws IfsException
IfsException
- (IFS-10604) if the operation failsprotected final void rollback() throws IfsException
IfsException
- (IFS-10605) if the operation failsprotected final void rollback(String savepoint) throws IfsException
IfsException
- (IFS-10606) if the operation failsprotected final void rollbackOrDispose() throws IfsException
IfsException
- (IFS-10605) if the operation failsprotected final void rollbackOrDispose(String savepoint) throws IfsException
IfsException
- (IFS-10606) if the operation failsprotected final boolean isValid() throws IfsException
IfsException
- (IFS-10601) if the operation failsprotected void verifyConnectionValidity() throws SQLException, IfsException
SQLException
- if the operation failsIfsException
- if the operation failsprotected final boolean isDisposed()
protected void verifyNotDisposed() throws IfsException
IfsException
- if the operation failsprotected final void dispose() throws IfsException
IfsException
- (IFS-10601) if the operation failsprotected void resetCachedStatements()
protected int handleResetOfCachedStatements()
protected int purge()
This will attempt to close enough of the least recently used statements such that the number of cached statements does not exceed that maximum set when the connection was established.
protected int closePreparedStatements(int closeCount, int sizeest, long seqTarget)
closeCount
- the number of statements closed so farsizeest
- the number of statements that we want to closeseqTarget
- the sequence that represents LRUprotected int closeLibraryQueryStatements(int closeCount, int sizeest, long seqTarget)
closeCount
- the number of statements closed so farsizeest
- the number of statements that we want to closeseqTarget
- the sequence that represents LRUprotected void disposeCachedStatements()
Copyright © 2023. All rights reserved.