Sophie

Sophie

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

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="7. Data Access Interfaces" />
  <meta name="dc.subject" content="7. Data Access Interfaces" />
  <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="accessinterfaces.html" title="Chapter Contents" />
  <link rel="prev" href="accintudsockets.html" title="Unix Domain Socket Connections" />
  <link rel="next" href="contents.html" title="Contents" />
  <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>7. Data Access Interfaces</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="dataccessclientsconfailandbalance" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>7. Data Access Interfaces</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="accessinterfaces.html">Chapter Contents</a> | <a class="link" href="accintudsockets.html" title="Unix Domain Socket Connections">Prev</a> | <a class="link" href="sqlreference.html" title="SQL Reference">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="accessinterfaces.html">Data Access Interfaces</a>
   </div>
    <br />
   <div>
      <a href="virtclientref.html">ADO.Net Data Provider</a>
   </div>
   <div>
      <a href="isql.html">Interactive SQL Utility</a>
   </div>
   <div>
      <a href="odbcimplementation.html">Virtuoso Driver for ODBC</a>
   </div>
   <div>
      <a href="VirtuosoDriverJDBC.html">Virtuoso Driver for JDBC</a>
   </div>
   <div>
      <a href="virtoledb.html">OLE DB Provider for Virtuoso</a>
   </div>
   <div>
      <a href="inprocess.html">Virtuoso In-Process Client</a>
   </div>
   <div>
      <a href="accintudsockets.html">Unix Domain Socket Connections</a>
   </div>
   <div class="selected">
      <a href="dataccessclientsconfailandbalance.html">Virtuoso Data Access Clients Connection Fail over and Load Balancing Support</a>
    <div>
        <a href="#dataccessclientsconfailandbalanceodbc" title="ODBC">ODBC</a>
        <a href="#dataccessclientsconfailandbalanceado" title="ADO.Net">ADO.Net</a>
        <a href="#dataccessclientsconfailandbalancejdbc" title="JDBC">JDBC</a>
        <a href="#dataccessclientsconfailandbalanceole" title="OLE DB">OLE DB</a>
        <a href="#dataccessclientsconfailandbalancesesm" title="Sesame">Sesame</a>
    </div>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="dataccessclientsconfailandbalance" />
    <h2>7.8. Virtuoso Data Access Clients Connection Fail over and Load Balancing Support</h2>
  <p>The Virtuoso Data Access Clients ODBC, JDBC, ADO.Net, OLE DB, Sesame, Jena and Redland as of Release 6.1 and above support round
robin connections to Virtuoso server instances enabling server fail over, load balancing and fault tolerant connections to be performed
across multiple server instances configured in a cluster or as separate server instances.
  </p>
  <p>Fail over connections are enabled by specifying a comma delimited list of servers to failover to, in the &quot;Host&quot; or &#39;Server&quot;
connect string attribute, with the list being worked through in the order presented to determine which Virtuoso Server instance is
used. A Round robin (load balanced) connection can be configured by adding the connect string attribute &quot;RoundRobin&quot; = [True | Yes |
False | No], in which case the server for the connection is chosen at random from the comma delimited provided as for a Failover
connection above.
  </p>
  <p>Example connect strings for Virtuoso ODBC, JDBC, ADO.Net and OLE DB driver/providers are provided below. The Virtuoso Sesame
and Jena providers which make use of the JDBC driver and Redland Provider which makes use of the ODBC driver, would simply make use
of a suitably configured JDBC or ODBC connect string to enable Failover or Round Robin connections to be made with them.
  </p>
  <a name="dataccessclientsconfailandbalanceodbc" />
    <h3>7.8.1. ODBC</h3>
    <a name="dataccessclientsconfailandbalanceodbcf" />
    <h4>7.8.1.1. Failover Connect String format</h4>
<div>
      <pre class="programlisting">
Driver={OpenLink Virtuoso};Host=server1:port1,server2:port2,server3:port3;UID=dba;PWD=dba;
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalanceodbcr" />
    <h4>7.8.1.2. Round Robin Connect String format</h4>
<div>
      <pre class="programlisting">
Driver={OpenLink Virtuoso};Host=server1:port1,server2:port2,server3:port3;UID=dba;PWD=dba;RoundRobin=Yes&quot;
</pre>
    </div>
      <p>Or alternatively ensure the &quot;use Round Robin for failover connection&quot; check box in the setup dialog.</p>
      <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="ODBC Round Robin Connect String format" src="../images/ui/adf1.png" />
     </td>
    </tr>
    <tr>
        <td>Figure: 7.8.1.2.1. ODBC Round Robin Connect String format</td>
    </tr>
    </table>
    <br />
  <br />
  <a name="dataccessclientsconfailandbalanceado" />
    <h3>7.8.2. ADO.Net</h3>
    <a name="dataccessclientsconfailandbalanceadof" />
    <h4>7.8.2.1. Failover Connect String format</h4>
<div>
      <pre class="programlisting">
Server=server1:port1,server2:port2,server3;UserId=dba;Password=dba;
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalanceador" />
    <h4>7.8.2.2. Round Robin Connect String format</h4>
<div>
      <pre class="programlisting">
Server=server1:port1,server2:port2,server3;UserId=dba;Password=dba;Round Robin=true;Pooling=false;
</pre>
    </div>
    <br />
  <br />
  <a name="dataccessclientsconfailandbalancejdbc" />
    <h3>7.8.3. JDBC</h3>
    <a name="dataccessclientsconfailandbalancejdbcf" />
    <h4>7.8.3.1. Failover Connect String format</h4>
<div>
      <pre class="programlisting">
jdbc:virtuoso://server1:port1,server2:port2,server3/UID=dba/PWD=dba/;
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalancejdbcr" />
    <h4>7.8.3.2. Round Robin Connect String format</h4>
<div>
      <pre class="programlisting">
jdbc:virtuoso://server1:port1,server2:port2,server3:1111/UID=dba/PWD=dba/ROUNDROBIN=yes;
</pre>
    </div>
    <br />
  <br />
  <a name="dataccessclientsconfailandbalanceole" />
    <h3>7.8.4. OLE DB</h3>
    <a name="dataccessclientsconfailandbalanceolef" />
    <h4>7.8.4.1. Failover Connect String format</h4>
<div>
      <pre class="programlisting">
Provider=VIRTOLEDB;Data Source=server1:port1,server2:port2,server3;User Id=dba;Password=dba;Initial Catalog=Demo;Prompt=NoPrompt;
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalanceoler" />
    <h4>7.8.4.2. Round Robin Connect String format</h4>
<div>
      <pre class="programlisting">
  Provider=VIRTOLEDB;Data Source=server1:port1,server2:port2,server3;User Id=dba;
Password=dba;Initial Catalog=Demo;Prompt=NoPrompt;Round Robin=true
</pre>
    </div>
    <br />
  <br />
  <a name="dataccessclientsconfailandbalancesesm" />
    <h3>7.8.5. Sesame</h3>
    <a name="dataccessclientsconfailandbalancesesmf" />
    <h4>7.8.5.1. Failover Connect String format</h4>
<div>
      <pre class="programlisting">
VirtuosoRepository(&quot;server1:port1,server2:port2,server3&quot;, &quot;uid&quot;, &quot;pwd&quot;);
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalancesesmr" />
    <h4>7.8.5.2. Round Robin Connect String format</h4>
<div>
      <pre class="programlisting">
VirtuosoRepository(&quot;server1:port1,server2:port2,server3&quot;, &quot;uid&quot;, &quot;pwd&quot;);
((VirtuosoRepository)repository).setRoundrobin(true);
</pre>
    </div>
    <br />
    <a name="dataccessclientsconfailandbalancesesms" />
    <h4>7.8.5.3. Sample program</h4>
<div>
      <pre class="programlisting">
/*
 *  $Id: accessinterfaces.xml,v 1.6.2.6 2011/03/05 00:03:22 source Exp $
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2009 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

import java.sql.*;
import java.util.*;
import java.lang.*;

import org.openrdf.model.*;
import org.openrdf.query.*;
import org.openrdf.repository.*;
import org.openrdf.rio.*;
import virtuoso.jdbc4.*;

import virtuoso.sesame2.driver.*;

public class TestSesame2 {

  public static void main(String[] args) {

      Repository repository = new
	VirtuosoRepository(&quot;localhost:1111,localhost:1311,localhost:1312,localhost:1313&quot;, &quot;dba&quot;, &quot;dba&quot;);
      ((VirtuosoRepository)repository).setRoundrobin(true);

      RepositoryConnection con = null;
      Random rnd = new Random();
      for (int i = 0; i &lt; 1000000; ) {
	  try {
	      if (null == con) {
		  System.out.println(&quot;New connection&quot;);
		  con = repository.getConnection();
	      }

	      TupleQuery query = con.prepareTupleQuery(
		      QueryLanguage.SPARQL, &quot;INSERT INTO &lt;test_g&gt; { &lt;sub&quot; + i + &quot;&gt; &lt;pred&gt; &lt;obj&quot; + i+ &quot;&gt; . &quot; +
		      &quot; &lt;r&quot; + Math.abs (rnd.nextInt()) + &quot;&gt; &lt;rndpred&gt; &lt;r&quot; + Math.abs (rnd.nextInt ()) + &quot;&gt; . }&quot;);
	      TupleQueryResult queryResult = query.evaluate();
	      /*long count = 0;
	      while (queryResult.hasNext())
	      {
		  queryResult.next();
		  count++;
		  if (count % 1000 == 0)
		  {
		      System.out.println(&quot;Passed &quot; + count + &quot; results...&quot;);
		  }
	      }
	      */
	      queryResult.close();
	      i++;
	      try { Thread.sleep(100); } catch (InterruptedException ie) { }

	  } catch (Exception e) {
	      String state = &quot;&quot;;
	      if (e.getCause() instanceof SQLException) {
		  state = ((SQLException)e.getCause()).getSQLState();
	      }
	      System.out.println(&quot;ERROR:&quot; + state + &quot; &quot; + e.getCause());
	      try { Thread.sleep(2000); } catch (InterruptedException ie) { }
	      System.out.println(&quot;ERROR:&quot; + e.toString ());
	      if (state == &quot;&quot;)
	        e.printStackTrace();
	      try {
		  if (con != null /*&amp;&amp; (state == &quot;08U01&quot; || state == &quot;S2801&quot;)*/) {
		      System.out.println(&quot;Closing Connection.&quot;);
		      con.close();
		      con = null;
		  }
	      } catch (RepositoryException re) {
		  System.out.println(&quot;Test Failed.&quot;);
		  re.printStackTrace();
		  System.exit (1);
	      }
	  } finally {
	  }
      }
  }
}
</pre>
    </div>
    <br />
  <br />
<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="accintudsockets.html" title="Unix Domain Socket Connections">Previous</a>
          <br />Unix Domain Socket Connections</td>
     <td align="center" width="34%">
          <a href="accessinterfaces.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="sqlreference.html" title="SQL Reference">Next</a>
          <br />Contents of SQL Reference</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>