protected void log(LogRecord record) throws SQLException {
    Object obj = record.getParameters()[0];
    CommandLogMessage clMessage = null;
    try {
      clMessage = (CommandLogMessage) obj;
    } catch (Throwable e) {
      e.printStackTrace();
    }

    Connection connection = null;
    try {
      if (!clMessage.isSource()) {
        if (!vdbFilteredNames.isEmpty() && vdbFilteredNames.contains(clMessage.getVdbName())) {
          return;
        }
        connection = datasource.getConnection();
        if (clMessage.getStatus() == CommandLogMessage.Event.NEW) {
          logNoSource_NewEvent(clMessage, connection, "START USER COMMAND");
        } else {
          logNoSource(clMessage, connection, clMessage.getStatus().toString() + " USER COMMAND");
        }
      } else {
        if (!modelFilteredNames.isEmpty()
            && modelFilteredNames.contains(clMessage.getModelName())) {
          return;
        }
        connection = datasource.getConnection();
        if (clMessage.getStatus() == CommandLogMessage.Event.NEW) {
          logSourceNewEvent(clMessage, connection, "START DATA SRC COMMAND");
        } else {
          logSourceEvent(
              clMessage, connection, clMessage.getStatus().toString() + " DATA SRC COMMAND");
        }
      }

    } catch (SQLException e) {
      if (!connection.getAutoCommit()) {
        connection.rollback();
      }
      throw e;
    } finally {
      if (connection != null) {
        try {
          connection.close();
        } catch (SQLException se) {
          // do nothing
        }
      }
    }
  }
  private void logNoSource_NewEvent(CommandLogMessage msg, Connection connection, String eventType)
      throws SQLException {
    PreparedStatement stmt = connection.prepareStatement(NOSOURCE_NEW);

    stmt.setTimestamp(1, new java.sql.Timestamp(msg.getTimestamp()));
    stmt.setString(2, msg.getVdbName());
    stmt.setObject(3, msg.getVdbVersion());
    stmt.setString(4, eventType);
    stmt.setString(5, msg.getApplicationName());
    stmt.setString(6, msg.getSessionID());
    stmt.setString(7, msg.getRequestID());
    stmt.setString(8, msg.getTransactionID());
    stmt.setString(9, msg.getPrincipal());
    stmt.setString(10, msg.getSql());

    stmt.execute();

    if (!connection.getAutoCommit()) {
      connection.commit();
    }

    stmt.close();
  }
Beispiel #3
0
  /**
   * Add begin point to transaction monitoring table.
   *
   * @param qr Request that contains the MetaMatrix command information in the transaction.
   */
  void logSRCCommand(
      AtomicRequestMessage qr,
      ExecutionContext context,
      Event cmdStatus,
      Integer finalRowCnt,
      Long cpuTime,
      Object[] command) {
    if (!LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.DETAIL)) {
      return;
    }
    String sqlStr = null;
    if (cmdStatus == Event.NEW) {
      Command cmd = qr.getCommand();
      sqlStr = cmd != null ? cmd.toString() : null;
    }
    String userName = qr.getWorkContext().getUserName();
    String transactionID = null;
    if (qr.isTransactional()) {
      transactionID = qr.getTransactionContext().getTransactionId();
    }

    String modelName = qr.getModelName();
    AtomicRequestID sid = qr.getAtomicRequestID();

    String principal = userName == null ? "unknown" : userName; // $NON-NLS-1$

    CommandLogMessage message = null;
    if (cmdStatus == Event.NEW) {
      message =
          new CommandLogMessage(
              System.currentTimeMillis(),
              qr.getRequestID().toString(),
              sid.getNodeID(),
              transactionID,
              modelName,
              translatorName,
              qr.getWorkContext().getSessionId(),
              principal,
              sqlStr,
              context);
    } else {
      message =
          new CommandLogMessage(
              System.currentTimeMillis(),
              qr.getRequestID().toString(),
              sid.getNodeID(),
              transactionID,
              modelName,
              translatorName,
              qr.getWorkContext().getSessionId(),
              principal,
              finalRowCnt,
              cmdStatus,
              context,
              cpuTime);
      if (cmdStatus == Event.SOURCE) {
        message.setSourceCommand(command);
      }
    }
    LogManager.log(MessageLevel.DETAIL, LogConstants.CTX_COMMANDLOGGING, message);
  }
  private void logSourceEvent(CommandLogMessage msg, Connection connection, String eventType)
      throws SQLException {
    PreparedStatement stmt = connection.prepareStatement(SOURCE_OTHER);

    stmt.setTimestamp(1, new java.sql.Timestamp(msg.getTimestamp()));
    stmt.setString(2, msg.getVdbName());
    stmt.setObject(3, msg.getVdbVersion());
    stmt.setString(4, eventType);
    stmt.setString(5, msg.getSessionID());
    stmt.setString(6, msg.getRequestID());
    stmt.setObject(7, msg.getSourceCommandID().longValue());
    stmt.setString(8, msg.getTransactionID());
    stmt.setString(9, msg.getPrincipal());
    stmt.setString(10, msg.getModelName());
    stmt.setString(11, msg.getTranslatorName());
    stmt.setObject(12, msg.getRowCount());
    stmt.setString(13, (msg.getPlan() != null ? msg.getPlan().toString() : "noplan"));

    stmt.execute();

    if (!connection.getAutoCommit()) {
      connection.commit();
    }

    stmt.close();
  }