diff --git a/webapp/lib/aduna-commons-collections-2.3.jar b/webapp/lib/aduna-commons-collections-2.3.jar deleted file mode 100644 index 665f995d9..000000000 Binary files a/webapp/lib/aduna-commons-collections-2.3.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-concurrent-2.2.jar b/webapp/lib/aduna-commons-concurrent-2.2.jar deleted file mode 100644 index f2d73fdf7..000000000 Binary files a/webapp/lib/aduna-commons-concurrent-2.2.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-io-2.4.jar b/webapp/lib/aduna-commons-io-2.4.jar deleted file mode 100644 index 6642ac658..000000000 Binary files a/webapp/lib/aduna-commons-io-2.4.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-iteration-2.3.jar b/webapp/lib/aduna-commons-iteration-2.3.jar deleted file mode 100644 index 366d2cbe6..000000000 Binary files a/webapp/lib/aduna-commons-iteration-2.3.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-lang-2.2.jar b/webapp/lib/aduna-commons-lang-2.2.jar deleted file mode 100644 index 842faee4b..000000000 Binary files a/webapp/lib/aduna-commons-lang-2.2.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-net-2.2.jar b/webapp/lib/aduna-commons-net-2.2.jar deleted file mode 100644 index 88273c0c9..000000000 Binary files a/webapp/lib/aduna-commons-net-2.2.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-text-2.2.jar b/webapp/lib/aduna-commons-text-2.2.jar deleted file mode 100644 index 76b817335..000000000 Binary files a/webapp/lib/aduna-commons-text-2.2.jar and /dev/null differ diff --git a/webapp/lib/aduna-commons-xml-2.2.jar b/webapp/lib/aduna-commons-xml-2.2.jar deleted file mode 100644 index 76ece0936..000000000 Binary files a/webapp/lib/aduna-commons-xml-2.2.jar and /dev/null differ diff --git a/webapp/lib/aopalliance-1.0.jar b/webapp/lib/aopalliance-1.0.jar new file mode 100644 index 000000000..578b1a0c3 Binary files /dev/null and b/webapp/lib/aopalliance-1.0.jar differ diff --git a/webapp/lib/asm-3.1.jar b/webapp/lib/asm-3.1.jar new file mode 100644 index 000000000..8217cae0a Binary files /dev/null and b/webapp/lib/asm-3.1.jar differ diff --git a/webapp/lib/cglib-2.2.jar b/webapp/lib/cglib-2.2.jar new file mode 100644 index 000000000..084ef6e54 Binary files /dev/null and b/webapp/lib/cglib-2.2.jar differ diff --git a/webapp/lib/commons-cli-1.2.jar b/webapp/lib/commons-cli-1.2.jar new file mode 100644 index 000000000..ce4b9fffe Binary files /dev/null and b/webapp/lib/commons-cli-1.2.jar differ diff --git a/webapp/lib/commons-codec-1.4.jar b/webapp/lib/commons-codec-1.4.jar new file mode 100644 index 000000000..458d432da Binary files /dev/null and b/webapp/lib/commons-codec-1.4.jar differ diff --git a/webapp/lib/commons-dbcp-1.3.jar b/webapp/lib/commons-dbcp-1.3.jar new file mode 100644 index 000000000..d29339738 Binary files /dev/null and b/webapp/lib/commons-dbcp-1.3.jar differ diff --git a/webapp/lib/commons-pool-1.5.4.jar b/webapp/lib/commons-pool-1.5.4.jar new file mode 100644 index 000000000..43edf9963 Binary files /dev/null and b/webapp/lib/commons-pool-1.5.4.jar differ diff --git a/webapp/lib/sesame-config-2.6.2.jar b/webapp/lib/sesame-config-2.6.2.jar new file mode 100644 index 000000000..26cbc0963 Binary files /dev/null and b/webapp/lib/sesame-config-2.6.2.jar differ diff --git a/webapp/lib/sesame-console-2.6.2.jar b/webapp/lib/sesame-console-2.6.2.jar new file mode 100644 index 000000000..fe26b29b7 Binary files /dev/null and b/webapp/lib/sesame-console-2.6.2.jar differ diff --git a/webapp/lib/sesame-http-client-2.2.3.jar b/webapp/lib/sesame-http-client-2.2.3.jar deleted file mode 100644 index 99950b701..000000000 Binary files a/webapp/lib/sesame-http-client-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-http-client-2.6.2.jar b/webapp/lib/sesame-http-client-2.6.2.jar new file mode 100644 index 000000000..e97f4c373 Binary files /dev/null and b/webapp/lib/sesame-http-client-2.6.2.jar differ diff --git a/webapp/lib/sesame-http-protocol-2.2.3.jar b/webapp/lib/sesame-http-protocol-2.6.2.jar similarity index 64% rename from webapp/lib/sesame-http-protocol-2.2.3.jar rename to webapp/lib/sesame-http-protocol-2.6.2.jar index e34a1bcb0..eae330cc3 100644 Binary files a/webapp/lib/sesame-http-protocol-2.2.3.jar and b/webapp/lib/sesame-http-protocol-2.6.2.jar differ diff --git a/webapp/lib/sesame-http-server-spring-2.6.2.jar b/webapp/lib/sesame-http-server-spring-2.6.2.jar new file mode 100644 index 000000000..5ef8a9be9 Binary files /dev/null and b/webapp/lib/sesame-http-server-spring-2.6.2.jar differ diff --git a/webapp/lib/sesame-model-2.2.3.jar b/webapp/lib/sesame-model-2.2.3.jar deleted file mode 100644 index 16976caa0..000000000 Binary files a/webapp/lib/sesame-model-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-model-2.6.2.jar b/webapp/lib/sesame-model-2.6.2.jar new file mode 100644 index 000000000..441853df5 Binary files /dev/null and b/webapp/lib/sesame-model-2.6.2.jar differ diff --git a/webapp/lib/sesame-query-2.2.3.jar b/webapp/lib/sesame-query-2.2.3.jar deleted file mode 100644 index a6715a2fe..000000000 Binary files a/webapp/lib/sesame-query-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-query-2.6.2.jar b/webapp/lib/sesame-query-2.6.2.jar new file mode 100644 index 000000000..9771e39aa Binary files /dev/null and b/webapp/lib/sesame-query-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryalgebra-evaluation-2.6.2.jar b/webapp/lib/sesame-queryalgebra-evaluation-2.6.2.jar new file mode 100644 index 000000000..d8b06eb82 Binary files /dev/null and b/webapp/lib/sesame-queryalgebra-evaluation-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryalgebra-model-2.6.2.jar b/webapp/lib/sesame-queryalgebra-model-2.6.2.jar new file mode 100644 index 000000000..65ac7d5f6 Binary files /dev/null and b/webapp/lib/sesame-queryalgebra-model-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryparser-api-2.6.2.jar b/webapp/lib/sesame-queryparser-api-2.6.2.jar new file mode 100644 index 000000000..4636125f9 Binary files /dev/null and b/webapp/lib/sesame-queryparser-api-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryparser-serql-2.6.2.jar b/webapp/lib/sesame-queryparser-serql-2.6.2.jar new file mode 100644 index 000000000..e2b7d9a64 Binary files /dev/null and b/webapp/lib/sesame-queryparser-serql-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryparser-sparql-2.6.2.jar b/webapp/lib/sesame-queryparser-sparql-2.6.2.jar new file mode 100644 index 000000000..cd7463424 Binary files /dev/null and b/webapp/lib/sesame-queryparser-sparql-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryresultio-api-2.2.3.jar b/webapp/lib/sesame-queryresultio-api-2.6.2.jar similarity index 64% rename from webapp/lib/sesame-queryresultio-api-2.2.3.jar rename to webapp/lib/sesame-queryresultio-api-2.6.2.jar index 6242ec0eb..bd28e0202 100644 Binary files a/webapp/lib/sesame-queryresultio-api-2.2.3.jar and b/webapp/lib/sesame-queryresultio-api-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryresultio-binary-2.6.2.jar b/webapp/lib/sesame-queryresultio-binary-2.6.2.jar new file mode 100644 index 000000000..bc9345185 Binary files /dev/null and b/webapp/lib/sesame-queryresultio-binary-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryresultio-sparqljson-2.6.2.jar b/webapp/lib/sesame-queryresultio-sparqljson-2.6.2.jar new file mode 100644 index 000000000..97db0b69d Binary files /dev/null and b/webapp/lib/sesame-queryresultio-sparqljson-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryresultio-sparqlxml-2.6.2.jar b/webapp/lib/sesame-queryresultio-sparqlxml-2.6.2.jar new file mode 100644 index 000000000..c3c45fd97 Binary files /dev/null and b/webapp/lib/sesame-queryresultio-sparqlxml-2.6.2.jar differ diff --git a/webapp/lib/sesame-queryresultio-text-2.6.2.jar b/webapp/lib/sesame-queryresultio-text-2.6.2.jar new file mode 100644 index 000000000..d3e195511 Binary files /dev/null and b/webapp/lib/sesame-queryresultio-text-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-api-2.2.3.jar b/webapp/lib/sesame-repository-api-2.2.3.jar deleted file mode 100644 index dd1d902ee..000000000 Binary files a/webapp/lib/sesame-repository-api-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-api-2.6.2.jar b/webapp/lib/sesame-repository-api-2.6.2.jar new file mode 100644 index 000000000..2b47de0a3 Binary files /dev/null and b/webapp/lib/sesame-repository-api-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-contextaware-2.6.2.jar b/webapp/lib/sesame-repository-contextaware-2.6.2.jar new file mode 100644 index 000000000..f69b04a5a Binary files /dev/null and b/webapp/lib/sesame-repository-contextaware-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-dataset-2.6.2.jar b/webapp/lib/sesame-repository-dataset-2.6.2.jar new file mode 100644 index 000000000..36490be86 Binary files /dev/null and b/webapp/lib/sesame-repository-dataset-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-event-2.6.2.jar b/webapp/lib/sesame-repository-event-2.6.2.jar new file mode 100644 index 000000000..92ba79803 Binary files /dev/null and b/webapp/lib/sesame-repository-event-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-http-2.2.3.jar b/webapp/lib/sesame-repository-http-2.2.3.jar deleted file mode 100644 index 3aec0b909..000000000 Binary files a/webapp/lib/sesame-repository-http-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-repository-http-2.6.2.jar b/webapp/lib/sesame-repository-http-2.6.2.jar new file mode 100644 index 000000000..576f07c80 Binary files /dev/null and b/webapp/lib/sesame-repository-http-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-manager-2.6.2.jar b/webapp/lib/sesame-repository-manager-2.6.2.jar new file mode 100644 index 000000000..52cd8a834 Binary files /dev/null and b/webapp/lib/sesame-repository-manager-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-sail-2.6.2.jar b/webapp/lib/sesame-repository-sail-2.6.2.jar new file mode 100644 index 000000000..97b4406eb Binary files /dev/null and b/webapp/lib/sesame-repository-sail-2.6.2.jar differ diff --git a/webapp/lib/sesame-repository-sparql-2.6.2.jar b/webapp/lib/sesame-repository-sparql-2.6.2.jar new file mode 100644 index 000000000..8229628b1 Binary files /dev/null and b/webapp/lib/sesame-repository-sparql-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-api-2.2.3.jar b/webapp/lib/sesame-rio-api-2.2.3.jar deleted file mode 100644 index 5a7d2b14e..000000000 Binary files a/webapp/lib/sesame-rio-api-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-api-2.6.2.jar b/webapp/lib/sesame-rio-api-2.6.2.jar new file mode 100644 index 000000000..159f80184 Binary files /dev/null and b/webapp/lib/sesame-rio-api-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-binary-2.6.2.jar b/webapp/lib/sesame-rio-binary-2.6.2.jar new file mode 100644 index 000000000..0f4eeb4d7 Binary files /dev/null and b/webapp/lib/sesame-rio-binary-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-n3-2.2.3.jar b/webapp/lib/sesame-rio-n3-2.2.3.jar deleted file mode 100644 index 285b119e1..000000000 Binary files a/webapp/lib/sesame-rio-n3-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-n3-2.6.2.jar b/webapp/lib/sesame-rio-n3-2.6.2.jar new file mode 100644 index 000000000..156f688bc Binary files /dev/null and b/webapp/lib/sesame-rio-n3-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-ntriples-2.2.3.jar b/webapp/lib/sesame-rio-ntriples-2.2.3.jar deleted file mode 100644 index 97fb1089d..000000000 Binary files a/webapp/lib/sesame-rio-ntriples-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-ntriples-2.6.2.jar b/webapp/lib/sesame-rio-ntriples-2.6.2.jar new file mode 100644 index 000000000..617183506 Binary files /dev/null and b/webapp/lib/sesame-rio-ntriples-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-rdfxml-2.2.3.jar b/webapp/lib/sesame-rio-rdfxml-2.2.3.jar deleted file mode 100644 index 99b5677b9..000000000 Binary files a/webapp/lib/sesame-rio-rdfxml-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-rdfxml-2.6.2.jar b/webapp/lib/sesame-rio-rdfxml-2.6.2.jar new file mode 100644 index 000000000..2d82b3435 Binary files /dev/null and b/webapp/lib/sesame-rio-rdfxml-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-trig-2.6.2.jar b/webapp/lib/sesame-rio-trig-2.6.2.jar new file mode 100644 index 000000000..da521398e Binary files /dev/null and b/webapp/lib/sesame-rio-trig-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-trix-2.6.2.jar b/webapp/lib/sesame-rio-trix-2.6.2.jar new file mode 100644 index 000000000..0de2a4d6b Binary files /dev/null and b/webapp/lib/sesame-rio-trix-2.6.2.jar differ diff --git a/webapp/lib/sesame-rio-turtle-2.2.3.jar b/webapp/lib/sesame-rio-turtle-2.2.3.jar deleted file mode 100644 index e209e4750..000000000 Binary files a/webapp/lib/sesame-rio-turtle-2.2.3.jar and /dev/null differ diff --git a/webapp/lib/sesame-rio-turtle-2.6.2.jar b/webapp/lib/sesame-rio-turtle-2.6.2.jar new file mode 100644 index 000000000..fc69da302 Binary files /dev/null and b/webapp/lib/sesame-rio-turtle-2.6.2.jar differ diff --git a/webapp/lib/sesame-runtime-2.6.2.jar b/webapp/lib/sesame-runtime-2.6.2.jar new file mode 100644 index 000000000..3e8078917 Binary files /dev/null and b/webapp/lib/sesame-runtime-2.6.2.jar differ diff --git a/webapp/lib/sesame-sail-api-2.6.2.jar b/webapp/lib/sesame-sail-api-2.6.2.jar new file mode 100644 index 000000000..c42382c13 Binary files /dev/null and b/webapp/lib/sesame-sail-api-2.6.2.jar differ diff --git a/webapp/lib/sesame-sail-inferencer-2.6.2.jar b/webapp/lib/sesame-sail-inferencer-2.6.2.jar new file mode 100644 index 000000000..65b67c73d Binary files /dev/null and b/webapp/lib/sesame-sail-inferencer-2.6.2.jar differ diff --git a/webapp/lib/sesame-sail-memory-2.6.2.jar b/webapp/lib/sesame-sail-memory-2.6.2.jar new file mode 100644 index 000000000..6825d207b Binary files /dev/null and b/webapp/lib/sesame-sail-memory-2.6.2.jar differ diff --git a/webapp/lib/sesame-sail-nativerdf-2.6.2.jar b/webapp/lib/sesame-sail-nativerdf-2.6.2.jar new file mode 100644 index 000000000..9ebaa81f9 Binary files /dev/null and b/webapp/lib/sesame-sail-nativerdf-2.6.2.jar differ diff --git a/webapp/lib/sesame-sail-rdbms-2.6.2.jar b/webapp/lib/sesame-sail-rdbms-2.6.2.jar new file mode 100644 index 000000000..a9a3f6e86 Binary files /dev/null and b/webapp/lib/sesame-sail-rdbms-2.6.2.jar differ diff --git a/webapp/lib/sesame-util-2.6.2.jar b/webapp/lib/sesame-util-2.6.2.jar new file mode 100644 index 000000000..b20b81b0e Binary files /dev/null and b/webapp/lib/sesame-util-2.6.2.jar differ diff --git a/webapp/lib/spring-aop-2.5.6.jar b/webapp/lib/spring-aop-2.5.6.jar new file mode 100644 index 000000000..a11cc3aa5 Binary files /dev/null and b/webapp/lib/spring-aop-2.5.6.jar differ diff --git a/webapp/lib/spring-beans-2.5.6.jar b/webapp/lib/spring-beans-2.5.6.jar new file mode 100644 index 000000000..3f306b673 Binary files /dev/null and b/webapp/lib/spring-beans-2.5.6.jar differ diff --git a/webapp/lib/spring-context-2.5.6.jar b/webapp/lib/spring-context-2.5.6.jar new file mode 100644 index 000000000..29fabcc1d Binary files /dev/null and b/webapp/lib/spring-context-2.5.6.jar differ diff --git a/webapp/lib/spring-context-support-2.5.6.jar b/webapp/lib/spring-context-support-2.5.6.jar new file mode 100644 index 000000000..2927c6ebf Binary files /dev/null and b/webapp/lib/spring-context-support-2.5.6.jar differ diff --git a/webapp/lib/spring-core-2.5.6.jar b/webapp/lib/spring-core-2.5.6.jar new file mode 100644 index 000000000..aafa33609 Binary files /dev/null and b/webapp/lib/spring-core-2.5.6.jar differ diff --git a/webapp/lib/spring-web-2.5.6.jar b/webapp/lib/spring-web-2.5.6.jar new file mode 100644 index 000000000..432e8f036 Binary files /dev/null and b/webapp/lib/spring-web-2.5.6.jar differ diff --git a/webapp/lib/spring-webmvc-2.5.6.jar b/webapp/lib/spring-webmvc-2.5.6.jar new file mode 100644 index 000000000..613f5953d Binary files /dev/null and b/webapp/lib/spring-webmvc-2.5.6.jar differ diff --git a/webapp/lib/standard-1.1.2.jar b/webapp/lib/standard-1.1.2.jar new file mode 100644 index 000000000..bc528acb9 Binary files /dev/null and b/webapp/lib/standard-1.1.2.jar differ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/EmptyReifier.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/EmptyReifier.java new file mode 100644 index 000000000..95535cce8 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/EmptyReifier.java @@ -0,0 +1,117 @@ +package edu.cornell.mannlib.vitro.webapp.dao.jena; + +import java.util.Collections; + +import com.hp.hpl.jena.graph.Graph; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.Reifier; +import com.hp.hpl.jena.graph.Triple; +import com.hp.hpl.jena.graph.TripleMatch; +import com.hp.hpl.jena.shared.ReificationStyle; +import com.hp.hpl.jena.util.iterator.ExtendedIterator; +import com.hp.hpl.jena.util.iterator.WrappedIterator; + +public class EmptyReifier implements Reifier { + + private Graph g; + + public EmptyReifier(Graph g) { + this.g = g; + } + + @Override + public Triple getTriple(Node arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ExtendedIterator allNodes() { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + + @Override + public ExtendedIterator allNodes(Triple arg0) { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public ExtendedIterator find(TripleMatch arg0) { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + + @Override + public ExtendedIterator findEither(TripleMatch arg0, boolean arg1) { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + + @Override + public ExtendedIterator findExposed(TripleMatch arg0) { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + + @Override + public Graph getParentGraph() { + return g; + } + + @Override + public ReificationStyle getStyle() { + return ReificationStyle.Minimal; + } + + @Override + public boolean handledAdd(Triple arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean handledRemove(Triple arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasTriple(Node arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean hasTriple(Triple arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Node reifyAs(Node arg0, Triple arg1) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void remove(Triple arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void remove(Node arg0, Triple arg1) { + // TODO Auto-generated method stub + + } + + @Override + public int size() { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java new file mode 100644 index 000000000..54d0d9280 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SparqlGraph.java @@ -0,0 +1,392 @@ +package edu.cornell.mannlib.vitro.webapp.dao.jena; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openrdf.query.GraphQuery; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.Update; +import org.openrdf.query.UpdateExecutionException; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.http.HTTPRepository; + +import com.hp.hpl.jena.graph.BulkUpdateHandler; +import com.hp.hpl.jena.graph.Capabilities; +import com.hp.hpl.jena.graph.Graph; +import com.hp.hpl.jena.graph.GraphEventManager; +import com.hp.hpl.jena.graph.GraphStatisticsHandler; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.Reifier; +import com.hp.hpl.jena.graph.TransactionHandler; +import com.hp.hpl.jena.graph.Triple; +import com.hp.hpl.jena.graph.TripleMatch; +import com.hp.hpl.jena.graph.impl.GraphWithPerform; +import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler; +import com.hp.hpl.jena.graph.impl.SimpleEventManager; +import com.hp.hpl.jena.graph.query.QueryHandler; +import com.hp.hpl.jena.graph.query.SimpleQueryHandler; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.shared.AddDeniedException; +import com.hp.hpl.jena.shared.DeleteDeniedException; +import com.hp.hpl.jena.shared.PrefixMapping; +import com.hp.hpl.jena.shared.impl.PrefixMappingImpl; +import com.hp.hpl.jena.sparql.resultset.ResultSetMem; +import com.hp.hpl.jena.util.iterator.ExtendedIterator; +import com.hp.hpl.jena.util.iterator.SingletonIterator; +import com.hp.hpl.jena.util.iterator.WrappedIterator; + +public class SparqlGraph implements GraphWithPerform { + + private String endpointURI; + private static final Log log = LogFactory.getLog(SparqlGraph.class); + + private BulkUpdateHandler bulkUpdateHandler; + private PrefixMapping prefixMapping = new PrefixMappingImpl(); + private GraphEventManager eventManager; + private Reifier reifier = new EmptyReifier(this); + private GraphStatisticsHandler graphStatisticsHandler; + private TransactionHandler transactionHandler; + private QueryHandler queryHandler; + + private Repository repository; + + public SparqlGraph(String endpointURI) { + this.endpointURI = endpointURI; + this.repository = new HTTPRepository(endpointURI); + } + + private RepositoryConnection getConnection() { + try { + return this.repository.getConnection(); + } catch (RepositoryException e) { + throw new RuntimeException(e); + } + } + + @Override + public void add(Triple arg0) throws AddDeniedException { + performAdd(arg0); + } + + @Override + public void performAdd(Triple t) { + + String updateString = "INSERT DATA { " + + sparqlNode(t.getSubject(), "") + " " + + sparqlNode(t.getPredicate(), "") + " " + + sparqlNode(t.getObject(), "") + + "}"; + + try { + RepositoryConnection conn = getConnection(); + try { + Update u = conn.prepareUpdate(QueryLanguage.SPARQL, updateString); + u.execute(); + } catch (MalformedQueryException e) { + throw new RuntimeException(e); + } catch (UpdateExecutionException e) { + throw new RuntimeException(e); + } finally { + conn.close(); + } + } catch (RepositoryException re) { + throw new RuntimeException(re); + } + + } + + @Override + public void performDelete(Triple t) { + String updateString = "DELETE DATA { " + + sparqlNode(t.getSubject(), "") + " " + + sparqlNode(t.getPredicate(), "") + " " + + sparqlNode(t.getObject(), "") + + "}"; + + try { + RepositoryConnection conn = getConnection(); + try { + Update u = conn.prepareUpdate(QueryLanguage.SPARQL, updateString); + u.execute(); + } catch (MalformedQueryException e) { + throw new RuntimeException(e); + } catch (UpdateExecutionException e) { + throw new RuntimeException(e); + } finally { + conn.close(); + } + } catch (RepositoryException re) { + throw new RuntimeException(re); + } + } + + @Override + public void close() { + // can't close a remote endpoint + } + + @Override + public boolean contains(Triple arg0) { + return contains(arg0.getSubject(), arg0.getPredicate(), arg0.getObject()); + } + + @Override + public boolean contains(Node subject, Node predicate, Node object) { + if (subject.isBlank() || predicate.isBlank() || object.isBlank()) { + return false; + } + StringBuffer containsQuery = new StringBuffer("ASK { \n") + .append(sparqlNode(subject, "?s")) + .append(" ") + .append(sparqlNode(predicate, "?p")) + .append(" ") + .append(sparqlNode(object, "?o")) + .append("\n}"); + return execAsk(containsQuery.toString()); + } + + @Override + public void delete(Triple arg0) throws DeleteDeniedException { + performDelete(arg0); + } + + @Override + public boolean dependsOn(Graph arg0) { + return false; // who knows? + } + + @Override + public ExtendedIterator find(TripleMatch arg0) { + //log.info("find(TripleMatch) " + arg0); + Triple t = arg0.asTriple(); + return find(t.getSubject(), t.getPredicate(), t.getObject()); + } + + private String sparqlNode(Node node, String varName) { + if (node == null || node.isVariable()) { + return varName; + } else if (node.isBlank()) { + return "<" + "fake:blank" + ">"; // or throw exception? + } else if (node.isURI()) { + StringBuffer uriBuff = new StringBuffer(); + return uriBuff.append("<").append(node.getURI()).append(">").toString(); + } else if (node.isLiteral()) { + StringBuffer literalBuff = new StringBuffer(); + literalBuff.append("\"").append(node.getLiteralLexicalForm()).append("\""); + if (node.getLiteralDatatypeURI() != null) { + literalBuff.append("^^<").append(node.getLiteralDatatypeURI()).append(">"); + } else if (node.getLiteralLanguage() != null && node.getLiteralLanguage() != "") { + literalBuff.append("@").append(node.getLiteralLanguage()); +; } + return literalBuff.toString(); + } else { + return varName; + } + } + + @Override + public ExtendedIterator find(Node subject, Node predicate, Node object) { + if (!isVar(subject) && !isVar(predicate) && !isVar(object)) { + if (contains(subject, predicate, object)) { + return new SingletonIterator(new Triple(subject, predicate, object)); + } else { + return WrappedIterator.create(Collections.EMPTY_LIST.iterator()); + } + } + StringBuffer findQuery = new StringBuffer("SELECT * WHERE { \n") + .append(sparqlNode(subject, "?s")) + .append(" ") + .append(sparqlNode(predicate, "?p")) + .append(" ") + .append(sparqlNode(object, "?o")) + .append("\n}"); + + log.info(findQuery.toString()); + ResultSet rs = execSelect(findQuery.toString()); + //rs = execSelect(findQuery.toString()); + //rs = execSelect(findQuery.toString()); + + List triplist = new ArrayList(); + while (rs.hasNext()) { + QuerySolution soln = rs.nextSolution(); + Triple t = new Triple(isVar(subject) ? soln.get("?s").asNode() : subject, + isVar(predicate) ? soln.get("?p").asNode() : predicate, + isVar(object) ? soln.get("?o").asNode() : object); + //log.info(t); + triplist.add(t); + } + return WrappedIterator.create(triplist.iterator()); + } + + private boolean isVar(Node node) { + return (node == null || node.isVariable() || node == Node.ANY); + } + + @Override + public BulkUpdateHandler getBulkUpdateHandler() { + if (this.bulkUpdateHandler == null) { + this.bulkUpdateHandler = new SimpleBulkUpdateHandler(this); + } + return this.bulkUpdateHandler; + } + + @Override + public Capabilities getCapabilities() { + return capabilities; + } + + @Override + public GraphEventManager getEventManager() { + if (eventManager == null) { + eventManager = new SimpleEventManager(this); + } + return eventManager; + } + + @Override + public PrefixMapping getPrefixMapping() { + return prefixMapping; + } + + @Override + public Reifier getReifier() { + //if (reifier == null) { + // reifier = new SimpleReifier(this, ReificationStyle.Standard); + //} + return reifier; + } + + @Override + public GraphStatisticsHandler getStatisticsHandler() { + return null; + } + + @Override + public TransactionHandler getTransactionHandler() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isClosed() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isEmpty() { + return (size() == 0); + } + + @Override + public boolean isIsomorphicWith(Graph arg0) { + throw new UnsupportedOperationException("isIsomorphicWith() not supported " + + "by SPARQL graphs"); + } + + @Override + public QueryHandler queryHandler() { + if (queryHandler == null) { + queryHandler = new SimpleQueryHandler(this); + } + return queryHandler; + } + + @Override + public int size() { + return find(null, null, null).toList().size(); + } + + private final static Capabilities capabilities = new Capabilities() { + + public boolean addAllowed() { + return false; + } + + public boolean addAllowed(boolean everyTriple) { + return false; + } + + public boolean canBeEmpty() { + return true; + } + + public boolean deleteAllowed() { + return false; + } + + public boolean deleteAllowed(boolean everyTriple) { + return false; + } + + public boolean findContractSafe() { + return true; + } + + public boolean handlesLiteralTyping() { + return true; + } + + public boolean iteratorRemoveAllowed() { + return false; + } + + public boolean sizeAccurate() { + return true; + } + }; + + private boolean execAsk(String queryStr) { + Query askQuery = QueryFactory.create(queryStr); + QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, askQuery); + try { + return qe.execAsk(); + } finally { + qe.close(); + } + } + + private ResultSet execSelect(String queryStr) { + +// long startTime1 = System.currentTimeMillis(); +// try { +// +// RepositoryConnection conn = getConnection(); +// try { +// GraphQuery q = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryStr); +// q.evaluate(); +// } catch (MalformedQueryException e) { +// throw new RuntimeException(e); +// } finally { +// conn.close(); +// } +// } catch (Exception re) { +// //log.info(re,re); +// } + +// log.info((System.currentTimeMillis() - startTime1) + " to execute via sesame"); + + long startTime = System.currentTimeMillis(); + Query askQuery = QueryFactory.create(queryStr); + QueryExecution qe = QueryExecutionFactory.sparqlService(endpointURI, askQuery); + try { + return new ResultSetMem(qe.execSelect()); + } finally { + log.info((System.currentTimeMillis() - startTime) + " to execute via Jena"); + qe.close(); + } + } + + +}