private long getNextEventId(Connection con, SQLGenerator sqlGenerator, long numValues)
      throws SQLException, MetaException {

    /*
     * FOR UPDATE means something different in Derby than in most other vendor
     * implementations therefore it is required to lock the entire table. Since
     * there is only one row in the table, this should not cause any performance
     * degradation.
     *
     * see: https://db.apache.org/derby/docs/10.1/ref/rrefsqlj31783.html
     */
    if (sqlGenerator.getDbProduct().isDERBY()) {
      final String lockingQuery = sqlGenerator.lockTable("NOTIFICATION_SEQUENCE", false);
      LOG.debug("Locking Derby table [{}]", lockingQuery);
      try (Statement stmt = con.createStatement()) {
        stmt.execute(lockingQuery);
      }
    }

    final String sfuSql = sqlGenerator.addForUpdateClause(EV_SEL_SQL);
    Optional<Long> nextSequenceValue = Optional.empty();

    LOG.debug("Going to execute query [{}]", sfuSql);
    try (Statement stmt = con.createStatement()) {
      ResultSet rs = stmt.executeQuery(sfuSql);
      if (rs.next()) {
        nextSequenceValue = Optional.of(rs.getLong(1));
      }
    }

    final long updatedEventId = numValues + nextSequenceValue.orElseThrow(
        () -> new MetaException("Transaction database not properly configured, failed to determine next event ID"));

    LOG.debug("Going to execute query [{}][1={}]", EV_UPD_SQL, updatedEventId);
    try (PreparedStatement stmt = con.prepareStatement(EV_UPD_SQL)) {
      stmt.setLong(1, updatedEventId);
      final int rowCount = stmt.executeUpdate();
      LOG.debug("Updated {} rows for NOTIFICATION_SEQUENCE table", rowCount);
    }

    return nextSequenceValue.get();
  }
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