From: <tho...@us...> - 2011-04-15 17:00:30
|
Revision: 4405 http://bigdata.svn.sourceforge.net/bigdata/?rev=4405&view=rev Author: thompsonbry Date: 2011-04-15 17:00:24 +0000 (Fri, 15 Apr 2011) Log Message: ----------- Added support for the 'default-graph-uri' and 'named-graph-uri' protocol parameters for SPARQL queries. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServer.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java 2011-04-15 16:26:21 UTC (rev 4404) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java 2011-04-15 17:00:24 UTC (rev 4405) @@ -20,8 +20,12 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.Dataset; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryLanguage; +import org.openrdf.query.impl.AbstractQuery; +import org.openrdf.query.impl.DatasetImpl; import org.openrdf.query.parser.ParsedQuery; import org.openrdf.query.parser.QueryParser; import org.openrdf.query.parser.sparql.SPARQLParserFactory; @@ -268,15 +272,17 @@ protected final String fileExt; /** The request. */ - private final HttpServletRequest req; + protected final HttpServletRequest req; /** Where to write the response. */ - private final OutputStream os; + protected final OutputStream os; /** * Sesame has an option for a base URI during query evaluation. This * provides a symbolic place holder for that URI in case we ever provide * a hook to set it. + * + * FIXME This should be the service end point URI. */ protected final String baseURI = null; @@ -359,6 +365,42 @@ } /** + * If the {@link HttpServletRequest} included one or more + * <code>default-graph-uri</code>s and/or or a + * <code>named-graph-uri</code>s then the {@link Dataset} for the query + * is replaced by the {@link Dataset} constructed from those protocol + * parameters. + * + * @param query + * The query. + */ + protected void overrideDataset(final AbstractQuery query) { + + final String[] defaultGraphURIs = req + .getParameterValues("default-graph-uri"); + + final String[] namedGraphURIs = req + .getParameterValues("named-graph-uri"); + + if (defaultGraphURIs != null || namedGraphURIs != null) { + + final DatasetImpl dataset = new DatasetImpl(); + + if (defaultGraphURIs != null) + for (String graphURI : defaultGraphURIs) + dataset.addDefaultGraph(new URIImpl(graphURI)); + + if (namedGraphURIs != null) + for (String graphURI : namedGraphURIs) + dataset.addNamedGraph(new URIImpl(graphURI)); + + query.setDataset(dataset); + + } + + } + + /** * Execute the query. * * @param cxn @@ -443,6 +485,9 @@ final BigdataSailBooleanQuery query = cxn.prepareBooleanQuery( QueryLanguage.SPARQL, queryStr, baseURI); + // Override query if data set protocol parameters were used. + overrideDataset(query); + // Note: getQueryTask() verifies that format will be non-null. final BooleanQueryResultFormat format = BooleanQueryResultWriterRegistry .getInstance().getFileFormatForMIMEType(mimeType); @@ -481,6 +526,9 @@ final BigdataSailTupleQuery query = cxn.prepareTupleQuery( QueryLanguage.SPARQL, queryStr, baseURI); + // Override query if data set protocol parameters were used. + overrideDataset(query); + // Note: getQueryTask() verifies that format will be non-null. final TupleQueryResultFormat format = TupleQueryResultWriterRegistry .getInstance().getFileFormatForMIMEType(mimeType); @@ -518,6 +566,9 @@ final BigdataSailGraphQuery query = cxn.prepareGraphQuery( QueryLanguage.SPARQL, queryStr, baseURI); + // Override query if data set protocol parameters were used. + overrideDataset(query); + /* * FIXME An error thrown here (such as if format is null and we do * not check it) will cause the response to hang, at least for the Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServer.java 2011-04-15 16:26:21 UTC (rev 4404) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServer.java 2011-04-15 17:00:24 UTC (rev 4405) @@ -74,8 +74,16 @@ * Test suite for {@link RESTServlet} (SPARQL end point and REST API for RDF * data). * - * @todo Test default-graph-uri(s) and named-graph-uri(s). + * @todo Test default-graph-uri(s) and named-graph-uri(s). [To test this, it + * might help to refactor into unit tests for QUERY, INSERT, DELETE, and + * UPDATE and unit tests for TRIPLES (w/ and w/o inferences), SIDS, and + * QUADS] * + * @todo How is the REST API supposed to handle INSERT w/ body and DELETE w/ + * body against a quad store? + * + * @todo Security model? + * * @todo An NQUADS RDFWriter needs to be written. Then we can test NQUADS * interchange. * @@ -120,15 +128,6 @@ new LocalTripleStore(m_jnl, namespace, ITx.UNISOLATED, properties) .create(); - // /* - // * Service will not hold a read lock. - // * - // * Queries will read from the last commit point by default and will - // use - // * a read-only tx to have snapshot isolation for that query. - // */ - // config.timestamp = ITx.READ_COMMITTED; - final Map<String, String> initParams = new LinkedHashMap<String, String>(); { @@ -248,18 +247,22 @@ */ private static class QueryOptions { - /** The URL of the SPARQL endpoint. */ + /** The URL of the SPARQL end point. */ public String serviceURL = null; + /** The HTTP method (GET, POST, etc). */ public String method = "GET"; - /** + + /** * The SPARQL query (this is a short hand for setting the * <code>query</code> URL query parameter). */ public String queryStr = null; + /** Request parameters to be formatted as URL query parameters. */ public Map<String,String[]> requestParams; - /** The accept header. */ + + /** The accept header. */ public String acceptHeader = // BigdataRDFServlet.MIME_SPARQL_RESULTS_XML + ";q=1" + // "," + // @@ -574,7 +577,8 @@ * Class representing the result of a mutation operation against the REST * API. * - * TODO Refactor into the non-test code base? + * TODO Refactor into the non-test code base along with the XML generation + * and XML parsing? */ private static class MutationResult { @@ -651,10 +655,9 @@ */ public void test_STATUS() throws Exception { - final HttpURLConnection conn = doConnect(m_serviceURL + "/status", "GET"); + final HttpURLConnection conn = doConnect(m_serviceURL + "/status", + "GET"); - // No solutions (assuming a told triple kb or quads kb w/o axioms). - // connect. conn.connect(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |