Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


        throws RepositoryException, MalformedQueryException, QueryEvaluationException
    {
        String query = "SELECT * FROM {x} p {y}";
        TupleQuery tq = repositoryConnection.prepareTupleQuery( QueryLanguage.SERQL, query );
        tq.setBinding( "x", classifierUri );
        TupleQueryResult result = tq.evaluate();

        while ( result.hasNext() )
        {
            BindingSet set = result.next();
            for ( Iterator<Binding> i = set.iterator(); i.hasNext(); )
            {
                Binding binding = i.next();
                if ( binding.getValue().toString().startsWith( "http://maven.apache.org/artifact/requirement" ) )
                {
View Full Code Here


                                           Value dependencyUri )
        throws RepositoryException, MalformedQueryException, QueryEvaluationException
    {
        TupleQuery tq = repositoryConnection.prepareTupleQuery( QueryLanguage.SERQL, dependencyQuery );
        tq.setBinding( "x", dependencyUri );
        TupleQueryResult dependencyResult = tq.evaluate();
        try
        {
            while ( dependencyResult.hasNext() )
            {
                ProjectDependency projectDependency = new ProjectDependency();
                BindingSet bs = dependencyResult.next();
                projectDependency.setGroupId( bs.getBinding( ProjectUri.GROUP_ID.getObjectBinding() ).getValue().toString() );
                projectDependency.setArtifactId( bs.getBinding( ProjectUri.ARTIFACT_ID.getObjectBinding() ).getValue().toString() );
                projectDependency.setVersion( bs.getBinding( ProjectUri.VERSION.getObjectBinding() ).getValue().toString() );
                projectDependency.setArtifactType( bs.getBinding( ProjectUri.ARTIFACT_TYPE.getObjectBinding() ).getValue().toString() );

                Binding classifierBinding = bs.getBinding( ProjectUri.CLASSIFIER.getObjectBinding() );
                if ( classifierBinding != null )
                {
                    projectDependency.setPublicKeyTokenId( classifierBinding.getValue().toString().replace( ":", "" ) );
                }

                project.addProjectDependency( projectDependency );
                if ( bs.hasBinding( ProjectUri.DEPENDENCY.getObjectBinding() ) )
                {
                    addDependenciesToProject( projectDependency, repositoryConnection,
                                              bs.getValue( ProjectUri.DEPENDENCY.getObjectBinding() ) );
                }
            }
        }
        finally
        {
            dependencyResult.close();
        }
    }
View Full Code Here

              SailRepositoryConnection connection = (SailRepositoryConnection)
                  database.getRepository().getConnection();
             
              try {
                  TupleQuery query = _builder.makeTupleQuery(_itemVar, connection);
                  TupleQueryResult queryResult = query.evaluate();
                  try {
                      while (queryResult.hasNext()) {
                          BindingSet bindingSet = queryResult.next();
                          Value v = bindingSet.getValue(_itemVar.getName());
                          if (v instanceof URI) {
                              if (count < 20) {
                                String itemID = database.getItemId((URI) v);
                                  itemIDs.add(itemID);
                                  lenses.add(_context.generateLens(itemID));
                              }
                              count++;
                          }
                      }
                  } finally {
                      queryResult.close();
                  }
              } finally {
                  connection.close();
              }
          } catch (Exception e) {
View Full Code Here

                "GROUP BY ?c1 ?p ?c2";

        System.out.println(queryString);

        TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
        TupleQueryResult result = tupleQuery.evaluate();
        try {
          while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            Value valueOfC1 = bindingSet.getValue("c1");
            Value valueOfP = bindingSet.getValue("p");
            Value valueOfC2 = bindingSet.getValue("c2");
            Value valueOfCount = bindingSet.getValue("count");

            if (valueOfC1 != null) {
              System.out.print(valueOfC1.stringValue() + "\t");
              resultFile.print(valueOfC1.stringValue() + ",");
            }
            if (valueOfP != null) {
              System.out.println(valueOfP.stringValue() + "\t");
              resultFile.print(valueOfP.stringValue() + ",");
            }
            if (valueOfC2 != null) {
              System.out.println(valueOfC2.stringValue() + "\t");
              resultFile.print(valueOfC2.stringValue() + ",");
            }
            if (valueOfCount != null) {
              System.out.println(valueOfCount.stringValue() + "\t");
              resultFile.print(valueOfCount.stringValue());
            }
            System.out.println();
            resultFile.print("\n");
         
        } finally {
          long responseTime = System.currentTimeMillis() - start;
          logger.info("response time: " + (responseTime/1000F));
          result.close();
        }

      } catch (MalformedQueryException e) {
        e.printStackTrace();
      } catch (QueryEvaluationException e1) {
View Full Code Here

                "GROUP BY ?c ?p";

        System.out.println(queryString);

        TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
        TupleQueryResult result = tupleQuery.evaluate();
        try {
          while (result.hasNext()) {
            BindingSet bindingSet = result.next();
            Value valueOfC = bindingSet.getValue("c");
            Value valueOfP = bindingSet.getValue("p");
            Value valueOfCount = bindingSet.getValue("count");

            if (valueOfC != null) {
              System.out.print(valueOfC.stringValue() + "\t");
              resultFile.print(valueOfC.stringValue() + ",");
            }
            if (valueOfP != null) {
              System.out.println(valueOfP.stringValue() + "\t");
              resultFile.print(valueOfP.stringValue() + ",");
            }
            if (valueOfCount != null) {
              System.out.println(valueOfCount.stringValue() + "\t");
              resultFile.print(valueOfCount.stringValue());
            }
            System.out.println();
            resultFile.print("\n");
         
        } finally {
          long responseTime = System.currentTimeMillis() - start;
          logger.info("response time: " + (responseTime/1000F));
          result.close();
        }

      } catch (MalformedQueryException e) {
        e.printStackTrace();
      } catch (QueryEvaluationException e1) {
View Full Code Here

    boolean r = false;
   
        try {
      ExpressionQueryResult eqr = _conditionExpression.computeOutputOnValue(value, database, connection);
          if (eqr != null) {
                TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                try {
          if ("if-exists".equals(_conditionTest)) {
            r = queryResult.hasNext();
          } else if ("if".equals(_conditionTest)) {
            if (queryResult.hasNext()) {
              BindingSet bindingSet = queryResult.next();
              Value value2 = bindingSet.getValue(eqr.resultVar.getName());
              if (value2 instanceof Literal) {
                r = ((Literal) value2).booleanValue();
              }
            }
          }
                } finally {
                    queryResult.close();
                }
          } else {
        if (value instanceof Literal) {
          r = ((Literal) value).booleanValue();
        }
View Full Code Here

    ScriptableArrayBuilder arrayBuilder = new ScriptableArrayBuilder();
   
        try {
      ExpressionQueryResult eqr = _contentExpression.computeOutputOnValue(value, database, connection);
          if (eqr != null) {
                TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                try {
                  while (queryResult.hasNext()) {
                    BindingSet bindingSet = queryResult.next();
                    Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                   
                    arrayBuilder.add(generateInnerContentWithInnerTemplates(value2, database, connection));
                  }
                } finally {
                    queryResult.close();
                }
          } else {
            arrayBuilder.add(generateInnerContentWithInnerTemplates(value, database, connection));
          }
    } catch (Exception e) {
View Full Code Here

    String valueType = "text";
   
        try {
      ExpressionQueryResult eqr = _contentExpression.computeOutputOnValue(value, database, connection);
          if (eqr != null) {
                TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                try {
                  while (queryResult.hasNext()) {
                    BindingSet bindingSet = queryResult.next();
                    Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                   
                     arrayBuilder.add(renderInnerValue(value2, database, connection));
                  }
                } finally {
                    queryResult.close();
                }
          }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

                  Order order = "value".equals(_sortMode) ?
                      new Order(projection, new OrderElem(_valueVar, "forward".equals(_sortDirection))) :
                      new Order(projection, new OrderElem(_countVar, !"forward".equals(_sortDirection)));
                 
                  TupleQuery query = new MyTupleQuery(new ParsedTupleQuery(order), connection);
                  TupleQueryResult queryResult = query.evaluate();
                  try {
                    return createComponentState(queryResult);
                  } finally {
                      queryResult.close();
                  }
              } finally {
                  connection.close();
              }
          } catch (Exception e) {
View Full Code Here

            boolean first = true;
            StringBuffer sb = new StringBuffer();
           
        ExpressionQueryResult eqr = a.expression.computeOutputOnValue(value, database, connection);
            if (eqr != null) {
                  TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                  try {
                    while (queryResult.hasNext()) {
                      BindingSet bindingSet = queryResult.next();
                      Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                     
                      if (first) {
                        first = false;
                      } else {
                        sb.append(";");
                      }
                     
                      sb.append(renderInnerValueToText(value2, database, connection));
                    }
                  } finally {
                      queryResult.close();
                  }
            }
           
            o.put("value", o, sb.toString());
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.openrdf.query.TupleQueryResult

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.