From: <tho...@us...> - 2011-06-20 14:06:22
|
Revision: 4740 http://bigdata.svn.sourceforge.net/bigdata/?rev=4740&view=rev Author: thompsonbry Date: 2011-06-20 14:06:10 +0000 (Mon, 20 Jun 2011) Log Message: ----------- Moved the QueryType class into com.bigdata.rdf.sail. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlClient.java 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/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBOps.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryType.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryType.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryType.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -2913,6 +2913,14 @@ } + public CloseableIteration<? extends Statement, SailException> getStatements( + final Resource s, final URI p, final Value o, + final Resource context) + throws SailException { + return getStatements(s,p,o,true/*includeInferred*/,context==null? + new Resource[]{}:new Resource[]{context}); + } + /** * Note: if the context is <code>null</code>, then you will see data * from each context in a quad store, including anything in the Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -49,7 +49,7 @@ public class BigdataSailGraphQuery extends SailGraphQuery implements BigdataSailQuery { - protected static Logger log = Logger.getLogger(BigdataSailGraphQuery.class); + private static Logger log = Logger.getLogger(BigdataSailGraphQuery.class); /** * Query hints are embedded in query strings as namespaces. Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -19,8 +19,6 @@ import com.bigdata.rdf.changesets.IChangeLog; import com.bigdata.rdf.changesets.IChangeRecord; import com.bigdata.rdf.sail.BigdataSail.BigdataSailConnection; -import com.bigdata.rdf.sail.bench.NanoSparqlClient; -import com.bigdata.rdf.sail.bench.NanoSparqlClient.QueryType; import com.bigdata.rdf.store.AbstractTripleStore; /** @@ -81,7 +79,7 @@ baseURI); final boolean describe = ql == QueryLanguage.SPARQL - && NanoSparqlClient.QueryType.fromQuery(qs) == QueryType.DESCRIBE; + && QueryType.fromQuery(qs) == QueryType.DESCRIBE; return new BigdataSailGraphQuery(parsedQuery, this, queryHints, describe); @@ -157,7 +155,7 @@ } else if (parsedQuery instanceof ParsedGraphQuery) { final boolean describe = ql == QueryLanguage.SPARQL - && NanoSparqlClient.QueryType.fromQuery(qs) == QueryType.DESCRIBE; + && QueryType.fromQuery(qs) == QueryType.DESCRIBE; return new BigdataSailGraphQuery((ParsedGraphQuery) parsedQuery, this, queryHints, describe); Copied: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryType.java (from rev 4738, branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryType.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryType.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryType.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -0,0 +1,137 @@ +package com.bigdata.rdf.sail; + +import java.util.Arrays; + +/** + * Helper class to figure out the type of a query. + */ +public enum QueryType { + + ASK(0), DESCRIBE(1), CONSTRUCT(2), SELECT(3); + + private final int order; + + private QueryType(final int order) { + + this.order = order; + + } + + private static QueryType getQueryType(final int order) { + switch (order) { + case 0: + return ASK; + case 1: + return DESCRIBE; + case 2: + return CONSTRUCT; + case 3: + return SELECT; + default: + throw new IllegalArgumentException("order=" + order); + } + } + + /** + * Used to note the offset at which a keyword was found. + */ + static private class P implements Comparable<QueryType.P> { + + final int offset; + + final QueryType queryType; + + public P(final int offset, final QueryType queryType) { + this.offset = offset; + this.queryType = queryType; + } + + /** Sort into ascending offset. */ + public int compareTo(final QueryType.P o) { + + return offset - o.offset; + + } + + public int hashCode() { + + return offset; + + } + + public boolean equals(final Object o) { + + if (this == o) + return true; + + if (o instanceof P) { + + final P t = (P) o; + + return this.offset == t.offset && this.queryType == t.queryType; + + } + + return false; + + } + + public String toString() { + + return "{offset=" + offset + ",type=" + queryType + "}"; + + } + + } + + /** + * Hack returns the query type based on the first occurrence of the + * keyword for any known query type in the query. + * + * @param queryStr + * The query. + * + * @return The query type. + */ + static public QueryType fromQuery(final String queryStr) { + + // force all to lower case. + final String s = queryStr.toUpperCase(); + + final int ntypes = QueryType.values().length; + + final QueryType.P[] p = new QueryType.P[ntypes]; + + int nmatch = 0; + for (int i = 0; i < ntypes; i++) { + + final QueryType queryType = getQueryType(i); + + final int offset = s.indexOf(queryType.toString()); + + if (offset == -1) + continue; + + p[nmatch++] = new P(offset, queryType); + + } + + if (nmatch == 0) { + + throw new RuntimeException( + "Could not determine the query type: " + queryStr); + + } + + Arrays.sort(p, 0/* fromIndex */, nmatch/* toIndex */); + + final QueryType.P tmp = p[0]; + + // System.out.println("QueryType: offset=" + tmp.offset + ", type=" + // + tmp.queryType); + + return tmp.queryType; + + } + +} \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlClient.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlClient.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/bench/NanoSparqlClient.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -65,6 +65,7 @@ import com.bigdata.counters.CAT; import com.bigdata.jsr166.LinkedBlockingQueue; +import com.bigdata.rdf.sail.QueryType; /** * A flyweight utility for issuing queries to an http SPARQL endpoint. @@ -89,106 +90,106 @@ */ static private final int DEFAULT_TIMEOUT = 60*1000; - /** - * Helper class to figure out the type of a query. - */ - public static enum QueryType { - - ASK(0), - DESCRIBE(1), - CONSTRUCT(2), - SELECT(3); - - private final int order; - - private QueryType(final int order) { - this.order = order; - } - - private static QueryType getQueryType(final int order) { - switch (order) { - case 0: - return ASK; - case 1: - return DESCRIBE; - case 2: - return CONSTRUCT; - case 3: - return SELECT; - default: - throw new IllegalArgumentException("order=" + order); - } - } - - /** - * Used to note the offset at which a keyword was found. - */ - static private class P implements Comparable<P> { - - final int offset; - final QueryType queryType; - - public P(final int offset, final QueryType queryType) { - this.offset = offset; - this.queryType = queryType; - } - /** Sort into descending offset. */ - public int compareTo(final P o) { - return o.offset - offset; - } - } - - /** - * Hack returns the query type based on the first occurrence of the - * keyword for any known query type in the query. - * - * @param queryStr - * The query. - * - * @return The query type. - */ - static public QueryType fromQuery(final String queryStr) { - - // force all to lower case. - final String s = queryStr.toUpperCase(); - - final int ntypes = QueryType.values().length; - - final P[] p = new P[ntypes]; - - int nmatch = 0; - for (int i = 0; i < ntypes; i++) { - - final QueryType queryType = getQueryType(i); - - final int offset = s.indexOf(queryType.toString()); - - if (offset == -1) - continue; - - p[nmatch++] = new P(offset, queryType); - - } - - if (nmatch == 0) { - - throw new RuntimeException( - "Could not determine the query type: " + queryStr); - - } - - Arrays.sort(p, 0/* fromIndex */, nmatch/* toIndex */); - - final P tmp = p[0]; - -// System.out.println("QueryType: offset=" + tmp.offset + ", type=" -// + tmp.queryType); - - return tmp.queryType; - - } - - } +// /** +// * Helper class to figure out the type of a query. +// */ +// private static enum QueryType { +// +// ASK(0), +// DESCRIBE(1), +// CONSTRUCT(2), +// SELECT(3); +// +// private final int order; +// +// private QueryType(final int order) { +// this.order = order; +// } +// +// private static QueryType getQueryType(final int order) { +// switch (order) { +// case 0: +// return ASK; +// case 1: +// return DESCRIBE; +// case 2: +// return CONSTRUCT; +// case 3: +// return SELECT; +// default: +// throw new IllegalArgumentException("order=" + order); +// } +// } +// +// /** +// * Used to note the offset at which a keyword was found. +// */ +// static private class P implements Comparable<P> { +// +// final int offset; +// final QueryType queryType; +// +// public P(final int offset, final QueryType queryType) { +// this.offset = offset; +// this.queryType = queryType; +// } +// /** Sort into descending offset. */ +// public int compareTo(final P o) { +// return o.offset - offset; +// } +// } +// +// /** +// * Hack returns the query type based on the first occurrence of the +// * keyword for any known query type in the query. +// * +// * @param queryStr +// * The query. +// * +// * @return The query type. +// */ +// static public QueryType fromQuery(final String queryStr) { +// +// // force all to lower case. +// final String s = queryStr.toUpperCase(); +// +// final int ntypes = QueryType.values().length; +// +// final P[] p = new P[ntypes]; +// +// int nmatch = 0; +// for (int i = 0; i < ntypes; i++) { +// +// final QueryType queryType = getQueryType(i); +// +// final int offset = s.indexOf(queryType.toString()); +// +// if (offset == -1) +// continue; +// +// p[nmatch++] = new P(offset, queryType); +// +// } +// +// if (nmatch == 0) { +// +// throw new RuntimeException( +// "Could not determine the query type: " + queryStr); +// +// } +// +// Arrays.sort(p, 0/* fromIndex */, nmatch/* toIndex */); +// +// final P tmp = p[0]; +// +//// System.out.println("QueryType: offset=" + tmp.offset + ", type=" +//// + tmp.queryType); +// +// return tmp.queryType; +// +// } +// +// } /** * Class runs a SPARQL query against an HTTP endpoint. 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-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFContext.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -62,6 +62,7 @@ import com.bigdata.rdf.sail.BigdataSailRepositoryConnection; import com.bigdata.rdf.sail.BigdataSailTupleQuery; import com.bigdata.rdf.sail.QueryHints; +import com.bigdata.rdf.sail.QueryType; import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.relation.AbstractResource; import com.bigdata.relation.RelationSchema; Deleted: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryType.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryType.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/QueryType.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -1,103 +0,0 @@ -package com.bigdata.rdf.sail.webapp; - -import java.util.Arrays; - -/** - * Helper class to figure out the type of a query. - */ -public enum QueryType { - - ASK(0), DESCRIBE(1), CONSTRUCT(2), SELECT(3); - - private final int order; - - private QueryType(final int order) { - this.order = order; - } - - private static QueryType getQueryType(final int order) { - switch (order) { - case 0: - return ASK; - case 1: - return DESCRIBE; - case 2: - return CONSTRUCT; - case 3: - return SELECT; - default: - throw new IllegalArgumentException("order=" + order); - } - } - - /** - * Used to note the offset at which a keyword was found. - */ - static private class P implements Comparable<QueryType.P> { - - final int offset; - - final QueryType queryType; - - public P(final int offset, final QueryType queryType) { - this.offset = offset; - this.queryType = queryType; - } - - /** Sort into descending offset. */ - public int compareTo(final QueryType.P o) { - return o.offset - offset; - } - } - - /** - * Hack returns the query type based on the first occurrence of the - * keyword for any known query type in the query. - * - * @param queryStr - * The query. - * - * @return The query type. - */ - static public QueryType fromQuery(final String queryStr) { - - // force all to lower case. - final String s = queryStr.toUpperCase(); - - final int ntypes = QueryType.values().length; - - final QueryType.P[] p = new QueryType.P[ntypes]; - - int nmatch = 0; - for (int i = 0; i < ntypes; i++) { - - final QueryType queryType = getQueryType(i); - - final int offset = s.indexOf(queryType.toString()); - - if (offset == -1) - continue; - - p[nmatch++] = new P(offset, queryType); - - } - - if (nmatch == 0) { - - throw new RuntimeException( - "Could not determine the query type: " + queryStr); - - } - - Arrays.sort(p, 0/* fromIndex */, nmatch/* toIndex */); - - final QueryType.P tmp = p[0]; - - // System.out.println("QueryType: offset=" + tmp.offset + ", type=" - // + tmp.queryType); - - return tmp.queryType; - - } - -} \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -81,8 +81,11 @@ final TestSuite suite = new TestSuite("Sesame 2.x integration"); - // unit tests for extracting query hints from a SPARQL query. + // test suite for extracting query hints from a SPARQL query. suite.addTestSuite(TestQueryHintsUtility.class); + + // test suite for utility to extract the type of a SPARQL query. + suite.addTestSuite(TestQueryType.class); // bootstrap tests for the BigdataSail suite.addTestSuite(TestBootstrapBigdataSail.class); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBOps.java 2011-06-20 12:42:13 UTC (rev 4739) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBOps.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -46,7 +46,6 @@ import org.openrdf.query.impl.BindingImpl; import com.bigdata.rdf.axioms.NoAxioms; -import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.store.BD; import com.bigdata.rdf.vocab.NoVocabulary; @@ -56,12 +55,12 @@ */ public class TestBOps extends ProxyBigdataSailTestCase { - protected static final Logger log = Logger.getLogger(TestBOps.class); + private static final Logger log = Logger.getLogger(TestBOps.class); @Override public Properties getProperties() { - Properties props = super.getProperties(); + final Properties props = super.getProperties(); props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); @@ -89,6 +88,7 @@ public void testSimpleJoin() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -97,17 +97,17 @@ try { - final ValueFactory vf = sail.getValueFactory(); +// final ValueFactory vf = sail.getValueFactory(); final String ns = BD.NAMESPACE; - URI mike = new URIImpl(ns+"Mike"); - URI bryan = new URIImpl(ns+"Bryan"); - URI person = new URIImpl(ns+"Person"); - URI likes = new URIImpl(ns+"likes"); - URI rdf = new URIImpl(ns+"RDF"); - Literal l1 = new LiteralImpl("Mike"); - Literal l2 = new LiteralImpl("Bryan"); + final URI mike = new URIImpl(ns+"Mike"); + final URI bryan = new URIImpl(ns+"Bryan"); + final URI person = new URIImpl(ns+"Person"); + final URI likes = new URIImpl(ns+"likes"); + final URI rdf = new URIImpl(ns+"RDF"); + final Literal l1 = new LiteralImpl("Mike"); + final Literal l2 = new LiteralImpl("Bryan"); /**/ cxn.setNamespace("ns", ns); @@ -132,7 +132,7 @@ { - String query = + final String query = "PREFIX rdf: <"+RDF.NAMESPACE+"> " + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + "PREFIX ns: <"+ns+"> " + @@ -146,13 +146,13 @@ final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - TupleQueryResult result = tupleQuery.evaluate(); + final TupleQueryResult result = tupleQuery.evaluate(); // while (result.hasNext()) { // System.err.println(result.next()); // } - Collection<BindingSet> solution = new LinkedList<BindingSet>(); + final Collection<BindingSet> solution = new LinkedList<BindingSet>(); solution.add(createBindingSet(new Binding[] { new BindingImpl("s", mike), new BindingImpl("likes", rdf), @@ -167,9 +167,10 @@ compare(result, solution); } - + } finally { + cxn.close(); + } } finally { - cxn.close(); sail.__tearDownUnitTest(); } @@ -178,6 +179,7 @@ public void testSimpleConstraint() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -190,17 +192,17 @@ final String ns = BD.NAMESPACE; - URI jill = new URIImpl(ns+"Jill"); - URI jane = new URIImpl(ns+"Jane"); - URI person = new URIImpl(ns+"Person"); - URI age = new URIImpl(ns+"age"); - URI IQ = new URIImpl(ns+"IQ"); - Literal l1 = new LiteralImpl("Jill"); - Literal l2 = new LiteralImpl("Jane"); - Literal age1 = vf.createLiteral(20); - Literal age2 = vf.createLiteral(30); - Literal IQ1 = vf.createLiteral(130); - Literal IQ2 = vf.createLiteral(140); + final URI jill = new URIImpl(ns+"Jill"); + final URI jane = new URIImpl(ns+"Jane"); + final URI person = new URIImpl(ns+"Person"); + final URI age = new URIImpl(ns+"age"); + final URI IQ = new URIImpl(ns+"IQ"); + final Literal l1 = new LiteralImpl("Jill"); + final Literal l2 = new LiteralImpl("Jane"); + final Literal age1 = vf.createLiteral(20); + final Literal age2 = vf.createLiteral(30); + final Literal IQ1 = vf.createLiteral(130); + final Literal IQ2 = vf.createLiteral(140); /**/ cxn.setNamespace("ns", ns); @@ -227,7 +229,7 @@ { - String query = + final String query = "PREFIX rdf: <"+RDF.NAMESPACE+"> " + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + "PREFIX ns: <"+ns+"> " + @@ -243,13 +245,13 @@ final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - TupleQueryResult result = tupleQuery.evaluate(); + final TupleQueryResult result = tupleQuery.evaluate(); // while (result.hasNext()) { // System.err.println(result.next()); // } - Collection<BindingSet> solution = new LinkedList<BindingSet>(); + final Collection<BindingSet> solution = new LinkedList<BindingSet>(); solution.add(createBindingSet(new Binding[] { new BindingImpl("s", jill), new BindingImpl("age", age1), @@ -260,9 +262,10 @@ compare(result, solution); } - } finally { cxn.close(); + } + } finally { sail.__tearDownUnitTest(); } @@ -271,6 +274,7 @@ public void testSimpleOptional() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -279,17 +283,17 @@ try { - final ValueFactory vf = sail.getValueFactory(); +// final ValueFactory vf = sail.getValueFactory(); final String ns = BD.NAMESPACE; - URI mike = new URIImpl(ns+"Mike"); - URI bryan = new URIImpl(ns+"Bryan"); - URI person = new URIImpl(ns+"Person"); - URI likes = new URIImpl(ns+"likes"); - URI rdf = new URIImpl(ns+"RDF"); - Literal l1 = new LiteralImpl("Mike"); - Literal l2 = new LiteralImpl("Bryan"); + final URI mike = new URIImpl(ns+"Mike"); + final URI bryan = new URIImpl(ns+"Bryan"); + final URI person = new URIImpl(ns+"Person"); + final URI likes = new URIImpl(ns+"likes"); + final URI rdf = new URIImpl(ns+"RDF"); + final Literal l1 = new LiteralImpl("Mike"); +// final Literal l2 = new LiteralImpl("Bryan"); /**/ cxn.setNamespace("ns", ns); @@ -314,7 +318,7 @@ { - String query = + final String query = "PREFIX rdf: <"+RDF.NAMESPACE+"> " + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + "PREFIX ns: <"+ns+"> " + @@ -328,13 +332,13 @@ final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - TupleQueryResult result = tupleQuery.evaluate(); + final TupleQueryResult result = tupleQuery.evaluate(); // while (result.hasNext()) { // System.err.println(result.next()); // } - Collection<BindingSet> solution = new LinkedList<BindingSet>(); + final Collection<BindingSet> solution = new LinkedList<BindingSet>(); solution.add(createBindingSet(new Binding[] { new BindingImpl("s", mike), new BindingImpl("likes", rdf), @@ -349,9 +353,10 @@ compare(result, solution); } - } finally { cxn.close(); + } + } finally { sail.__tearDownUnitTest(); } @@ -360,6 +365,7 @@ public void testOrEquals() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -368,20 +374,20 @@ try { - final ValueFactory vf = sail.getValueFactory(); - - final LexiconRelation lex = sail.getDatabase().getLexiconRelation(); +// final ValueFactory vf = sail.getValueFactory(); +// +// final LexiconRelation lex = sail.getDatabase().getLexiconRelation(); final String ns = BD.NAMESPACE; - URI mike = new URIImpl(ns+"Mike"); - URI bryan = new URIImpl(ns+"Bryan"); - URI martyn = new URIImpl(ns+"Martyn"); - URI person = new URIImpl(ns+"Person"); - URI p = new URIImpl(ns+"p"); - Literal l1 = new LiteralImpl("Mike"); - Literal l2 = new LiteralImpl("Bryan"); - Literal l3 = new LiteralImpl("Martyn"); + final URI mike = new URIImpl(ns+"Mike"); + final URI bryan = new URIImpl(ns+"Bryan"); + final URI martyn = new URIImpl(ns+"Martyn"); + final URI person = new URIImpl(ns+"Person"); + final URI p = new URIImpl(ns+"p"); + final Literal l1 = new LiteralImpl("Mike"); + final Literal l2 = new LiteralImpl("Bryan"); + final Literal l3 = new LiteralImpl("Martyn"); /**/ cxn.setNamespace("ns", ns); @@ -420,13 +426,13 @@ final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - TupleQueryResult result = tupleQuery.evaluate(); + final TupleQueryResult result = tupleQuery.evaluate(); // while (result.hasNext()) { // System.err.println(result.next()); // } - Collection<BindingSet> solution = new LinkedList<BindingSet>(); + final Collection<BindingSet> solution = new LinkedList<BindingSet>(); solution.add(createBindingSet(new Binding[] { new BindingImpl("s", mike), new BindingImpl("p", RDFS.LABEL), @@ -441,9 +447,10 @@ compare(result, solution); } - } finally { cxn.close(); + } + } finally { sail.__tearDownUnitTest(); } @@ -452,6 +459,7 @@ public void testHashJoin() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -460,21 +468,21 @@ try { - final ValueFactory vf = sail.getValueFactory(); - - final LexiconRelation lex = sail.getDatabase().getLexiconRelation(); +// final ValueFactory vf = sail.getValueFactory(); +// +// final LexiconRelation lex = sail.getDatabase().getLexiconRelation(); final String ns = BD.NAMESPACE; - URI mikeA = new URIImpl(ns+"MikeA"); - URI mikeB = new URIImpl(ns+"MikeB"); - URI bryan = new URIImpl(ns+"Bryan"); - URI martyn = new URIImpl(ns+"Martyn"); - URI person = new URIImpl(ns+"Person"); - URI name = new URIImpl(ns+"name"); - Literal l1 = new LiteralImpl("Mike"); - Literal l2 = new LiteralImpl("Bryan"); - Literal l3 = new LiteralImpl("Martyn"); + final URI mikeA = new URIImpl(ns+"MikeA"); + final URI mikeB = new URIImpl(ns+"MikeB"); + final URI bryan = new URIImpl(ns+"Bryan"); + final URI martyn = new URIImpl(ns+"Martyn"); + final URI person = new URIImpl(ns+"Person"); + final URI name = new URIImpl(ns+"name"); + final Literal l1 = new LiteralImpl("Mike"); + final Literal l2 = new LiteralImpl("Bryan"); + final Literal l3 = new LiteralImpl("Martyn"); /**/ cxn.setNamespace("ns", ns); @@ -525,7 +533,7 @@ //// " filter(!bound(?s2) || ?s1 != ?s2) . " + // "}"; - String query = + final String query = "PREFIX "+QueryHints.PREFIX+": <"+QueryHints.NAMESPACE+QueryHints.HASH_JOIN+"=true> " + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + @@ -546,11 +554,12 @@ final TupleQuery tupleQuery = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - TupleQueryResult result = tupleQuery.evaluate(); + final TupleQueryResult result = tupleQuery.evaluate(); while (result.hasNext()) { final BindingSet tmp = result.next(); - if(log.isInfoEnabled())log.info(tmp.toString()); + if (log.isInfoEnabled()) + log.info(tmp.toString()); } // Collection<BindingSet> solution = new LinkedList<BindingSet>(); @@ -568,9 +577,10 @@ // compare(result, solution); } - } finally { cxn.close(); + } + } finally { sail.__tearDownUnitTest(); } Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryType.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryType.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryType.java 2011-06-20 14:06:10 UTC (rev 4740) @@ -0,0 +1,116 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Jun 20, 2011 + */ + +package com.bigdata.rdf.sail; + +import junit.framework.TestCase2; + +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; + +import com.bigdata.rdf.store.BD; + +/** + * Test suite for {@link QueryType}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestQueryType extends TestCase2 { + + /** + * + */ + public TestQueryType() { + } + + /** + * @param name + */ + public TestQueryType(String name) { + super(name); + } + + public void test_select() { + + final String s = "select ?p ?o where {<http://bigdata.com/foo> ?p ?o}"; + + assertEquals(QueryType.SELECT, QueryType.fromQuery(s)); + + } + + public void test_select_with_ask_in_URI() { + + final String s = "select ?p ?o where {<http://blablabla.com/ask_something> ?p ?o}"; + + assertEquals(QueryType.SELECT, QueryType.fromQuery(s)); + + } + + public void test_describe() { + + final String s = + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + "describe ?x " +// + "WHERE { " +// + " ?x rdf:type bd:Person . " +// + " ?x bd:likes bd:RDF " +// + "}"; + + assertEquals(QueryType.DESCRIBE, QueryType.fromQuery(s)); + + } + + public void test_construct() { + + /* + * Sample query from the SPARQL 1.0 Recommendation. + */ + final String s = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + + "PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>" + + "CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name }" + + "WHERE { ?x foaf:name ?name }"; + + assertEquals(QueryType.CONSTRUCT, QueryType.fromQuery(s)); + + } + + public void test_ask() { + + /* + * Sample query from the SPARQL 1.0 Recommendation. + */ + final String s = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + + "ASK { ?x foaf:name \"Alice\" }"; + + assertEquals(QueryType.ASK, QueryType.fromQuery(s)); + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryType.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |