コード例 #1
0
  /**
   * {@inheritDoc}
   *
   * <p>Note: Since indexes are not always explicitly named in databases, the sorting routine orders
   * the indexes by the names of the columns in the index.
   */
  @Override
  public int compareTo(final NamedObject obj) {
    if (obj == null) {
      return -1;
    }

    final Index other = (Index) obj;
    int comparison = 0;
    final Column[] thisColumns = getColumns();
    final Column[] otherColumns = other.getColumns();

    if (comparison == 0) {
      comparison = thisColumns.length - otherColumns.length;
    }
    if (comparison == 0) {
      for (int i = 0; i < thisColumns.length; i++) {
        final Column thisColumn = thisColumns[i];
        final Column otherColumn = otherColumns[i];
        if (comparison == 0) {
          comparison = thisColumn.compareTo(otherColumn);
        } else {
          break;
        }
      }
    }
    if (comparison == 0) {
      comparison = super.compareTo(other);
    }

    return comparison;
  }
コード例 #2
0
  /**
   * {@inheritDoc}
   *
   * <p>Note: Since indexes are not always explicitly named in databases, the sorting routine orders
   * the indexes by the names of the columns in the index.
   */
  @Override
  public int compareTo(final NamedObject obj) {
    if (obj == null || !(obj instanceof Index)) {
      return -1;
    }

    final Index that = (Index) obj;

    int compareTo = 0;

    if (compareTo == 0) {
      final List<IndexColumn> thisColumns = getColumns();
      final List<IndexColumn> thatColumns = that.getColumns();

      compareTo = CompareUtility.compareLists(thisColumns, thatColumns);
    }

    if (compareTo == 0) {
      if (isUnique != that.isUnique()) {
        compareTo = isUnique ? -1 : 1;
      }
    }

    if (compareTo == 0) {
      compareTo = indexType.ordinal() - that.getIndexType().ordinal();
    }

    if (compareTo == 0) {
      compareTo = super.compareTo(obj);
    }

    return compareTo;
  }
コード例 #3
0
  private Set<Column> listTableKeys(final Table table) {
    final Set<Column> tableKeys = new HashSet<>();

    final PrimaryKey primaryKey = table.getPrimaryKey();
    if (primaryKey != null && primaryKey.getColumns().size() == 1) {
      tableKeys.add(primaryKey.getColumns().get(0));
    }

    for (final Index index : table.getIndexes()) {
      if (index != null && index.isUnique() && index.getColumns().size() == 1) {
        tableKeys.add(index.getColumns().get(0));
      }
    }

    return tableKeys;
  }
コード例 #4
0
 /**
  * Copies information from an index.
  *
  * @param index Index
  */
 MutablePrimaryKey(final Index index) {
   super((Table) index.getParent(), index.getName());
   setCardinality(index.getCardinality());
   setPages(index.getPages());
   setRemarks(index.getRemarks());
   setType(index.getType());
   setUnique(index.isUnique());
   // Copy columns
   for (final IndexColumn column : index.getColumns()) {
     addColumn((MutableIndexColumn) column);
   }
 }