Skip to content

Instantly share code, notes, and snippets.

View kendall's full-sized avatar

Kendall Clark kendall

View GitHub Profile
// 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
Graph aGraph = new GraphImpl();
URI aBook = aGraph.getValueFactory().createURI("urn:x-domain:oreilly.com:product:9780596514129.IP");
aGraph.add(aBook,
aGraph.getValueFactory().createURI("http://purl.org/dc/terms/publisher"),
aGraph.getValueFactory().createLiteral("O'Reilly Media / Pogue Press"));
aGraph.add(aBook,
aGraph.getValueFactory().createURI("http://purl.org/dc/terms/title"),
aGraph.getValueFactory().createLiteral(
"Switching to the Mac: The Missing Manual, Leopard Edition"));
<rdf:Description rdf:about="urn:x-domain:oreilly.com:product:9780596514129.IP">
<foaf1:primarySubjectOf rdf:resource="http://oreilly.com/catalog/9780596514129"/>
<dc1:title xml:lang="en">Switching to the Mac: The Missing Manual, Leopard Edition</dc1:title>
<dc1:title>Switching to the Mac: The Missing Manual, Leopard Edition</dc1:title>
<dc1:creator rdf:resource="urn:x-domain:oreilly.com:agent:pdb:350"/>
<dc1:publisher xml:lang="en">O'Reilly Media / Pogue Press</dc1:publisher>
<dc1:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2008-02-26</dc1:issued>
<frbr1:embodiment rdf:resource="urn:x-domain:oreilly.com:product:9780596514129.BOOK"/>
<frbr1:embodiment rdf:resource="urn:x-domain:oreilly.com:product:9780596802899.EBOOK"/>
<frbr1:embodiment rdf:resource="urn:x-domain:oreilly.com:product:9780596514129.SAF"/>
@RdfProperty("dc:title")
private String title;
@RdfProperty("dc:publisher")
private String publisher;
@RdfProperty("dc:issued")
private Date issued;
@RdfProperty("frbr:embodiment")
// now we can delete our new book
aManager.remove(aNewBook);
// false!
System.err.println(aManager.contains(aNewBook));
// but the new manifestation still exists, since we did not specify that deletes should cascade...
// true!
System.err.println(aManager.contains(aPDFManifestation));
@Entity
public class Book
// ... annotations ...
public class Book implements SupportsRdfId
private String title;
private String publisher;
private Date issued;
@OneToMany(fetch = FetchType.LAZY,
cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private Collection<Manifestation> mEmbodiments = new HashSet<Manifestation>();
Empire.init(new OpenRdfEmpireModule());