public void setBackgroundException(DbException e) { if (backgroundException == null) { backgroundException = e; TraceSystem t = getTraceSystem(); if (t != null) { t.getTrace(Trace.DATABASE).error(e, "flush"); } } }
/** * Create a trace object for this module. Trace modules with names are not * cached. * * @param module the module name * @return the trace object */ public Trace getTrace(String module) { return new Trace(writer, module); }
/** * Write the operation to the trace system if debug trace is enabled. * * @param operation the operation performed * @param id the id of the operation */ public void traceOperation(String operation, int id) { if (trace.isDebugEnabled()) { trace.debug("{0} {1}", operation, id); } }
/** * Write trace information in the form objectName.text. * * @param text the trace text */ protected void debugCode(String text) { if (trace.isDebugEnabled()) { trace.debugCode(getTraceObjectName() + "." + text); } }
/** * Log an exception and convert it to a SQL exception if required. * * @param ex the exception * @return the SQL exception object */ protected SQLException logAndConvert(Throwable ex) { SQLException e = null; try { e = DbException.toSQLException(ex); if (trace == null) { DbException.traceThrowable(e); } else { int errorCode = e.getErrorCode(); if (errorCode >= 23000 && errorCode < 24000) { trace.info(e, "exception"); } else { trace.error(e, "exception"); } } } catch(Throwable ignore) { if (e == null) { e = new SQLException("", "HY000", ex); } e.addSuppressed(ignore); } return e; }
/** * Print information about the statement executed if info trace level is * enabled. * * @param startTimeNanos when the statement was started * @param rowCount the query or update row count */ void trace(long startTimeNanos, int rowCount) { if (session.getTrace().isInfoEnabled() && startTimeNanos > 0) { long deltaTimeNanos = System.nanoTime() - startTimeNanos; String params = Trace.formatParams(parameters); session.getTrace().infoSQL(sqlStatement, params, rowCount, deltaTimeNanos / 1000 / 1000); } // startTime_nanos can be zero for the command that actually turns on // statistics if (session.getDatabase().getQueryStatistics() && startTimeNanos != 0) { long deltaTimeNanos = System.nanoTime() - startTimeNanos; session.getDatabase().getQueryStatisticsData(). update(toString(), deltaTimeNanos, rowCount); } }
private void addIndex(List<Column> list, IndexType indexType) { // bind the index to the leading recognized columns in the index // (null columns might come from a function-based index) int firstNull = list.indexOf(null); if (firstNull == 0) { trace.info("Omitting linked index - no recognized columns."); return; } else if (firstNull > 0) { trace.info("Unrecognized columns in linked index. " + "Registering the index against the leading {0} " + "recognized columns of {1} total columns.", firstNull, list.size()); list = list.subList(0, firstNull); } Column[] cols = list.toArray(new Column[0]); Index index = new LinkedIndex(this, 0, IndexColumn.wrap(cols), indexType); indexes.add(index); }
/** * Check if the trace level is equal or higher than INFO. * * @return true if it is */ public boolean isInfoEnabled() { return isEnabled(TraceSystem.INFO); }
this.user = ci.getUserName(); if (isInfoEnabled()) { trace.infoCode("Connection " + getTraceObjectName() + " = DriverManager.getConnection(" + quote(ci.getOriginalURL()) + ", " + quote(user)
@Override public void stop() { session.endStatement(); session.setCurrentCommand(null, false); if (!isTransactional()) { session.commit(true); } else if (session.getAutoCommit()) { session.commit(false); } else if (session.getDatabase().isMultiThreaded()) { Database db = session.getDatabase(); if (db != null) { if (db.getLockMode() == Constants.LOCK_MODE_READ_COMMITTED) { session.unlockReadLocks(); } } } if (trace.isInfoEnabled() && startTimeNanos > 0) { long timeMillis = (System.nanoTime() - startTimeNanos) / 1000 / 1000; if (timeMillis > Constants.SLOW_QUERY_LIMIT_MS) { trace.info("slow query: {0} ms", timeMillis); } } }
@Override public String toString() { return sql + Trace.formatParams(getParameters()); }
/** * Close without further writing. */ void close() { trace.debug("log close"); if (pageOut != null) { pageOut.close(); pageOut = null; } writeBuffer = null; }
/** * Check if the debug trace level is enabled. * * @return true if it is */ protected boolean isDebugEnabled() { return trace.isDebugEnabled(); }
/** * Write trace information as a method call in the form * objectName.methodName(). * * @param methodName the method name */ protected void debugCodeCall(String methodName) { if (trace.isDebugEnabled()) { trace.debugCode(getTraceObjectName() + "." + methodName + "();"); } }
return; trace.info("closing {0} from shutdown hook", databaseName); closeAllSessionsException(null); trace.info("closing {0}", databaseName); if (eventListener != null) { trigger.close(); } catch (SQLException e) { trace.error(e, "close"); trace.error(e, "close"); closeOpenFilesAndUnlock(true); } catch (DbException e) { trace.error(e, "close"); trace.info("closed"); traceSystem.close(); if (closeOnExit != null) {
/** * Print information about the statement executed if info trace level is * enabled. * * @param startTime when the statement was started * @param rowCount the query or update row count */ void trace(long startTime, int rowCount) { if (session.getTrace().isInfoEnabled() && startTime > 0) { long deltaTime = System.currentTimeMillis() - startTime; String params = Trace.formatParams(parameters); session.getTrace().infoSQL(sqlStatement, params, rowCount, deltaTime); } if (session.getDatabase().getQueryStatistics()) { long deltaTime = System.currentTimeMillis() - startTime; session.getDatabase().getQueryStatisticsData(). update(toString(), deltaTime, rowCount); } }
/** * Create a session for the given user. * * @param user the user * @return the session, or null if the database is currently closing * @throws DbException if the database is in exclusive mode */ synchronized Session createSession(User user) { if (closing) { return null; } if (exclusiveSession.get() != null) { throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE); } Session session = new Session(this, user, ++nextSessionId); userSessions.add(session); trace.info("connecting session #{0} to {1}", session.getId(), databaseName); if (delayedCloser != null) { delayedCloser.reset(); delayedCloser = null; } return session; }