<docbook><section><title>VirtJenaProvider</title><para>  </para>
<title> Virtuoso Jena Provider</title> Virtuoso Jena Provider
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> What is Jena?</bridgehead>
<para>Jena is an open source Semantic Web framework for Java.
 It provides an API to extract data from and write to RDF graphs.
The graphs are represented as an abstract &quot;model&quot;.
 A model can be sourced with data from files, databases, URIs or a combination of these.
 A Model can also be queried through SPARQL and updated through SPARUL.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> What is the Virtuoso Jena Provider?</bridgehead>
<para>The Virtuoso Jena RDF Data Provider is a fully operational Native Graph Model Storage Provider for the Jena Framework, which enables Semantic Web applications written using the Jena RDF Frameworks to directly query the Virtuoso RDF Quad Store.
 <ulink url="VOSDownload#Jena%20Provider">Providers are available</ulink> for the latest <ulink url="http://jena.sourceforge.net/">Jena</ulink> 2.6.x - 2.13.x, 3.0.x and 4.3.x versions.
<figure><graphic fileref="VirtJenaProvider/virt_jena_arch4.png" /></figure></para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Setup</bridgehead>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Prerequisites</bridgehead>
<ulink url="VOSDownload#Jena%20Provider">Download the latest</ulink> Virtuoso Jena Provider for your Jena framework version, Virtuoso JDBC Driver, Jena Framework, and associated classes and sample programs.<itemizedlist mark="bullet" spacing="compact"><listitem><emphasis><emphasis>Note:</emphasis> You must use a matching set of Jena Provider and JDBC Driver.</emphasis> <itemizedlist mark="bullet" spacing="compact"><listitem><emphasis>The Jena Provider for Jena 2.6 requires the Virtuoso JDBC 3 Driver.</emphasis> </listitem>
<listitem><emphasis>The Jena Provider for Jena 2.1x.x and 3.0.x requires the Virtuoso JDBC 4 Driver.</emphasis> </listitem>
<listitem><emphasis>The Jena Provider for Jena 4.3.x requires the Virtuoso JDBC 4.3 Driver.</emphasis>  </listitem>
</itemizedlist></listitem>
<listitem>The version of the Jena Provider (virt_jena.jar) can be verified thus: <programlisting>$ java -jar virt_jena4.jar 
OpenLink Virtuoso(TM) Provider for Jena(TM) Version 4.3.1 [Build 1.34]

$ java -jar virt_jena3.jar
OpenLink Virtuoso(TM) Provider for Jena(TM) Version 3.0.0 [Build 1.25]

$ java -jar ./virt_jena2.jar
OpenLink Virtuoso(TM) Provider for Jena(TM) Version 2.10.1 [Build 1.10]

$ java -jar ./virt_jena.jar
OpenLink Virtuoso(TM) Provider for Jena(TM) Version 2.6.2 [Build 1.10]
</programlisting></listitem>
<listitem>Files contained in the zip files are generally older than specifically linked downloads (e.g., the Virtuoso JDBC Driver, virtjdbc3.jar), so don&#39;t replace if prompted during extraction.
 Instead, rename the file extracted from the zip, and compare their versions to be sure you keep only the most recent.
<programlisting>$ java -cp ./virtjdbc3.jar virtuoso.jdbc3.Driver
OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.62]

$ java -cp ./virtjdbc3.fromzip.jar virtuoso.jdbc3.Driver
OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.11]
</programlisting> </listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h3"> Compiling Jena Sample Programs</bridgehead>
<orderedlist spacing="compact"><listitem>Edit the sample programs VirtuosoSPARQLExample<emphasis>X</emphasis>.java, where <emphasis>X</emphasis> = {1,2,3,4,5,6,7,8,9,13,14}.
 Set the JDBC connection strings therein to point to a valid Virtuoso Server instance, using the form: <programlisting>&quot;jdbc:virtuoso://&lt;virtuoso-hostname-or-IP-address&gt;[:&lt;data port&gt;]/charset=UTF-8/log_enable=2&quot;, &quot;&lt;username&gt;&quot;, &quot;&lt;password&gt;&quot;   
</programlisting>For example, <programlisting>&quot;jdbc:virtuoso://localhost:1111/charset=UTF-8/log_enable=2&quot;, &quot;dba&quot;, &quot;dba&quot;   
</programlisting><itemizedlist mark="bullet" spacing="compact"><listitem>Use <emphasis>charset=UTF-8</emphasis> to ensure compatibility with non-Western codepages or character sets such as Cyrillic </listitem>
<listitem>Use <emphasis>log_enable=2</emphasis> to turn on row-level autocommit, important when processing large RDF data sets </listitem>
</itemizedlist></listitem>
<listitem>Ensure your active CLASSPATH includes full paths to all of the following files <itemizedlist mark="bullet" spacing="compact"><listitem>Required Jena jar file for the version being used, as indicated in the Testing section next </listitem>
<listitem>virt_jenaX.jar - Virtuoso Jena Provider for the required version </listitem>
<listitem>virtjdbcX.jar - Virtuoso JDBC Driver for the required version </listitem>
</itemizedlist></listitem>
<listitem>Compile the Jena Sample applications using the following command: <programlisting>javac VirtuosoSPARQLExample*.java
</programlisting> </listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Testing</bridgehead>
<para>Once the Provider classes and sample program have been successfully compiled, the Provider can be tested using the included sample programs.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Prerequisites</bridgehead>
<para>Ensure your active CLASSPATH includes the full path to the directory containing the compiled <ulink url="VirtuosoSPARQLExample">VirtuosoSPARQLExample</ulink>*.class files, as well as to each of the following files depending on Jena version in use --</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h4"> Jena 2.6</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem>icu4j_3_4.jar </listitem>
<listitem>iri.jar </listitem>
<listitem>xercesImpl.jar </listitem>
<listitem>axis.jar </listitem>
<listitem>commons-logging-1.1.1.jar </listitem>
<listitem>jena.jar </listitem>
<listitem>arq.jar </listitem>
<listitem>virtjdbc3.jar </listitem>
<listitem>virt_jena.jar</listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h4"> Jena 2.7</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem>jena-arq-2.9.4.jar </listitem>
<listitem>jena-iri-0.9.4.jar </listitem>
<listitem>jena-core-2.7.4.jar </listitem>
<listitem>jcl-over-slf4j-1.6.4.jar </listitem>
<listitem>log4j-1.2.16.jarslf4j-api-1.6.4.jar </listitem>
<listitem>slf4j-log4j12-1.6.4.jar </listitem>
<listitem>xercesImpl-2.10.0.jar </listitem>
<listitem>xml-apis-1.4.01.jar </listitem>
<listitem>commons-lang3-3.4.jar </listitem>
<listitem>virtjdbc4.jar </listitem>
<listitem>virt_jena2.jar</listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h4"> Jena 2.1x.x</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem>junit-4.5.jar </listitem>
<listitem>jena-arq-2.10.1.jar </listitem>
<listitem>jena-iri-0.9.6.jar </listitem>
<listitem>jena-core-2.10.1.jar </listitem>
<listitem>jena-core-2.10.1-tests.jar </listitem>
<listitem>jcl-over-slf4j-1.6.4.jar </listitem>
<listitem>log4j-1.2.16.jar </listitem>
<listitem>slf4j-api-1.6.4.jar </listitem>
<listitem>slf4j-log4j12-1.6.4.jar </listitem>
<listitem>xercesImpl-2.11.0.jar </listitem>
<listitem>xml-apis-1.4.01.jar </listitem>
<listitem>virtjdbc4.jar </listitem>
<listitem>virt_jena2.jar</listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h4"> Jena 3.x</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem>junit-4.5.jar </listitem>
<listitem>commons-lang3-3.3.2.jar </listitem>
<listitem>jena-arq-3.0.0.jar </listitem>
<listitem>jena-iri-3.0.0.jar </listitem>
<listitem>jena-base-3.0.0.jar </listitem>
<listitem>jena-core-3.0.0.jar </listitem>
<listitem>jena-core-3.0.0-tests.jar </listitem>
<listitem>jcl-over-slf4j-1.7.12.jar </listitem>
<listitem>log4j-1.2.17.jar </listitem>
<listitem>slf4j-api-1.7.12.jar </listitem>
<listitem>slf4j-log4j12-1.7.12.jar </listitem>
<listitem>xercesImpl-2.11.0.jar </listitem>
<listitem>xml-apis-1.4.01.jar </listitem>
<listitem>jena-shaded-guava-3.0.0.jar </listitem>
<listitem>virtjdbc4.jar </listitem>
<listitem>virt_jena3.jar</listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h4"> Jena 4.3.x</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem>jena-arq-4.3.1.jar </listitem>
<listitem>jena-iri-4.3.1.jar </listitem>
<listitem>jena-core-4.3.1.jar </listitem>
<listitem>jena-base-4.3.1.jar </listitem>
<listitem>jena-shaded-guava-4.3.1.jar </listitem>
<listitem>commons-lang3-3.12.0.jar </listitem>
<listitem>commons-compress-1.21.jar </listitem>
<listitem>libthrift-0.15.0.jar </listitem>
<listitem>collection-0.7.jar </listitem>
<listitem>commons-cli-1.5.jar </listitem>
<listitem>commons-codec-1.15.jar </listitem>
<listitem>commons-csv-1.9.jar </listitem>
<listitem>commons-io-2.11.jar </listitem>
<listitem>jena-rdfconnection-4.3.1.jar </listitem>
<listitem>jena-tdb-4.3.1.jar </listitem>
<listitem>jsonld-java-0.13.3.jar </listitem>
<listitem>jackson-annotations-2.13.0.jar </listitem>
<listitem>jackson-core-2.13.0.jar </listitem>
<listitem>jackson-databind-2.13.0.jar </listitem>
<listitem>httpclient-4.5.13.jar </listitem>
<listitem>httpclient-cache-4.5.13.jar </listitem>
<listitem>httpcore-4.4.13.jar </listitem>
<listitem>jena-cmds-4.3.1.jar </listitem>
<listitem>jcl-over-slf4j-1.7.32.jar </listitem>
<listitem>log4j-api-2.15.0.jar </listitem>
<listitem>log4j-core-2.15.0.jar </listitem>
<listitem>log4j-slf4j-impl-2.15.0.jar </listitem>
<listitem>slf4j-api-1.7.32.jar</listitem>
</itemizedlist><para>If you&#39;ve extracted the zips into the same directory where you compiled the example files, a command like this should do the job -- </para>
<programlisting>export CLASSPATH=`pwd`:`pwd`/*.jar:$CLASSPATH
</programlisting><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> The Tests</bridgehead>
<orderedlist spacing="compact"><listitem><ulink url="VirtJenaSPARQLExample1">Example 1</ulink> returns the contents of the RDF Quad store of the targeted Virtuoso instance, with the following command: <programlisting>java VirtuosoSPARQLExample1
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample2">Example 2</ulink> reads in the contents of the following FOAF URIs -- <programlisting>http://kidehen.idehen.net/dataspace/person/kidehen#this
http://www.w3.org/People/Berners-Lee/card#i
http://demo.openlinksw.com/dataspace/person/demo#this
</programlisting>-- and returns the RDF data stored, with the following command: <programlisting>java VirtuosoSPARQLExample2
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample3">Example 3</ulink> performs simple addition and deletion operation on the content of the triple store, with the following command: <programlisting>java VirtuosoSPARQLExample3
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample4">Example 4</ulink> demonstrates the use of the graph.contains method for searching triples, with the following command: <programlisting>java VirtuosoSPARQLExample4
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample5">Example 5</ulink> demonstrates the use of the graph.find method for searching triples, with the following command: <programlisting>java VirtuosoSPARQLExample5
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample6">Example 6</ulink> demonstrates the use of the graph.getTransactionHandler method, with the following command: <programlisting>java VirtuosoSPARQLExample6
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample7">Example 7</ulink> demonstrates the use of the graph.getBulkUpdateHandler method, with the following command: <programlisting>java VirtuosoSPARQLExample7
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample8">Example 8</ulink> demonstrates how to insert triples into a graph, with the following command: <programlisting>java VirtuosoSPARQLExample8
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample9">Example 9</ulink> demonstrates the use of the CONSTRUCT, DESCRIBE, and ASK SPARQL query forms, with the following command: <programlisting>java VirtuosoSPARQLExample9
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample12">Example 12</ulink> demonstrates the execution of a SPARQL query against a virtuoso url and prints results, with the following command: <programlisting>java VirtuosoSPARQLExample12
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample13">Example 13</ulink> demonstrates the use of inference rules with the following command: <programlisting>java VirtuosoSPARQLExample13
</programlisting></listitem>
<listitem><ulink url="VirtJenaSPARQLExample14">Example 14</ulink> demonstrates the use of the Jena in memory Inference and Ontology Model rules with the following command: <programlisting>java VirtuosoSPARQLExample14
</programlisting> </listitem>
</orderedlist><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Javadoc API Documentation</bridgehead>
<para>Javadocs covers the complete set of classes, interfaces, and methods implemented by the provider:</para>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="http://docs.openlinksw.com/jena/">Javadoc API Documentation for the Jena 2.6 Provider</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/jena2/">Javadoc API Documentation for the Jena 2.10+ Provider</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/jena3/">Javadoc API Documentation for the Jena 3.x+ Provider</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/jena4/">Javadoc API Documentation for the Jena 4.x+ Provider</ulink></listitem>
</itemizedlist><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Notes</bridgehead>
<bridgehead class="http://www.w3.org/1999/xhtml:h3"> Bypass Jena/ARQ parser</bridgehead>
<para>To use Virtuoso-specific SPARQL extensions (such as bif:contains), queries must bypass the Jena/ARQ parser and go straight to the Virtuoso server.
 This is done by using the VirtuosoQueryExecutionFactory.create() method, instead of and without the Jena-specific QueryFactory.create() method, which always invokes the Jena/ARQ parser, which in turn rejects any Virtuoso-specific extensions.
 Thus one would execute a query as follows to bypass the Jena parser -- </para>
<programlisting>VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (query, set);
vqe.execSelect();
</programlisting><para>-- rather than -- </para>
<programlisting>Query sparql = QueryFactory.create(query);
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, set);
vqe.execSelect();
</programlisting><para> <ulink url="CategoryRDF">CategoryRDF</ulink> <ulink url="CategoryOpenSource">CategoryOpenSource</ulink> <ulink url="CategoryVirtuoso">CategoryVirtuoso</ulink> <ulink url="CategoryVOS">CategoryVOS</ulink> <ulink url="CategoryJena">CategoryJena</ulink> <ulink url="CategoryDocumentation">CategoryDocumentation</ulink></para>
<para> </para>
</section></docbook>