private void addNotificationLogBatch(List<NotificationEvent> eventList, List<ListenerEvent> listenerEventList,
                                 Connection dbConn, SQLGenerator sqlGenerator) throws MetaException, SQLException {
    if ((dbConn == null) || (sqlGenerator == null)) {
      LOG.info("connection or sql generator is not set so executing sql via DN");
      for (int idx = 0; idx < eventList.size(); idx++) {
        LOG.debug("DbNotificationListener: adding notification log for : {}", eventList.get(idx).getMessage());
        process(eventList.get(idx), listenerEventList.get(idx));
      }
      return;
    }

    try (Statement stmt = dbConn.createStatement()) {
      if (sqlGenerator.getDbProduct().isMYSQL()) {
        stmt.execute("SET @@session.sql_mode=ANSI_QUOTES");
      }
    }

    long nextEventId = getNextEventId(dbConn, sqlGenerator, eventList.size());
    long nextNLId = getNextNLId(dbConn, sqlGenerator,
            "org.apache.hadoop.hive.metastore.model.MNotificationLog", eventList.size());

    String columns = "\"NL_ID\"" + ", \"EVENT_ID\"" + ", \"EVENT_TIME\"" + ", \"EVENT_TYPE\"" + ", \"MESSAGE\""
            + ", \"MESSAGE_FORMAT\"" + ", \"DB_NAME\"" + ", \"TBL_NAME\"" + ", \"CAT_NAME\"";
    String insertVal = "insert into \"NOTIFICATION_LOG\" (" + columns + ") VALUES ("
            + "?,?,?,?,?,?,?,?,?"
            + ")";

    try (PreparedStatement pst = dbConn.prepareStatement(insertVal)) {
      int numRows = 0;

      for (int idx = 0; idx < eventList.size(); idx++) {
        NotificationEvent event = eventList.get(idx);
        ListenerEvent listenerEvent = listenerEventList.get(idx);

        LOG.debug("DbNotificationListener: adding notification log for : {}", event.getMessage());
        event.setMessageFormat(msgEncoder.getMessageFormat());

        pst.setLong(1, nextNLId);
        pst.setLong(2, nextEventId);
        pst.setLong(3, event.getEventTime());
        pst.setString(4, event.getEventType());
        pst.setString(5, event.getMessage());
        pst.setString(6, event.getMessageFormat());
        pst.setString(7, event.getDbName());
        pst.setString(8, event.getTableName());
        pst.setString(9, event.getCatName());

        LOG.debug("Going to execute insert <" + insertVal + ">");
        pst.addBatch();
        numRows++;

        if (numRows == maxBatchSize) {
          pst.executeBatch();
          numRows = 0;
        }

        event.setEventId(nextEventId);
        // Set the DB_NOTIFICATION_EVENT_ID for future reference by other listeners.
        if (event.isSetEventId()) {
          listenerEvent.putParameter(
                  MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME,
                  Long.toString(event.getEventId()));
        }
        nextNLId++;
        nextEventId++;
      }
      if (numRows != 0) {
        pst.executeBatch();
      }
    } catch (SQLException e) {
      LOG.warn("failed to add notification log ", e);
      throw e;
    }
  }
Get the next event ID.

@return The next ID to use for an event.
@throws SQLException if a database access error occurs or this method is
          called on a closed connection
@throws MetaException if the sequence table is not properly initialized
hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java