Responsible for handling Volt limit constraints section of CREATE TABLE ...

@param c check constraint
327535
void readLimitConstraintCondition(Constraint c) {
        readThis(Tokens.PARTITION);
        readThis(Tokens.ROWS);

        int rowsLimit = readInteger();
        c.rowsLimit = rowsLimit;

        // The optional EXECUTE (DELETE ...) clause
        if (readIfThis(Tokens.EXECUTE)) {
            // Capture the statement between parentheses following the EXECUTE keyword,
            // as in
            //
            // LIMIT PARTITION ROWS 10 EXECUTE (DELETE FROM tbl WHERE b = 1)
            //
            readThis(Tokens.OPENBRACKET);

            startRecording();

            int numOpenBrackets = 1;
            while (numOpenBrackets > 0) {
                switch(token.tokenType) {
                case Tokens.OPENBRACKET:
                    numOpenBrackets++;
                    read();
                    break;

                case Tokens.CLOSEBRACKET:
                    numOpenBrackets--;
                    if (numOpenBrackets > 0) {
                        // don't want the final parenthesis
                        read();
                    }
                    break;

                case Tokens.X_ENDPARSE:
                    throw unexpectedToken();

                default:
                    read();
                }
            }

            Token[] stmtTokens = getRecordedStatement();

            // This captures the DELETE statement exactly, including embedded whitespace, etc.
            c.rowsLimitDeleteStmt = Token.getSQL(stmtTokens);
            readThis(Tokens.CLOSEBRACKET);
        }
    }
1191765
private void visit(int v, int c) {
        remaining--;
        component[v] = c;
        for (int w : g[v])
            if (component[w] == 0) visit(w, c);
    }
866329
public final <C extends AbstractConstraint<?>> boolean addRoutingConstraint(String activity, C constraint) throws CompatibilityException {
                return addRoutingConstraint(activity, constraint, true);
        }
937572
private static void checkValidity(ECField field, BigInteger c,
        String cName) {
        // can only perform check if field is ECFieldFp or ECFieldF2m.
        if (field instanceof ECFieldFp) {
            BigInteger p = ((ECFieldFp)field).getP();
            if (p.compareTo(c) != 1) {
                throw new IllegalArgumentException(cName + " is too large");
            } else if (c.signum() < 0) {
                throw new IllegalArgumentException(cName + " is negative");
            }
        } else if (field instanceof ECFieldF2m) {
            int m = ((ECFieldF2m)field).getM();
            if (c.bitLength() > m) {
                throw new IllegalArgumentException(cName + " is too large");
            }
        }
    }
974824
private void addConstraintToCatalog(Table table,
            VoltXMLElement node,
            Map<String, String> indexReplacementMap,
            Map<String, Index> indexMap)
            throws VoltCompilerException
    {
        assert node.name.equals("constraint");

        String name = node.attributes.get("name");
        String typeName = node.attributes.get("constrainttype");
        ConstraintType type = ConstraintType.valueOf(typeName);
        String tableName = table.getTypeName();

        if (type == ConstraintType.LIMIT) {
            int tupleLimit = Integer.parseInt(node.attributes.get("rowslimit"));
            if (tupleLimit < 0) {
                throw m_compiler.new VoltCompilerException("Invalid constraint limit number '" + tupleLimit + "'");
            }
            if (tableLimitConstraintCounter.contains(tableName)) {
                throw m_compiler.new VoltCompilerException("Too many table limit constraints for table " + tableName);
            } else {
                tableLimitConstraintCounter.add(tableName);
            }

            table.setTuplelimit(tupleLimit);
            String deleteStmt = node.attributes.get("rowslimitdeletestmt");
            if (deleteStmt != null) {
                Statement catStmt = table.getTuplelimitdeletestmt().add("limit_delete");
                catStmt.setSqltext(deleteStmt);
                validateTupleLimitDeleteStmt(catStmt);
            }
            return;
        }

        if (type == ConstraintType.CHECK) {
            String msg = "VoltDB does not enforce check constraints. ";
            msg += "Constraint on table " + tableName + " will be ignored.";
            m_compiler.addWarn(msg);
            return;
        }
        else if (type == ConstraintType.FOREIGN_KEY) {
            String msg = "VoltDB does not enforce foreign key references and constraints. ";
            msg += "Constraint on table " + tableName + " will be ignored.";
            m_compiler.addWarn(msg);
            return;
        }
        else if (type == ConstraintType.MAIN) {
            // should never see these
            assert(false);
        }
        else if (type == ConstraintType.NOT_NULL) {
            // these get handled by table metadata inspection
            return;
        }
        else if (type != ConstraintType.PRIMARY_KEY &&  type != ConstraintType.UNIQUE) {
            throw m_compiler.new VoltCompilerException("Invalid constraint type '" + typeName + "'");
        }

        // else, create the unique index below
        // primary key code is in other places as well

        // The constraint is backed by an index, therefore we need to create it
        // TODO: We need to be able to use indexes for foreign keys. I am purposely
        //       leaving those out right now because HSQLDB just makes too many of them.
        Constraint catalog_const = table.getConstraints().add(name);
        String indexName = node.attributes.get("index");
        assert(indexName != null);
        // handle replacements from duplicate index pruning
        if (indexReplacementMap.containsKey(indexName)) {
            indexName = indexReplacementMap.get(indexName);
        }

        Index catalog_index = indexMap.get(indexName);

        // Attach the index to the catalog constraint (catalog_const).
        if (catalog_index != null) {
            catalog_const.setIndex(catalog_index);
            // This may be redundant.
            catalog_index.setUnique(true);

            boolean assumeUnique = Boolean.parseBoolean(node.attributes.get("assumeunique"));
            catalog_index.setAssumeunique(assumeUnique);
        }
        catalog_const.setType(type.getValue());
    }
894603
public void check(CollectionDescriptorDef collDef, String checkLevel) throws ConstraintException
    {
        ensureElementClassRef(collDef, checkLevel);
        checkInheritedForeignkey(collDef, checkLevel);
        ensureCollectionClass(collDef, checkLevel);
        checkProxyPrefetchingLimit(collDef, checkLevel);
        checkOrderby(collDef, checkLevel);
        checkQueryCustomizer(collDef, checkLevel);
    }
1240086
private void enforceCpuLimits()
    {
        for (QueryExecution query : queryTracker.getAllQueries()) {
            Duration cpuTime = query.getTotalCpuTime();
            Duration sessionLimit = getQueryMaxCpuTime(query.getSession());
            Duration limit = Ordering.natural().min(maxQueryCpuTime, sessionLimit);
            if (cpuTime.compareTo(limit) > 0) {
                query.fail(new ExceededCpuLimitException(limit));
            }
        }
    }
422070
public void setVertexInput(Operator<Record> c) {
		this.iteration.setInitialSolutionSet(c);
		this.iteration.setInitialWorkset(c);
	}
919205
public void check(ReconfigurationPlan p) throws SatConstraintViolationException {
        if (checkers.isEmpty()) {
            return;
        }

        checkModel(p.getOrigin(), true);

        if (!p.getActions().isEmpty()) {
            PriorityQueue<Action> starts = new PriorityQueue<>(p.getActions().size(), STARTS_CMP);
            PriorityQueue<Action> ends = new PriorityQueue<>(p.getActions().size(), ENDS_CMP);
            starts.addAll(p.getActions());
            ends.addAll(p.getActions());

            //Starts the actions
            int curMoment = starts.peek().getStart();
            while (!starts.isEmpty() || !ends.isEmpty()) {
                Action a = ends.peek();
                while (a != null && a.getEnd() == curMoment) {
                    ends.remove();
                    startingEvent = false;
                    visitAndThrowOnViolation(a);
                    visitEvents(a, Action.Hook.POST);
                    a = ends.peek();
                }
                a = starts.peek();

                while (a != null && a.getStart() == curMoment) {
                    starts.remove();
                    startingEvent = true;
                    visitEvents(a, Action.Hook.PRE);
                    visitAndThrowOnViolation(a);
                    a = starts.peek();
                }
                int nextEnd = Integer.MAX_VALUE;
                if (!ends.isEmpty()) {
                    nextEnd = ends.peek().getEnd();
                }
                int nextStart = Integer.MAX_VALUE;
                if (!starts.isEmpty()) {
                    nextStart = starts.peek().getStart();
                }

                curMoment = Math.min(nextEnd, nextStart);
            }
        }
        Model mo = p.getResult();
        if (mo == null) {
            throw new InconsistentSolutionException(p.getOrigin(), p, "The resulting reconfiguration plan is not applyable");
        }
        checkModel(mo, false);
    }
368065
public void addConstraint(Constraint c) {

        int index = c.getConstraintType() == Constraint.PRIMARY_KEY ? 0
                                                                    : constraintList
                                                                        .length;

        constraintList =
            (Constraint[]) ArrayUtil.toAdjustedArray(constraintList, c, index,
                1);

        updateConstraintLists();
    }
1178807
private Statement compileAlterTableDropLimit(Table t) {

        HsqlName readName  = null;
        HsqlName writeName = null;
        boolean  cascade   = false;

        if (token.tokenType == Tokens.RESTRICT) {
            read();
        } else if (token.tokenType == Tokens.CASCADE) {
            read();

            cascade = true;
        }

        SchemaObject object = t.getLimitConstraint();
        if (object == null) {
            throw Error.error(ErrorCode.X_42501);
        }

        if (cascade) {
            writeName = database.getCatalogName();
        } else {
            writeName = t.getName();
        }

        Object[] args = new Object[] {
            object.getName(), Integer.valueOf(SchemaObject.CONSTRAINT),
            Boolean.valueOf(cascade), Boolean.valueOf(false)
        };
        String sql = getLastPart();

        return new StatementSchema(sql, StatementTypes.DROP_CONSTRAINT, args,
                                   readName, writeName);
    }
933064
protected void noteConstraints (int constrain, int size)
    {
        switch (constrain) {
        case HORIZONTAL:
            if (size == 0) {
                _constrain = HORIZONTAL;
            } else {
                _label.setTargetWidth(size);
            }
            break;

        case VERTICAL:
            if (size == 0) {
                _constrain = VERTICAL;
            } else {
                _label.setTargetHeight(size);
            }
            break;

        case GOLDEN:
            _label.setGoldenLayout();
            break;

        case NONE:
            // nothing doing
            break;

        default:
            throw new IllegalArgumentException("Invalid constraint orientation " + constrain);
        }
    }
748190
private void ensureDefaultOccurElements(IChemObjectBuilder builder) {
        if (mfRange == null) {
            String[] elements = new String[]{"C", "H", "O", "N", "Si", "P", "S", "F", "Cl", "Br", "I", "Sn", "B", "Pb",
                    "Tl", "Ba", "In", "Pd", "Pt", "Os", "Ag", "Zr", "Se", "Zn", "Cu", "Ni", "Co", "Fe", "Cr", "Ti",
                    "Ca", "K", "Al", "Mg", "Na", "Ce", "Hg", "Au", "Ir", "Re", "W", "Ta", "Hf", "Lu", "Yb", "Tm", "Er",
                    "Ho", "Dy", "Tb", "Gd", "Eu", "Sm", "Pm", "Nd", "Pr", "La", "Cs", "Xe", "Te", "Sb", "Cd", "Rh",
                    "Ru", "Tc", "Mo", "Nb", "Y", "Sr", "Rb", "Kr", "As", "Ge", "Ga", "Mn", "V", "Sc", "Ar", "Ne", "Be",
                    "Li", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu"};

            mfRange = new MolecularFormulaRange();
            for (int i = 0; i < elements.length; i++)
                mfRange.addIsotope(builder.newInstance(IIsotope.class, elements[i]), 0, 50);
        }
    }
439855
private void enforceTimeLimits()
    {
        for (T query : queries.values()) {
            if (query.isDone()) {
                continue;
            }
            Duration queryMaxRunTime = getQueryMaxRunTime(query.getSession());
            Duration queryMaxExecutionTime = getQueryMaxExecutionTime(query.getSession());
            Optional<DateTime> executionStartTime = query.getExecutionStartTime();
            DateTime createTime = query.getCreateTime();
            if (executionStartTime.isPresent() && executionStartTime.get().plus(queryMaxExecutionTime.toMillis()).isBeforeNow()) {
                query.fail(new PrestoException(EXCEEDED_TIME_LIMIT, "Query exceeded the maximum execution time limit of " + queryMaxExecutionTime));
            }
            if (createTime.plus(queryMaxRunTime.toMillis()).isBeforeNow()) {
                query.fail(new PrestoException(EXCEEDED_TIME_LIMIT, "Query exceeded maximum time limit of " + queryMaxRunTime));
            }
        }
    }
476715
private static void set32x64Bits(int[] table, int start, int limit) {
        assert (64 == table.length);
        int lead = start >> 6;  // Named for UTF-8 2-byte lead byte with upper 5 bits.
        int trail = start & 0x3f;  // Named for UTF-8 2-byte trail byte with lower 6 bits.

        // Set one bit indicating an all-one block.
        int bits = 1 << lead;
        if ((start + 1) == limit) { // Single-character shortcut.
            table[trail] |= bits;
            return;
        }

        int limitLead = limit >> 6;
        int limitTrail = limit & 0x3f;

        if (lead == limitLead) {
            // Partial vertical bit column.
            while (trail < limitTrail) {
                table[trail++] |= bits;
            }
        } else {
            // Partial vertical bit column,
            // followed by a bit rectangle,
            // followed by another partial vertical bit column.
            if (trail > 0) {
                do {
                    table[trail++] |= bits;
                } while (trail < 64);
                ++lead;
            }
            if (lead < limitLead) {
                bits = ~((1 << lead) - 1);
                if (limitLead < 0x20) {
                    bits &= (1 << limitLead) - 1;
                }
                for (trail = 0; trail < 64; ++trail) {
                    table[trail] |= bits;
                }
            }
            // limit<=0x800. If limit==0x800 then limitLead=32 and limitTrail=0.
            // In that case, bits=1<<limitLead == 1<<0 == 1
            // (because Java << uses only the lower 5 bits of the shift operand)
            // but the bits value is not used because trail<limitTrail is already false.
            bits = 1 << limitLead;
            for (trail = 0; trail < limitTrail; ++trail) {
                table[trail] |= bits;
            }
        }
    }
1185375
@SuppressWarnings("fallthrough")
    protected int handleGetLimit(int field, int limitType) {
        switch (field) {
        case ERA:
            if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {
                return 0;
            }
            return CURRENT_ERA;
        case YEAR:
        {
            switch (limitType) {
            case MINIMUM:
            case GREATEST_MINIMUM:
                return 1;
            case LEAST_MAXIMUM:
                return 1;
            case MAXIMUM:
                return super.handleGetLimit(field, MAXIMUM) - ERAS[CURRENT_ERA*3];
            }
            //Fall through to the default if not handled above
        }
        default:
            return super.handleGetLimit(field, limitType);
        }
    }
626876
protected boolean locked(final MSClause c) {
    return value(c.get(0)) == Tristate.TRUE && v(c.get(0)).reason() != null && v(c.get(0)).reason() == c;
  }