Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


         try
         {
           BindingSet bindingSet;

           TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, String.format(SELECT_CodeList_TEMPLATE,codeList));
           TupleQueryResult result = tupleQuery.evaluate();
              
           if(result.hasNext())
             {                
               bindingSet = result.next();
               codeListURI = bindingSet.getValue("sub").toString();
               codeListURI = codeListURI.substring(codeListURI.indexOf("#")+1);
              
             }
              
             result.close();              
         }
         finally {
           con.close();
         }
      }
View Full Code Here


            }
          }else{
            //return values without metadata
            RepositoryConnection connection = dataRepo.getConnection();
            TupleQuery compiledQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
            TupleQueryResult results = compiledQuery.evaluate()
           
         
            BindingSet set;
            Resource r;
            String variable = results.getBindingNames().get(0);
            while (results.hasNext()){
              //resources ++;
              set = results.next();
              r = (Resource) set.getValue(variable);
              // Don't render resource twice
              if (resSet.containsKey(r))
                continue;
              resSet.put(r, null);
View Full Code Here

         
          String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT * WHERE {<"+r+"> rdf:type ?o }";
 
          TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
 
          TupleQueryResult result = tupleQuery.evaluate();
          try {
            String firstBindingName = result.getBindingNames().get(0);
            while (result.hasNext()) {
              Value uri = result.next().getBinding(firstBindingName).getValue();
              if (uri instanceof URI) {
                list.add(uri.toString());
              }
            }
          } finally {
            result.close();
          }
        } catch (QueryEvaluationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MalformedQueryException e) {
View Full Code Here

        try {
          String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?o WHERE { ?s rdf:type ?o } ORDER BY ?o";
 
          TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
 
          TupleQueryResult result = tupleQuery.evaluate();
          try {
            String firstBindingName = result.getBindingNames().get(0);
            while (result.hasNext()) {
              Value uri = result.next().getBinding(firstBindingName).getValue();
              if ((uri instanceof URI) &&
                (!uri.toString().contains("http://www.w3.org/2004/03/trix"))){
             
                String uriString = uri.toString();               
                String classInfo = getClassInfo(uriString, location);
                String before = "";
                String after = "";
 
                /*
                if (uriString == resource) {
                  before = "<b>";
                  after = "</b>";
                }*/
 
                if (uriString.lastIndexOf("#") == -1) {
                  out = out.concat("<li><a onClick='setHrefs()' class='tooltip' title='::" + uriString + "' href='?class="
                      + URLEncoder.encode(uriString, "UTF-8") + dataLocation + dataMeta +"'>" + before
                      + uriString.subSequence(uriString.lastIndexOf("/") + 1, uriString.length()) + " " + classInfo + after + "</a></li>");
                } else {
                  out = out.concat("<li><a onClick='setHrefs()' class='tooltip' title='::" + uriString + "' href='?class="
                      + URLEncoder.encode(uriString, "UTF-8") + dataLocation + dataMeta +"'>" + before
                      + uriString.subSequence(uriString.lastIndexOf("#") + 1, uriString.length()) + " " + classInfo + after + "</a></li>");
                }
              }
            }
          } finally {
            result.close();
          }
        } catch (QueryEvaluationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MalformedQueryException e) {
View Full Code Here

    try {

      String query = "prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s WHERE { ?s rdf:type <" + uri + "> }";

      TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
      TupleQueryResult result = tupleQuery.evaluate();

      try {

        String firstBindingName = result.getBindingNames().get(0);
        while (result.hasNext()) {
         
          Value instance = result.next().getBinding(firstBindingName).getValue();
          //if (instance instanceof Resource) {           
            //if (isLensForResourceAvailable(((Resource) instance).stringValue(),location)) {
              //isLensAvailable = true;
            //}           
          //}
          i++;
        }
      } finally {
        result.close();
      }
    } finally {
      con.close();
    }
    int numberOfResources = 0;
View Full Code Here

        if(parsedQuery == null){
            throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
        }
        final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
        RepositoryConnection con = null;
        TupleQueryResult results = null;
        try {
            con = repository.getConnection();
            con.begin();
            //execute the query
            int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(),
                getConfig().getMaxQueryResultNumber());
            results = executeSparqlFieldQuery(con, query, limit, false);
            //parse the results
            List<String> ids = limit > 0 ? new ArrayList<String>(limit) : new ArrayList<String>();
            while(results.hasNext()){
                BindingSet result = results.next();
                Value value = result.getValue(query.getRootVariableName());
                if(value instanceof Resource){
                    ids.add(value.stringValue());
                }
            }
            con.commit();
            return new QueryResultListImpl<String>(query,ids,String.class);
        } catch (RepositoryException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } catch (QueryEvaluationException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } finally {
            if(results != null) { //close the result if present
                try {
                    results.close();
                } catch (QueryEvaluationException ignore) {/* ignore */}
            }
            if(con != null){
                try {
                    con.close();
View Full Code Here

        if(parsedQuery == null){
            throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
        }
        final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
        RepositoryConnection con = null;
        TupleQueryResult results = null;
        try {
            con = repository.getConnection();
            con.begin();
            //execute the query
            int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(),
                getConfig().getMaxQueryResultNumber());
            results = executeSparqlFieldQuery(con,query, limit, false);
            //parse the results and generate the Representations
            //create an own valueFactors so that all the data of the query results
            //are added to the same Sesame Model
            Model model = new TreeModel();
            RdfValueFactory valueFactory = new RdfValueFactory(model, sesameFactory);
            List<Representation> representations = limit > 0 ?
                    new ArrayList<Representation>(limit) : new ArrayList<Representation>();
            while(results.hasNext()){
                BindingSet result = results.next();
                Value value = result.getValue(query.getRootVariableName());
                if(value instanceof URI){
                    //copy all data to the model and create the representation
                    RdfRepresentation rep = createRepresentationGraph(con, valueFactory, (URI)value);
                    model.add(queryRoot, queryResult, value); //link the result with the query result
                    representations.add(rep);
                } //ignore non URI results
            }
            con.commit();
            return new SesameQueryResultList(model, query, representations);
        } catch (RepositoryException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } catch (QueryEvaluationException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } finally {
            if(results != null) { //close the result if present
                try {
                    results.close();
                } catch (QueryEvaluationException ignore) {/* ignore */}
            }
            if(con != null){
                try {
                    con.close();
View Full Code Here

        if(parsedQuery == null){
            throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
        }
        final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
        RepositoryConnection con = null;
        TupleQueryResult results = null;
        try {
            con = repository.getConnection();
            con.begin();
            //execute the query
            int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(),
                getConfig().getMaxQueryResultNumber());
            results = executeSparqlFieldQuery(con,query, limit, true);
            //parse the results and generate the Representations
            //create an own valueFactors so that all the data of the query results
            //are added to the same Sesame Model
            Model model = new TreeModel();
            RdfValueFactory valueFactory = new RdfValueFactory(model, sesameFactory);
            List<Representation> representations = limit > 0 ? new ArrayList<Representation>(limit)
                    : new ArrayList<Representation>();
            Map<String,URI> bindings = new HashMap<String,URI>(query.getFieldVariableMappings().size());
            for(Entry<String,String> mapping : query.getFieldVariableMappings().entrySet()){
                bindings.put(mapping.getValue(), sesameFactory.createURI(mapping.getKey()));
            }
            while(results.hasNext()){
                BindingSet result = results.next();
                Value value = result.getValue(query.getRootVariableName());
                if(value instanceof URI){
                    URI subject = (URI) value;
                    //link the result with the query result
                    model.add(queryRoot, queryResult, subject);
                    //now copy over the other selected data
                    for(String binding : result.getBindingNames()){
                        URI property = bindings.get(binding);
                        if(property != null){
                            model.add(subject, property, result.getValue(binding));
                        } //else no mapping for the query.getRootVariableName()
                    }
                    //create a representation and add it to the results
                    representations.add(valueFactory.createRdfRepresentation(subject));
                } //ignore non URI results
            }
            con.commit();
            return new SesameQueryResultList(model, query, representations);
        } catch (RepositoryException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } catch (QueryEvaluationException e) {
            throw new YardException("Unable to execute findReferences query", e);
        } finally {
            if(results != null) { //close the result if present
                try {
                    results.close();
                } catch (QueryEvaluationException ignore) {/* ignore */}
            }
            if(con != null){
                try {
                    con.close();
View Full Code Here

    }

    public Set<Project> getAllProjects()
            throws ProjectDaoException {
        Set<Project> projects = new HashSet<Project>();
        TupleQueryResult result = null;
        try
        {
            TupleQuery tupleQuery = repositoryConnection.prepareTupleQuery( QueryLanguage.SERQL, projectQuery );
            result = tupleQuery.evaluate();
            while ( result.hasNext() )
            {
                BindingSet set = result.next();

                String groupId = set.getBinding( ProjectUri.GROUP_ID.getObjectBinding() ).getValue().toString();
                String version = set.getBinding( ProjectUri.VERSION.getObjectBinding() ).getValue().toString();
                String artifactId = set.getBinding( ProjectUri.ARTIFACT_ID.getObjectBinding() ).getValue().toString();
                String artifactType =
                    set.getBinding( ProjectUri.ARTIFACT_TYPE.getObjectBinding() ).getValue().toString();
                String classifier = null;
                if ( set.hasBinding( ProjectUri.CLASSIFIER.getObjectBinding() ) )
                {
                    classifier = set.getBinding( ProjectUri.CLASSIFIER.getObjectBinding() ).getValue().toString();
                }

                // Project project = getProjectFor( groupId, artifactId, version, artifactType, null );
                /*
                 * for ( Iterator<Binding> i = set.iterator(); i.hasNext(); ) { Binding b = i.next();
                 * System.out.println( b.getName() + ":" + b.getValue() ); }
                 */
                projects.add( getProjectFor( groupId, artifactId, version, artifactType, classifier ) );
            }
        }
        catch ( RepositoryException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-000: Message = " + e.getMessage(), e );
        }
        catch ( MalformedQueryException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-001: Message = " + e.getMessage(), e );
        }
        catch ( QueryEvaluationException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-002: Message = " + e.getMessage(), e );
        }
        finally
        {
            if ( result != null )
            {
                try
                {
                    result.close();
                }
                catch ( QueryEvaluationException e )
                {

                }
View Full Code Here

        project.setGroupId( groupId );
        project.setVersion( version );
        project.setArtifactType( artifactType );
        project.setPublicKeyTokenId( publicKeyTokenId );

        TupleQueryResult result = null;

        try
        {
            TupleQuery tupleQuery = repositoryConnection.prepareTupleQuery( QueryLanguage.SERQL, projectQuery );
            tupleQuery.setBinding( ProjectUri.GROUP_ID.getObjectBinding(), valueFactory.createLiteral( groupId ) );
            tupleQuery.setBinding( ProjectUri.ARTIFACT_ID.getObjectBinding(), valueFactory.createLiteral( artifactId ) );
            tupleQuery.setBinding( ProjectUri.VERSION.getObjectBinding(), valueFactory.createLiteral( version ) );
            tupleQuery.setBinding( ProjectUri.ARTIFACT_TYPE.getObjectBinding(),
                                   valueFactory.createLiteral( artifactType ) );

            if ( publicKeyTokenId != null )
            {
                tupleQuery.setBinding( ProjectUri.CLASSIFIER.getObjectBinding(),
                                       valueFactory.createLiteral( publicKeyTokenId ) );
                project.setPublicKeyTokenId( publicKeyTokenId.replace( ":", "" ) );
            }

            result = tupleQuery.evaluate();

            if ( !result.hasNext() )
            {
               
                //if ( artifactType != null && ArtifactTypeHelper.isDotnetAnyGac( artifactType ) )
                if ( artifactType != null )
                {
                   
                    Artifact artifact = createArtifactFrom( project, artifactFactory );
                   
                    if ( !artifact.getFile().exists() )
                    {
                        throw new ProjectDaoException( "NPANDAY-180-123: Could not find GAC assembly: Group ID = " + groupId
                            + ", Artifact ID = " + artifactId + ", Version = " + version + ", Artifact Type = "
                            + artifactType + ", File Path = " + artifact.getFile().getAbsolutePath() );
                    }
                    project.setResolved( true );
                    return project;
                }

                throw new ProjectDaoException( "NPANDAY-180-124: Could not find the project: Group ID = " + groupId
                    + ", Artifact ID =  " + artifactId + ", Version = " + version + ", Artifact Type = " + artifactType );
            }

            while ( result.hasNext() )
            {
                BindingSet set = result.next();
                /*
                 * for ( Iterator<Binding> i = set.iterator(); i.hasNext(); ) { Binding b = i.next();
                 * System.out.println( b.getName() + ":" + b.getValue() ); }
                 */
                if ( set.hasBinding( ProjectUri.IS_RESOLVED.getObjectBinding() )
                    && set.getBinding( ProjectUri.IS_RESOLVED.getObjectBinding() ).getValue().toString().equalsIgnoreCase(
                                                                                                                           "true" ) )
                {
                    project.setResolved( true );
                }

                project.setArtifactType( set.getBinding( ProjectUri.ARTIFACT_TYPE.getObjectBinding() ).getValue().toString() );
                /*
                 * if ( set.hasBinding( ProjectUri.PARENT.getObjectBinding() ) ) { String pid = set.getBinding(
                 * ProjectUri.PARENT.getObjectBinding() ).getValue().toString(); String[] tokens = pid.split( "[:]" );
                 * Project parentProject = getProjectFor( tokens[0], tokens[1], tokens[2], null, null );
                 * project.setParentProject( parentProject ); }
                 */
                if ( set.hasBinding( ProjectUri.DEPENDENCY.getObjectBinding() ) )
                {
                    Binding binding = set.getBinding( ProjectUri.DEPENDENCY.getObjectBinding() );
                    addDependenciesToProject( project, repositoryConnection, binding.getValue() );
                }

                if ( set.hasBinding( ProjectUri.CLASSIFIER.getObjectBinding() ) )
                {
                    Binding binding = set.getBinding( ProjectUri.CLASSIFIER.getObjectBinding() );
                    addClassifiersToProject( project, repositoryConnection, binding.getValue() );
                }
            }
        }
        catch ( QueryEvaluationException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-005: Message = " + e.getMessage(), e );
        }
        catch ( RepositoryException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-006: Message = " + e.getMessage(), e );
        }
        catch ( MalformedQueryException e )
        {
            throw new ProjectDaoException( "NPANDAY-180-007: Message = " + e.getMessage(), e );
        }
        finally
        {
            if ( result != null )
            {
                try
                {
                    result.close();
                }
                catch ( QueryEvaluationException 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.