Esempio n. 1
0
  /** Constructor declaration for PK and UNIQUE */
  public Constraint(HsqlName name, Table t, Index index, int type) {

    core = new ConstraintCore();
    this.name = name;
    constType = type;
    core.mainTable = t;
    core.mainIndex = index;
    core.mainCols = index.getColumns();
  }
Esempio n. 2
0
 public Constraint(
     HsqlNameManager.HsqlName paramHsqlName, Table paramTable, Index paramIndex, int paramInt) {
   this.name = paramHsqlName;
   this.constType = paramInt;
   this.core = new ConstraintCore();
   this.core.mainTable = paramTable;
   this.core.mainIndex = paramIndex;
   this.core.mainCols = paramIndex.getColumns();
   for (int i = 0; i < this.core.mainCols.length; i++) {
     Type localType = paramTable.getColumn(this.core.mainCols[i]).getDataType();
     if (localType.isLobType()) throw Error.error(5534);
   }
 }
    boolean addToIndexConditions(Expression e) {

      if (opType == OpTypes.EQUAL || opType == OpTypes.IS_NULL) {
        if (indexedColumnCount < rangeIndex.getColumnCount()) {
          if (rangeIndex.getColumns()[indexedColumnCount] == e.getLeftNode().getColumnIndex()) {
            indexCond[indexedColumnCount] = e;

            indexedColumnCount++;

            opType = e.opType;
            opTypeEnd = OpTypes.MAX;

            return true;
          }
        }
      }

      return false;
    }
    private boolean addToIndexEndConditions(Expression e) {

      if (opType == OpTypes.EQUAL || opType == OpTypes.IS_NULL) {
        if (indexedColumnCount < rangeIndex.getColumnCount()) {
          if (rangeIndex.getColumns()[indexedColumnCount] == e.getLeftNode().getColumnIndex()) {
            Expression condition = ExpressionLogical.newNotNullCondition(e.getLeftNode());

            indexCond[indexedColumnCount] = condition;
            indexEndCond[indexedColumnCount] = e;
            indexEndCondition = ExpressionLogical.andExpressions(indexEndCondition, e);
            opType = OpTypes.NOT;
            opTypes[indexedColumnCount] = OpTypes.NOT;
            opTypeEnd = e.opType;
            opTypesEnd[indexedColumnCount] = e.opType;

            indexedColumnCount++;

            return true;
          }
        }
      }

      return false;
    }
    void addCondition(Expression e) {

      if (e == null) {
        return;
      }

      if (e instanceof ExpressionLogical) {
        if (((ExpressionLogical) e).isTerminal) {
          terminalCondition = e;
        }
      }

      nonIndexCondition = ExpressionLogical.andExpressions(nonIndexCondition, e);

      if (Expression.EXPR_FALSE.equals(nonIndexCondition)) {
        isFalse = true;
      }

      if (rangeIndex == null || rangeIndex.getColumnCount() == 0) {
        return;
      }

      if (indexedColumnCount == 0) {
        return;
      }

      if (e.getIndexableExpression(rangeVar) == null) {
        return;
      }

      int colIndex = e.getLeftNode().getColumnIndex();
      int[] indexCols = rangeIndex.getColumns();

      switch (e.getType()) {
        case OpTypes.GREATER:
        case OpTypes.GREATER_EQUAL:
        case OpTypes.GREATER_EQUAL_PRE:
          {

            // replaces existing condition
            if (opType == OpTypes.NOT) {
              if (indexCols[indexedColumnCount - 1] == colIndex) {
                nonIndexCondition =
                    ExpressionLogical.andExpressions(
                        nonIndexCondition, indexCond[indexedColumnCount - 1]);
                indexCond[indexedColumnCount - 1] = e;
                opType = e.opType;
                opTypes[indexedColumnCount - 1] = e.opType;

                if (e.getType() == OpTypes.GREATER_EQUAL_PRE && indexedColumnCount == 1) {
                  indexEndCond[indexedColumnCount - 1] =
                      ExpressionLogical.andExpressions(
                          indexEndCond[indexedColumnCount - 1], e.nodes[2]);
                }
              }
            } else {
              addToIndexConditions(e);
            }

            break;
          }
        case OpTypes.SMALLER:
        case OpTypes.SMALLER_EQUAL:
          {
            if (opType == OpTypes.GREATER
                || opType == OpTypes.GREATER_EQUAL
                || opType == OpTypes.GREATER_EQUAL_PRE
                || opType == OpTypes.NOT) {
              if (opTypeEnd != OpTypes.MAX) {
                break;
              }

              if (indexCols[indexedColumnCount - 1] == colIndex) {
                indexEndCond[indexedColumnCount - 1] = e;
                indexEndCondition = ExpressionLogical.andExpressions(indexEndCondition, e);
                opTypeEnd = e.opType;
                opTypesEnd[indexedColumnCount - 1] = e.opType;
              }
            } else {
              addToIndexEndConditions(e);
            }

            break;
          }
        default:
      }
    }