Package org.openrdf.query.impl

Examples of org.openrdf.query.impl.DatasetImpl


// build a dataset, if specified
        String[] defaultGraphURIs = form.getValuesArray( DEFAULT_GRAPH_PARAM_NAME );
        String[] namedGraphURIs = form.getValuesArray( NAMED_GRAPH_PARAM_NAME );

        DatasetImpl dataset = null;
        if( defaultGraphURIs.length > 0 || namedGraphURIs.length > 0 )
        {
            dataset = new DatasetImpl();

            if( defaultGraphURIs.length > 0 )
            {
                for( String defaultGraphURI : defaultGraphURIs )
                {
                    try
                    {
                        URI uri = repository.getValueFactory().createURI( defaultGraphURI );
                        dataset.addDefaultGraph( uri );
                    }
                    catch( IllegalArgumentException e )
                    {
                        throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Illegal URI for default graph: "
                                                                                      + defaultGraphURI );
                    }
                }
            }

            if( namedGraphURIs.length > 0 )
            {
                for( String namedGraphURI : namedGraphURIs )
                {
                    try
                    {
                        URI uri = repository.getValueFactory().createURI( namedGraphURI );
                        dataset.addNamedGraph( uri );
                    }
                    catch( IllegalArgumentException e )
                    {
                        throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Illegal URI for named graph: "
                                                                                      + namedGraphURI );
View Full Code Here


   *         If DatasetClause does not contain a valid URI.
   */
  public static Dataset process(ASTQueryContainer qc)
    throws MalformedQueryException
  {
    DatasetImpl dataset = null;

    List<ASTDatasetClause> datasetClauses = qc.getQuery().getDatasetClauseList();

    if (!datasetClauses.isEmpty()) {
      dataset = new DatasetImpl();

      for (ASTDatasetClause dc : datasetClauses) {
        ASTIRI astIri = dc.jjtGetChild(ASTIRI.class);

        try {
          URI uri = new URIImpl(astIri.getValue());
          if (dc.isNamed()) {
            dataset.addNamedGraph(uri);
          }
          else {
            dataset.addDefaultGraph(uri);
          }
        }
        catch (IllegalArgumentException e) {
          throw new MalformedQueryException(e.getMessage(), e);
        }
View Full Code Here

    // build a dataset, if specified
    String[] defaultGraphURIs = request.getParameterValues(DEFAULT_GRAPH_PARAM_NAME);
    String[] namedGraphURIs = request.getParameterValues(NAMED_GRAPH_PARAM_NAME);

    DatasetImpl dataset = null;
    if (defaultGraphURIs != null || namedGraphURIs != null) {
      dataset = new DatasetImpl();

      if (defaultGraphURIs != null) {
        for (String defaultGraphURI : defaultGraphURIs) {
          try {
            URI uri = repository.getValueFactory().createURI(defaultGraphURI);
            dataset.addDefaultGraph(uri);
          }
          catch (IllegalArgumentException e) {
            throw new ClientHTTPException(SC_BAD_REQUEST, "Illegal URI for default graph: "
                + defaultGraphURI);
          }
        }
      }

      if (namedGraphURIs != null) {
        for (String namedGraphURI : namedGraphURIs) {
          try {
            URI uri = repository.getValueFactory().createURI(namedGraphURI);
            dataset.addNamedGraph(uri);
          }
          catch (IllegalArgumentException e) {
            throw new ClientHTTPException(SC_BAD_REQUEST, "Illegal URI for named graph: "
                + namedGraphURI);
          }
View Full Code Here

    BooleanQuery query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    assertTrue(query.evaluate());

    DatasetImpl dataset = new DatasetImpl();

    // default graph: {context1}
    dataset.addDefaultGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.evaluate());

    // default graph: {context1, context2}
    dataset.addDefaultGraph(context2);
    query.setDataset(dataset);
    assertTrue(query.evaluate());

    // default graph: {context2}
    dataset.removeDefaultGraph(context1);
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    queryBuilder.setLength(0);
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ GRAPH ?g { ?p foaf:name ?name } }");

    query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    // default graph: {context2}; named graph: {}
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    // default graph: {context1, context2}; named graph: {context2}
    dataset.addDefaultGraph(context1);
    dataset.addNamedGraph(context2);
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    // default graph: {context1, context2}; named graph: {context1, context2}
    dataset.addNamedGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.evaluate());
  }
View Full Code Here

      // Query named graphs
      namedGraphsQuery.setBinding("action", action);
      TupleQueryResult namedGraphs = namedGraphsQuery.evaluate();

      DatasetImpl dataset = null;

      if (defaultGraphURI != null || namedGraphs.hasNext()) {
        dataset = new DatasetImpl();

        if (defaultGraphURI != null) {
          dataset.addDefaultGraph(defaultGraphURI);
        }

        while (namedGraphs.hasNext()) {
          BindingSet graphBindings = namedGraphs.next();
          URI namedGraphURI = (URI)graphBindings.getValue("graph");
          dataset.addNamedGraph(namedGraphURI);
        }
      }

      suite.addTest(factory.createSPARQLQueryTest(testURI, testName, queryFile, resultFile, dataset));
    }
View Full Code Here

            Update query1 = con1.prepareUpdate(QueryLanguage.SPARQL, queryString);
            // workaround for a Sesame bug: we explicitly set the context for the query in the dataset

            URI context = new URIImpl("http://localhost/mycontext");
            DatasetImpl ds = new DatasetImpl();
            //ds.addDefaultGraph(context);
            //ds.addNamedGraph(context);
            //ds.addDefaultRemoveGraph(context);
            ds.setDefaultInsertGraph(context);
            query1.setDataset(ds);

            query1.execute();

            con1.commit();
View Full Code Here

            String queryStr1 = "SELECT * WHERE { GRAPH <"+context1.stringValue()+"> { ?X ?P ?Y } }";

            TupleQuery query1 = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStr1);

            // workaround for a bug in sesame
            DatasetImpl ds = new DatasetImpl();
            ds.addDefaultGraph(context1);
            ds.addNamedGraph(context1);
            ds.addDefaultRemoveGraph(context1);
            ds.setDefaultInsertGraph(context1);
            query1.setDataset(ds);


            List<BindingSet> result1 = Iterations.asList(query1.evaluate());
            Assert.assertEquals(2, result1.size());
View Full Code Here

TOP

Related Classes of org.openrdf.query.impl.DatasetImpl

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.