Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 849

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="14. RDF Data Access and Data Management" />
  <meta name="dc.subject" content="14. RDF Data Access and Data Management" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="rdfandsparql.html" title="Chapter Contents" />
  <link rel="prev" href="rdfperformancetuning.html" title="RDF Performance Tuning" />
  <link rel="next" href="rdfgraphreplication.html" title="RDF Graph Replication" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>14. RDF Data Access and Data Management</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="rdfnativestorageproviders" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>14. RDF Data Access and Data Management</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="rdfandsparql.html">Chapter Contents</a> | <a class="link" href="rdfperformancetuning.html" title="RDF Performance Tuning">Prev</a> | <a class="link" href="rdfgraphreplication.html" title="RDF Graph Replication">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="rdfandsparql.html">RDF Data Access and Data Management</a>
   </div>
    <br />
   <div>
      <a href="rdfdatarepresentation.html">Data Representation</a>
   </div>
   <div>
      <a href="rdfsparql.html">SPARQL</a>
   </div>
   <div>
      <a href="sparqlextensions.html">Extensions</a>
   </div>
   <div>
      <a href="rdfgraphsecurity.html">RDF Graphs Security</a>
   </div>
   <div>
      <a href="rdfviews.html">Linked Data Views over RDBMS Data Source</a>
   </div>
   <div>
      <a href="rdfrdfviewgnr.html">Automated Generation of RDF Views over Relational Data Sources</a>
   </div>
   <div>
      <a href="rdfviewsenterpr.html">Examples of Linked Data Views</a>
   </div>
   <div>
      <a href="rdfinsertmethods.html">RDF Insert Methods in Virtuoso</a>
   </div>
   <div>
      <a href="virtuososponger.html">RDFizer Middleware (Sponger)</a>
   </div>
   <div>
      <a href="virtuosospongerfacetinstall.html">Virtuoso Faceted Browser Installation and configuration</a>
   </div>
   <div>
      <a href="virtuosospongerfacent.html">Virtuoso Faceted Web Service</a>
   </div>
   <div>
      <a href="rdfiridereferencing.html">Linked Data</a>
   </div>
   <div>
      <a href="rdfsparqlrule.html">Inference Rules &amp; Reasoning</a>
   </div>
   <div>
      <a href="rdfsparqlgeospat.html">RDF and Geometry</a>
   </div>
   <div>
      <a href="rdfperformancetuning.html">RDF Performance Tuning</a>
   </div>
   <div class="selected">
      <a href="rdfnativestorageproviders.html">RDF Data Access Providers (Drivers)</a>
    <div>
        <a href="#rdfnativestorageprovidersjena" title="Virtuoso Jena Provider">Virtuoso Jena Provider</a>
        <a href="#rdfnativestorageproviderssesame" title="Virtuoso Sesame Provider">Virtuoso Sesame Provider</a>
        <a href="#rdfnativestorageproviderredland" title="Virtuoso Redland Provider">Virtuoso Redland Provider</a>
    </div>
   </div>
   <div>
      <a href="rdfgraphreplication.html">RDF Graph Replication</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="rdfnativestorageproviders" />
    <h2>14.16. RDF Data Access Providers (Drivers)</h2>
  <a name="rdfnativestorageprovidersjena" />
    <h3>14.16.1. Virtuoso Jena Provider</h3>
    <a name="rdfnativestorageprovidersjenawhatis" />
    <h4>14.16.1.1. What is Jena</h4>
    <p>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.
    </p>
    <br />
    <a name="rdfnativestorageprovidersjenawhatisv" />
    <h4>14.16.1.2. What is the Virtuoso Jena Provider</h4>
    <p>The Virtuoso Jena RDF Data Provider is a fully operational Native Graph Model Storage
Provider for the Jena Framework, enables Semantic Web applications written using the Jena RDF
Frameworks to query the Virtuoso RDF Quad store directly. The Provider has been tested against
the <a href="http://jena.sourceforge.net/">Jena 2.5.5</a> version currently available.
    </p>
    <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="Virtuoso Jena RDF Data Provider" src="../images/ui/VirtJenaProvider.png" />
     </td>
    </tr>
    <tr>
        <td>Figure: 14.16.1.2.1. Virtuoso Jena RDF Data Provider</td>
    </tr>
    </table>
    <br />
    <a name="rdfnativestorageprovidersjenasetup" />
    <h4>14.16.1.3. Setup</h4>
    <a name="rdfnativestorageprovidersjenareqfiles" />
    <h5>14.16.1.3.1. Required Files</h5>
    <ul>
      <li>Virtuoso Jena Provider JAR file, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload/virt_jena.jar">virt_jena.jar</a>
      </li>
      <li>Virtuoso JDBC Driver 3 JAR file, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload/virtjdbc3.jar">virtjdbc3.jar</a>
      </li>
      <li>Virtuoso JDBC Driver 4 JAR file, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload/virtjdbc4.jar">virtjdbc4.jar</a>
      </li>      
      <li>Jena Framework and associated classes, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload/jenajars.zip">jenajars.zip</a>
      </li>
      <li>Sample programs, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload/virtjenasamples.zip">virtjenasamples.zip</a>
      </li>
    </ul>
    <br />
    <a name="rdfnativestorageprovidersjenacmsmpr" />
    <h5>14.16.1.3.2. Compiling Jena Sample Programs</h5>
    <ol>
      <li>Edit the sample programs VirtuosoSPARQLExampleX.java, where X = 1 to 9.
Set the JDBC connection strings within to point to a valid Virtuoso Server instance of the form:
<div>
          <pre class="programlisting">
&quot;jdbc:virtuoso://localhost:1111/charset=UTF-8/log_enable=2&quot;
</pre>
        </div>
      <ul>
         <li>charset=UTF-8  will be added by Jena provider, if it isn&#39;t in connection string.
So now you don&#39;t need add &quot;charset=UTF-8&quot; to the connection string any more, it is done by Jena provider.

         </li>
         <li>log_enable=2: to use row auto commit
         </li>
         <li>use these settings to process large rdf data.
         </li>
      </ul>
      </li>
      <li>Ensure that full paths to <strong>jena.jar, arq.jar,</strong> and
<strong>virtjdbc3.jar</strong> are included in the active CLASSPATH setting.
      </li>
      <li>Compile the Jena Sample applications using the following command:
<div>
          <pre class="programlisting">
javac -cp &quot;jena.jar:arq.jar:virtjdbc3.jar:virt_jena.jar:.&quot; VirtuosoSPARQLExample1.java
VirtuosoSPARQLExample2.java VirtuosoSPARQLExample3.java VirtuosoSPARQLExample4.java
VirtuosoSPARQLExample5.java VirtuosoSPARQLExample6.java VirtuosoSPARQLExample7.java
VirtuosoSPARQLExample8.java VirtuosoSPARQLExample9.java
</pre>
        </div>
      </li>
    </ol>
    <br />
    <a name="rdfnativestorageprovidersjenatesting" />
    <h5>14.16.1.3.3. Testing</h5>
    <p>Once the Provider classes and sample program have been successfully compiled,
the Provider can be tested using the sample programs included. Ensure your active CLASSPATH
includes full paths to all of the following files, before executing the example commands:
    </p>
    <ul>
      <li>icu4j_3_4.jar</li>
      <li>iri.jar</li>
      <li>xercesImpl.jar</li>
      <li>axis.jar</li>
      <li>commons-logging-1.1.1.jar</li>
      <li>jena.jar</li>
      <li>arq.jar</li>
      <li>virtjdbc3.jar</li>
      <li>virt_jena.jar</li>
    </ul>
    <ol>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples1">VirtuosoSPARQLExample1</a> returns the contents of the RDF Quad store of the targeted Virtuoso instance, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample1
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples2">VirtuosoSPARQLExample2</a> reads in the contents of the following FOAF URIs --
<div>
          <pre class="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
</pre>
        </div>
      <p>-- and returns the RDF data stored, with the following command:</p>
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample2
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples3">VirtuosoSPARQLExample3</a> performs simple addition and deletion operation on
the content of the triple store, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample3
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples4">VirtuosoSPARQLExample4</a> demonstrates the use of the <strong>graph.contains</strong> method for searching triples, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample4
</pre>
        </div>
</li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples5">VirtuosoSPARQLExample5</a> demonstrates the use of the <strong>graph.find</strong> method for searching triples, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample5
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples6">VirtuosoSPARQLExample6</a> demonstrates the use of the <strong>graph.getTransactionHandler</strong> method, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample6
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples7">VirtuosoSPARQLExample7</a> demonstrates the use of the graph.getBulkUpdateHandler method, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample7
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples8">VirtuosoSPARQLExample8</a> demonstrates how to insert triples into a graph, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample8
</pre>
        </div>
      </li>
      <li>
        <a href="rdfnativestorageproviders.html#rdfnativestorageprovidersjenaexamples9">VirtuosoSPARQLExample9</a> demonstrates the use of the <strong>CONSTRUCT, DESCRIBE,</strong> and <strong>ASK</strong> SPARQL query forms, with the following command:
<div>
          <pre class="programlisting">
java VirtuosoSPARQLExample9
</pre>
        </div>
     </li>
    </ol>
    <br />
    <br />
    <a name="rdfnativestorageprovidersjenaexamples" />
    <h4>14.16.1.4. Examples</h4>
    <a name="rdfnativestorageprovidersjenaexamples1" />
    <h5>14.16.1.4.1. VirtJenaSPARQLExample1</h5>
<div>
      <pre class="programlisting">
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample1 {

	/**
	 * Executes a SPARQL query against a virtuoso url and prints results.
	 */
	public static void main(String[] args) {

		String url;
		if(args.length == 0)
		    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
		else
		    url = args[0];

/*			STEP 1			*/
		VirtGraph set = new VirtGraph (url, &quot;dba&quot;, &quot;dba&quot;);

/*			STEP 2			*/


/*			STEP 3			*/
/*		Select all data in virtuoso	*/
		Query sparql = QueryFactory.create(&quot;SELECT * WHERE { GRAPH ?graph { ?s ?p ?o } } limit 100&quot;);

/*			STEP 4			*/
		VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, set);

		ResultSet results = vqe.execSelect();
		while (results.hasNext()) {
			QuerySolution result = results.nextSolution();
		    RDFNode graph = result.get(&quot;graph&quot;);
		    RDFNode s = result.get(&quot;s&quot;);
		    RDFNode p = result.get(&quot;p&quot;);
		    RDFNode o = result.get(&quot;o&quot;);
		    System.out.println(graph + &quot; { &quot; + s + &quot; &quot; + p + &quot; &quot; + o + &quot; . }&quot;);
		}
	}
}

</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples2" />
    <h5>14.16.1.4.2. VirtJenaSPARQLExample2</h5>
<div>
      <pre class="programlisting">
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample2 {

	/**
	 * Executes a SPARQL query against a virtuoso url and prints results.
	 */
	public static void main(String[] args) {

		String url;
		if(args.length == 0)
		    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
		else
		    url = args[0];

/*			STEP 1			*/
		VirtGraph graph = new VirtGraph (&quot;Example2&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

/*			STEP 2			*/
/*		Load data to Virtuoso		*/
		graph.clear ();

		System.out.print (&quot;Begin read from &#39;http://www.w3.org/People/Berners-Lee/card#i&#39;  &quot;);
		graph.read(&quot;http://www.w3.org/People/Berners-Lee/card#i&quot;, &quot;RDF/XML&quot;);
		System.out.println (&quot;\t\t\t Done.&quot;);

		System.out.print (&quot;Begin read from &#39;http://demo.openlinksw.com/dataspace/person/demo#this&#39;  &quot;);
		graph.read(&quot;http://demo.openlinksw.com/dataspace/person/demo#this&quot;, &quot;RDF/XML&quot;);
		System.out.println (&quot;\t Done.&quot;);

		System.out.print (&quot;Begin read from &#39;http://kidehen.idehen.net/dataspace/person/kidehen#this&#39;  &quot;);
		graph.read(&quot;http://kidehen.idehen.net/dataspace/person/kidehen#this&quot;, &quot;RDF/XML&quot;);
		System.out.println (&quot;\t Done.&quot;);


/*			STEP 3			*/
/*		Select only from VirtGraph	*/
		Query sparql = QueryFactory.create(&quot;SELECT ?s ?p ?o WHERE { ?s ?p ?o }&quot;);

/*			STEP 4			*/
		VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, graph);

		ResultSet results = vqe.execSelect();
		while (results.hasNext()) {
			QuerySolution result = results.nextSolution();
		    RDFNode graph_name = result.get(&quot;graph&quot;);
		    RDFNode s = result.get(&quot;s&quot;);
		    RDFNode p = result.get(&quot;p&quot;);
		    RDFNode o = result.get(&quot;o&quot;);
		    System.out.println(graph_name + &quot; { &quot; + s + &quot; &quot; + p + &quot; &quot; + o + &quot; . }&quot;);
		}

		System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());
	}
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples3" />
    <h5>14.16.1.4.3. VirtJenaSPARQLExample3</h5>
<div>
      <pre class="programlisting">
import java.util.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample3
{
    public static void main(String[] args)
    {
	String url;

	if(args.length == 0)
	    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
	else
	    url = args[0];

	Node foo1 = Node.createURI(&quot;http://example.org/#foo1&quot;);
	Node bar1 = Node.createURI(&quot;http://example.org/#bar1&quot;);
	Node baz1 = Node.createURI(&quot;http://example.org/#baz1&quot;);

	Node foo2 = Node.createURI(&quot;http://example.org/#foo2&quot;);
	Node bar2 = Node.createURI(&quot;http://example.org/#bar2&quot;);
	Node baz2 = Node.createURI(&quot;http://example.org/#baz2&quot;);

	Node foo3 = Node.createURI(&quot;http://example.org/#foo3&quot;);
	Node bar3 = Node.createURI(&quot;http://example.org/#bar3&quot;);
	Node baz3 = Node.createURI(&quot;http://example.org/#baz3&quot;);

	List &lt;Triple&gt; triples = new ArrayList &lt;Triple&gt; ();

	VirtGraph graph = new VirtGraph (&quot;Example3&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

	graph.clear ();

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;Add 3 triples to graph &lt;Example3&gt;.&quot;);

	graph.add(new Triple(foo1, bar1, baz1));
	graph.add(new Triple(foo2, bar2, baz2));
	graph.add(new Triple(foo3, bar3, baz3));

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	triples.add(new Triple(foo1, bar1, baz1));
	triples.add(new Triple(foo2, bar2, baz2));

	graph.isEmpty();

	System.out.println(&quot;Remove 2 triples from graph &lt;Example3&gt;&quot;);
	graph.remove(triples);
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());
	System.out.println(&quot;Please check result with isql tool.&quot;);

	/* EXPECTED RESULT:

SQL&gt; SPARQL
SELECT ?s ?p ?o
FROM &lt;Example3&gt;
WHERE {?s ?p ?o};
s                                                    p                                                             o
VARCHAR                                    VARCHAR                                              VARCHAR
_______________________________________________________________________________

http://example.org/#foo3              http://example.org/#bar3                         http://example.org/#baz3

1 Rows. -- 26 msec.
SQL&gt;

*/

	}
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples4" />
    <h5>14.16.1.4.4. VirtJenaSPARQLExample4</h5>
<div>
      <pre class="programlisting">
import java.util.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample4
{

    public static void main(String[] args)
    {
	String url;
	if(args.length == 0)
	    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
	else
	    url = args[0];

	Node foo1 = Node.createURI(&quot;http://example.org/#foo1&quot;);
	Node bar1 = Node.createURI(&quot;http://example.org/#bar1&quot;);
	Node baz1 = Node.createURI(&quot;http://example.org/#baz1&quot;);

	Node foo2 = Node.createURI(&quot;http://example.org/#foo2&quot;);
	Node bar2 = Node.createURI(&quot;http://example.org/#bar2&quot;);
	Node baz2 = Node.createURI(&quot;http://example.org/#baz2&quot;);

	Node foo3 = Node.createURI(&quot;http://example.org/#foo3&quot;);
	Node bar3 = Node.createURI(&quot;http://example.org/#bar3&quot;);
	Node baz3 = Node.createURI(&quot;http://example.org/#baz3&quot;);

	VirtGraph graph = new VirtGraph (&quot;Example4&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

	graph.clear ();

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());

	System.out.println(&quot;Add 3 triples to graph &lt;Example4&gt;.&quot;);

	graph.add(new Triple(foo1, bar1, baz1));
	graph.add(new Triple(foo2, bar2, baz2));
	graph.add(new Triple(foo3, bar3, baz3));

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	System.out.println (&quot;graph.contains(new Triple(foo2, bar2, baz2) - &quot; + graph.contains(new Triple(foo2, bar2, baz2)));
	System.out.println (&quot;graph.contains(new Triple(foo2, bar2, baz3) - &quot; + graph.contains(new Triple(foo2, bar2, baz3)));

	graph.clear ();

    }
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples5" />
    <h5>14.16.1.4.5. VirtJenaSPARQLExample5</h5>
<div>
      <pre class="programlisting">
import java.util.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample5
{

    public static void main(String[] args)
    {
	String url;
	if(args.length == 0)
	    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
	else
	    url = args[0];

	Node foo1 = Node.createURI(&quot;http://example.org/#foo1&quot;);
	Node bar1 = Node.createURI(&quot;http://example.org/#bar1&quot;);
	Node baz1 = Node.createURI(&quot;http://example.org/#baz1&quot;);

	Node foo2 = Node.createURI(&quot;http://example.org/#foo2&quot;);
	Node bar2 = Node.createURI(&quot;http://example.org/#bar2&quot;);
	Node baz2 = Node.createURI(&quot;http://example.org/#baz2&quot;);

	Node foo3 = Node.createURI(&quot;http://example.org/#foo3&quot;);
	Node bar3 = Node.createURI(&quot;http://example.org/#bar3&quot;);
	Node baz3 = Node.createURI(&quot;http://example.org/#baz3&quot;);

	VirtGraph graph = new VirtGraph (&quot;Example5&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

	graph.clear ();

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());

	System.out.println(&quot;Add 3 triples to graph &lt;Example5&gt;.&quot;);

	graph.add(new Triple(foo1, bar1, baz1));
	graph.add(new Triple(foo2, bar2, baz2));
	graph.add(new Triple(foo3, bar3, baz3));
	graph.add(new Triple(foo1, bar2, baz2));
	graph.add(new Triple(foo1, bar3, baz3));

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	ExtendedIterator iter = graph.find(foo1, Node.ANY, Node.ANY);
	System.out.println (&quot;\ngraph.find(foo1, Node.ANY, Node.ANY) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	iter = graph.find(Node.ANY, Node.ANY, baz3);
	System.out.println (&quot;\ngraph.find(Node.ANY, Node.ANY, baz3) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	iter = graph.find(foo1, Node.ANY, baz3);
	System.out.println (&quot;\ngraph.find(foo1, Node.ANY, baz3) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	graph.clear ();

    }
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples6" />
    <h5>14.16.1.4.6. VirtJenaSPARQLExample6</h5>
<div>
      <pre class="programlisting">
import java.util.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample6
{

    public static void main(String[] args)
    {
	String url;
	if(args.length == 0)
	    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
	else
	    url = args[0];

	Node foo1 = Node.createURI(&quot;http://example.org/#foo1&quot;);
	Node bar1 = Node.createURI(&quot;http://example.org/#bar1&quot;);
	Node baz1 = Node.createURI(&quot;http://example.org/#baz1&quot;);

	Node foo2 = Node.createURI(&quot;http://example.org/#foo2&quot;);
	Node bar2 = Node.createURI(&quot;http://example.org/#bar2&quot;);
	Node baz2 = Node.createURI(&quot;http://example.org/#baz2&quot;);

	Node foo3 = Node.createURI(&quot;http://example.org/#foo3&quot;);
	Node bar3 = Node.createURI(&quot;http://example.org/#bar3&quot;);
	Node baz3 = Node.createURI(&quot;http://example.org/#baz3&quot;);

	VirtGraph graph = new VirtGraph (&quot;Example6&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

	graph.clear ();

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());

	System.out.println(&quot;test Transaction Commit.&quot;);
	graph.getTransactionHandler().begin();
	System.out.println(&quot;begin Transaction.&quot;);
	System.out.println(&quot;Add 3 triples to graph &lt;Example6&gt;.&quot;);

	graph.add(new Triple(foo1, bar1, baz1));
	graph.add(new Triple(foo2, bar2, baz2));
	graph.add(new Triple(foo3, bar3, baz3));

	graph.getTransactionHandler().commit();
	System.out.println(&quot;commit Transaction.&quot;);
	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	ExtendedIterator iter = graph.find(Node.ANY, Node.ANY, Node.ANY);
	System.out.println (&quot;\ngraph.find(Node.ANY, Node.ANY, Node.ANY) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	graph.clear ();
	System.out.println(&quot;\nCLEAR graph &lt;Example6&gt;&quot;);
	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());

	System.out.println(&quot;Add 1 triples to graph &lt;Example6&gt;.&quot;);
	graph.add(new Triple(foo1, bar1, baz1));

	System.out.println(&quot;test Transaction Abort.&quot;);
	graph.getTransactionHandler().begin();
	System.out.println(&quot;begin Transaction.&quot;);
	System.out.println(&quot;Add 2 triples to graph &lt;Example6&gt;.&quot;);

	graph.add(new Triple(foo2, bar2, baz2));
	graph.add(new Triple(foo3, bar3, baz3));

	graph.getTransactionHandler().abort();
	System.out.println(&quot;abort Transaction.&quot;);
	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	iter = graph.find(Node.ANY, Node.ANY, Node.ANY);
	System.out.println (&quot;\ngraph.find(Node.ANY, Node.ANY, Node.ANY) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	graph.clear ();
	System.out.println(&quot;\nCLEAR graph &lt;Example6&gt;&quot;);

    }
}


</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples7" />
    <h5>14.16.1.4.7. VirtJenaSPARQLExample7</h5>
<div>
      <pre class="programlisting">
import java.util.*;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample7
{

    public static void main(String[] args)
    {
	String url;
	if(args.length == 0)
	    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
	else
	    url = args[0];

	Node foo1 = Node.createURI(&quot;http://example.org/#foo1&quot;);
	Node bar1 = Node.createURI(&quot;http://example.org/#bar1&quot;);
	Node baz1 = Node.createURI(&quot;http://example.org/#baz1&quot;);

	Node foo2 = Node.createURI(&quot;http://example.org/#foo2&quot;);
	Node bar2 = Node.createURI(&quot;http://example.org/#bar2&quot;);
	Node baz2 = Node.createURI(&quot;http://example.org/#baz2&quot;);

	Node foo3 = Node.createURI(&quot;http://example.org/#foo3&quot;);
	Node bar3 = Node.createURI(&quot;http://example.org/#bar3&quot;);
	Node baz3 = Node.createURI(&quot;http://example.org/#baz3&quot;);

	List triples1 = new ArrayList();
	triples1.add(new Triple(foo1, bar1, baz1));
	triples1.add(new Triple(foo2, bar2, baz2));
	triples1.add(new Triple(foo3, bar3, baz3));

	List triples2 = new ArrayList();
	triples2.add(new Triple(foo1, bar1, baz1));
	triples2.add(new Triple(foo2, bar2, baz2));

	VirtGraph graph = new VirtGraph (&quot;Example7&quot;, url, &quot;dba&quot;, &quot;dba&quot;);

	graph.clear ();

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;Add List with 3 triples to graph &lt;Example7&gt; via BulkUpdateHandler.&quot;);

	graph.getBulkUpdateHandler().add(triples1);

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	ExtendedIterator iter = graph.find(Node.ANY, Node.ANY, Node.ANY);
	System.out.println (&quot;\ngraph.find(Node.ANY, Node.ANY, Node.ANY) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());


	System.out.println(&quot;\n\nDelete List of 2 triples from graph &lt;Example7&gt; via BulkUpdateHandler.&quot;);

	graph.getBulkUpdateHandler().delete(triples2);

	System.out.println(&quot;graph.isEmpty() = &quot; + graph.isEmpty());
	System.out.println(&quot;graph.getCount() = &quot; + graph.getCount());

	iter = graph.find(Node.ANY, Node.ANY, Node.ANY);
	System.out.println (&quot;\ngraph.find(Node.ANY, Node.ANY, Node.ANY) \nResult:&quot;);
	for ( ; iter.hasNext() ; )
	    System.out.println ((Triple) iter.next());

	graph.clear ();
	System.out.println(&quot;\nCLEAR graph &lt;Example7&gt;&quot;);

    }
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples8" />
    <h5>14.16.1.4.8. VirtJenaSPARQLExample8</h5>
<div>
      <pre class="programlisting">
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample8 {

	/**
	 * Executes a SPARQL query against a virtuoso url and prints results.
	 */
	public static void main(String[] args) {

		String url;
		if(args.length == 0)
		    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
		else
		    url = args[0];

/*			STEP 1			*/
		VirtGraph set = new VirtGraph (url, &quot;dba&quot;, &quot;dba&quot;);

/*			STEP 2			*/
System.out.println(&quot;\nexecute: CLEAR GRAPH &lt;http://test1&gt;&quot;);
                String str = &quot;CLEAR GRAPH &lt;http://test1&gt;&quot;;
                VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, set);
                vur.exec();

System.out.println(&quot;\nexecute: INSERT INTO GRAPH &lt;http://test1&gt; { &lt;aa&gt; &lt;bb&gt; &#39;cc&#39; . &lt;aa1&gt; &lt;bb1&gt; 123. }&quot;);
                str = &quot;INSERT INTO GRAPH &lt;http://test1&gt; { &lt;aa&gt; &lt;bb&gt; &#39;cc&#39; . &lt;aa1&gt; &lt;bb1&gt; 123. }&quot;;
                vur = VirtuosoUpdateFactory.create(str, set);
                vur.exec();

/*			STEP 3			*/
/*		Select all data in virtuoso	*/
System.out.println(&quot;\nexecute: SELECT * FROM &lt;http://test1&gt; WHERE { ?s ?p ?o }&quot;);
		Query sparql = QueryFactory.create(&quot;SELECT * FROM &lt;http://test1&gt; WHERE { ?s ?p ?o }&quot;);

/*			STEP 4			*/
		VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, set);

		ResultSet results = vqe.execSelect();
		while (results.hasNext()) {
			QuerySolution rs = results.nextSolution();
		    RDFNode s = rs.get(&quot;s&quot;);
		    RDFNode p = rs.get(&quot;p&quot;);
		    RDFNode o = rs.get(&quot;o&quot;);
		    System.out.println(&quot; { &quot; + s + &quot; &quot; + p + &quot; &quot; + o + &quot; . }&quot;);
    }


System.out.println(&quot;\nexecute: DELETE FROM GRAPH &lt;http://test1&gt; { &lt;aa&gt; &lt;bb&gt; &#39;cc&#39; }&quot;);
                str = &quot;DELETE FROM GRAPH &lt;http://test1&gt; { &lt;aa&gt; &lt;bb&gt; &#39;cc&#39; }&quot;;
                vur = VirtuosoUpdateFactory.create(str, set);
                vur.exec();

System.out.println(&quot;\nexecute: SELECT * FROM &lt;http://test1&gt; WHERE { ?s ?p ?o }&quot;);
		vqe = VirtuosoQueryExecutionFactory.create (sparql, set);
                results = vqe.execSelect();
		while (results.hasNext()) {
			QuerySolution rs = results.nextSolution();
		    RDFNode s = rs.get(&quot;s&quot;);
		    RDFNode p = rs.get(&quot;p&quot;);
		    RDFNode o = rs.get(&quot;o&quot;);
		    System.out.println(&quot; { &quot; + s + &quot; &quot; + p + &quot; &quot; + o + &quot; . }&quot;);
    }


}
}
</pre>
    </div>
    <br />
    <a name="rdfnativestorageprovidersjenaexamples9" />
    <h5>14.16.1.4.9. VirtJenaSPARQLExample9</h5>
<div>
      <pre class="programlisting">
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.rdf.model.*;
import java.util.Iterator;

import virtuoso.jena.driver.*;

public class VirtuosoSPARQLExample9 {

	/**
	 * Executes a SPARQL query against a virtuoso url and prints results.
	 */
	public static void main(String[] args) {

		String url;
		if(args.length == 0)
		    url = &quot;jdbc:virtuoso://localhost:1111&quot;;
		else
		    url = args[0];

/*			STEP 1			*/
		VirtGraph set = new VirtGraph (url, &quot;dba&quot;, &quot;dba&quot;);

/*			STEP 2			*/
                String str = &quot;CLEAR GRAPH &lt;http://test1&gt;&quot;;
                VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, set);
                vur.exec();

                str = &quot;INSERT INTO GRAPH &lt;http://test1&gt; { &lt;http://aa&gt; &lt;http://bb&gt; &#39;cc&#39; . &lt;http://aa1&gt; &lt;http://bb&gt; 123. }&quot;;
                vur = VirtuosoUpdateFactory.create(str, set);
                vur.exec();


/*		Select all data in virtuoso	*/
		Query sparql = QueryFactory.create(&quot;SELECT * FROM &lt;http://test1&gt; WHERE { ?s ?p ?o }&quot;);
		VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, set);
		ResultSet results = vqe.execSelect();
                System.out.println(&quot;\nSELECT results:&quot;);
		while (results.hasNext()) {
			QuerySolution rs = results.nextSolution();
		    RDFNode s = rs.get(&quot;s&quot;);
		    RDFNode p = rs.get(&quot;p&quot;);
		    RDFNode o = rs.get(&quot;o&quot;);
		    System.out.println(&quot; { &quot; + s + &quot; &quot; + p + &quot; &quot; + o + &quot; . }&quot;);
}

		sparql = QueryFactory.create(&quot;DESCRIBE &lt;http://aa&gt; FROM &lt;http://test1&gt;&quot;);
		vqe = VirtuosoQueryExecutionFactory.create (sparql, set);

		Model model = vqe.execDescribe();
 	        Graph g = model.getGraph();
                System.out.println(&quot;\nDESCRIBE results:&quot;);
	        for (Iterator i = g.find(Node.ANY, Node.ANY, Node.ANY); i.hasNext();)
{
	              Triple t = (Triple)i.next();
		      System.out.println(&quot; { &quot; + t.getSubject() + &quot; &quot; +
		      				 t.getPredicate() + &quot; &quot; +
		      				 t.getObject() + &quot; . }&quot;);
	        }



		sparql = QueryFactory.create(&quot;CONSTRUCT { ?x &lt;http://test&gt; ?y } FROM &lt;http://test1&gt; WHERE { ?x &lt;http://bb&gt; ?y }&quot;);
		vqe = VirtuosoQueryExecutionFactory.create (sparql, set);

		model = vqe.execConstruct();
 	        g = model.getGraph();
                System.out.println(&quot;\nCONSTRUCT results:&quot;);
	        for (Iterator i = g.find(Node.ANY, Node.ANY, Node.ANY); i.hasNext();)
    {
	              Triple t = (Triple)i.next();
		      System.out.println(&quot; { &quot; + t.getSubject() + &quot; &quot; +
		      				 t.getPredicate() + &quot; &quot; +
		      				 t.getObject() + &quot; . }&quot;);
	        }


		sparql = QueryFactory.create(&quot;ASK FROM &lt;http://test1&gt; WHERE { &lt;http://aa&gt; &lt;http://bb&gt; ?y }&quot;);
		vqe = VirtuosoQueryExecutionFactory.create (sparql, set);

		boolean res = vqe.execAsk();
                System.out.println(&quot;\nASK results: &quot;+res);


    }
}
</pre>
    </div>
    <br />
    <br />
    <a name="rdfnativestorageprovidersjenajavadoc" />
    <h4>14.16.1.5. Javadoc API Documentation</h4>
    <p>
      <a href="http://docs.openlinksw.com/jena/">Jena Provider Javadoc API Documentation</a> is available enabling the complete set of classes, interfaces and methods implemented for the provider to be viewed.
</p>
    <br />
<br />  
  <a name="rdfnativestorageproviderssesame" />
    <h3>14.16.2. Virtuoso Sesame Provider</h3>
    <a name="rdfnativestorageproviderssesamewhatis" />
    <h4>14.16.2.1. What is Sesame</h4>
      <p>Sesame is an open source Java framework for storing, querying and reasoning with RDF and RDF Schema. It can be used as a database for RDF and RDF Schema, or as a Java library for applications that need to work with RDF internally. For example, suppose you need to read a big RDF file, find the relevant information for your application, and use that information. Sesame provides you with the necessary tools to parse, interpret, query and store all this information, embedded in your own application if you want, or, if you prefer, in a separate database or even on a remote server. More generally: Sesame provides an application developer a toolbox that contains useful hammers screwdrivers etc. for doing &#39;Do-It-Yourself&#39; with RDF.
    </p>
    <br />
    <a name="rdfnativestorageproviderssesamewhatisvirtuososesameprovider" />
    <h4>14.16.2.2. What is the Virtuoso Sesame Provider</h4>
    <p>The Virtuoso Sesame Provider is a fully operational Native Graph Model Storage Providers for the Sesame Framework, allowing users of Virtuoso to leverage the Sesame framework for modifying, querying, and reasoning with the Virtuoso quad store using the Java language. The Sesame Repository API offers a central access point for connecting to the Virtuoso quad store. Its purpose is to provides a java-friendly access point to Virtuoso. It offers various methods for querying and updating the data, while abstracting the details of the underlying machinery. The Provider has been tested against the <a href="http://sourceforge.net/project/showfiles.php?group_id=46509&amp;package_id=168413">Sesame 2.1.2</a> version currently available.
    </p>
    <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="Fig. 1 Sesame Component Stack" src="../images/ui/VirtSesame2Provider.png" />
     </td>
    </tr>
    <tr>
        <td>Figure: 14.16.2.2.1. Fig. 1 Sesame Component Stack</td>
    </tr>
    </table>
    <p>If you need more information about how to set up your environment for working with the Sesame APIs, take a look at Chapter 4 of the Sesame User Guide, <a href="http://www.openrdf.org/doc/sesame2/users/RDF">Setting up to use the Sesame libraries</a>.
    </p>
    <br />
    <a name="rdfnativestorageproviderssesamesetup" />
    <h4>14.16.2.3. Setup</h4>
    <a name="rdfnativestorageproviderssesamereqfiles" />
    <h5>14.16.2.3.1. Required Files</h5>
    <p>This tutorial assumes you have Virtuoso server installed and that the database is accessible at &quot;localhost:1111&quot;. In addition, you will need the latest version of the Virtuoso Sesame Provider, and Sesame 2 or greater installed.
    <p>You should download the Virtuoso Sesame 2 Provider JAR archive, Virtuoso JDBC Driver, Sesame Framework and associated classes and sample programs from our <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSDownload">download page</a>
      </p>
    </p>
    <br />
    <a name="rdfnativestorageproviderssesamecmppr" />
    <h5>14.16.2.3.2. Compiling Sesame Sample Program</h5>
    <ol>
      <li>Ensure that full paths to the following files are all included in the active CLASSPATH setting --
    <ul>
      <li>openrdf-sesame-2.1.2-onejar.jar</li>
      <li>slf4j-api-1.5.0.jar</li>
      <li>slf4j-jdk14-1.5.0.jar</li>
      <li>virtjdbc3.jar</li>
      <li>virt_sesame2.jar</li>
   </ul>
      </li>
      <li>Execute the following command:
<div>
          <pre class="programlisting">
javac VirtuosoTest.java
</pre>
        </div>
      <p>Note: to use utf-8 and to use row auto commit is recommended to add the following to the connect string: 
      </p>
<div>
          <pre class="programlisting">
&quot;/charset=UTF-8/log_enable=2&quot;
-- i.e. in VirtuosoTest.java the line:
Repository repository = new VirtuosoRepository(&quot;jdbc:virtuoso://&quot; + sa[0] + &quot;:&quot; + sa[1], sa[2], sa[3]);
-- should become:
Repository repository = new VirtuosoRepository(&quot;jdbc:virtuoso://&quot; + sa[0] + &quot;:&quot; + sa[1]+ &quot;/charset=UTF-8/log_enable=2&quot;, sa[2], sa[3]);
</pre>
        </div>
      </li>
    </ol>
    <br />
    <a name="rdfnativestorageproviderssesametesting" />
    <h5>14.16.2.3.3. Testing</h5>
    <ol>
      <li>Ensure that full paths to the following files are all included in the active CLASSPATH setting:
    <ul>
      <li>openrdf-sesame-2.1.2-onejar.jar</li>
      <li>slf4j-api-1.5.0.jar</li>
      <li>slf4j-jdk14-1.5.0.jar</li>
      <li>virtjdbc3.jar</li>
      <li>virt_sesame2.jar</li>
      <li>virtuoso_driver</li>
    </ul>
      </li>
      <li>Run the <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtSesame2Provider?att=VirtuosoTest.java">VirtuosoTest</a> program to test the Sesame 2 Provider with the following command:
<div>
          <pre class="programlisting">
java VirtuosoTest &lt;hostname&gt; &lt;port&gt; &lt;uid&gt; &lt;pwd&gt;
</pre>
        </div>
      </li>
      <li>The test run should look like this:
<div>
          <pre class="programlisting">
$ java VirtuosoTest localhost 1111 dba dba

== TEST 1:  : Start
   Loading data from URL: http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com/foaf.rdf
== TEST 1:  : End
PASSED: TEST 1

== TEST 2:  : Start
   Clearing triple store
== TEST 2:  : End
PASSED: TEST 2

== TEST 3:  : Start
   Loading data from file: virtuoso_driver/data.nt
== TEST 3:  : End
PASSED: TEST 3

== TEST 4:  : Start
   Loading UNICODE single triple
== TEST 4:  : End
PASSED: TEST 4

== TEST 5:  : Start
   Loading single triple
== TEST 5:  : End
PASSED: TEST 5

== TEST 6:  : Start
   Casted value type
== TEST 6:  : End
PASSED: TEST 6

== TEST 7:  : Start
   Selecting property
== TEST 7:  : End
PASSED: TEST 7

== TEST 8:  : Start
   Statement does not exists
== TEST 8:  : End
PASSED: TEST 8

== TEST 9:  : Start
   Statement exists (by resultset size)
== TEST 9:  : End
PASSED: TEST 9

== TEST 10:  : Start
   Statement exists (by hasStatement())
== TEST 10:  : End
PASSED: TEST 10

== TEST 11:  : Start
   Retrieving namespaces
== TEST 11:  : End
PASSED: TEST 11

== TEST 12:  : Start
   Retrieving statement (http://myopenlink.net/dataspace/person/kidehen http://myopenlink.net/foaf/name null)
== TEST 12:  : End
PASSED: TEST 12

== TEST 13:  : Start
   Writing the statements to file: (/Users/hughwilliams/src/virtuoso-opensource/binsrc/sesame2/results.n3.txt)
== TEST 13:  : End
PASSED: TEST 13

== TEST 14:  : Start
   Retrieving graph ids
== TEST 14:  : End
PASSED: TEST 14

== TEST 15:  : Start
   Retrieving triple store size
== TEST 15:  : End
PASSED: TEST 15

== TEST 16:  : Start
   Sending ask query
== TEST 16:  : End
PASSED: TEST 16

== TEST 17:  : Start
   Sending construct query
== TEST 17:  : End
PASSED: TEST 17

== TEST 18:  : Start
   Sending describe query
== TEST 18:  : End
PASSED: TEST 18

============================
PASSED:18 FAILED:0
</pre>
        </div>
      </li>
    </ol>
    <br />
    <br />
    <a name="rdfnativestorageproviderssesamegettingstarted" />
    <h4>14.16.2.4. Getting Started</h4>
    <p>This section covers the essentials for connecting to and manipulating data stored in a Virtuoso repository using the Sesame API. More information on the Sesame Framework, including extended examples on how to use the API, can be found in Chapter 8 of the Sesame User&#39;s guide, 
<a href="http://www.openrdf.org/doc/sesame2/2.1.2/users/ch08.html#d0e833">the RepositoryConnection API</a>.
    </p>
    <p>The interfaces for the Repository API can be found in packages virtuoso.sesame2.driver and org.openrdf.repository. Several implementations for these interface exist in the Virtuoso Provider download package. The 
    	<a href="http://www.openrdf.org/doc/sesame2/2.1.2/apidocs/">Javadoc reference for the Sesame API</a>
is available online and can also be found in the doc directory of the download.
    </p>
    <a name="rdfnativestorageproviderssesamegettingstartedcrrep" />
    <h5>14.16.2.4.1. Creating a VirtuosoRepositoryRDF object</h5>
      <p>The first step to connecting to Virtuoso through the Sesame API is to create a Repository for it. The Repository object operates on (stacks of) Sail object(s) for storage and retrieval of RDF data.
      </p>
      <p>One of the simplest configurations is a repository that just stores RDF data in main memory without applying any inference or whatsoever. This is also by far the fastest type of repository that can be used. The following code creates and initialize a non-inferencing main-memory repository:
      </p>
<div>
      <pre class="programlisting">
import virtuoso.sesame2.driver.VirtuosoRepository;

Repository myRepository = VirtuosoRepository(&quot;jdbc:virtuoso://localhost:1111”,”dba”,”dba”);

myRepository.initialize();
</pre>
    </div>
      <p>The constructor of the VirtuosoRepository class accepts the JDBC URL of the Virtuoso engine (the default port is 1111), the username and password of an authorized user. Following this example, the repository needs to be initialized to prepare the Sail(s) that it operates on, which includes operations such as restoring previously stored data, setting up connections to a relational database, etc.
      </p>
      <p>The repository that is created by the above code is volatile: its contents are lost when the object is garbage collected or when the program is shut down. This is fine for cases where, for example, the repository is used as a means for manipulating an RDF model in memory.
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartedrdfvirtcr" />
    <h5>14.16.2.4.2. Creating a Virtuoso Repository Connection</h5>
      <p>Now that we have created a VirtuosoRepository object instance, we want to do something 
      	with it. This is achieved through the use of the VirtuosoRepositoryConnection class, which 
      	can be created by the VirtuosoRepository class.
      </p>
      <p>A VirtuosoRepositoryConnection represents - as the name suggests - a connection to the 
      	actual Virtuoso quad store. We can issue operations over this connection, and close it when 
      	we are done to make sure we are not keeping resources unnecessarily occupied.
      </p>
      <p>In the following sections, we will show some examples of basic operations using the Northwind dataset.
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartedrdfvirt" />
    <h5>14.16.2.4.3. Adding RDF to Virtuoso</h5>
      <p>The Repository implements the Sesame Repository API offers various methods for adding data to a repository. Data can be added pro grammatically by specifying the location of a file that contains RDF data, and statements can be added individually or in collections.
      </p>
      <p>We perform operations on the repository by requesting a RepositoryConnection from the 
      	repository, which returns a VirtuosoRepositoryConnection object. On this 
      	VirtuosoRepositoryConnection object we can perform the various operations, such as query 
      	evaluation, getting, adding, or removing statements, etc.
      </p>
      <p>The following example code adds two files, one local and one located on the WWW, to a repository:
      </p>
<div>
      <pre class="programlisting">
import org.openrdf.repository.RepositoryException;

import org.openrdf.repository.Repository;

import org.openrdf.repository.RepositoryConnection;

import org.openrdf.rio.RDFFormat;

import java.io.File;

import java.net.URL;

File file = new File(&quot;/path/to/example.rdf&quot;);

String baseURI = &quot;http://example.org/example/localRDF&quot;;

?

try {

   RepositoryConnection con = myRepository.getConnection();

   try {

      con.add(file, baseURI, RDFFormat.RDFXML);

      URL url = new URL(&quot;http://example.org/example/remoteRDF&quot;);

      con.add(url, url.toString(), RDFFormat.RDFXML);

	}

   finally {

      con.close();

   }

}

catch (RepositoryException rex) {

   // handle exception

}

catch (java.io.IOEXception e) {

   // handle io exception

    }
</pre>
    </div>
      <p>More information on other available methods can be found in the javadoc
reference of the RepositoryConnection interface.
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartedqr" />
    <h5>14.16.2.4.4. Querying Virtuoso</h5>
      <p>The Repository API has a number of methods for creating and evaluating queries. Three types of queries are distinguished: tuple queries, graph queries and boolean queries. The query types differ in the type of results that they produce.
      </p>
      <p>
      <strong>Select Query:</strong> The result of a select query is a set of tuples (or 
      variable bindings), where each tuple represents a solution of a query. This type of query is 
      commonly used to get specific values (URIs, blank nodes, literals) from the stored RDF data. 
      The method QueryFactory.executeQuery() returns a Value [ ][ ] for sparql “SELECT” queries. 
The method QueryFactory.executeQuery() also calls the QueryFactory.setResult() which populates
a set of tuples for SPARQL &quot;SELECT&quot; queries. The graph can be retrieved using
QueryFactory.getBooleanResult().
      </p>
      <p>
      <strong>Graph Query:</strong> The result of graph queries is an RDF graph (or set of statements). This type of query is very useful for extracting sub-graphs from the stored RDF data, which can then be queried further, serialized to an RDF document, etc. The method QueryFactory.executeQuery() calls the QueryFactory.setGraphResult() which populates a graph for SPARQL “DESCRIBE” and “CONSTRUCT” queries. The graph can be retrieved using QueryFactory.getGraphResult().
      </p>
      <p>
      <strong>Boolean Query:</strong> The result of boolean queries is a simple boolean value, i.e. true of false. This type of query can be used to check if a repository contains specific information. The method QueryFactory.executeQuery() calls the QueryFactory.setBooleanResult() which sets a boolean value for sparql &quot;ASK&quot; queries. The value can be retrieved using QueryFactory.getBooleanResult().
      </p>
      <p>Note: Although Sesame 2 currently supports two query languages: SeRQL and SPARQL, the Virtuoso provider only supports the W3C SPARQL specification. 
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartevq" />
    <h5>14.16.2.4.5. Evaluating a SELECT Query</h5>
      <p>To evaluate a tuple query we simply do the following:
      </p>
<div>
      <pre class="programlisting">
import java.util.List;

import org.openrdf.OpenRDFException;

import org.openrdf.repository.RepositoryConnection;

import org.openrdf.query.TupleQuery;

import org.openrdf.query.TupleQueryResult;

import org.openrdf.query.BindingSet;

import org.openrdf.query.QueryLanguage;

?

try {

   RepositoryConnection con = myRepository.getConnection();

   try {

      String queryString = &quot;SELECT x, y FROM  WHERE {x} p {y}&quot;;

      TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);

      TupleQueryResult result = tupleQuery.evaluate();

      try {

         ? // do something with the result

      }

      finally {

         result.close();

    }

}

   finally {

      con.close();

   }

}

catch (RepositoryException e) {

   // handle exception

}
</pre>
    </div>
      <p>This evaluates a SPARQL query and returns a TupleQueryResult, which consists of a sequence 
      	of BindingSet objects. Each BindingSet contains a set of pairs called Binding objects. A 
      	Binding object represents a name/value pair for each variable in the query&#39;s projection.
      </p>
      <p>We can use the TupleQueryResult to iterate over all results and get each individual result for x and y:
      </p>
<div>
      <pre class="programlisting">
while (result.hasNext()) {

   BindingSet bindingSet = result.next();

   Value valueOfX = bindingSet.getValue(&quot;x&quot;);

   Value valueOfY = bindingSet.getValue(&quot;y&quot;);

   // do something interesting with the query variable values here?

}
</pre>
    </div>
      <p>As you can see, we retrieve values by name rather than by an index. The names used should be the names of variables as specified in your query. The TupleQueryResult.getBindingNames() method returns a list of binding names, in the order in which they were specified in the query. To process the bindings in each binding set in the order specified by the projection, you can do the following:
      </p>
<div>
      <pre class="programlisting">
List bindingNames = result.getBindingNames();

while (result.hasNext()) {

   BindingSet bindingSet = result.next();

   Value firstValue = bindingSet.getValue(bindingNames.get(0));

   Value secondValue = bindingSet.getValue(bindingNames.get(1));

   // do something interesting with the values here?

}
</pre>
    </div>
      <p>It is important to invoke the close() operation on the TupleQueryResult, 
      	after we are done with it. A TupleQueryResult evaluates lazily and keeps resources 
      	(such as connections to the underlying database) open. Closing the TupleQueryResult 
      	frees up these resources. Do not forget that iterating over a result may cause exceptions! 
      	The best way to make sure no connections are kept open unnecessarily is to invoke close() 
      	in the finally clause.
      </p>
      <p>An alternative to producing a TupleQueryResult is to supply an object that implements the 
      	TupleQueryResultHandler interface to the query&#39;s evaluate() method. The main difference is 
      	that when using a return object, the caller has control over when the next answer is retrieved, 
      	whereas with the use of a handler, the connection simply pushes answers to the handler object 
      	as soon as it has them available.
      </p>
      <p>As an example we will use SPARQLResultsXMLWriter, which is a TupleQueryResultHandler
implementation that writes SPARQL Results XML documents to an output stream or to a writer:
      </p>
<div>
      <pre class="programlisting">
import org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter;

?

FileOutputStream out = new FileOutputStream(&quot;/path/to/result.srx&quot;);

try {

   SPARQLResultsXMLWriter sparqlWriter = new SPARQLResultsXMLWriter(out);

   RepositoryConnection con = myRepository.getConnection();

   try {

      String queryString = &quot;SELECT * FROM  WHERE {x} p {y}&quot;;

      TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);

      tupleQuery.evaluate(sparqlWriter);

   }

   finally {

      con.close();

   }

}

finally {

   out.close();

}
</pre>
    </div>
      <p>You can just as easily supply your own application-specific implementation of TupleQueryResultHandler though.
      </p>
      <p>Lastly, an important warning: as soon as you are done with the RepositoryConnection
object, you should close it. Notice that during processing of the TupleQueryResult object
      	(for example, when iterating over its contents), the RepositoryConnection should still be 
      	open. We can invoke con.close() after we have finished with the result. 
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartevcnq" />
    <h5>14.16.2.4.6. Evaluating a CONSTRUCT query</h5>
      <p>The following code evaluates a graph query on a repository:
      </p>
<div>
      <pre class="programlisting">
import org.openrdf.query.GraphQueryResult;

GraphQueryResult graphResult = con.prepareGraphQuery(

      QueryLanguage.SPARQL, &quot;CONSTRUCT * FROM {x} p {y}&quot;).evaluate();
</pre>
    </div>
      <p> A GraphQueryResult is similar to TupleQueryResult in that is an object that 
      	iterates over the query results. However, for graph queries the query results are RDF 
      	statements, so a GraphQueryResult iterates over Statement objects:
      </p>
<div>
      <pre class="programlisting">
while (graphResult.hasNext()) {

   Statement st = graphResult.next();

   // ? do something with the resulting statement here.


}
</pre>
    </div>
      <p>The TupleQueryResultHandler equivalent for graph queries is org.openrdf.rio.RDFHandler.
      	Again, this is a generic interface, each object implementing it can process the reported RDF 
      	statements in any way it wants.
      </p>
      <p>All writers from Rio (such as the RDFXMLWriter, TurtleWriter, TriXWriter, etc.) implement
      	the RDFHandler interface. This allows them to be used in combination with querying quite easily. 
      	In the following example, we use a TurtleWriter to write the result of a SPARQL graph query to 
      	standard output in Turtle format:
      </p>
<div>
      <pre class="programlisting">
import org.openrdf.rio.turtle.TurtleWriter;

?

RepositoryConnection con = myRepository.getConnection();

try {

   TurtleWriter turtleWriter = new TurtleWriter(System.out);

   con.prepareGraphQuery(QueryLanguage.SPARQL, &quot;CONSTRUCT * FROM  WHERE {x} p {y}&quot;).evaluate(turtleWriter);

    }

finally {

   con.close();

}
</pre>
    </div>
      <p>Again, note that as soon as we are done with the result of the query (either after iterating over the contents of the GraphQueryResult? or after invoking the RDFHandler), we invoke con.close() to close the connection and free resources.
      </p>
    <br />
    <a name="rdfnativestorageproviderssesamegettingstartevcnqapi" />
    <h5>14.16.2.4.7. Javadoc API Documentation</h5>
      <p>
      <a href="http://docs.openlinksw.com/sesame/">Sesame Provider Javadoc API Documentation</a> is available enabling the complete set of classes, interfaces and methods implemented for the provider to be viewed.</p>
    <br />
    <br />
    <a name="rdfnativestorageproviderssesamestpandtesting" />
    <h4>14.16.2.5. Virtuoso Sesame HTTP Repository Configuration and Usage</h4>
      <a name="rdfnativestorageproviderssesamestpandtestingwhat" />
    <h5>14.16.2.5.1. What</h5>
<p>Sesame is an open source Java framework for storing, querying and reasoning with RDF and RDF Schema. It can be used as a
database for RDF and RDF Schema, or as a Java library for applications that need to work with RDF internally. The Sesame HTTP
repository serves as a proxy for a RDF store hosted on a remote Sesame server, enabling the querying of the RDF store using
the Sesame HTTP protocol.
</p>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestingwhy" />
    <h5>14.16.2.5.2. Why</h5>
<p>The Sesame HTTP repository endpoint provides users with the greater flexibility for manipulating the RDF store via a common
interface. Sesame provides you with the necessary tools to parse, interpret, query and store all this information, embedded
in your own application if you want, or, if you prefer, in a separate database or even on a remote server.
</p>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestinghow" />
    <h5>14.16.2.5.3. How</h5>
<p>To create a new Sesame HTTP repository, the Console needs to create such an RDF document and submit it to the SYSTEM
repository. The Console uses so called repository configuration templates to accomplish this. Repository configuration templates
are simple Turtle RDF files that describe a repository configuration, where some of the parameters are replaced with variables.
The Console parses these templates and asks the user to supply values for the variables. The variables are then substituted with
the specified values, which produces the required configuration data.
</p>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestingmain" />
    <h5>14.16.2.5.4. Setup and Testing</h5>
<p>This section details the steps required for configuring and testing a Virtuoso Sesame
Repository, both using the HTTP and Console Sesame repositories.</p>
      <a name="rdfnativestorageproviderssesamestpandtestingreq" />
    <h6>Requirements</h6>
<ul>
  <li>
        <a href="http://www.openrdf.org/download.jsp">Sesame 2.3.1</a> or higher</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtSesame2HttpRepository/virt_sesame2.jar">Virtuoso Sesame 2 Provider </a> (virt_sesame2.jar)</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtSesame2HttpRepository/virtjdbc3.jar">Virtuoso JDBC Driver</a> (virtjdbc3.jar)</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtSesame2HttpRepository/create.xsl">Sesame System Repository config file</a> (create.xsl)</li>
  <li>
        <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VirtSesame2HttpRepository/create-virtuoso.xsl">Sesame Virtuoso Repository config file </a> (create-virtuoso.xsl)</li>
  <li>
        <a href="http://tomcat.apache.org/download-60.cgi">Apache Tomcat</a> version 5 or 6</li>
</ul>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestinghttprep" />
    <h6>Setup Sesame HTTP Repository</h6>
<p>This section details the steps required for configuring and testing a Virtuoso HTTP Sesame Repository.</p>
<ol>
      <li>Install <a href="http://tomcat.apache.org/tomcat-6.0-doc/index.html">Apache Tomcat</a> web server</li>
      <li>From the Sesame 2.3.1 or higher &quot;lib&quot; directory copy the &quot;openrdf-sesame.war&quot; and &quot;openrdf-worbbench.war&quot; files to the
tomcat &quot;webapps&quot; directory where they will automatically be deployed creating two new sub directories &quot;openrdf-sesame&quot; and
&quot;openrdf-workbench&quot;.</li>
      <li>Place the Virtuoso Sesame Provider &quot;virt_sesame2.jar&quot; and JDBC Driver &quot;virtjdbc3.jar&quot; into the Tomcat
~/webapps/openrdf-sesame/WEB-INF/lib/ and ~/webapps/openrdf-workbench/WEB-INF/lib/ directories for
use by the Sesame HTTP Repository for accessing the Virtuoso RDF repository.</li>
      <li>Place the &quot;create.xsl&quot; and &quot;create-virtuoso.xsl&quot; files in the Tomcat
~/webapps/openrdf-workbench/transformations/ directory. Note &quot;create.xsl&quot; replaces the default provided with Sesame and contains the necessary entries required to reference the new &quot;create-virtuoso.xsl&quot; template file for Virtuoso repository configuration.</li>
      <li>The Sesame HTTP Repository will now be accessible on the URLs
<div>
          <pre class="programlisting">
http://localhost:8080/openrdf-sesame
http://localhost:8080/openrdf-workbench
</pre>
        </div>
</li>
      <li>The Sesame OpenRDF Workbench is used for accessing the Sesame HTTP Repositories, loading
&quot;<a href="http://localhost:8080/openrdf-workbench">http://localhost:8080/openrdf-workbench</a>&quot; will enable the
default &quot;SYSTEM&quot; repository to be accessed.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss1.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;New Repository&quot; link in the left frame to create a new Sesame Repository.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss2.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Select the &quot;Virtuoso RDF Store&quot; from the &quot;Type&quot; drop down list box presented.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss3.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Choose suitable repository &quot;ID&quot; and &quot;Title&quot; for the Virtuoso repository to be created and click &quot;Next&quot;.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss4.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Fill in the connection parameters for the target Virtuoso sever the repository is to be created for and
click the &quot;create&quot; button. The minimum required are the hostname, port number, username and password of the Virtuoso Server.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss5.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>The new Virtuoso respository will be created and its summary page displayed.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss6.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;Namespaces&quot; link in the left frame to obtain a list of the available namespaces in the Virtuoso repository.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss7.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;Context&quot; link in the left frame to obtain a list of the available contexts in the Virtuoso repository.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss8.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;Types&quot; link in the left frame to obtain a list of the available types in the Virtuoso repository.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss9.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;Query&quot; link in the left frame, enter a suitable SPARQL query to execute against the Virtuoso repository
and click the &quot;execute&quot; button.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss10.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>The results of the SPARQL query are returned.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss11.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
      <li>Click on the &quot;Repositories&quot; link in the left frame and the newly created Virtuoso repository entry is displayed along side
the default SYSTEM repository.
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss12.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>
  </li>
    </ol>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestingcons" />
    <h6>Setup Sesame Console Repository</h6>
<p>This section details the steps required for configuring and testing a Virtuoso Sesame Console Repository:</p>
<ol>
      <li>Extract Sesame 2.3.1 or higher archive to a location of choice and place the virt_sesame2.jar and virtjdbc3.jar
files to the sesame 2.3.1 &quot;lib&quot; directory</li>
      <li>Start the <a href="http://www.openrdf.org/doc/sesame2/users/ch07.html#section-console-repository-creation">sesame console application</a> by running the &quot;console.bat&quot; script in the sesame &quot;bin&quot; directory and then &quot;exit.&quot; the program
<div>
          <pre class="programlisting">
$ sh console.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/logback-classic-0.9.18.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/slf4j-jdk14-1.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
10:32:38.317 [main] DEBUG info.aduna.platform.PlatformFactory - os.name &lt;http://os.name&gt; &lt;http://os.name&gt; = mac os x
10:32:38.351 [main] DEBUG info.aduna.platform.PlatformFactory - Detected Mac OS X platform
Connected to default data directory
Commands end with &#39;.&#39; at the end of a line
Type &#39;help.&#39; for help
exit.
</pre>
        </div>
</li>
      <li>This will create the necessary sesame application data directories as detailed in the sesame
<a href="http://www.openrdf.org/doc/sesame2/2.3.1/users/userguide.html#chapter-datadir-config">data directory configuration</a> documentation.
<div>
          <pre class="programlisting">
Windows - C:\Documents and Settings\LocalService\Application Data\Aduna\
Mac OS X - /Users/myuser/Library/Application Support/Aduna/
Linux - $HOME/.aduna/
</pre>
        </div>
</li>
      <li>If you do not want to use the default sesame data directory location the Sesame console application can be started by
specifying a custom data directory location with the &quot;-d&quot; option. Note in this case the directory &quot;OpenRDF Sesame console&quot; always
has to be manually appended to the directory as Sesame assumes the data file will reside in a sub directory of this name.
<div>
          <pre class="programlisting">
$ sh console.sh -d /Users/myuser/OpenRDF Sesame console
</pre>
        </div>
</li>
      <li>Start the sesame console application with the required data directory location and create a Virtuoso repository as
detailed in the steps below, the key parameters to be specified being the target Virtuoso server hostname, port number,
username, password and a unique &quot;Repository ID&quot;.
<div>
          <pre class="programlisting">
$ sh console.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/logback-classic-0.9.18.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/slf4j-jdk14-1.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
10:32:38.317 [main] DEBUG info.aduna.platform.PlatformFactory - os.name &lt;http://os.name&gt; &lt;http://os.name&gt; = mac os x
10:32:38.351 [main] DEBUG info.aduna.platform.PlatformFactory - Detected Mac OS X platform
Connected to default data directory
Commands end with &#39;.&#39; at the end of a line
Type &#39;help.&#39; for help
create virtuoso .
Please specify values for the following variables:
Host list [localhost:1111]:
Username [dba]:
Password [dba]:
Default graph name [sesame:nil]:
Enable using batch optimization (false|true) [false]:
Use RoundRobin for connection (false|true) [false]:
Buffer fetch size [200]:
Inference RuleSet name [null]:
Repository ID [virtuoso]: myvirt
Repository title [Virtuoso repository]:
Repository created
show r .
+----------
|SYSTEM
|myvirt (&quot;Virtuoso repository&quot;)
+----------
open myvirt .
Opened repository &#39;myvirt&#39;
myvirt&gt; show n .
+----------
|bif  bif:
|dawgt  http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#
|dbpedia  http://dbpedia.org/resource/
|dbpprop  http://dbpedia.org/property/
|dc  http://purl.org/dc/elements/1.1/
|foaf  http://xmlns.com/foaf/0.1/
|geo  http://www.w3.org/2003/01/geo/wgs84_pos#
|go  http://purl.org/obo/owl/GO#
|math  http://www.w3.org/2000/10/swap/math#
|mesh  http://purl.org/commons/record/mesh/
|mf  http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#
|nci  http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#
|obo  http://www.geneontology.org/formats/oboInOwl#
|owl  http://www.w3.org/2002/07/owl#
|protseq  http://purl.org/science/protein/bysequence/
|rdf  http://www.w3.org/1999/02/22-rdf-syntax-ns#
|rdfdf  http://www.openlinksw.com/virtrdf-data-formats#
|rdfs  http://www.w3.org/2000/01/rdf-schema#
|sc  http://purl.org/science/owl/sciencecommons/
|scovo  http://purl.org/NET/scovo#
|skos  http://www.w3.org/2004/02/skos/core#
|sql  sql:
|vcard  http://www.w3.org/2001/vcard-rdf/3.0#
|virtrdf  http://www.openlinksw.com/schemas/virtrdf#
|void  http://rdfs.org/ns/void#
|xf  http://www.w3.org/2004/07/xpath-functions
|xml  http://www.w3.org/XML/1998/namespace
|xsd  http://www.w3.org/2001/XMLSchema#
|xsl10  http://www.w3.org/XSL/Transform/1.0
|xsl1999  http://www.w3.org/1999/XSL/Transform
|xslwd  http://www.w3.org/TR/WD-xsl
|yago  http://dbpedia.org/class/yago/
+----------
exit.
</pre>
        </div>
</li>
    </ol>
      <br />
      <a name="rdfnativestorageproviderssesamestpandtestinghttpcons" />
    <h6>Connection to Sesame HTTP repository from Console repository</h6>
<p>The Sesame Console repository can connect to a Sesame HTTP repository and vice-versa, enabling access to remote Sesame
HTTP repositories from a local server.</p>
<ol>
      <li>The Sesame Console repository can connect to a Sesame HTTP repository and query it as if local using the &quot;connect&quot; command.
<div>
          <pre class="programlisting">
$ sh console.sh
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/logback-classic-0.9.18.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/myuser/openrdf-sesame-2.3.1/lib/slf4j-jdk14-1.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
10:32:38.317 [main] DEBUG info.aduna.platform.PlatformFactory - os.name &lt;http://os.name&gt; &lt;http://os.name&gt; = mac os x
10:32:38.351 [main] DEBUG info.aduna.platform.PlatformFactory - Detected Mac OS X platform
Connected to default data directory
Commands end with &#39;.&#39; at the end of a line
Type &#39;help.&#39; for help
&gt; connect http://localhost:8080/openrdf-sesame.
Connected to http://localhost:8080/openrdf-sesame
&gt; show r.
+----------
|SYSTEM (&quot;System configuration repository&quot;)
|VirtSesRep (&quot;Virtuoso Sesame HTTP Repository&quot;)
+----------
&gt; open VirtSesRep.
Opened repository &#39;VirtSesRep&#39;
VirtSesRep&gt; sparql select * from &lt;http://localhost:8890/Northwind&gt; where {?s ?p ?o} Limit 10.
Evaluating query...
+------------------------+------------------------+------------------------+
| s                      | p                      | o                      |
+------------------------+------------------------+------------------------+
| &lt;http://localhost:8890/Northwind/CustomerContact/ALFKI#this&gt;| rdf:type  | foaf:Person            |
| &lt;http://localhost:8890/Northwind/CustomerContact/ALFKI#this&gt;| rdf:type  | northwind:CustomerContact|
| &lt;http://localhost:8890/Northwind/CustomerContact/ALFKI#this&gt;| opl:isDescribedUsing   | northwind:             |
| &lt;http://localhost:8890/Northwind/CustomerContact/ANATR#this&gt;| rdf:type | foaf:Person            |
| &lt;http://localhost:8890/Northwind/CustomerContact/ANATR#this&gt;| rdf:type | northwind:CustomerContact|
| &lt;http://localhost:8890/Northwind/CustomerContact/ANATR#this&gt;| opl:isDescribedUsing   | northwind:             |
| &lt;http://localhost:8890/Northwind/CustomerContact/ANTON#this&gt;| rdf:type  | foaf:Person            |
| &lt;http://localhost:8890/Northwind/CustomerContact/ANTON#this&gt;| rdf:type  | northwind:CustomerContact|
| &lt;http://localhost:8890/Northwind/CustomerContact/ANTON#this&gt;| opl:isDescribedUsing   | northwind:             |
| &lt;http://localhost:8890/Northwind/CustomerContact/AROUT#this&gt;| rdf:type  | foaf:Person            |
+------------------------+------------------------+------------------------+
10 result(s) (530 ms)
VirtSesRep&gt; show n.
+----------
|SearchResults  http://www.zillow.com/static/xsd/SearchResults.xsd
|UpdatedPropertyDetails  http://www.zillow.com/static/xsd/UpdatedPropertyDetails.xsd
|a  http://www.w3.org/2005/Atom
|aapi  http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema#
|address  http://schemas.talis.com/2005/address/schema#
|admin  http://webns.net/mvcb/
|amz  http://webservices.amazon.com/AWSECommerceService/2005-10-05
|atom  http://atomowl.org/ontologies/atomrdf#
|audio  http://purl.org/media/audio#
|awol  http://bblfish.net/work/atom-owl/2006-06-06/#
|aws  http://soap.amazon.com/
|b3s  http://b3s.openlinksw.com/
</pre>
        </div>
</li>
      <li>Conversely the Sesame HTTP repository can be configured to access the repository created by the Sesame console.
To do this the location of the data directory for both needs to be reconfigured using the Java system property
info.aduna.platform.appdata.basedir (does not include &quot;OpenRDF Sesame console directory) to point to the same location.
When you are using Tomcat as the servlet container then you can set this property using the JAVA_OPTS parameter.
Note, if you are using Apache Tomcat as a Windows Service you should use the Windows Services configuration tool to
set this property. Other users can either edit the Tomcat startup script or set the property some other way.
<div>
          <pre class="programlisting">
 * set JAVA_OPTS=-Dinfo.aduna.platform.appdata.basedir=\path\to\other\dir\ (on Windows)
    * export JAVA_OPTS=&#39;-Dinfo.aduna.platform.appdata.basedir=/path/to/other/dir/&#39; (on Linux/UNIX/Mac OS X)
</pre>
        </div>
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
      <tr>
       <td>
              <img alt="Virtuoso Sesame HTTP Repository Configuration and Usage" src="../images/ui/ss13.png" />
       </td>
      </tr>
      <tr>
            <td>Figure: 14.16.2.5.4.1. Virtuoso Sesame HTTP Repository Configuration and Usage</td>
      </tr>
        </table>

</li>
    </ol>
       <br />
    <br />
    <br />
    <a name="rdfnativestorageproviderssesamejavadoc" />
    <h4>14.16.2.6. Javadoc API Documentation</h4>
    <p>
      <a href="http://docs.openlinksw.com/sesame/">Sesame Provider Javadoc API Documentation</a>
is available enabling the complete set of classes, interfaces and methods implemented for the provider to be viewed.
    </p>
    <br />
  <br />
  <a name="rdfnativestorageproviderredland" />
    <h3>14.16.3. Virtuoso Redland Provider</h3>
     <a name="rdfnativestorageproviderredlandwhatis" />
    <h4>14.16.3.1. What is Redland</h4>
     <p>
      <a href="http://librdf.org/">Redland</a> is a set of free software &#39;C&#39; libraries that
provide support for the Resource Description Framework (RDF), providing modular, object based libraries
and APIs for manipulating the RDF graph, triples, URIs and Literals. Redland includes several high-level
language APIs providing RDF manipulation and storage and requires the
<a href="http://librdf.org/raptor/">Raptor</a> RDF parser and <a href="http://librdf.org/rasqal/">Rasqal</a>
RDF syntax and query library
for its use.
      </p>
    <br />
    <a name="rdfnativestorageproviderredlandwhatisv" />
    <h4>14.16.3.2. What is the Virtuoso Redland Provider</h4>
    <p>The Virtuoso Redland RDF Provider is an implementation of the Storage API, Model and Query
interfaces of the Redland framework for RDF. This provider enables the execution of queries via the
Redland Rasqal query engine or via Virtuoso query engine directly against the Virtuoso Quad store.
The Virtuoso Redland Provider uses ODBC as the data access mechanism for communicating the Virtuoso
Quad Store and requires the Virtuoso ODBC Driver be installed on the Redland client and a suitable
ODBC DSN be configured for connecting to the target Virtuoso Quad Store instance. The provider has
been tested against the <a href="http://download.librdf.org/source/">Redland 1.0.8</a> version currently available for download.
    </p>
    <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="Redland Component Stack" src="../images/ui/VirtRedLand.png" />
     </td>
    </tr>
    <tr>
        <td>Figure: 14.16.3.2.1. Redland Component Stack</td>
    </tr>
    </table>
    <p>As indicated in the above diagram the Virtuoso Provider can be used to execute RDF queries either
directly against the Virtuoso graph storage module supporting the <a href="http://dbpedia.org/resource/SPARQL">SPARQL</a>,
<a href="http://dbpedia.org/resource/SPARUL">SPARQL</a>SPARUL, <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSArticleBISPARQL2">SPARQL-BI</a>
query languages or via the Rasqal query engine built into Redland which supports the SPARQL query language.
This is done by simply changing the syntax of the query using the &quot;vsparql&quot; rather then default &quot;sparql&quot;
construct when executing a query as indicated in the sample queries below:
    </p>
<div>
      <pre class="programlisting">
rdfproc -r xml -t &quot;user=&#39;dba&#39;,password=&#39;dba&#39;,dsn=&#39;Demo&#39;&quot; gr query sparql - &quot;SELECT * WHERE { ?s ?p ?o }&quot;   ;; via Redland Rasqal engine

rdfproc -r xml -t &quot;user=&#39;dba&#39;,password=&#39;dba&#39;,dsn=&#39;Demo&#39;&quot; gr query vsparql - &quot;SELECT * WHERE { ?s ?p ?o }&quot;  ;; direct to Virtuoso storage module
</pre>
    </div>
    <p>The Virtuoso Provider uses the <a href="http://virtuoso.openlinksw.com/dataspace/dav/wiki/Main/VOSSQL2RDF">SPASQL</a> query language for querying the remote Virtuoso QUAD store.
    </p>
    <br />
    <a name="rdfnativestorageproviderredlandsetup" />
    <h4>14.16.3.3. Setup</h4>
      <a name="rdfnativestorageproviderredlandreqfiles" />
    <h5>14.16.3.3.1. Required Files</h5>
      <p>The Virtuoso Redland Provider has been integrated into the Redland RDF Framework and submitted to
the open source project to become part of the standard distribution available for
<a href="http://librdf.org/INSTALL.html">download</a>. Until this
submission has been accepted and committed into the available Redland release a tar ball created by
OpenLink Software and a diff for application to a Redland 1.0.8 tree can be obtained from:
    </p>
    <ul>
        <li>
        <a href="ftp://download.openlinksw.com/support/vos/redland-vos-1.0.8.tar.gz" />Redland 1.0.8 tar ball with Virtuoso storage support</li>
        <li>
        <a href="ftp://download.openlinksw.com/support/vos/redland-vos.diff">Redland 1.0.8 Diff file of changes made for Virtuoso storage support</a>
      </li>
      </ul>
      <br />
      <a name="rdfnativestorageprovidersredlandcmsmpr" />
    <h5>14.16.3.3.2. Compiling Redland with Virtuoso storage support</h5>
        <ul>
          <li>
        <a href="http://svn.librdf.org/">Download Redland</a>, extract and apply diff
above or download the tar ball above with diff already applied and extract to a location of choice.</li>
          <li>The following additional configure options are available for enabling the Virtuoso
storage support:
<div>
          <pre class="programlisting">
  --with-virtuoso(=yes|no) Enable Virtuoso RDF store (default=auto)
  --with-iodbc(=DIR)        Select iODBC support
                            DIR is the iODBC base install directory
                            (default=/usr/local)
  --with-unixodbc(=DIR)   Select UnixODBC support
                            DIR is the UnixODBC base install directory
                            (default=/usr/local)
  --with-datadirect(=DIR) Select DataDirect support
                            DIR is the DataDirect base install directory
                            (default=/usr/local)
  --with-odbc-inc=DIR     Specify custom ODBC include directory
                            (default=/usr/local/include)
  --with-odbc-lib=DIR     Specify custom ODBC lib directory
                            (default=/usr/local/lib)
</pre>
        </div>
          </li>
          <li>The &quot;--with-virtuoso&quot; option default to being auto enable if a valid ODBC Driver Manager
(iODBC, UnixODBC? or DataDirect?) or include and lib directories for required ODBC header files and libraries
are located with the suitable setting for one or more of the other ODBC related options above. Assuming
iODBC is installed the following option can be used to enable Virtuoso storage support to be configured
for compilation into your Redland build:
<div>
          <pre class="programlisting">
./configure --with-iodbc=/usr/local/iODBC
</pre>
        </div>
          </li>
          <li>Run &quot;make&quot; to compile the Redland libraries and &quot;sudo make install&quot; to install in
the default &quot;/usr/local&quot; location</li>
          <li>Test compilation with test utility utils/rdfproc:
<div>
          <pre class="programlisting">

rdfproc test parse http://planetrdf.com/guide/rss.rdf
rdfproc test print
rdfproc test serialize ntriples
</pre>
        </div>
          <p>This test will use the default &#39;hashes&#39; storage.</p>
          </li>
          <li>Ensure you have the Virtuoso ODBC Driver installed and a valid ODBC DSN called
&quot;Local Virtuoso&quot; configured for your target Virtuoso Server</li>
          <li>Set the following environment variable:
<div>
          <pre class="programlisting">
export RDFPROC_STORAGE_TYPE=virtuoso                                   ;; Enable Virtuoso Storage
export ODBCINI=&lt;path_to_odbcini_directory&gt;/odbc.ini                      ;; Enable ODBC DSN to be located
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH                     ;; May be required to enable Redland libraries to be located

</pre>
        </div>
          </li>
          <li>Test Virtuoso storage with the provided test program utils/vtest:
<div>
          <pre class="programlisting">
$ utils/vtest
  1: Remove all triples in &lt;http://red&gt; context
**PASSED**: removed context triples from the graph
  2: Add triples to &lt;http://red&gt; context
**PASSED**: add triple to context
  3: Print all triples in &lt;http://red&gt; context
[[
  {[aa], [bb], [cc]} with context [http://red]
  {[aa], [bb1], [cc]} with context [http://red]
  {[aa], [a2], &quot;cc&quot;} with context [http://red]
  {[aa], [a2], (cc)} with context [http://red]
  {[mm], [nn], &quot;Some long literal with language@en&quot;} with context [http://red]
  {[oo], [pp], &quot;12345^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;&quot;} with context [http://red]
]]
**PASSED**:
  4: Count of triples in &lt;http://red&gt; context
**PASSED**: graph has 6 triples
  5: Exec:  ARC  aa bb
Matched node: [cc]
**PASSED**:
  6: Exec:  ARCS  aa cc
Matched node: [bb] with context [http://red]
Matched node: [bb1] with context [http://red]
: matching nodes: 2
**PASSED**:
  7: Exec:  ARCS-IN  cc
Matched arc: [bb] with context [http://red]
Matched arc: [bb1] with context [http://red]
**PASSED**: matching arcs: 2
  8: Exec:  ARCS-OUT  aa
Matched arc: [bb] with context [http://red]
Matched arc: [bb1] with context [http://red]
Matched arc: [a2] with context [http://red]
Matched arc: [a2] with context [http://red]
**PASSED**: matching arcs: 4
  9: Exec:  CONTAINS aa bb1 cc
**PASSED**: the graph contains the triple
 10: Exec:  FIND aa - -
Matched triple: {[aa], [bb], [cc]} with context [http://red]
Matched triple: {[aa], [bb1], [cc]} with context [http://red]
Matched triple: {[aa], [a2], &quot;cc&quot;} with context [http://red]
Matched triple: {[aa], [a2], (cc)} with context [http://red]
**PASSED**: matching triples: 4
 11: Exec:  HAS-ARC-IN cc bb
**PASSED**: the graph contains the arc
 12: Exec:  HAS-ARC-OUT aa bb
**PASSED**: the graph contains the arc
 13: Exec:  SOURCE  aa cc
Matched node: [aa]
**PASSED**:
 14: Exec:  SOURCES  bb cc
Matched node: [aa] with context [http://red]
: matching nodes: 1
**PASSED**:
 15: Exec:  TARGET  aa bb
Matched node: [cc]
**PASSED**:
 16: Exec:  TARGETS  aa bb
Matched node: [cc] with context [http://red]
: matching nodes: 1
**PASSED**:
 17: Exec:  REMOVE aa bb1 cc
**PASSED**: removed triple from the graph
 18: Exec:  QUERY &quot;CONSTRUCT {?s ?p ?o} FROM &lt;http://red&gt; WHERE {?s ?p ?o}&quot;
Matched triple: {[aa], [a2], &quot;cc&quot;}
Matched triple: {[oo], [pp], &quot;12345^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;&quot;}
Matched triple: {[aa], [a2], (cc)}
Matched triple: {[aa], [bb], [cc]}
Matched triple: {[mm], [nn], &quot;Some long literal with language@en&quot;}
**PASSED**: matching triples: 5
 19: Exec1:  QUERY_AS_BINDINGS &quot;SELECT * WHERE {graph &lt;http://red&gt; { ?s ?p ?o }}&quot;
**: Formatting query result as &#39;xml&#39;:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;sparql xmlns=&quot;http://www.w3.org/2005/sparql-results#&quot;&gt;
  &lt;head&gt;
    &lt;variable name=&quot;s&quot;/&gt;
    &lt;variable name=&quot;p&quot;/&gt;
    &lt;variable name=&quot;o&quot;/&gt;
  &lt;/head&gt;
  &lt;results&gt;
    &lt;result&gt;
      &lt;binding name=&quot;s&quot;&gt;&lt;uri&gt;aa&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;p&quot;&gt;&lt;uri&gt;bb&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;o&quot;&gt;&lt;uri&gt;cc&lt;/uri&gt;&lt;/binding&gt;
    &lt;/result&gt;
    &lt;result&gt;
      &lt;binding name=&quot;s&quot;&gt;&lt;uri&gt;aa&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;p&quot;&gt;&lt;uri&gt;a2&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;o&quot;&gt;&lt;literal&gt;cc&lt;/literal&gt;&lt;/binding&gt;
    &lt;/result&gt;
    &lt;result&gt;
      &lt;binding name=&quot;s&quot;&gt;&lt;uri&gt;aa&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;p&quot;&gt;&lt;uri&gt;a2&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;o&quot;&gt;&lt;bnode&gt;cc&lt;/bnode&gt;&lt;/binding&gt;
    &lt;/result&gt;
    &lt;result&gt;
      &lt;binding name=&quot;s&quot;&gt;&lt;uri&gt;mm&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;p&quot;&gt;&lt;uri&gt;nn&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;o&quot;&gt;&lt;literal&gt;Some long literal with language@en&lt;/literal&gt;&lt;/binding&gt;
    &lt;/result&gt;
    &lt;result&gt;
      &lt;binding name=&quot;s&quot;&gt;&lt;uri&gt;oo&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;p&quot;&gt;&lt;uri&gt;pp&lt;/uri&gt;&lt;/binding&gt;
      &lt;binding name=&quot;o&quot;&gt;&lt;literal&gt;12345^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;&lt;/literal&gt;&lt;/binding&gt;
    &lt;/result&gt;
  &lt;/results&gt;
&lt;/sparql&gt;
**PASSED**:
 20: Exec2:  QUERY_AS_BINDINGS &quot;SELECT * WHERE {graph &lt;http://red&gt; { ?s ?p ?o }}&quot;
: Query returned bindings results:
result: [s=[aa], p=[bb], o=[cc]]
result: [s=[aa], p=[a2], o=cc]
result: [s=[aa], p=[a2], o=(cc)]
result: [s=[mm], p=[nn], o=Some long literal with language@en]
result: [s=[oo], p=[pp], o=12345^^&lt;http://www.w3.org/2001/XMLSchema#int&gt;]
: Query returned 5 results
**PASSED**:
=============================================
PASSED: 20  FAILED:  0
</pre>
        </div>
          </li>
        </ul>
      <br />
      <a name="rdfnativestorageprovidersredlandcp" />
    <h5>14.16.3.3.3. Connection Parameters</h5>
        <p>The Virtuoso provider has the following connection parameters available fro use:</p>
        <ul>
          <li>
        <strong>dsn</strong> - ODBC datasource name</li>
          <li>
        <strong>user</strong> - user name of database server</li>
          <li>
        <strong>password</strong> - password of database server</li>
          <li>
        <strong>host</strong> - hostname:portno of the database server</li>
          <li>
        <strong>charset</strong> - database charset to use</li>
    </ul>
        <p>NOTE: Take care exposing the password as for example, program arguments or environment
variables. The rdfproc utility can help this by reading the password from standard input. Inside programs,
one way to prevent storing the password in a string is to construct a Redland hash of the storage options
such as via librdf hash_from_string and use librdf_new_storage_with_options to create a storage. The
rdfproc utility source code demonstrates this.
        </p>
        <p>The storage name parameter given to the storage constructor librdf new_storage is used
inside the virtuoso store to allow multiple stores inside one Virtuoso database instance as parameterized
with the above options.
        </p>
        <p>This store always provides contexts; the boolean storage option contexts is not checked.</p>
        <p>Examples:</p>
<div>
      <pre class="programlisting">
  /* A new Virtuoso store */
  storage=librdf_new_storage(world, &quot;virtuoso&quot;, &quot;db1&quot;,
      &quot;dsn=&#39;Local Virtuoso&#39;,user=&#39;demo&#39;,password=&#39;demo&#39;&quot;);

  /* A different, existing Virtuoso store in the same database as above */
  storage=librdf_new_storage(world, &quot;virtuoso&quot;, &quot;db2&quot;,
      &quot;dsn=&#39;Local Virtuoso&#39;,user=&#39;demo&#39;,password=&#39;demo&#39;&quot;);

  /* An existing Virtuoso store on a different database server */
  storage=librdf_new_storage(world, &quot;virtuoso&quot;, &quot;http://red3&quot;,
      &quot;dsn=&#39;Remote Virtuoso&#39;,user=&#39;demo&#39;,password=&#39;demo&#39;&quot;);

  /* Opening with an options hash */
  options=librdf_new_hash(world, NULL);
  librdf_hash_from_string(options,
      &quot;dsn=&#39;Local Virtuoso&#39;,user=&#39;demo&#39;&quot;);
  librdf_hash_put_strings(options, &quot;password&quot;, user_password);
  storage=librdf_new_storage_with_options(world, &quot;virtuoso&quot;, &quot;http://red3&quot;, options);
</pre>
    </div>
    <br />
    <br />
    <a name="rdfnativestorageprovidersredlandref" />
    <h4>14.16.3.4. References</h4>
    <ul>
        <li>
        <a href="http://librdf.org/docs/api/redland-storage.html">RedLand Triple 
        Store</a>
      </li>
        <li>
        <a href="http://librdf.org/docs/api/redland-storage-modules.html">RedLand 
        Storage Modules</a>
      </li>
   </ul>
    <br />
  <br />
<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="rdfperformancetuning.html" title="RDF Performance Tuning">Previous</a>
          <br />RDF Performance Tuning</td>
     <td align="center" width="34%">
          <a href="rdfandsparql.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="rdfgraphreplication.html" title="RDF Graph Replication">Next</a>
          <br />RDF Graph Replication</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>