Package org.openrdf.query.algebra

Examples of org.openrdf.query.algebra.Or


      else {
        expandedPattern = new LeftJoin(statementPattern, joinOfAttributePatterns);
      }

      // build an Or-ed set of filter conditions on the status and team.
      Or filterConditions = new Or();

      /* first condition is that none are bound: this is the case where the subject
       * is not a restricted resource (and therefore has no associated attributes)
       *
       * And(Not(Bound(?acl_attr1)), Not(Bound(?acl_attr_1), ...)
       */
      And and = new And();
      for (Var attributeVar : attributeVars) {
        and.addArg(new Not(new Bound(attributeVar)));
      }

      if (and.getArgs().size() == 1) {
        filterConditions.addArg(and.getArg(0));
      }
      else {
        filterConditions.addArg(and);
      }

      if (permissions == null) {
        List<URI> roles = getRolesForUser(getCurrentUser());
        permissions = getAssignedPermissions(roles, ACL.VIEW);
      }

      // for each permission, we add an additional condition to the filter,
      // checking that either
      // team, or status, or both match.
      for (URI permission : permissions) {
        And permissionCondition = new And();

        for (int j = 0; j < attributes.size(); j++) {
          URI attribute = attributes.get(j);
          URI attributePermissionValue = getAttributeValueForPermission(permission, attribute);

          Compare attributeValueCompare = null;
          if (attributePermissionValue != null) {
            attributeValueCompare = new Compare(attributeVars.get(j), new Var("acl_attr_val_" + j,
                attributePermissionValue));
            permissionCondition.addArg(attributeValueCompare);
          }
        }

        if (permissionCondition.getNumberOfArguments() == 1) {
          filterConditions.addArg(permissionCondition.getArg(0));
        }
        else {
          // add the permission-defined condition to the set of Or-ed
          // filter conditions.
          filterConditions.addArg(permissionCondition);
        }
      }

      // set the filter conditions on the query pattern
      if (filterConditions.getNumberOfArguments() == 1) {
        // no second argument in the or
        expandedPattern = new Filter(expandedPattern, filterConditions.getArg(0));
      }
      else {
        expandedPattern = new Filter(expandedPattern, filterConditions);
      }

View Full Code Here


  protected class OrSameTermOptimizer extends QueryModelVisitorBase<RuntimeException> {

    @Override
    public void meet(Filter filter) {
      if (filter.getCondition() instanceof Or) {
        Or orNode = (Or)filter.getCondition();

        // Search constraints that contain SameTerm's
        List<ValueExpr> constraints = new ArrayList<ValueExpr>();

        for (ValueExpr arg : orNode.getArgs()) {
          if (containsSameTerm(arg)) {
            constraints.add(arg);
            orNode.removeArg(arg);
          }
        }

        // Check there were any constraints with SameTerm's
        if (!constraints.isEmpty()) {
          // Add the rest of the constraint to the args list
          if (orNode.getNumberOfArguments() == 1) {
            constraints.add(orNode.getArg(0));
          }
          else if (orNode.getNumberOfArguments() > 1) {
            constraints.add(orNode);
          }

          // remove the existing Filter
          TupleExpr filterArg = filter.getArg();
View Full Code Here

  @Override
  public ValueExpr visit(ASTOr node, Object data)
    throws VisitorException
  {
    Or or = new Or();

    for (ASTBooleanExpr expr : node.getOperandList()) {
      ValueExpr arg = (ValueExpr)expr.jjtAccept(this, null);
      or.addArg(arg);
    }

    return or;
  }
View Full Code Here

      sameTerms.add(new SameTerm(subjVar.clone(), resource));
      sameTerms.add(new SameTerm(objVar.clone(), resource));
    }

    ValueExpr constraint = new Or(sameTerms);

    result = new Filter(result, constraint);

    ProjectionElemList projElemList = new ProjectionElemList();
    projElemList.addElement(new ProjectionElem(subjVar.getName(), "subject"));
View Full Code Here

  public Or visit(ASTOr node, Object data)
    throws VisitorException
  {
    ValueExpr leftArg = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null);
    ValueExpr rightArg = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null);
    return new Or(leftArg, rightArg);
  }
View Full Code Here

        ValueExpr previousClauses
    ) {
        Value value = stringToValue(valueAsString);
        Compare compare = new Compare(input, builder.makeVar("v", value), CompareOp.EQ);
       
        return previousClauses == null ? compare : new Or(previousClauses, compare);
    }
View Full Code Here

    ValueExpr result = (ValueExpr)iter.next().jjtAccept(this, null);

    while (iter.hasNext()) {
      ValueExpr operand = (ValueExpr)iter.next().jjtAccept(this, null);
      result = new Or(result, operand);
    }

    return result;
  }
View Full Code Here

      sameTerms.add(new SameTerm(objVar.clone(), resource));
    }

    ValueExpr constraint = sameTerms.get(0);
    for (int i = 0; i < sameTerms.size(); i++) {
      constraint = new Or(constraint, sameTerms.get(i));
    }

    result = new Filter(result, constraint);

    ProjectionElemList projElemList = new ProjectionElemList();
View Full Code Here

  public Or visit(ASTOr node, Object data)
    throws VisitorException
  {
    ValueExpr leftArg = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null);
    ValueExpr rightArg = (ValueExpr)node.jjtGetChild(1).jjtAccept(this, null);
    return new Or(leftArg, rightArg);
  }
View Full Code Here

TOP

Related Classes of org.openrdf.query.algebra.Or

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.