<docbook><section><title>VirtJenaSPARQLExample6</title><para> </para>
<title> Virtuoso Jena Provider - SPARQL Example 6</title> Virtuoso Jena Provider - SPARQL Example 6
<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;);

    }
}
</programlisting><para> </para>
</section></docbook>