示例#1
0
  @Override
  public void addColumn(IndexColumn indexColumn) {
    Table indexTable = indexColumn.getColumn().getTable();
    Integer indexTableDepth = indexTable.getDepth();
    assert indexTableDepth != null;

    super.addColumn(indexColumn);
    GroupIndexHelper.actOnGroupIndexTables(this, indexColumn, GroupIndexHelper.ADD);

    // Add the table into our navigable map if needed. Confirm it's within the branch
    ParticipatingTable participatingTable = tablesByDepth.get(indexTableDepth);
    if (participatingTable == null) {
      Map.Entry<Integer, ParticipatingTable> rootwardEntry =
          tablesByDepth.floorEntry(indexTableDepth);
      Map.Entry<Integer, ParticipatingTable> leafwardEntry =
          tablesByDepth.ceilingEntry(indexTableDepth);
      checkIndexTableInBranchNew(indexColumn, indexTable, indexTableDepth, rootwardEntry, true);
      checkIndexTableInBranchNew(indexColumn, indexTable, indexTableDepth, leafwardEntry, false);
      participatingTable = new ParticipatingTable(indexTable);
      tablesByDepth.put(indexTableDepth, participatingTable);
    } else if (participatingTable.table != indexTable) {
      throw new BranchingGroupIndexException(
          indexColumn.getIndex().getIndexName().getName(),
          indexTable.getName(),
          participatingTable.table.getName());
    }
    participatingTable.markInvolvedInIndex(indexColumn.getColumn());
  }
示例#2
0
 private void computeFieldAssociations(
     Map<Table, Integer> ordinalMap, Map<? extends Table, Integer> flattenedRowOffsets) {
   freezeColumns();
   allColumns = new ArrayList<>();
   allColumns.addAll(keyColumns);
   AssociationBuilder toIndexRowBuilder = new AssociationBuilder();
   List<Column> indexColumns = new ArrayList<>();
   // Add index key fields
   for (IndexColumn iColumn : getKeyColumns()) {
     Column column = iColumn.getColumn();
     indexColumns.add(column);
     toIndexRowBuilder.rowCompEntry(columnPosition(flattenedRowOffsets, column), -1);
   }
   // Add hkey fields not already included
   int indexColumnPosition = indexColumns.size();
   HKey hKey = hKey();
   for (HKeySegment hKeySegment : hKey.segments()) {
     Integer ordinal = ordinalMap.get(hKeySegment.table());
     assert ordinal != null : hKeySegment.table();
     for (HKeyColumn hKeyColumn : hKeySegment.columns()) {
       Column undeclaredHKeyColumn = undeclaredHKeyColumn(hKeyColumn);
       if (!indexColumns.contains(undeclaredHKeyColumn)) {
         toIndexRowBuilder.rowCompEntry(
             columnPosition(flattenedRowOffsets, undeclaredHKeyColumn), -1);
         indexColumns.add(undeclaredHKeyColumn);
         allColumns.add(
             new IndexColumn(this, undeclaredHKeyColumn, indexColumnPosition++, true, 0));
       }
     }
   }
   indexRowComposition = toIndexRowBuilder.createIndexRowComposition();
   computeHKeyDerivations(ordinalMap);
 }
示例#3
0
 private int positionOf(Column column) {
   for (IndexColumn indexColumn : allColumns) {
     if (indexColumn.getColumn() == column) {
       return indexColumn.getPosition();
     }
   }
   return -1;
 }
示例#4
0
  public List<String> getColumns() {
    if (columns == null) return Collections.emptyList();

    if (columns.size() > 1) {
      Collections.sort(this.columns, IndexColumn.getSequenceSorter());
    }
    List<String> result = new ArrayList<>(columns.size());
    for (IndexColumn col : columns) {
      result.add(col.getColumn());
    }
    return result;
  }
  @XmlTransient
  public List<Column> getColumnList() {
    if (columnList != null) {
      return columnList;
    }
    if (indexColumnList == null) {
      return null;
    }
    columnList = new ArrayList<Column>();
    for (IndexColumn indexColumn : indexColumnList) {
      columnList.add(entity.getColumn(indexColumn.getId()));
    }

    return columnList;
  }
 @Override
 public Index getScanIndex(Session session) {
   if (getStep(session) == 0) {
     throw DbException.get(ErrorCode.STEP_SIZE_MUST_NOT_BE_ZERO);
   }
   return new RangeIndex(this, IndexColumn.wrap(columns));
 }
示例#7
0
 private Index addIndex(String name, ArrayList<Column> list, IndexType indexType) {
   Column[] cols = new Column[list.size()];
   list.toArray(cols);
   Index index = new Index(this, name, IndexColumn.wrap(cols), indexType);
   indexes.add(index);
   return index;
 }
示例#8
0
  private void checkIndexTableInBranchNew(
      IndexColumn indexColumn,
      Table indexTable,
      int indexTableDepth,
      Map.Entry<Integer, ParticipatingTable> entry,
      boolean entryIsRootward) {
    if (entry == null) {
      return;
    }
    if (entry.getKey() == indexTableDepth) {
      throw new BranchingGroupIndexException(
          indexColumn.getIndex().getIndexName().getName(),
          indexTable.getName(),
          entry.getValue().table.getName());
    }
    Table entryTable = entry.getValue().table;

    final Table rootward;
    final Table leafward;
    if (entryIsRootward) {
      assert entry.getKey() < indexTableDepth
          : String.format("failed %d < %d", entry.getKey(), indexTableDepth);
      rootward = entryTable;
      leafward = indexTable;
    } else {
      assert entry.getKey() > indexTableDepth
          : String.format("failed %d < %d", entry.getKey(), indexTableDepth);
      rootward = indexTable;
      leafward = entryTable;
    }

    if (!leafward.isDescendantOf(rootward)) {
      throw new BranchingGroupIndexException(
          indexColumn.getIndex().getIndexName().getName(),
          indexTable.getName(),
          entry.getValue().table.getName());
    }
  }
示例#9
0
  /*
   * (non-Javadoc)
   * @see com.lexst.db.view.View#find(com.lexst.db.statement.Condition)
   */
  @Override
  public Set<Long> find(Condition condi) {
    IndexColumn num = condi.getValue();
    if (num == null || num.getClass() != ShortIndex.class) {
      throw new IllegalArgumentException("null pointer or invalid index!");
    }
    short value = ((ShortIndex) num).getValue();

    // 找到范围分片截止点
    HashSet<Long> all = new HashSet<Long>(1024);
    // 列名在左,参数值在右(固定!, 检查可以的范围)
    switch (condi.getCompare()) {
      case Condition.EQUAL:
        for (ShortRange range : mapSet.keySet()) {
          if (range.inside(value)) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.NOT_EQUAL:
        for (ShortRange range : mapSet.keySet()) {
          if (range.getBegin() != value || range.getEnd() != value) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.LESS:
        for (ShortRange range : mapSet.keySet()) {
          if (range.getBegin() < value || range.getEnd() < value) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.LESS_EQUAL:
        for (ShortRange range : mapSet.keySet()) {
          if (range.getBegin() <= value || range.getEnd() <= value) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.GREATER:
        for (ShortRange range : mapSet.keySet()) {
          if (range.getBegin() > value || range.getEnd() > value) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.GREATER_EQUAL:
        for (ShortRange range : mapSet.keySet()) {
          if (range.getBegin() >= value || range.getEnd() >= value) {
            IdentitySet set = mapSet.get(range);
            all.addAll(set.keySet());
          }
        }
        break;
      case Condition.LIKE:
        for (IdentitySet set : mapSet.values()) {
          all.addAll(set.keySet());
        }
        break;
    }
    return all;
  }