private List getTableColumns(
      Table table, List primaryKeys, List indices, Map uniqueIndices, Map uniqueColumns)
      throws SQLException {
    // get the columns
    List columns = new LinkedList();
    ResultSet columnRs = getColumnsResultSet(table);

    while (columnRs.next()) {
      int sqlType = columnRs.getInt("DATA_TYPE");
      String sqlTypeName = columnRs.getString("TYPE_NAME");
      String columnName = columnRs.getString("COLUMN_NAME");
      String columnDefaultValue = columnRs.getString("COLUMN_DEF");

      String remarks = columnRs.getString("REMARKS");
      if (remarks == null && dbHelper.isOracleDataBase()) {
        remarks = getOracleColumnComments(table.getSqlName(), columnName);
      }

      // if columnNoNulls or columnNullableUnknown assume "not nullable"
      boolean isNullable = (DatabaseMetaData.columnNullable == columnRs.getInt("NULLABLE"));
      int size = columnRs.getInt("COLUMN_SIZE");
      int decimalDigits = columnRs.getInt("DECIMAL_DIGITS");

      boolean isPk = primaryKeys.contains(columnName);
      boolean isIndexed = indices.contains(columnName);
      String uniqueIndex = (String) uniqueIndices.get(columnName);
      List columnsInUniqueIndex = null;
      if (uniqueIndex != null) {
        columnsInUniqueIndex = (List) uniqueColumns.get(uniqueIndex);
      }

      boolean isUnique = columnsInUniqueIndex != null && columnsInUniqueIndex.size() == 1;
      if (isUnique) {
        GLogger.trace("unique column:" + columnName);
      }
      Column column =
          new Column(
              table,
              sqlType,
              sqlTypeName,
              columnName,
              size,
              decimalDigits,
              isPk,
              isNullable,
              isIndexed,
              isUnique,
              columnDefaultValue,
              remarks);
      BeanHelper.copyProperties(
          column, TableOverrideValuesProvider.getColumnOverrideValues(table, column));
      columns.add(column);
    }
    columnRs.close();
    return columns;
  }
  private static List<String> getTablesToTruncate(Connection connection) {
    List<String> result = new ArrayList<>();

    try (ResultSet tables = getTables(connection)) {
      while (tables.next()) {
        String tableName = tables.getString(3);
        if (!TABLES_THAT_SHOULD_NOT_BE_TRUNCATED.contains(tableName)) {
          result.add(tableName);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return result;
  }
  public String buildEventSelect(Notification notice) throws IOException, FileNotFoundException {
    // The list of events needs to be transposed to (label, uei) in
    // order to sort it by label for display.
    List eventVendors =
        EventConfigurationManager.getEventsByVendor(NotificationWizardServlet.WT_VENDOR_NAME);
    StringBuffer buffer = new StringBuffer();
    SortedMap sortedEvents = (SortedMap) new TreeMap();

    List excludeList = NotificationWizardServlet.getExcludeList();

    for (Iterator iter = eventVendors.iterator(); iter.hasNext(); ) {
      com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) iter.next();
      sortedEvents.put(e.getLabel(), e);
    }

    Iterator j = sortedEvents.keySet().iterator();

    while (j.hasNext()) {
      String label = (String) j.next();
      com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) sortedEvents.get(label);
      String uei = e.getUei();
      String trimmedUei = NotificationWizardServlet.stripUei(uei);

      if (!excludeList.contains(trimmedUei)) {
        boolean foundUei = NotificationWizardServlet.isEventInNotification(notice, e);
        int id = e.getId();

        if (foundUei) {
          buffer.append("<option selected VALUE=\"" + id + "\">" + label + "</option>");
        } else {
          buffer.append("<option value=\"" + id + "\">" + label + "</option>");
        }
      }
    }

    return buffer.toString();
  }
  /**
   * Builds the vendor events tree.
   *
   * @param notice the selected notification so that events that match this notification can be
   *     preselected
   * @param vendorExcludeList a list of vendors to exclude from the result
   * @return an xml tree of vendors and their events
   */
  public String buildTree(Notification notice, List vendorExcludeList)
      throws IOException, FileNotFoundException {
    StringBuffer buffer = new StringBuffer();
    String itemPrefix = "i_";
    String sectionPrefix = "s_";
    int sid = 1, iid = 1;
    List ueiExcludeList = NotificationWizardServlet.getExcludeList();

    buffer
        .append("<xTree>")
        .append("<item id=\"")
        .append(sectionPrefix)
        .append(sid)
        .append("\">")
        .append("<itemPrimaryData><![CDATA[System Monitoring Events]]></itemPrimaryData>")
        .append("<subitems>");

    List vendors = EventConfigurationManager.getVendorNames();
    for (Iterator iter = vendors.iterator(); iter.hasNext(); ) {
      String vendor = (String) iter.next();

      // Don't show any excluded vendors
      if (vendorExcludeList != null && vendorExcludeList.contains(vendor)) {
        continue;
      }

      sid++;

      buffer
          .append("<item id=\"")
          .append(sectionPrefix)
          .append(sid)
          .append("\">")
          .append("<itemPrimaryData><![CDATA[<input type=\"checkbox\" id=\"c_")
          .append(sectionPrefix)
          .append(sid)
          .append("\" onClick=\"tcs('")
          .append(sectionPrefix)
          .append(sid)
          .append("');us()\">");

      // Write the vendor name
      buffer.append(vendor);

      buffer.append("]]></itemPrimaryData>").append("<subitems>");

      // Now write all the events for the vendor.
      List eventVendors = EventConfigurationManager.getEventsByVendor(vendor);
      SortedMap sortedEvents = (SortedMap) new TreeMap();
      for (Iterator iter2 = eventVendors.iterator(); iter2.hasNext(); ) {
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) iter2.next();
        sortedEvents.put(e.getLabel(), e);
      }

      for (Iterator iter2 = sortedEvents.entrySet().iterator(); iter2.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter2.next();
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) entry.getValue();
        String uei = e.getUei();

        if (!ueiExcludeList.contains(NotificationWizardServlet.stripUei(uei))) {
          iid++;
          boolean inNotification = NotificationWizardServlet.isEventInNotification(notice, e);

          buffer
              .append("<item id=\"")
              .append(itemPrefix)
              .append(iid)
              .append("\">")
              .append(
                  "<itemPrimaryData><![CDATA[<input type=\"checkbox\" name=\"tree_check\" id=\"c_")
              .append(itemPrefix)
              .append(iid)
              .append("\" value=\"")
              .append(e.getId())
              .append("\" onClick=\"us()\"")
              .append((inNotification ? " checked" : ""))
              .append(">");

          // Write the event info
          buffer.append(e.getLabel());

          buffer.append("]]></itemPrimaryData>").append("</item>");
        }
      }

      buffer.append("</subitems></item>");
    }

    buffer.append("</subitems></item></xTree>");

    return buffer.toString();
  }