Strabon
changeset 5:4742cd1f751c
update functionality added (not fully tested yet)
.hgignore edited (added patterns: .project classpath settings)
.hgignore edited (added patterns: .project classpath settings)
author | Giorgos Garbis <ggarbis@di.uoa.gr> |
---|---|
date | Wed Feb 01 20:14:26 2012 +0200 (2012-02-01) |
parents | ca4328324835 |
children | 23e6ac4be21d |
files | .hgignore generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/InvalidDatasetFormatFault.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java |
line diff
1.1 --- a/.hgignore Fri Jan 27 01:14:54 2012 +0200 1.2 +++ b/.hgignore Wed Feb 01 20:14:26 2012 +0200 1.3 @@ -1,1 +1,6 @@ 1.4 /target$ 1.5 +\.project 1.6 +\.hgignore 1.7 +classpath 1.8 +settings 1.9 +
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java Fri Jan 27 01:14:54 2012 +0200 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java Wed Feb 01 20:14:26 2012 +0200 2.3 @@ -5,12 +5,12 @@ 2.4 */ 2.5 package org.openrdf.sail.generaldb; 2.6 2.7 +import info.aduna.concurrent.locks.Lock; 2.8 +import info.aduna.concurrent.locks.WritePrefReadWriteLockManager; 2.9 + 2.10 import java.io.IOException; 2.11 import java.sql.SQLException; 2.12 2.13 -import info.aduna.concurrent.locks.Lock; 2.14 -import info.aduna.concurrent.locks.WritePrefReadWriteLockManager; 2.15 - 2.16 import org.openrdf.model.BNode; 2.17 import org.openrdf.model.Literal; 2.18 import org.openrdf.model.Resource; 2.19 @@ -18,23 +18,26 @@ 2.20 import org.openrdf.model.URI; 2.21 import org.openrdf.model.Value; 2.22 import org.openrdf.model.ValueFactory; 2.23 +import org.openrdf.model.impl.LiteralImpl; 2.24 +import org.openrdf.model.impl.URIImpl; 2.25 import org.openrdf.model.impl.ValueFactoryBase; 2.26 -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 2.27 -import org.openrdf.sail.rdbms.exceptions.RdbmsException; 2.28 -import org.openrdf.sail.rdbms.exceptions.RdbmsRuntimeException; 2.29 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 2.30 import org.openrdf.sail.generaldb.managers.BNodeManager; 2.31 import org.openrdf.sail.generaldb.managers.LiteralManager; 2.32 import org.openrdf.sail.generaldb.managers.PredicateManager; 2.33 import org.openrdf.sail.generaldb.managers.UriManager; 2.34 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 2.35 +import org.openrdf.sail.generaldb.schema.IdSequence; 2.36 +import org.openrdf.sail.generaldb.schema.LiteralTable; 2.37 +import org.openrdf.sail.generaldb.schema.ValueTable; 2.38 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 2.39 +import org.openrdf.sail.rdbms.exceptions.RdbmsRuntimeException; 2.40 import org.openrdf.sail.rdbms.model.RdbmsBNode; 2.41 import org.openrdf.sail.rdbms.model.RdbmsLiteral; 2.42 import org.openrdf.sail.rdbms.model.RdbmsResource; 2.43 import org.openrdf.sail.rdbms.model.RdbmsStatement; 2.44 import org.openrdf.sail.rdbms.model.RdbmsURI; 2.45 import org.openrdf.sail.rdbms.model.RdbmsValue; 2.46 -import org.openrdf.sail.generaldb.schema.IdSequence; 2.47 -import org.openrdf.sail.generaldb.schema.LiteralTable; 2.48 -import org.openrdf.sail.generaldb.schema.ValueTable; 2.49 2.50 import com.vividsolutions.jts.io.ParseException; 2.51 2.52 @@ -224,9 +227,60 @@ 2.53 return null; 2.54 if (value instanceof Literal) 2.55 return asRdbmsLiteral((Literal)value); 2.56 + /*****************************************/ 2.57 + if (value instanceof GeneralDBPolyhedron) 2.58 + return asRdbmsLiteral((GeneralDBPolyhedron)value); 2.59 + if (value instanceof StrabonPolyhedron) 2.60 + return asRdbmsLiteral((StrabonPolyhedron)value); 2.61 + /****************************************/ 2.62 return asRdbmsResource((Resource)value); 2.63 } 2.64 2.65 + /****************************************************/ 2.66 + public RdbmsLiteral asRdbmsLiteral(GeneralDBPolyhedron polyhedron) { 2.67 + try { 2.68 + URI wkt = new URIImpl(StrabonPolyhedron.ogcGeometry); 2.69 + RdbmsLiteral literal = new RdbmsLiteral(new LiteralImpl(polyhedron.stringValue(), wkt)); 2.70 + 2.71 + if (polyhedron instanceof GeneralDBPolyhedron) { 2.72 + literals.cache(literal); 2.73 + return (RdbmsLiteral)literal; 2.74 + } 2.75 + RdbmsLiteral lit = literals.findInCache(literal); 2.76 + if (lit == null) { 2.77 + lit = new RdbmsLiteral(literal); 2.78 + literals.cache(lit); 2.79 + } 2.80 + return lit; 2.81 + } 2.82 + catch (InterruptedException e) { 2.83 + throw new RdbmsRuntimeException(e); 2.84 + } 2.85 + } 2.86 + 2.87 + public RdbmsLiteral asRdbmsLiteral(StrabonPolyhedron polyhedron) { 2.88 + try { 2.89 + URI wkt = new URIImpl(StrabonPolyhedron.ogcGeometry); 2.90 + RdbmsLiteral literal = new RdbmsLiteral(new LiteralImpl(polyhedron.stringValue(), wkt)); 2.91 + 2.92 + if (polyhedron instanceof StrabonPolyhedron) { 2.93 + literals.cache(literal); 2.94 + return (RdbmsLiteral)literal; 2.95 + } 2.96 + RdbmsLiteral lit = literals.findInCache(literal); 2.97 + if (lit == null) { 2.98 + lit = new RdbmsLiteral(literal); 2.99 + literals.cache(lit); 2.100 + } 2.101 + return lit; 2.102 + } 2.103 + catch (InterruptedException e) { 2.104 + throw new RdbmsRuntimeException(e); 2.105 + } 2.106 +} 2.107 + /****************************************************/ 2.108 + 2.109 + 2.110 public RdbmsLiteral asRdbmsLiteral(Literal literal) { 2.111 try { 2.112 if (literal instanceof RdbmsLiteral) {
3.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Fri Jan 27 01:14:54 2012 +0200 3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Wed Feb 01 20:14:26 2012 +0200 3.3 @@ -252,6 +252,7 @@ 3.4 bool |= datatypes.expunge(condition); 3.5 bool |= numeric.expunge(condition); 3.6 bool |= dateTime.expunge(condition); 3.7 + bool |= geoSpatialTable.expunge(condition); 3.8 return bool; 3.9 } 3.10 }
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/InvalidDatasetFormatFault.java Wed Feb 01 20:14:26 2012 +0200 4.3 @@ -0,0 +1,5 @@ 4.4 +package eu.earthobservatory.runtime.generaldb; 4.5 + 4.6 +public class InvalidDatasetFormatFault extends Exception { 4.7 + 4.8 +}
5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Fri Jan 27 01:14:54 2012 +0200 5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed Feb 01 20:14:26 2012 +0200 5.3 @@ -1,13 +1,14 @@ 5.4 package eu.earthobservatory.runtime.generaldb; 5.5 5.6 import java.io.DataOutputStream; 5.7 +import java.io.File; 5.8 import java.io.IOException; 5.9 import java.io.OutputStreamWriter; 5.10 import java.io.StringReader; 5.11 +import java.net.URL; 5.12 import java.nio.charset.Charset; 5.13 import java.sql.SQLException; 5.14 import java.util.ArrayList; 5.15 -import java.util.Scanner; 5.16 import java.util.Set; 5.17 5.18 import javax.xml.namespace.QName; 5.19 @@ -16,7 +17,9 @@ 5.20 import org.geotools.kml.KML; 5.21 import org.geotools.kml.KMLConfiguration; 5.22 import org.geotools.xml.Encoder; 5.23 +import org.openrdf.model.URI; 5.24 import org.openrdf.model.Value; 5.25 +import org.openrdf.model.ValueFactory; 5.26 import org.openrdf.query.Binding; 5.27 import org.openrdf.query.BindingSet; 5.28 import org.openrdf.query.MalformedQueryException; 5.29 @@ -31,6 +34,8 @@ 5.30 import org.openrdf.repository.RepositoryException; 5.31 import org.openrdf.repository.sail.SailRepository; 5.32 import org.openrdf.repository.sail.SailRepositoryConnection; 5.33 +import org.openrdf.rio.RDFFormat; 5.34 +import org.openrdf.rio.RDFParseException; 5.35 import org.openrdf.sail.helpers.SailBase; 5.36 5.37 import com.vividsolutions.jts.geom.Geometry; 5.38 @@ -178,7 +183,7 @@ 5.39 5.40 while (result.hasNext()) { 5.41 BindingSet bindingSet = result.next(); 5.42 - //System.out.println(bindingSet.toString()); 5.43 + System.out.println(bindingSet.toString()); 5.44 5.45 ret.add(bindingSet.toString()); 5.46 } 5.47 @@ -474,7 +479,8 @@ 5.48 e.printStackTrace(); 5.49 } 5.50 5.51 - //System.out.println(retStream.toString()); 5.52 + // Print results. 5.53 + System.out.println(retStream.toString()); 5.54 5.55 //return ret; 5.56 return retStream.toString(); 5.57 @@ -491,18 +497,136 @@ 5.58 e.printStackTrace(); 5.59 } 5.60 5.61 - //System.out.println("Placemark0"); 5.62 + System.out.println("Placemark0"); 5.63 System.out.println("\n\n\nGot query: " + updateString + "\n\n\n"); 5.64 5.65 try { 5.66 update.execute(); 5.67 - } catch (UpdateExecutionException e) { 5.68 + } catch (UpdateExecutionException e) { e.printStackTrace(); 5.69 + } 5.70 + 5.71 + System.out.println("-------------------------------------------"); 5.72 + System.out.println("- UPDATE EXECUTED -"); 5.73 + System.out.println("-------------------------------------------"); 5.74 + } 5.75 + 5.76 + private void store(File file, String baseURI, RDFFormat format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault { 5.77 + con1.add(file, baseURI, format); 5.78 + } 5.79 + public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault 5.80 + { 5.81 + storeInRepo(src, null, null, format); 5.82 + } 5.83 + 5.84 + public void storeInRepo(Object src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault 5.85 + { 5.86 + RDFFormat realFormat = null; 5.87 + 5.88 + if ((baseURI != null) && (baseURI.equals(""))) 5.89 + baseURI = null; 5.90 + 5.91 + URI uriContext; 5.92 + 5.93 + if ((context == null) || (context.equals(""))) { 5.94 + uriContext = null; 5.95 + } else { 5.96 + ValueFactory f = repo1.getValueFactory(); 5.97 + uriContext = f.createURI(context); 5.98 + } 5.99 + 5.100 + 5.101 + if(format.equalsIgnoreCase("N3")) 5.102 + { 5.103 + realFormat = RDFFormat.N3; 5.104 + } 5.105 + else if(format.equalsIgnoreCase("NTRIPLES")) 5.106 + { 5.107 + realFormat = RDFFormat.NTRIPLES; 5.108 + } 5.109 + else if(format.equalsIgnoreCase("RDFXML")) 5.110 + { 5.111 + realFormat = RDFFormat.RDFXML; 5.112 + } 5.113 + else if(format.equalsIgnoreCase("TURTLE")) 5.114 + { 5.115 + realFormat = RDFFormat.TURTLE; 5.116 + } 5.117 + else 5.118 + { 5.119 + throw new InvalidDatasetFormatFault(); 5.120 + } 5.121 + 5.122 + try 5.123 + { 5.124 + if(File.class.isInstance(src)) 5.125 + { 5.126 + storeFile((File)src, baseURI, uriContext, realFormat); 5.127 + } 5.128 + else if(URL.class.isInstance(src)) 5.129 + { 5.130 + storeURL((URL)src, baseURI, uriContext, realFormat); 5.131 + } 5.132 + else if(String.class.isInstance(src)) 5.133 + { 5.134 + storeString((String)src, baseURI, uriContext, realFormat); 5.135 + } 5.136 + } 5.137 + catch(NullPointerException e) 5.138 + { 5.139 e.printStackTrace(); 5.140 } 5.141 + } 5.142 + 5.143 + private void storeFile(File file, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 5.144 + { 5.145 + System.out.println("File : " + file.getName()); 5.146 + System.out.println("Base URI : " + ((baseURI == null) ? "null" : baseURI)); 5.147 + System.out.println("Context : " + ((context == null) ? "null" : context)); 5.148 + System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 5.149 5.150 - //System.out.println("-------------------------------------------"); 5.151 - System.out.println("- UPDATE EXECUTED -"); 5.152 - //System.out.println("-------------------------------------------"); 5.153 + if (context == null) { 5.154 + System.out.println("[1]"); 5.155 + con1.add(file, baseURI, format); 5.156 + } else { 5.157 + System.out.println("[2]"); 5.158 + con1.add(file, baseURI, format, context); 5.159 + } 5.160 + } 5.161 + 5.162 + private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 5.163 + { 5.164 + System.out.println("URL : " + url.toString()); 5.165 + System.out.println("Base URI : " + ((baseURI == null) ? "null" : baseURI)); 5.166 + System.out.println("Context : " + ((context == null) ? "null" : context)); 5.167 + System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 5.168 + 5.169 + if (context == null) { 5.170 + System.out.println("[3]"); 5.171 + con1.add(url, baseURI, format); 5.172 + } else { 5.173 + System.out.println("[4]"); 5.174 + con1.add(url, baseURI, format, context); 5.175 + } 5.176 + } 5.177 + 5.178 + private void storeString(String text, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 5.179 + { 5.180 + if (baseURI == null) 5.181 + baseURI = ""; 5.182 + 5.183 + System.out.println("Text : " + text); 5.184 + System.out.println("Base URI : " + ((baseURI == null) ? "null" : baseURI)); 5.185 + System.out.println("Context : " + ((context == null) ? "null" : context)); 5.186 + System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 5.187 + 5.188 + StringReader reader = new StringReader(text); 5.189 + if (context == null) { 5.190 + System.out.println("[5]"); 5.191 + con1.add(reader, baseURI, format); 5.192 + } else { 5.193 + System.out.println("[6]"); 5.194 + con1.add(reader, baseURI, format, context); 5.195 + } 5.196 } 5.197 5.198 }
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Wed Feb 01 20:14:26 2012 +0200 6.3 @@ -0,0 +1,66 @@ 6.4 +package eu.earthobservatory.runtime.postgis; 6.5 + 6.6 + 6.7 +public class QueryOp { 6.8 + 6.9 + /** 6.10 + * @param args 6.11 + * @throws Exception 6.12 + */ 6.13 + public static void main(String[] args) throws Exception { 6.14 + 6.15 + if (args.length < 6) { 6.16 + System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> "); 6.17 + System.err.println(" where <HOST> is the postgis database host to connect to"); 6.18 + System.err.println(" <PORT> is the port to connect to on the database host"); 6.19 + System.err.println(" <DATABASE> is the spatially enabled postgis database that Strabon will use as a backend, "); 6.20 + System.err.println(" <USERNAME> is the username to use when connecting to the database "); 6.21 + System.err.println(" <PASSWORD> is the password to use when connecting to the database"); 6.22 + System.err.println(" <QUERY> is the stSPARQL query to evaluate."); 6.23 + System.err.println(" [<FORMAT>] is the format of your results (XML)"); 6.24 + System.exit(0); 6.25 + } 6.26 + 6.27 + String host = args[0]; 6.28 + Integer port = new Integer(args[1]); 6.29 + String db = args[2]; 6.30 + String user = args[3]; 6.31 + String passwd = args[4]; 6.32 + String queryString = args[5]; 6.33 + String resultsFormat = ""; 6.34 + if ( args.length == 7 ) { 6.35 + resultsFormat = args[6]; 6.36 + } 6.37 + 6.38 + 6.39 + 6.40 + 6.41 + Strabon strabon = new Strabon(db, user, passwd, port, host, true); 6.42 + 6.43 + strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection()); 6.44 + 6.45 + strabon.close(); 6.46 + } 6.47 + /* 6.48 + private static void query(String queryString, SailRepositoryConnection con) throws MalformedQueryException, RepositoryException, QueryEvaluationException, IOException, ClassNotFoundException, TupleQueryResultHandlerException { 6.49 + TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString); 6.50 + 6.51 + System.out.println(queryString); 6.52 + TupleQueryResult result = tupleQuery.evaluate(); 6.53 + 6.54 + System.out.println("-------------------------------------------"); 6.55 + System.out.println("- RESULTS -"); 6.56 + System.out.println("-------------------------------------------"); 6.57 + 6.58 + tupleQuery.evaluate(new SPARQLResultsXMLWriter(System.out)); 6.59 + 6.60 + List<String> bindingNames = result.getBindingNames(); 6.61 + while (result.hasNext()) { 6.62 + BindingSet bindingSet = result.next(); 6.63 + System.out.println(bindingSet.toString()); 6.64 + } 6.65 + System.out.println("-------------------------------------------"); 6.66 + System.out.flush(); 6.67 + } 6.68 + */ 6.69 +}