Index: VirtGraph.java
===================================================================
RCS file: /cvsroot/virtuoso/virtuoso-opensource/binsrc/jena/virtuoso_driver/VirtGraph.java,v
retrieving revision 1.18
diff -u -r1.18 VirtGraph.java
--- VirtGraph.java	18 Sep 2009 08:57:40 -0000	1.18
+++ VirtGraph.java	17 Jan 2010 03:52:52 -0000
@@ -23,31 +23,29 @@
 
 package virtuoso.jena.driver;
 
+import java.net.*;
 import java.sql.*;
-import java.io.*;
 import java.util.*;
 
 import virtuoso.sql.*;
 
 import com.hp.hpl.jena.graph.*;
 import com.hp.hpl.jena.graph.impl.*;
-import com.hp.hpl.jena.graph.impl.LiteralLabel;
 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
-import com.hp.hpl.jena.util.iterator.NiceIterator;
-import com.hp.hpl.jena.db.impl.ResultSetIterator;
 import com.hp.hpl.jena.shared.*;
-import com.hp.hpl.jena.db.impl.*;
 import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.graph.query.*;
 import com.hp.hpl.jena.datatypes.*;
 import com.hp.hpl.jena.rdf.model.*;
 
 import virtuoso.jdbc3.VirtuosoConnectionPoolDataSource;
 
+
 public class VirtGraph extends GraphBase
 {
+	
     static public final String DEFAULT = "virt:DEFAULT";
     private String graphName;
+    private boolean readFromAllGraphs = false;
     private String url_hostlist;
     private String user;
     private String password;
@@ -173,8 +171,6 @@
         delete(t);
     }
 
-
-
 // GraphBase overrides
     String Node2Str(Node n)
     {
@@ -207,7 +203,15 @@
       }
     }
 
-    void bindSubject(PreparedStatement ps, int col, Node n) throws SQLException 
+    public boolean getReadFromAllGraphs() {
+		return readFromAllGraphs;
+	}
+
+	public void setReadFromAllGraphs(boolean readFromAllGraphs) {
+		this.readFromAllGraphs = readFromAllGraphs;
+	}
+
+	void bindSubject(PreparedStatement ps, int col, Node n) throws SQLException 
     {
       if (n == null)
 	return;
@@ -312,7 +316,11 @@
      */
 //--java5 or newer    @Override
     protected int graphBaseSize() {
-	String query = "select count(*) from (sparql define input:storage \"\" select * where { graph `iri(??)` { ?s ?p ?o }})f";
+	String query = "select count(*) from (sparql define input:storage \"\" select * where { graph `iri(??)` { ?s ?p ?o }})";
+	
+	if ( readFromAllGraphs )
+		query = "select count(*) from (sparql define input:storage \"\" select * where {?s ?p ?o })";
+	
 	ResultSet rs = null;
 	int ret = 0;
 
@@ -320,7 +328,10 @@
 
 	try {
 		java.sql.PreparedStatement ps = connection.prepareStatement(query);
-		ps.setString(1, graphName);
+		
+		if ( readFromAllGraphs == false )
+			ps.setString(1, graphName);
+		
 		rs = ps.executeQuery();
 		if (rs.next())
 		  ret = rs.getInt(1);
@@ -358,6 +369,9 @@
 
 	exec_text = "sparql define input:storage \"\" select * where { graph <"+ 
 			this.graphName +"> { " + S +" "+ P +" "+ O +" }} limit 1";
+	
+	if ( readFromAllGraphs )
+			exec_text = "sparql define input:storage \"\" select * where { " + S +" "+ P +" "+ O +" } limit 1";
 
 	try {
 		java.sql.Statement stmt = connection.createStatement();
@@ -389,8 +403,10 @@
 	if (tm.getMatchObject() != null)
 		O = Node2Str(tm.getMatchObject());
 
-	exec_text = "sparql select * from <" + this.graphName + "> where { " 
-			+ S +" "+ P +" "+ O + " }";
+	exec_text = "sparql select * from <" + this.graphName + "> where { " + S +" "+ P +" "+ O + " }";
+	
+	if ( readFromAllGraphs )
+		exec_text = "sparql select * where { "+ S +" "+ P +" "+ O + " }";
 
 	try {
 		java.sql.PreparedStatement stmt = connection
@@ -582,13 +598,11 @@
 	}
     }
 
-
     public ExtendedIterator reifierTriples( TripleMatch m )
-        { return NullIterator.instance; }
+        { return NullIterator.instance(); }
 
     public int reifierSize()
         { return 0; }
-
     
     
 //--java5 or newer    @Override
@@ -614,7 +628,14 @@
 	return m_prefixMapping; 
     }
 
-
+    private static Node validIRIOrLiteral(ExtendedString es){
+    	try {
+			return Node.createURI( (new URI( es.toString() )).toString() );
+		} catch (URISyntaxException e) {}
+		return Node.createLiteral(es.toString()); 
+    }
+    
+    
     public static Node Object2Node(Object o)
     {
       if (o == null) 
@@ -627,7 +648,7 @@
             if (vs.toString().indexOf ("_:") == 0)
               return Node.createAnon(AnonId.create(vs.toString().substring(2))); // _:
             else
-              return Node.createURI(vs.toString());
+              return validIRIOrLiteral(vs);
           } else if (vs.getIriType() == ExtendedString.BNODE) {
             return Node.createAnon(AnonId.create(vs.toString().substring(9))); // nodeID://
           } else {
