/** * Begin a transaction on the database. If not using managed transaction begin a local transaction. */ public void beginTransaction(AbstractSession session) throws DatabaseException { if (usesExternalTransactionController()) { setIsInTransaction(true); return; } session.log(SessionLog.FINER, SessionLog.TRANSACTION, "begin_transaction", (Object[])null, this); try { session.startOperationProfile(SessionProfiler.TRANSACTION); incrementCallCount(session); basicBeginTransaction(session); setIsInTransaction(true); } finally { decrementCallCount(); session.endOperationProfile(SessionProfiler.TRANSACTION); } }
/** * To be called after JTS transaction has been completed (committed or rolled back) */ public void afterJTSTransaction() { if (usesExternalTransactionController()) { setIsInTransaction(false); if ((getDatasourceConnection() != null) && usesExternalConnectionPooling()) { closeConnection(); setDatasourceConnection(null); } } }
/** * Close the accessor's connection. * This is used only for external connection pooling * when it is intended for the connection to be reconnected in the future. */ public void closeConnection() { try { if (getDatasourceConnection() != null) { if (isDatasourceConnected()) { closeDatasourceConnection(); } setDatasourceConnection(null); } } catch (DatabaseException exception) { // Ignore setDatasourceConnection(null); } }
/** * Used for load balancing and external pooling. */ public synchronized void decrementCallCount() { setCallCount(getCallCount() - 1); if (usesExternalConnectionPooling() && (!isInTransaction()) && (getCallCount() == 0)) { try { closeConnection(); } catch (DatabaseException ignore) { } // Don't allow for errors to be masked by disconnect. } }
if (usesExternalTransactionController()) { setIsInTransaction(false); if ((getDatasourceConnection() != null) && usesExternalConnectionPooling()) { closeConnection(); setDatasourceConnection(null); incrementCallCount(session); basicCommitTransaction(session); setIsInTransaction(false); } finally { decrementCallCount(); session.endOperationProfile(SessionProfiler.TRANSACTION);
/** * Connect to the datasource. Through using a CCI ConnectionFactory. * Catch exceptions and re-throw as TopLink exceptions. */ public void connect(Login login, AbstractSession session) throws DatabaseException { session.startOperationProfile(SessionProfiler.CONNECT); session.incrementProfile(SessionProfiler.TlConnects); try { if (session.shouldLog(SessionLog.CONFIG, SessionLog.CONNECTION)) {// Avoid printing if no logging required. session.log(SessionLog.CONFIG, SessionLog.CONNECTION, "connecting", new Object[] { login }, this); } setLogin(login); this.setDatasourcePlatform((DatasourcePlatform)session.getDatasourceLogin().getDatasourcePlatform()); try { connect(login); setIsInTransaction(false); } catch (RuntimeException exception) { session.handleSevere(exception); } session.getEventManager().postConnect(this); incrementCallCount(session); try { buildConnectLog(session); } finally { decrementCallCount(); } } finally { session.endOperationProfile(SessionProfiler.CONNECT); } }
/** * Disconnect from the datasource. */ public void disconnect(AbstractSession session) throws DatabaseException { session.log(SessionLog.CONFIG, SessionLog.CONNECTION, "disconnect", (Object[])null, this); if (getDatasourceConnection() == null) { return; } session.incrementProfile(SessionProfiler.TlDisconnects); session.startOperationProfile(SessionProfiler.CONNECT); closeDatasourceConnection(); setDatasourceConnection(null); setIsInTransaction(false); session.endOperationProfile(SessionProfiler.CONNECT); }
/** * Attempt to save some of the cost associated with getting a fresh connection. * Assume the DatabaseDriver has been cached, if appropriate. * Note: Connections that are participating in transactions will not be refreshd.^M */ protected void reconnect(AbstractSession session) throws DatabaseException { session.log(SessionLog.FINEST, SessionLog.CONNECTION, "reconnecting_to_external_connection_pool"); session.startOperationProfile(SessionProfiler.CONNECT); connect(getLogin()); session.endOperationProfile(SessionProfiler.CONNECT); }
/** * Execute the call. * @return depending of the type either the row count, row or vector of rows. */ public Object executeCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException { // If the login is null, then this accessor has never been connected. if (getLogin() == null) { throw DatabaseException.databaseAccessorNotConnected(); } if (session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {// pre-check to improve performance session.log(SessionLog.FINE, SessionLog.SQL, call.getLogString(this), (Object[])null, this, false); } Object result = basicExecuteCall(call, translationRow, session); return result; }
/** * Commit a transaction on the database. First flush any batched statements. */ public void commitTransaction(AbstractSession session) throws DatabaseException { this.writesCompleted(session); super.commitTransaction(session); }
/** * Connect to the database. * Exceptions are caught and re-thrown as TopLink exceptions. * Must set the transaction isolation. */ protected void connect(Login login) throws DatabaseException { super.connect(login); checkTransactionIsolation(); }
/** * Close the accessor's connection. * This is used only for external connection pooling * when it is intended for the connection to be reconnected in the future. */ public void closeConnection() { // Unfortunately do not have the session to pass, fortunately it is not used. clearStatementCache(null); super.closeConnection(); }
if (usesExternalTransactionController()) { setIsInTransaction(false); if ((getDatasourceConnection() != null) && usesExternalConnectionPooling()) { closeConnection(); setDatasourceConnection(null); incrementCallCount(session); basicRollbackTransaction(session); } finally { setIsInTransaction(false); decrementCallCount(); session.endOperationProfile(SessionProfiler.TRANSACTION);