Skip to content

Commit

Permalink
rfe10447: add AGGraphQuery#count() method
Browse files Browse the repository at this point in the history
<release-note>
rfe10447: add AGGraphQuery#count() method

With this change, the java client now supports counting for graph
queries (e.g CONSTRUCT and DESCRIBE) with the AGGraphQuery#count()
method.  Also added javadoc for the AGTupleQuery#count() method.
</release-note>

Added AGGraphQueryTests to prepush tests.
make prepush passes.
make javadoc runs clean.

Change-Id: Ifbf3069dbc544dccf103d41533335824929770d0
Reviewed-on: https://gerrit.franz.com:9080/1273
Reviewed-by: John O'Rourke <jor@franz.com>
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information
Bill Millar authored and dklayer committed Jun 9, 2011
1 parent 7c2eaa7 commit 83fd73c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/com/franz/agraph/repository/AGGraphQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public void evaluate(RDFHandler handler) throws QueryEvaluationException,
RDFFormat.NTRIPLES));
}

/**
* Evaluates the query and returns only the number of results
* to the client (counting is done on the server, the results
* are not returned).
*
* @return the number of results
* @throws QueryEvaluationException
*/
public long count() throws QueryEvaluationException {
AGResponseHandler handler = new AGResponseHandler(0L);
evaluate(handler);
return handler.getLong();
}
}
8 changes: 8 additions & 0 deletions src/com/franz/agraph/repository/AGTupleQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public void evaluate(TupleQueryResultHandler handler)
evaluate(new AGResponseHandler(httpCon.getRepository(), handler));
}

/**
* Evaluates the query and returns only the number of results
* to the client (counting is done on the server, the results
* are not returned).
*
* @return the number of results
* @throws QueryEvaluationException
*/
public long count() throws QueryEvaluationException {
AGResponseHandler handler = new AGResponseHandler(0L);
evaluate(handler);
Expand Down
52 changes: 52 additions & 0 deletions src/test/AGGraphQueryTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******************************************************************************
** Copyright (c) 2008-2010 Franz Inc.
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the Eclipse Public License v1.0
** which accompanies this distribution, and is available at
** http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/

package test;

import java.io.File;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openrdf.query.QueryLanguage;

import com.franz.agraph.repository.AGGraphQuery;
import com.franz.agraph.repository.AGRDFFormat;

public class AGGraphQueryTests extends AGAbstractTest {

@Test
@Category(TestSuites.Prepush.class)
public void graphQuery_count_rfe10447() throws Exception {
conn.add(new File("src/test/example.nq"), null, AGRDFFormat.NQUADS);
String queryString = "construct {?s ?p ?o} where {?s ?p ?o}";
AGGraphQuery q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
Assert.assertEquals("expected size 10", 10, q.count());
queryString =
"construct {?s ?p ?o} where " +
"{GRAPH <http://example.org/alice/foaf.rdf> {?s ?p ?o}}";
q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
Assert.assertEquals("expected size 7", 7, q.count());
queryString =
"construct {?s ?p ?o} where " +
"{GRAPH <http://example.org/bob/foaf.rdf> {?s ?p ?o}}";
q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
Assert.assertEquals("expected size 3", 3, q.count());
queryString =
"construct {?s ?p ?o} where " +
"{GRAPH <http://example.org/carol/foaf.rdf> {?s ?p ?o}}";
q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
Assert.assertEquals("expected size 0", 0, q.count());
queryString =
"describe <http://example.org/alice/foaf.rdf#me>";
q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
Assert.assertEquals("expected size 7", 7, q.count());
}

}
3 changes: 2 additions & 1 deletion src/test/TestSuites.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static class Temp {}
ServerCodeTests.class,
SpogiTripleCacheTests.class,
UploadCommitPeriodTests.class,
NQuadsTests.class
NQuadsTests.class,
AGGraphQueryTests.class
})
public static class Prepush {}

Expand Down

0 comments on commit 83fd73c

Please sign in to comment.