/** * Closes this connection. All open statements, prepared statements and result sets that where * created by this connection become invalid after calling this method. If there is an uncommitted * transaction, it will be rolled back. */ public synchronized void close() throws SQLException { try { debugCodeCall("close"); openStackTrace = null; if (executingStatement != null) { executingStatement.cancel(); } if (session == null) { return; } session.cancel(); try { synchronized (session) { if (!session.isClosed()) { try { // roll back unless that would require to re-connect // (the transaction can't be rolled back after re-connecting) if (!session.isReconnectNeeded(true)) { rollbackInternal(); session.afterWriting(); } closePreparedCommands(); } finally { session.close(); } } } } finally { session = null; } } catch (Exception e) { throw logAndConvert(e); } }
/** * INTERNAL. Check if this connection is closed. * * @param write if the next operation is possibly writing * @throws SQLException if the connection or session is closed */ protected void checkClosed(boolean write) throws SQLException { if (session == null) { throw DbException.get(ErrorCode.OBJECT_CLOSED); } if (session.isClosed()) { throw DbException.get(ErrorCode.DATABASE_CALLED_AT_SHUTDOWN); } if (session.isReconnectNeeded(write)) { trace.debug("reconnect"); closePreparedCommands(); session = session.reconnect(write); setTrace(session.getTrace()); } }