Strabon

changeset 178:3b65d91a4eac

correct indentation in generaldb/Strabon.java and add @SuppressWarnings("unchecked") in generaldb/SPARQL11Tests.java
author George Garbis <ggarbis@di.uoa.gr>
date Mon May 21 13:09:07 2012 +0300 (2012-05-21)
parents 8f711989f975
children 8521941bf589
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SPARQL11Tests.java
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon May 21 12:54:53 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Mon May 21 13:09:07 2012 +0300
     1.3 @@ -102,14 +102,14 @@
     1.4  	}
     1.5  
     1.6  	public Strabon(String databaseName, String user, String password, int port, String serverName, boolean checkForLockTable) 
     1.7 -			throws SQLException, ClassNotFoundException 
     1.8 -			{
     1.9 +	throws SQLException, ClassNotFoundException 
    1.10 +	{
    1.11  		if (checkForLockTable == true) {
    1.12  			checkAndDeleteLock(databaseName, user, password, port, serverName);
    1.13  		}
    1.14  
    1.15  		initiate(databaseName, user, password, port, serverName);
    1.16 -			}
    1.17 +	}
    1.18  
    1.19  
    1.20  	protected abstract void initiate(String databaseName, String user, String password, int port, String serverName) ;
    1.21 @@ -142,7 +142,7 @@
    1.22  
    1.23  
    1.24  	protected abstract void checkAndDeleteLock(String databaseName, String user, String password, int port, String serverName)
    1.25 -			throws SQLException, ClassNotFoundException ;
    1.26 +	throws SQLException, ClassNotFoundException ;
    1.27  
    1.28  	public SailRepositoryConnection getSailRepoConnection() {
    1.29  		return con1;
    1.30 @@ -171,27 +171,27 @@
    1.31  	}
    1.32  
    1.33  	public Object query(String queryString)
    1.34 -			throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.35 -			{
    1.36 +	throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.37 +	{
    1.38  		return query(queryString, "", this.getSailRepoConnection());	
    1.39 -			}
    1.40 +	}
    1.41  
    1.42  	public Object query(String queryString, String resultsFormat)
    1.43 -			throws  MalformedQueryException , QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.44 -			{
    1.45 +	throws  MalformedQueryException , QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.46 +	{
    1.47  		return query (queryString, resultsFormat, this.getSailRepoConnection());
    1.48 -			}
    1.49 +	}
    1.50  
    1.51  	public Object query(String queryString, SailRepositoryConnection con)
    1.52 -			throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.53 -			{
    1.54 +	throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException
    1.55 +	{
    1.56  		return query(queryString, "", con);	
    1.57 -			}
    1.58 +	}
    1.59  
    1.60  	public Object query(String queryString, String resultsFormat, SailRepositoryConnection con)
    1.61 -			throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 
    1.62 +	throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 
    1.63  
    1.64 -			{
    1.65 +	{
    1.66  		TupleQuery tupleQuery = null;
    1.67  		try {
    1.68  			tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    1.69 @@ -635,7 +635,7 @@
    1.70  				if(resultsFormat.equalsIgnoreCase("KML"))
    1.71  				{
    1.72  					writeOut.write(newString);
    1.73 -//					System.out.println(newString);
    1.74 +					//					System.out.println(newString);
    1.75  				}
    1.76  				else //KMZ
    1.77  				{
    1.78 @@ -650,30 +650,30 @@
    1.79  					//kmzout.setLevel(6);
    1.80  					kmzout.putNextEntry(entry);
    1.81  					kmzout.write(newString.getBytes());
    1.82 -				    kmzout.closeEntry();
    1.83 +					kmzout.closeEntry();
    1.84  					kmzout.close();
    1.85 -					
    1.86 +
    1.87  					//String kmzString = FileUtils.readFileToString(zfile);
    1.88 -		            //writeOut.write(kmzString);
    1.89 +					//writeOut.write(kmzString);
    1.90  					/*
    1.91  					try {
    1.92  						File file = new File("/tmp/tmp.kml");
    1.93  						String filename = "/tmp/tmp.kml";
    1.94  						FileUtils.writeStringToFile(file, newString);
    1.95 -						
    1.96 +
    1.97  						File zfile = new File("/tmp/tmp.kmz");
    1.98  			            String zipfilename = "/tmp/tmp.kmz";
    1.99 -						
   1.100 +
   1.101  			            byte[] buf = new byte[1024];
   1.102  			            FileInputStream fis = new FileInputStream(filename);
   1.103  			            fis.read(buf,0,buf.length);
   1.104 -			            
   1.105 +
   1.106  			            CRC32 crc = new CRC32();
   1.107  			            ZipOutputStream s = new ZipOutputStream(
   1.108  			                    (OutputStream)new FileOutputStream(zipfilename));
   1.109 -			            
   1.110 +
   1.111  			            //s.setLevel(6);
   1.112 -			            
   1.113 +
   1.114  			            ZipEntry entry = new ZipEntry(filename);
   1.115  			            entry.setSize((long)buf.length);
   1.116  			            crc.reset();
   1.117 @@ -683,17 +683,17 @@
   1.118  			            s.write(buf, 0, buf.length);
   1.119  			            s.finish();
   1.120  			            s.close();
   1.121 -			            
   1.122 +
   1.123  			            String kmzString = FileUtils.readFileToString(zfile);
   1.124  			            writeOut.write(kmzString);
   1.125 -			            
   1.126 +
   1.127  			            //FileUtils.forceDelete(file);
   1.128  			            //FileUtils.forceDelete(zfile);
   1.129 -			            
   1.130 +
   1.131  			        } catch (Exception e) {
   1.132  			            e.printStackTrace();
   1.133  			        }
   1.134 -						*/				
   1.135 +					 */				
   1.136  				}
   1.137  
   1.138  			} catch (IOException e) {
   1.139 @@ -776,7 +776,7 @@
   1.140  
   1.141  		//return ret;
   1.142  		return retStream.toString();
   1.143 -			}
   1.144 +	}
   1.145  
   1.146  	public void update(String updateString, SailRepositoryConnection con) throws MalformedQueryException 
   1.147  
     2.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SPARQL11Tests.java	Mon May 21 12:54:53 2012 +0300
     2.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SPARQL11Tests.java	Mon May 21 13:09:07 2012 +0300
     2.3 @@ -6,7 +6,6 @@
     2.4  import java.io.IOException;
     2.5  import java.util.ArrayList;
     2.6  
     2.7 -import org.junit.AfterClass;
     2.8  import org.junit.Test;
     2.9  import org.openrdf.model.vocabulary.RDF;
    2.10  import org.openrdf.model.vocabulary.XMLSchema;
    2.11 @@ -15,8 +14,6 @@
    2.12  import org.openrdf.query.TupleQueryResultHandlerException;
    2.13  import org.openrdf.repository.RepositoryException;
    2.14  
    2.15 -import eu.earthobservatory.runtime.generaldb.Strabon;
    2.16 -
    2.17  
    2.18  public class SPARQL11Tests {
    2.19  	public static Strabon strabon;
    2.20 @@ -59,6 +56,7 @@
    2.21  			"WHERE \n" +
    2.22  			"{ ?s ?p ?o . } \n";
    2.23  		
    2.24 +		@SuppressWarnings("unchecked")
    2.25  		ArrayList<String> results =  (ArrayList <String>)strabon.query(queryString, strabon.getSailRepoConnection());
    2.26  		assertEquals(62, results.size());
    2.27  	}
    2.28 @@ -73,6 +71,7 @@
    2.29  			" ?x foaf:mbox ?mbox ." +
    2.30  			" } \n";
    2.31  		
    2.32 +		@SuppressWarnings("unchecked")
    2.33  		ArrayList<String> results = (ArrayList <String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.34  		assertEquals(11, results.size());
    2.35  	}
    2.36 @@ -84,6 +83,7 @@
    2.37  		"SELECT ?v WHERE { ?v ns:p ?s . FILTER(str(?s) = \"cat\") } \n";
    2.38  //		"SELECT ?v WHERE { ?v ns:p \"cat\" } \n";
    2.39  		
    2.40 +		@SuppressWarnings("unchecked")
    2.41  		ArrayList<String> results = (ArrayList <String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.42  		assertEquals(1, results.size());
    2.43  		assertTrue(-1<results.indexOf("[v=http://example.org#x]"));
    2.44 @@ -95,6 +95,7 @@
    2.45  		String queryString = prefixes+
    2.46  			"SELECT ?v WHERE { ?v ns:p \"cat\"@en } \n";
    2.47  		
    2.48 +		@SuppressWarnings("unchecked")
    2.49  		ArrayList<String> results = (ArrayList <String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.50  		assertEquals(1, results.size());
    2.51  		assertTrue(-1<results.indexOf("[v=http://example.org#x]"));
    2.52 @@ -106,6 +107,7 @@
    2.53  		String queryString = prefixes+
    2.54  			"SELECT ?v WHERE { ?v ns:p 42 } \n";
    2.55  		
    2.56 +		@SuppressWarnings("unchecked")
    2.57  		ArrayList<String> results = (ArrayList <String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.58  		assertEquals(1, results.size());
    2.59  		assertTrue(-1<results.indexOf("[v=http://example.org#y]"));
    2.60 @@ -117,6 +119,7 @@
    2.61  		String queryString = prefixes+
    2.62  			"SELECT ?v WHERE { ?v ?p \"abc\"^^dt:specialDatatype } \n";
    2.63  		
    2.64 +		@SuppressWarnings("unchecked")
    2.65  		ArrayList<String> results = (ArrayList <String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.66  		assertEquals(1, results.size());
    2.67  		assertTrue(-1<results.indexOf("[v=http://example.org#z]"));
    2.68 @@ -133,6 +136,7 @@
    2.69  			" BIND( CONCAT(?G, \" \", ?S) AS ?name ) . \n"+
    2.70  			"} \n";
    2.71  		
    2.72 +		@SuppressWarnings("unchecked")
    2.73  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.74  		assertEquals(1, results.size());
    2.75  		assertTrue(-1<results.indexOf("[name=\"John Doe\"]"));
    2.76 @@ -146,6 +150,7 @@
    2.77  			"SELECT ( CONCAT(?G, \" \", ?S) AS ?name ) \n" +
    2.78  			"WHERE  { ?P foaf:givenName ?G ; foaf:surname ?S } \n";
    2.79  		
    2.80 +		@SuppressWarnings("unchecked")
    2.81  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.82  		assertEquals(1, results.size());
    2.83  		assertTrue(-1<results.indexOf("[name=\"John Doe\"]"));
    2.84 @@ -160,6 +165,7 @@
    2.85  			"	OPTIONAL { ?x  foaf:mbox  ?mbox } \n"+
    2.86         		"} \n";
    2.87  		
    2.88 +		@SuppressWarnings("unchecked")
    2.89  		ArrayList<String> results = (ArrayList<String>)strabon.query(queryString, strabon.getSailRepoConnection());
    2.90  		assertEquals(13, results.size());
    2.91  		assertTrue(-1<results.indexOf("[name=\"Alice\";mbox=mailto:alice@example.com]"));
    2.92 @@ -176,6 +182,7 @@
    2.93  			"	OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) } \n"+
    2.94          	"}\n";
    2.95  		
    2.96 +		@SuppressWarnings("unchecked")
    2.97  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
    2.98  		assertEquals(4, results.size());
    2.99  		assertTrue(-1<results.indexOf("[title=\"SPARQL Tutorial\"]"));
   2.100 @@ -194,9 +201,11 @@
   2.101  			"	OPTIONAL { ?x foaf:homepage ?hpage } . \n"+
   2.102         		"} ORDER BY ?name \n";
   2.103  		
   2.104 +		@SuppressWarnings("unchecked")
   2.105  		ArrayList<String> results = (ArrayList<String>)strabon.query(queryString, strabon.getSailRepoConnection());
   2.106 +		
   2.107  		assertEquals(13, results.size());
   2.108 -		assertTrue(-1<results.indexOf("[hpage=http://work.example.org/alice/;mbox=mailto:alice@example.com;name=\"A. Foo\"]"));
   2.109 +		assertTrue(-1<results.indexOf("[hpage=http://work.example.org/alice/;name=\"A. Foo\";mbox=mailto:alice@example.com]"));
   2.110  		assertTrue(-1<results.indexOf("[name=\"Bob\";mbox=mailto:bob@work.example]"));
   2.111  		assertTrue(-1<results.indexOf("[name=\"C. Baz\"]"));
   2.112  	}
   2.113 @@ -212,6 +221,7 @@
   2.114  			"	FILTER NOT EXISTS { ?person foaf:name ?name } . \n"+
   2.115  			"}    \n";
   2.116  		
   2.117 +		@SuppressWarnings("unchecked")
   2.118  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.119  		assertEquals(0, results.size()); // TODO add such an item
   2.120  	}
   2.121 @@ -226,6 +236,7 @@
   2.122  			"	FILTER EXISTS { ?person foaf:name ?name } \n"+
   2.123  			"} \n";
   2.124  		
   2.125 +		@SuppressWarnings("unchecked")
   2.126  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.127  		assertEquals(2, results.size());
   2.128  		assertTrue(-1<results.indexOf("[person=http://example.org#bob]"));
   2.129 @@ -243,6 +254,7 @@
   2.130  			"	?s foaf:givenName \"Bob\" . \n"+
   2.131  			"} } \n";
   2.132  		
   2.133 +		@SuppressWarnings("unchecked")
   2.134  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.135  		assertEquals(19, results.size());
   2.136  	}
   2.137 @@ -260,6 +272,7 @@
   2.138  			+"GROUP BY ?org HAVING (SUM(?lprice) > 10) \n"
   2.139  			;
   2.140  		
   2.141 +		@SuppressWarnings("unchecked")
   2.142  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.143  		assertEquals(1, results.size());
   2.144  		assertTrue(-1<results.indexOf("[totalPrice=\"21\"^^<http://www.w3.org/2001/XMLSchema#integer>]"));
   2.145 @@ -274,6 +287,7 @@
   2.146  			"	FILTER regex(?title, \"^SPARQL\") \n"+ 
   2.147          	"} ORDER BY ?title\n";
   2.148  		
   2.149 +		@SuppressWarnings("unchecked")
   2.150  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.151  		assertEquals(3, results.size());
   2.152  		assertTrue(-1<results.indexOf("[title=\"SPARQL Protocol Tutorial\"]"));
   2.153 @@ -290,6 +304,7 @@
   2.154  			"	FILTER regex(?title, \"web\", \"i\" ) ."+ 
   2.155          	"} \n";
   2.156  		
   2.157 +		@SuppressWarnings("unchecked")
   2.158  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.159  		assertEquals(1, results.size());
   2.160  		assertTrue(-1<results.indexOf("[title=\"The Semantic Web\"]"));
   2.161 @@ -302,6 +317,7 @@
   2.162  			"SELECT ?title \n"+
   2.163  			"WHERE  { { ?book dc10:title  ?title } UNION { ?book dc11:title  ?title } } \n";
   2.164  		
   2.165 +		@SuppressWarnings("unchecked")
   2.166  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.167  		assertEquals(6, results.size());
   2.168  		assertTrue(-1<results.indexOf("[title=\"SPARQL Query Language Tutorial\"]"));
   2.169 @@ -318,7 +334,8 @@
   2.170  		String queryString = prefixes+
   2.171  			"SELECT ?x ?y \n"+
   2.172  			"WHERE  { { ?book dc10:title  ?x } UNION { ?book dc11:title  ?y } } \n";
   2.173 -		
   2.174 +	
   2.175 +		@SuppressWarnings("unchecked")
   2.176  		ArrayList<String> results = (ArrayList<String>) strabon.query(queryString, strabon.getSailRepoConnection());
   2.177  		assertEquals(6, results.size());
   2.178  		assertTrue(-1<results.indexOf("[x=\"SPARQL Query Language Tutorial\"]"));