Skip to content

Instantly share code, notes, and snippets.

@kendall
Created May 7, 2010 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kendall/393596 to your computer and use it in GitHub Desktop.
Save kendall/393596 to your computer and use it in GitHub Desktop.
// Lastly, we can use the query API to run arbitrary sparql queries
// create a jpql-style partial SPARQL query (JPQL is currently unsupported)
Query aQuery = aManager.createQuery("where { ?result frbr:embodiment ?manifest." +
" ?foo <http://purl.org/goodrelations/v1#typeOfGood> ?manifest . " +
" ?foo <http://purl.org/goodrelations/v1#hasPriceSpecification> ?price. " +
" ?price <http://purl.org/goodrelations/v1#hasCurrencyValue> ?value. " +
" ?price <http://purl.org/goodrelations/v1#hasCurrency> \"USD\"@en." +
" filter(?value > ??min). }");
// this query should return instances of type Book
aQuery.setHint(RdfQuery.HINT_ENTITY_CLASS, Book.class);
// set the parameter in the query to the value for the min price
// parameters are prefixed with ?? -- this differs slightly from JPQL
aQuery.setParameter("min", 30);
// now execute the query to get the list of all books which are $30 USD
List aResults = aQuery.getResultList();
// 233 results
System.err.println("Num Results: " + aResults.size());
// print the titles of the first five results
for (int i = 0; i < 5; i++) {
Book aBookResult = (Book) aResults.get(i);
System.err.println(aBookResult.getTitle());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment