/** {@inheritDoc} */ @Override protected void toParsedText(StringBuilder writer, boolean actual) { // State field expression if (stateFieldExpression != null) { stateFieldExpression.toParsedText(writer, actual); } if (hasSpaceAfterStateFieldPathExpression) { writer.append(SPACE); } // '=' if (hasEqualSign) { writer.append(EQUAL); } if (hasSpaceAfterEqualSign) { writer.append(SPACE); } // New value if (newValue != null) { newValue.toParsedText(writer, actual); } }
// Even though this function applies generally to expressions and tables and not just to TVEs as // such, // this function is somewhat TVE-related because TVEs DO represent the points where expression // trees // depend on tables. public static AbstractExpression getOtherTableExpression(AbstractExpression expr, Table table) { assert (expr != null); AbstractExpression retval = expr.getLeft(); if (isOperandDependentOnTable(retval, table)) { retval = expr.getRight(); assert (!isOperandDependentOnTable(retval, table)); } return retval; }
public static void main(String[] args) { Context context = new Context(); List<AbstractExpression> expressions = new ArrayList<AbstractExpression>(); expressions.add(new TerminalExpression()); expressions.add(new NonTerminalExpression()); expressions.add(new TerminalExpression()); for (AbstractExpression abstractExpression : expressions) { abstractExpression.interpreter(context); } }
public static final void main(String[] args) { Context context = new Context(); List<AbstractExpression> list = new ArrayList<AbstractExpression>(); list.add(new TerminalExpression()); list.add(new NonterminalExpression()); list.add(new TerminalExpression()); list.add(new TerminalExpression()); for (AbstractExpression exp : list) { exp.interpret(context); } }
/** {@inheritDoc} */ @Override public JPQLQueryBNF findQueryBNF(Expression expression) { if ((stateFieldExpression != null) && stateFieldExpression.isAncestor(expression)) { return getQueryBNF(UpdateItemStateFieldPathExpressionBNF.ID); } if ((newValue != null) && newValue.isAncestor(expression)) { return getQueryBNF(NewValueBNF.ID); } return super.findQueryBNF(expression); }
/** {@inheritDoc} */ @Override protected void parse(WordParser wordParser, boolean tolerant) { // Parse state field if (tolerant) { stateFieldExpression = parse(wordParser, UpdateItemStateFieldPathExpressionBNF.ID, tolerant); } else { stateFieldExpression = new StateFieldPathExpression(this, wordParser.word()); stateFieldExpression.parse(wordParser, tolerant); } hasSpaceAfterStateFieldPathExpression = wordParser.skipLeadingWhitespace() > 0; // Parse '=' hasEqualSign = wordParser.startsWith(EQUAL); if (hasEqualSign) { wordParser.moveForward(1); hasSpaceAfterEqualSign = wordParser.skipLeadingWhitespace() > 0; if (stateFieldExpression != null) { hasSpaceAfterStateFieldPathExpression = true; } } // Parse new value newValue = parse(wordParser, NewValueBNF.ID, tolerant); if (!hasSpaceAfterEqualSign && (newValue != null)) { hasSpaceAfterEqualSign = true; } }
/** {@inheritDoc} */ @Override public JPQLQueryBNF findQueryBNF(Expression expression) { if ((upperBoundExpression != null) && upperBoundExpression.isAncestor(expression) || (lowerBoundExpression != null) && lowerBoundExpression.isAncestor(expression)) { return getQueryBNF(InternalBetweenExpressionBNF.ID); } // There is no generic BNF so we'll generalize with scalar expression if ((this.expression != null) && expression.isAncestor(expression)) { return getQueryBNF(ScalarExpressionBNF.ID); } return super.findQueryBNF(expression); }
@Override protected final void childrenChanged() { super.childrenChanged(); if (!children().isEmpty()) { throw new IllegalStateException(); } }
/** {@inheritDoc} */ @Override protected void toParsedText(StringBuilder writer, boolean actual) { // Expression if (hasExpression()) { expression.toParsedText(writer, actual); writer.append(SPACE); } // 'NOT' if (notIdentifier != null) { writer.append(actual ? notIdentifier : NOT); writer.append(SPACE); } // Identifier if (betweenIdentifier != null) { writer.append(actual ? betweenIdentifier : BETWEEN); } if (hasSpaceAfterBetween) { writer.append(SPACE); } // Lower bound expression if (lowerBoundExpression != null) { lowerBoundExpression.toParsedText(writer, actual); } if (hasSpaceAfterLowerBound) { writer.append(SPACE); } // 'AND' if (andIdentifier != null) { writer.append(actual ? andIdentifier : AND); } if (hasSpaceAfterAnd) { writer.append(SPACE); } // Upper bound expression if (upperBoundExpression != null) { upperBoundExpression.toParsedText(writer, actual); } }
/* (non-Javadoc) * @see org.exist.xquery.Expression#resetState() */ public void resetState(boolean postOptimization) { super.resetState(postOptimization); expression.resetState(postOptimization); for (Iterator i = predicates.iterator(); i.hasNext(); ) { Predicate pred = (Predicate) i.next(); pred.resetState(postOptimization); } }
/** {@inheritDoc} */ @Override AbstractExpression buildExpression( AbstractExpression parent, WordParser wordParser, String word, JPQLQueryBNF queryBNF, AbstractExpression expression, boolean tolerant) { expression = new OrderByClause(parent); expression.parse(wordParser, tolerant); return expression; }
/** {@inheritDoc} */ @Override protected AbstractExpression buildExpression( AbstractExpression parent, WordParser wordParser, String word, JPQLQueryBNF queryBNF, AbstractExpression expression, boolean tolerant) { expression = new SqrtExpression(parent); expression.parse(wordParser, tolerant); return expression; }
@Override @SuppressWarnings({"unchecked"}) protected void setJavaType(Class targetType) { super.setJavaType(targetType); TypeConverter<T> converter = getConverter(); if (converter == null) { converter = TypeUtils.getConverter(targetType); setConverter(converter); } if (converter != null) { literal = converter.convert(literal); } }
/** {@inheritDoc} */ @Override void toParsedText(StringBuilder writer, boolean includeVirtual) { // Update clause updateClause.toParsedText(writer, includeVirtual); if (hasSpaceAfterUpdateClause) { writer.append(SPACE); } // Where clause if (whereClause != null) { whereClause.toParsedText(writer, includeVirtual); } }
/** {@inheritDoc} */ @Override void parse(WordParser wordParser, boolean tolerant) { // Parse 'UPDATE' updateClause = new UpdateClause(this); updateClause.parse(wordParser, tolerant); hasSpaceAfterUpdateClause = wordParser.skipLeadingWhitespace() > 0; // Parse 'WHERE' if (wordParser.startsWithIdentifier(WHERE)) { whereClause = new WhereClause(this); whereClause.parse(wordParser, tolerant); } // Now fully qualify attribute names with a virtual identification variable accept(FullyQualifyPathExpressionVisitor.instance()); }
/** * Determines whether the new value section of the query was parsed. * * @return <code>true</code> the new value was parsed; <code>false</code> if nothing was parsed */ public boolean hasNewValue() { return newValue != null && !newValue.isNull(); }
public void setTypeSizeAndInBytes(AbstractExpression typeSource) { setValueType(typeSource.getValueType()); setValueSize(typeSource.getValueSize()); m_inBytes = typeSource.getInBytes(); }
/** * Determines whether the expression before the identifier was parsed. * * @return <code>true</code> if the query has the expression before <b>BETWEEN</b>; <code>false * </code> otherwise */ public boolean hasExpression() { return expression != null && !expression.isNull(); }
/** * Determines whether the lower bound expression was parsed. * * @return <code>true</code> if the query has the lower bound expression; <code>false</code> * otherwise */ public boolean hasLowerBoundExpression() { return lowerBoundExpression != null && !lowerBoundExpression.isNull(); }
/** * Determines whether the <b>WHERE</b> clause is defined or not. * * @return <code>true</code> if this statement has a <b>WHERE</b> clause; <code>false</code> if it * was not parsed */ public boolean hasWhereClause() { return whereClause != null && !whereClause.isNull(); }
/** * Determines whether the upper bound expression was parsed. * * @return <code>true</code> if the query has the upper bound expression; <code>false</code> * otherwise */ public boolean hasUpperBoundExpression() { return upperBoundExpression != null && !upperBoundExpression.isNull(); }
public void setContextDocSet(DocumentSet contextSet) { super.setContextDocSet(contextSet); expression.setContextDocSet(contextSet); }
/** * Determines whether the state field was parsed. * * @return <code>true</code> the state field was parsed; <code>false</code> otherwise */ public boolean hasStateFieldPathExpression() { return stateFieldExpression != null && !stateFieldExpression.isNull(); }
public void resetState(boolean postOptimization) { super.resetState(postOptimization); expression.resetState(postOptimization); }
private void defineTransformations() { MetaOverTwoRelation metaGroupDep = instOverTwoRelation.getMetaOverTwoRelation(); boolean targetActiveAttribute = false; if (instOverTwoRelation.getTargetRelations().size() > 0) // TODO support multiple targets targetActiveAttribute = (boolean) ((InstPairwiseRelation) instOverTwoRelation.getTargetRelations().get(0)) .getTargetRelations() .get(0) .getInstAttribute("Active") .getValue(); if (targetActiveAttribute && metaGroupDep != null) { relationType = (String) instOverTwoRelation .getInstAttribute(SemanticOverTwoRelation.VAR_RELATIONTYPE_IDEN) .getValue(); // System.out.println(relationType); for (String sourceName : instOverTwoRelation.getSourceAttributeNames()) { AbstractExpression abstractTransformation = null; Iterator<InstElement> instEdges1 = instOverTwoRelation.getSourceRelations().iterator(); AbstractExpression recursiveExpression1 = null; AbstractExpression recursiveExpression2 = null; if (instEdges1.hasNext()) { InstElement left1 = instEdges1.next(); while ((boolean) ((InstPairwiseRelation) left1) .getSourceRelations() .get(0) .getInstAttribute("Active") .getValue() == false) { if (instEdges1.hasNext()) left1 = instEdges1.next(); else return; } switch (relationType) { case "and": abstractTransformation = new AndBooleanExpression(); break; case "or": abstractTransformation = new OrBooleanExpression(); break; case "mutex": abstractTransformation = new SumNumericExpression(); break; case "range": abstractTransformation = new SumNumericExpression(); Iterator<InstElement> instEdges2 = instOverTwoRelation.getSourceRelations().iterator(); // instEdges2.next(); // TODO eliminate duplicated edges // from collection and remove this // line InstElement left2 = instEdges2.next(); Constructor<?> constructor3 = null, constructor4 = null; try { constructor3 = abstractTransformation .getClass() .getConstructor( InstElement.class, String.class, Boolean.TYPE, AbstractExpression.class); constructor4 = abstractTransformation .getClass() .getConstructor( InstElement.class, InstElement.class, String.class, String.class); } catch (NoSuchMethodException | SecurityException e) { e.printStackTrace(); } recursiveExpression2 = transformation(constructor3, constructor4, instEdges2, left2, sourceName); break; case "": return; default: return; } Constructor<?> constructor1 = null, constructor2 = null; try { constructor1 = abstractTransformation .getClass() .getConstructor( InstElement.class, String.class, Boolean.TYPE, AbstractExpression.class); constructor2 = abstractTransformation .getClass() .getConstructor( InstElement.class, InstElement.class, String.class, String.class); } catch (NoSuchMethodException | SecurityException e) { e.printStackTrace(); } switch (relationType) { case "and": // B_Satisfied #<=> ( ( A1_"attribute" #/\ // A2_"attribute" ) #/\ ... ) case "or": // B_Satisfied #<=> ( ( A1_"attribute" #\/ // A2_"attribute" ) #\/ ... ) recursiveExpression1 = transformation(constructor1, constructor2, instEdges1, left1, sourceName); getTransformations() .add( new DoubleImplicationBooleanExpression( instOverTwoRelation, sourceName, true, recursiveExpression1)); break; case "mutex": // B_Satisfied #<=> (( ( A1_"attribute" + A2_"attribute" // ) + ... ) #<=> 1) recursiveExpression1 = transformation(constructor1, constructor2, instEdges1, left1, sourceName); AbstractExpression transformation1 = new EqualsComparisonExpression( recursiveExpression1, new NumberNumericExpression(1)); getTransformations() .add( new DoubleImplicationBooleanExpression( instOverTwoRelation, sourceName, true, transformation1)); break; case "range": // B_"attribute" #<=> ( ( ( ( A1_"attribute" + // A2_"attribute" ) + ... ) #>= GD_LowCardinality) #/\ // ( ( ( A1_"attribute" + A2_"attribute" ) + ... ) #<= // GD_HighCardinality ) ) recursiveExpression1 = transformation(constructor1, constructor2, instEdges1, left1, sourceName); AbstractExpression transformation3 = new GreaterOrEqualsBooleanExpression( instOverTwoRelation, "lowCardinality", false, recursiveExpression1); AbstractExpression transformation4 = new LessOrEqualsBooleanExpression( instOverTwoRelation, "highCardinality", false, recursiveExpression2); AbstractExpression transformation5 = new AndBooleanExpression(transformation3, transformation4); getTransformations() .add( new DoubleImplicationBooleanExpression( instOverTwoRelation /* * .getTargetRelations * ().get(0) * .getToRelation() */, sourceName, true, transformation5)); break; default: return; } } } } }