예제 #1
0
 /* TODO: be able to bind a predicate node */
 private void bindNode(
     final MappableNodePattern p, final HashMap<String, String> variableBindings) {
   if (p.isVariable()) {
     StringBuilder existing = new StringBuilder();
     for (String variable : variableBindings.keySet()) {
       existing.append(variable + " = " + variableBindings.get(variable) + "\n");
     }
     LOG.debug("Considering " + p.getVarName() + " with respect to \n" + existing);
     if (!variableBindings.containsKey(p.getVarName())) {
       LOG.debug("Bound " + p.getVarName() + " to " + p.mappedName() + "\n");
       variableBindings.put(p.getVarName(), p.mappedName());
     }
   } else {
     if (!valueBindings.containsKey(p.boundTable().alias())) {
       valueBindings.put(p.boundTable().alias(), new HashSet<String>());
     }
     LOG.debug(
         "bindNode: adding valueBinding " + p.mappedName() + " = " + "'" + p.getNode() + "'\n");
     valueBindings
         .get(p.boundTable().alias())
         .add(
             p.mappedName()
                 + " = "
                 + DBUtil.quotedString(p.getNode().toString(), backslashEscape));
   }
 }
예제 #2
0
 /*
  * Get either an explicit value or a column/table reference for a given
  * mapped node pattern
  */
 private String getBoundValue(
     final MappableNodePattern n, final HashMap<String, String> variableBindings) {
   if (n.isVariable()) {
     return variableBindings.get(n.getVarName());
   } else {
     return DBUtil.quotedString(n.getNode().toString(), backslashEscape);
   }
 }
예제 #3
0
  private void addFilterConditions(
      final JoinConditions conditions,
      final HashMap<String, Set<MappableNodeFilter>> filters,
      final Set<MappableNodePattern> joinableVars,
      final HashMap<String, String> variableBindings) {
    for (String filterVar : new ArrayList<String>(filters.keySet())) {
      for (MappableNodePattern joinableVar : joinableVars) {
        if (joinableVar.isVariable() && joinableVar.getVarName().equals(filterVar)) {
          for (MappableNodeFilter f : filters.get(filterVar)) {
            String right;
            String left;

            if (f.getNode().isVariable() && f.getNode().getVarName().equals(filterVar)) {
              left = getBoundValue(joinableVar, variableBindings);
            } else if (f.getNode().isVariable()) {
              left = getBoundValue(f.getNode(), variableBindings);
            } else {
              left = DBUtil.quotedString(f.getNode().getNode().toString(), backslashEscape);
            }

            if (f.getConstraint().isVariable()
                && f.getConstraint().getVarName().equals(filterVar)) {
              right = getBoundValue(joinableVar, variableBindings);
            } else if (f.getConstraint().isVariable()) {
              right = getBoundValue(f.getConstraint(), variableBindings);
            } else {
              right = DBUtil.quotedString(f.getConstraint().getNode().toString(), backslashEscape);
            }

            conditions.addCondition(left, f.getOperator(), right);
            LOG.debug(
                "parseGraphPattern: Adding filter "
                    + "condition: "
                    + left
                    + " "
                    + f.getOperator()
                    + " "
                    + right
                    + "\n");
          }

          removeFromMap(filters.get(filterVar), filters);
        }
      }
    }
  }
예제 #4
0
 /** {@inheritDoc} */
 public QueryResults query(
     final Connection connection,
     final QueryLanguage language,
     final int fetchSize,
     final boolean autoReleaseConnection,
     final String query)
     throws QueryException {
   QueryResults results = null;
   try {
     QueryCompiler compiler = _compilerMap.get(language);
     if (compiler != null) {
       SQLProvider provider = compiler.compile(query);
       results = new SQLUnionQueryResults(connection, provider, fetchSize, autoReleaseConnection);
       return results;
     } else {
       throw new QueryException("Query language not supported: " + language.getName());
     }
   } finally {
     if (results == null && autoReleaseConnection) {
       DBUtil.release(connection);
     }
   }
 }
예제 #5
0
  private void processFilter(
      final MappableTriplePattern p, final String varName, final MappableNodeFilter f)
      throws QueryException {

    String mappedName;
    if (p.getSubject().isVariable() && p.getSubject().getVarName().equals(varName)) {
      mappedName = p.getSubject().mappedName();
    } else if (p.getObject().isVariable() && p.getObject().getVarName().equals(varName)) {
      mappedName = p.getObject().mappedName();
    } else {
      throw new QueryException("Variable " + varName + " in filter Cannot be found in graph query");
    }

    if (!valueBindings.containsKey(mappedName)) {
      valueBindings.put(mappedName, new HashSet<String>());
    }

    if (f.getNode().isVariable() && f.getNode().getVarName().equals(varName)) {
      if (f.getConstraint().isVariable()) {
        /* XXX It's probably not legal to be here.. */
        LOG.warn("Node filter constraint is variable?  " + "It's probably not legal to be here...");
      } else {
        valueBindings
            .get(mappedName)
            .add(
                mappedName
                    + " "
                    + f.getOperator()
                    + " "
                    + DBUtil.quotedString(f.getConstraint().getNode().toString(), backslashEscape));
        LOG.debug(
            "Remaining Filters: "
                + mappedName
                + " "
                + f.getOperator()
                + " '"
                + f.getConstraint().getNode()
                + "'"
                + "\n");
      }
    } else if (f.getConstraint().isVariable() && f.getConstraint().getVarName().equals(varName)) {
      if (f.getNode().isVariable()) {
        /* XXX: it's probably not legal to be here.. */
        LOG.warn(
            "Node filter constraint is variable and node is "
                + "variable?  It's probably not legal to be here...");
      } else {
        valueBindings
            .get(mappedName)
            .add(
                DBUtil.quotedString(f.getNode().getNode().toString(), backslashEscape)
                    + " "
                    + f.getOperator()
                    + " "
                    + mappedName);
        LOG.debug(
            "Remaining Filters: "
                + "'"
                + f.getNode().getNode()
                + "' "
                + f.getOperator()
                + " "
                + mappedName
                + "\n");
      }
    }
  }