| java.lang.Object com.teamkonzept.db.TKDBManager
All known Subclasses: com.teamkonzept.webman.db.TKWebmanDBManager,
TKDBManager | public class TKDBManager (Code) | | A manager for database connections of an application context.
Each thread is assigned to an application context. For each context this class
manages a pool of database connections using an object of class
TKDBConnectionManager TKDBConnectionManager .
Having initialized the database pool for each context,
a concrete connection is assigned to each thread after the first request,
until an explicit release of the connection.
Simultaneously, a thread can maintain several opened connections to different databases.
Each context is then assigned to a single connection. By changing the context a thread
may switch to another database connection.
This class is never instantiated.
author: $Author: alex $ version: $Revision: 1.26 $ See Also: TKDBConnectionManager |
Method Summary | |
public static void | beginTransaction() Using the methods beginTransaction , commitTransaction
and rollbackTransaction , it is possible to encapsulate several queries
in one transaction. | public static void | closeConnection() Closes the connection of the current thread. | public static void | closeNonsensitiveQueries() Closes all queries within the connection of the actual context,
not implementing the interface SensitiveQuery
by calling the queries´ close method. | public static void | commitTransaction() | public static synchronized void | deregister(boolean doClose) Deregisters the current thread from this TKDBManager . | protected static void | enterContext(Thread currThread, Object nextContext, boolean leaveOldContext) Changes the context of the specified thread to the specified nextContext. | public static void | executeAsTran(TKQuery[] queryArray) Executes the queries in the specified queryArray within one transaction. | public static void | freeConnection() Releases the connection of the current thread, so it can be used later. | public static Connection | getConnection() | public static int | getDBVendor() Returns the vendor of database out of the connect data within
the TKDBConnectionManager responsible for the actual context
of the current thread. | public static TKDBConnectionManager | getManager() Returns the TKDBConnectionManager assigned to the actual context of the current thread. | public static void | limitConnections(int count) Limits the number of opened connections of the current thread to
the specified value of count. | public static TKQuery | newQuery(Class queryClass) Returns an instance of the specified queryClass registered in the
TKDBConnectionManager responsible for the actual context
of the current thread. | public static void | prepareConnection(Properties prop) Sets all values within the TKDBConnectionManager responsible
for the context of the current thread, necessary to connect to database. | final protected static void | register(Thread currThread) Registers the specified thread at this TKDBManager . | public static void | register() Registers the current thread at this TKDBManager . | public static void | register(Object initialContext) Registers the current thread at this TKDBManager
and sets the specified context as its initial context. | protected static void | resetContext() Closes all opened connections in the TKDBConnectionManager assigned to
the current thread. | public static void | rollbackTransaction() | public static void | safeRollbackTransaction(Throwable t) Rollbacks a transaction begun in the TKDBConnection
in the actual context of the current thread
(connection is retrieved over TKDBConnectionManager ). |
beginTransaction | public static void beginTransaction() throws SQLException(Code) | | Using the methods beginTransaction , commitTransaction
and rollbackTransaction , it is possible to encapsulate several queries
in one transaction.
Usage:
TKDBManager.beginTransaction();
try{
q_1.execute();
q_1.close();
.
.
.
q_n.execute();
q_n.close();
commitTransaction();
}
catch(Throwable e){
TKDBManager.rollbackTransaction();
}
It is important to call close for each TKQuery ,
because only then the statement will be completed and SQLExceptions will be thrown.
As well important is to catch Throwable , because close may
throw a SQLError !
For details see method
TKDBManager.executeAsTran(TKQuery[] queryArray) executeAsTran throws: SQLException - |
closeConnection | public static void closeConnection() throws SQLException(Code) | | Closes the connection of the current thread.
|
closeNonsensitiveQueries | public static void closeNonsensitiveQueries() throws SQLException(Code) | | Closes all queries within the connection of the actual context,
not implementing the interface SensitiveQuery
by calling the queries´ close method.
throws: SQLException - |
commitTransaction | public static void commitTransaction() throws SQLException(Code) | | Commits a transaction begun in the TKDBConnection
in the actual context of the current thread
(connection is retrieved over TKDBConnectionManager )
throws: SQLException - |
deregister | public static synchronized void deregister(boolean doClose) throws SQLException(Code) | | Deregisters the current thread from this TKDBManager .
The specified value of doClose indicates, if all the connections contained
in the TKDBConnectionManager assigned to the current thread are
closed or only released.
Parameters: doClose - if true close connections of the current threadelse only release them for other threads. throws: SLQException - normaler SQL Fehler |
enterContext | protected static void enterContext(Thread currThread, Object nextContext, boolean leaveOldContext) throws SQLException(Code) | | Changes the context of the specified thread to the specified nextContext.
Depending on the specified value of leaveOldContext, the connection in the
previous context is released.
Parameters: currThread - the thread, of which the context has to be changed. Parameters: nextContext - this context replaces the previous context of the specified thread. Parameters: leaveOldContext - indicates if the connection in the previous context is released. throws: SQLException - normaler SQL Fehler |
executeAsTran | public static void executeAsTran(TKQuery[] queryArray)(Code) | | Executes the queries in the specified queryArray within one transaction.
If one TKQuery throws an exception, all
queries are rollbacked.
This method should be used, if the returned resultsets are not needed.
Parameters: queryArray - Array of TKQuery, to be executed within a transaction |
freeConnection | public static void freeConnection() throws SQLException(Code) | | Releases the connection of the current thread, so it can be used later.
|
getDBVendor | public static int getDBVendor()(Code) | | Returns the vendor of database out of the connect data within
the TKDBConnectionManager responsible for the actual context
of the current thread.
|
getManager | public static TKDBConnectionManager getManager()(Code) | | Returns the TKDBConnectionManager assigned to the actual context of the current thread.
the connection manager of the current thread. |
limitConnections | public static void limitConnections(int count)(Code) | | Limits the number of opened connections of the current thread to
the specified value of count.
|
newQuery | public static TKQuery newQuery(Class queryClass) throws SQLException(Code) | | Returns an instance of the specified queryClass registered in the
TKDBConnectionManager responsible for the actual context
of the current thread.
Parameters: queryClass - the class to instantiate a new TKQuery See Also: TKQuery See Also: TKDBConnectionManager See Also: TKDBConnection die erzeugte Query |
prepareConnection | public static void prepareConnection(Properties prop) throws SQLException(Code) | | Sets all values within the TKDBConnectionManager responsible
for the context of the current thread, necessary to connect to database.
Parameters: dbId - a string which determines the vendor of the used database Parameters: serverId - the connect string Parameters: prop - properties of the used database connection(database, user_name, password, server, ...) |
register | final protected static void register(Thread currThread)(Code) | | Registers the specified thread at this TKDBManager .
Parameters: currThread - the thread to be registered. |
register | public static void register()(Code) | | Registers the current thread at this TKDBManager .
|
register | public static void register(Object initialContext)(Code) | | Registers the current thread at this TKDBManager
and sets the specified context as its initial context.
Parameters: initialContext - the initial context to be assigned to the current thread. |
resetContext | protected static void resetContext()(Code) | | Closes all opened connections in the TKDBConnectionManager assigned to
the current thread.
|
rollbackTransaction | public static void rollbackTransaction() throws SQLException(Code) | | Rollbacks a transaction begun in the TKDBConnection
in the actual context of the current thread
(connection is retrieved over TKDBConnectionManager )
|
safeRollbackTransaction | public static void safeRollbackTransaction(Throwable t)(Code) | | Rollbacks a transaction begun in the TKDBConnection
in the actual context of the current thread
(connection is retrieved over TKDBConnectionManager ).
Is called by
executeAsTran(TKQuery [] queryArray) executeAsTran in the catch-clause and analyzes the specified Throwable .
Throws a TKSQLError , which encapsulates a SQLException .
Parameters: t - Ursprungsexception |
|
|