# HG changeset patch # User George Garbis # Date 1364301247 -7200 # Node ID f662352c379961652833433b73dde357d4572ed1 # Parent 93d1b4ce44a644b363b48f782f8035ffcc3262ef# Parent 2daceed2f0d0bd968586b8c25ca9fccf92955cdd merge with default for full GeoSPARQL support diff -r 93d1b4ce44a6 -r f662352c3799 .hgtags --- a/.hgtags Sun Mar 10 22:14:24 2013 +0200 +++ b/.hgtags Tue Mar 26 14:34:07 2013 +0200 @@ -16,3 +16,4 @@ 7089b2d52c7f36b40301063efc73476a093f2134 v3.2.5 97afadc6d589b318924ca774659418c055fdf3a0 v3.2.6 b3e0d7415823df2e814aa6fa45aa13374a81e706 v3.2.7 +389213ce7843a9c490be447400c1a5c46d44cc96 v3.2.8 diff -r 93d1b4ce44a6 -r f662352c3799 ChangeLog --- a/ChangeLog Sun Mar 10 22:14:24 2013 +0200 +++ b/ChangeLog Tue Mar 26 14:34:07 2013 +0200 @@ -1,7 +1,23 @@ -Day Month Date Hour:Min:Sec Year Pyravlos Team +Tue Mar 26 13:28:26 2013 Pyravlos Team * Version 3.2.8 released. + * Added support for handling (storing/querying) GeoSPARQL datatypes. + (bug #31: http://bug.strabon.di.uoa.gr/ticket/31) + + * Fixed a bug in StoreOp that wouldn't close the connection, neither + rollback the transaction upon an exception. This had as a side effect + the abnormal termination of StoreOp (through for example the use of + Ctrl-C signal) which was leaving the database locked. + + * Fixed bug where spatial aggregates (e.g., union) didn't work as + expected when the query didn't contain a `GROUP BY' clause. + (bug #22: http://bug.strabon.di.uoa.gr/ticket/22) + + * Updated GeoSPARQL namespaces and fixed function names to comply with + the GeoSPARQL specification. + (bug #25: http://bug.strabon.di.uoa.gr/ticket/25) + Wed Jan 09 18:06:41 2013 Pyravlos Team * Version 3.2.7 released. diff -r 93d1b4ce44a6 -r f662352c3799 README --- a/README Sun Mar 10 22:14:24 2013 +0200 +++ b/README Tue Mar 26 14:34:07 2013 +0200 @@ -211,7 +211,7 @@ * Charalampos Nikolaou * Stella Gianakopoulou * Panagiotis Smeros -* Kallirroi Dogani +* Kallirroi Dogani Mailing-list diff -r 93d1b4ce44a6 -r f662352c3799 endpoint/src/log4j.properties --- a/endpoint/src/log4j.properties Sun Mar 10 22:14:24 2013 +0200 +++ b/endpoint/src/log4j.properties Tue Mar 26 14:34:07 2013 +0200 @@ -22,4 +22,4 @@ # "Disable" logging for several services in Tomcat log4j.logger.org.springframework=WARN -log4j.logger.org.apache.jasper=WARN +#log4j.logger.org.apache.jasper=WARN diff -r 93d1b4ce44a6 -r f662352c3799 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Tue Mar 26 14:34:07 2013 +0200 @@ -0,0 +1,135 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (C) 2013, Pyravlos Team + * + * http://www.strabon.di.uoa.gr/ + */ +package org.openrdf.query.algebra.evaluation.function.spatial; + +import java.net.URI; + + +/** + * This class generalizes WKT literal values that can be given according + * to the specification of stRDF/stSPARQL or GeoSPARQL. Notice that no + * actual parsing is carried out, so the representation at this point + * might not be valid. + * + * @author Charalampos Nikolaou + */ +public class AbstractWKT { + + /** + * WKT representation for an empty geometry + * + * When used with POINT instead of MULTIPOLYGON, JTS throws an + * Illegal argument exception, since empty geometries for points + * are not represented in WKB (see + * http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/io/WKBWriter.html). + * + * EMPTY_GEOM is present here to address Req. 13 of GeoSPARQL for empty geometries. + * However, we act in the same way for strdf:WKT. + */ + protected final String EMPTY_GEOM = "MULTIPOLYGON EMPTY"; + + /** + * The datatype of this WKT literal + * + * Should be either {@link GeoConstants.WKT} or {@link GeoConstants.WKTLITERAL} + */ + private String datatype; + + /** + * true when this WKT is given according to the specification of stRDF/stSPARQL + * false when it is given according to GeoSPARQL + */ + private boolean isstRDFWKT; + + /** + * The actual/standard WKT value as read by JTSWrapper + */ + private String wkt; + + /** + * The SRID for the represented geometry + */ + private int srid; + + public AbstractWKT(String literalValue, String datatype) { + this.datatype = datatype; + + if (GeoConstants.WKT.equals(datatype)) { // stRDF:WKT + isstRDFWKT = true; + parsestRDFWKT(literalValue); + + } else if (GeoConstants.WKTLITERAL.equals(datatype)) { // wktLiteral + isstRDFWKT = false; + parseWKTLITERAL(literalValue); + + } // naturally, whoever creates AbstractWKT instances, + // should have either of the two datatypes, thus we don't check for errors + } + + /** + * Parses a WKT literal according to the specification of stRDF/stSPARQL. + * The literal value may (not) specify the URI of a spatial reference system. + * + * @param literalValue + */ + private void parsestRDFWKT(String literalValue) { + if (literalValue.trim().length() == 0) { + literalValue = EMPTY_GEOM; + } + + // we already have this case in {@link WKTHelper} + wkt = WKTHelper.getWithoutSRID(literalValue); + srid = WKTHelper.getSRID(literalValue); + } + + private void parseWKTLITERAL(String literalValue) { + wkt = literalValue.trim(); + // FIXME: the default value for wktLiteral + srid = GeoConstants.WGS84_LON_LAT_SRID; + + if (wkt.length() == 0) { // empty geometry + wkt = EMPTY_GEOM; + } + + if (wkt.charAt(0) == '<') {// if a CRS URI is specified + int uriIndx = wkt.indexOf('>'); + URI crs = URI.create(wkt.substring(1, uriIndx)); + + // FIXME: handle invalid URIs + // FIXME: get the SRID for crs properly. HOW?? + if (GeoConstants.WGS84_LAT_LON.equals(crs.toString())) { + srid = GeoConstants.WGS84_LAT_LON_SRID; + + } else if (GeoConstants.WGS84_LON_LAT.equals(crs.toString())) { + srid = GeoConstants.WGS84_LON_LAT_SRID; + + } + + // trim spaces after URI and get the WKT value + wkt = wkt.substring(uriIndx + 1).trim(); + } + } + + public String getWKT() { + return wkt; + } + + public int getSRID() { + return srid; + } + + public String getDatatype() { + return datatype; + } + + boolean isstRDFWKT() { + return isstRDFWKT; + } +} diff -r 93d1b4ce44a6 -r f662352c3799 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java Sun Mar 10 22:14:24 2013 +0200 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java Tue Mar 26 14:34:07 2013 +0200 @@ -17,6 +17,7 @@ * * @author Charalampos Nikolaou * @author Kostis Kyzirakos + * @author Kallirroi Dogani */ public class GeoConstants { /** * @@ -32,36 +33,30 @@ * The namespace for the RDFi framework */ public static final String rdfi = "http://rdfi.di.uoa.gr/ontology#"; - - /** - * The namespace for GeoSPARQL - */ - public static final String geo = "http://www.opengis.net/ont/geosparql#"; + + + /** * + * GeoSPARQL Version 1.0.1 Document# 11-052r4 * + * http://schemas.opengis.net/geosparql/geosparql-1_0_1.zip */ /** - * The URI for the datatype SemiLinearPointSet - * (linear constraint-based representation of geometries) + * The namespace for GeoSPARQL ontology */ - public static final String stRDFSemiLinearPointset = stRDF + "SemiLinearPointSet"; - + public static final String GEO = "http://www.opengis.net/ont/geosparql#"; + /** - * The URI for the datatype Well-Known Text (WKT) + * The namespace for geometry functions declared by GeoSPARQL */ - // TODO ggarbis variable WKT variable changed to support geo:wktLiteral for benchmarking - public static final String WKT = geo + "wktLiteral"; -// public static final String WKT = = stRDF + "WKT"; - + public static final String GEOF = "http://www.opengis.net/def/function/geosparql/"; + /** - * The URI for the datatype Geography Markup Language (GML) as it defined - * in the model stRDF and query language stSPARQL + * The namespace for the ontology of simple features */ - // TODO ggarbis variable GML variable changed to support geo:gmlLiteral for benchmarking - public static final String GML = geo + "wktLiteral";//= stRDF + "GML"; -// public static final String GML = = stRDF + "GML"; - + public static final String SF = "http://www.opengis.net/ont/sf#"; + /** * - * The URI for the namespace of GML. + * The namespace of GML. * * Initially, it was set to "http://www.opengis.net/def/geometryType/OGC-GML/3.2/". * Afterwards, it was set to "http://www.opengis.net/gml/3.2/" in order to be compliant @@ -77,10 +72,79 @@ */ public static final String GML_OGC = "http://www.opengis.net/gml"; + + + + /** * + * URIs * + * */ + + /** * + * GeoSPARQL Version 1.0.1 Document# 11-052r4 * + * http://schemas.opengis.net/geosparql/geosparql-1_0_1.zip */ + + /** The following GeoSPARQL classes and properties are + * commented out because they are not currently used. + */ + /** - * The namespace for geometry functions declared by GeoSPARQL + * The URIs for GeoSPARQL classes */ - public static final String geof = "http://www.opengis.net/def/queryLanguage/OGC-GeoSPARQL/1.0/function/"; +/* public static final String SpatialObject = GEO + "SpatialObject"; + public static final String Geometry = GEO + "Geometry"; + public static final String Feauture = GEO + "Feature"; +*/ + + /** + * The URIs for GeoSPARQL properties + */ +/* public static final String hasGeometry_OGC = GEO + "hasGeometry"; + public static final String defaultGeometry_OGC = GEO + "defaultGeometry"; + public static final String dimension_OGC = GEO + "dimension"; + public static final String coordinateDimension_OGC = GEO + "coordinateDimension"; + public static final String spatialDimension_OGC = GEO + "spatialDimension"; + public static final String isEmpty_OGC = GEO + "isEmpty"; + public static final String isSimple_OGC = GEO + "isSimple"; + public static final String asWKT_OGC = GEO + "asWKT"; + public static final String asGML_OGC = GEO + "asGML"; +*/ + + + /** * + * URIs for datatypes * + * */ + + + /** + * The URI for the datatype SemiLinearPointSet + * (linear constraint-based representation of geometries) + */ + public static final String stRDFSemiLinearPointset = stRDF + "SemiLinearPointSet"; + + + /** + * The URI for the datatype Well-Known Text (WKT) + */ + public static final String WKT = stRDF + "WKT"; + + /** + * The URI for the datatype Geography Markup Language (GML) as it defined + * in the model stRDF and query language stSPARQL + */ + public static final String GML = stRDF + "GML"; + + /** + * The URI for the datatype wktLiteral + */ + public static final String WKTLITERAL = GEO + "wktLiteral"; + + /** + * The URI for the datatype gmlLiteral + */ + public static final String GMLLITERAL = GEO + "gmlLiteral"; + + + /** * * Extended functions * @@ -139,57 +203,79 @@ public static final String extent = stRDF + "extent"; /** - * Default SRID + * WGS 84 latitude-longitude (EPSG:4326) */ - public static final Integer defaultSRID = 4326; + public static final String WGS84_LAT_LON = "http://www.opengis.net/def/crs/EPSG/0/4326"; + + /** + * WGS 84 longitude-longitude + * (used as the default CRS for GeoSPARQL geometries) + */ + public static final String WGS84_LON_LAT = "http://www.opengis.net/def/crs/OGC/1.3/CRS84"; + + /** + * EPSG:4326 + */ + public static final Integer WGS84_LAT_LON_SRID = 4326; + + /** + * EPSG:3857 (not sure whether this is correct for WGS84_LON_LAT) + * http://spatialreference.org/ref/sr-org/7483/ + */ + public static final Integer WGS84_LON_LAT_SRID = 3857; + + /** + * Default SRID (WGS84 latitude-longitude) + */ + public static final Integer defaultSRID = WGS84_LAT_LON_SRID; /** * * Extended functions * * GeoSPARQL * * */ // Non-topological - public static final String geoSparqlDistance = geof + "distance"; //3 arguments - public static final String geoSparqlBuffer = geof + "buffer"; //3 arguments - public static final String geoSparqlConvexHull = geof + "convexHull"; - public static final String geoSparqlIntersection = geof + "intersection"; - public static final String geoSparqlUnion = geof + "union"; - public static final String geoSparqlDifference = geof + "difference"; - public static final String geoSparqlSymmetricDifference = geof + "symmetricDifference"; - public static final String geoSparqlEnvelope = geof + "envelope"; - public static final String geoSparqlBoundary = geof + "boundary"; + public static final String geoSparqlDistance = GEOF + "distance"; //3 arguments + public static final String geoSparqlBuffer = GEOF + "buffer"; //3 arguments + public static final String geoSparqlConvexHull = GEOF + "convexHull"; + public static final String geoSparqlIntersection = GEOF + "intersection"; + public static final String geoSparqlUnion = GEOF + "union"; + public static final String geoSparqlDifference = GEOF + "difference"; + public static final String geoSparqlSymmetricDifference = GEOF + "symmetricDifference"; + public static final String geoSparqlEnvelope = GEOF + "envelope"; + public static final String geoSparqlBoundary = GEOF + "boundary"; // Simple Features - 8 functions - all with 2 arguments + boolean - public static final String sfEquals = geof + "sf-equals"; - public static final String sfDisjoint = geof + "sf-disjoint"; - public static final String sfIntersects = geof + "sf-intersects"; - public static final String sfTouches = geof + "sf-touches"; - public static final String sfCrosses = geof + "sf-crosses"; - public static final String sfWithin = geof + "sf-within"; - public static final String sfContains = geof + "sf-contains"; - public static final String sfOverlaps = geof + "sf-overlaps"; + public static final String sfEquals = GEOF + "sfEquals"; + public static final String sfDisjoint = GEOF + "sfDisjoint"; + public static final String sfIntersects = GEOF + "sfIntersects"; + public static final String sfTouches = GEOF + "sfTouches"; + public static final String sfCrosses = GEOF + "sfCrosses"; + public static final String sfWithin = GEOF + "sfWithin"; + public static final String sfContains = GEOF + "sfContains"; + public static final String sfOverlaps = GEOF + "sfOverlaps"; // Egenhofer - 8 functions - all with 2 arguments + boolean - public static final String ehEquals = geof + "eh-equals"; - public static final String ehDisjoint = geof + "eh-disjoint"; - public static final String ehMeet = geof + "eh-meet"; - public static final String ehOverlap = geof + "eh-overlap"; - public static final String ehCovers = geof + "eh-covers"; - public static final String ehCoveredBy = geof + "eh-coveredBy"; - public static final String ehInside = geof + "eh-inside"; - public static final String ehContains = geof + "eh-contains"; + public static final String ehEquals = GEOF + "ehEquals"; + public static final String ehDisjoint = GEOF + "ehDisjoint"; + public static final String ehMeet = GEOF + "ehMeet"; + public static final String ehOverlap = GEOF + "ehOverlap"; + public static final String ehCovers = GEOF + "ehCovers"; + public static final String ehCoveredBy = GEOF + "ehCoveredBy"; + public static final String ehInside = GEOF + "ehInside"; + public static final String ehContains = GEOF + "ehContains"; // RCC8 - 8 functions - all with 2 arguments + boolean - public static final String rccEquals = geof + "rcc8-eq"; - public static final String rccDisconnected = geof + "rcc8-dc"; - public static final String rccExternallyConnected = geof + "rcc8-ec"; - public static final String rccPartiallyOverlapping = geof + "rcc8-po"; - public static final String rccTangentialProperPartInverse = geof + "rcc8-tppi"; - public static final String rccTangentialProperPart = geof + "rcc8-tpp"; - public static final String rccNonTangentialProperPart = geof + "rcc8-ntpp"; - public static final String rccNonTangentialProperPartInverse = geof + "rcc8-ntppi"; + public static final String rccEquals = GEOF + "rcc8eq"; + public static final String rccDisconnected = GEOF + "rcc8dc"; + public static final String rccExternallyConnected = GEOF + "rcc8ec"; + public static final String rccPartiallyOverlapping = GEOF + "rcc8po"; + public static final String rccTangentialProperPartInverse = GEOF + "rcc8tppi"; + public static final String rccTangentialProperPart = GEOF + "rcc8tpp"; + public static final String rccNonTangentialProperPart = GEOF + "rcc8ntpp"; + public static final String rccNonTangentialProperPartInverse = GEOF + "rcc8ntppi"; // The generic relate function - public static final String geoSparqlRelate = geof + "relate"; + public static final String geoSparqlRelate = GEOF + "relate"; /** * Addition for datetime metric functions @@ -208,7 +294,7 @@ public static final String rdfiEC = rdfi + "EC"; public static final String rdfiPO = rdfi + "PO"; public static final String rdfiNTPP = rdfi + "NTPP"; - public static final String rdfiNTPPi = rdfi + "NTPPi"; + public static final String rdfiNTPPi = rdfi + "NTPPi"; public static final String rdfiTPP = rdfi + "TPP"; public static final String rdfiTPPi = rdfi + "TPPi"; public static final String rdfiEQ = rdfi + "EQ"; diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBStore.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBStore.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBStore.java Tue Mar 26 14:34:07 2013 +0200 @@ -8,15 +8,12 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import java.util.Iterator; -import javax.imageio.spi.ServiceRegistry; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; - import org.openrdf.sail.SailConnection; import org.openrdf.sail.SailException; import org.openrdf.sail.helpers.SailBase; diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBTripleRepository.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBTripleRepository.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBTripleRepository.java Tue Mar 26 14:34:07 2013 +0200 @@ -48,6 +48,7 @@ * {@link LiteralTable} for adding, removing, and retrieving statements from the * database. * + * @author Manos Karpathiotatis * @author James Leigh */ public abstract class GeneralDBTripleRepository { @@ -490,20 +491,19 @@ } } - /****XXX MY ADDITION 21/4/10 ***/ - public void clearGeoValues() - throws RdbmsException + /** + * @author Manos Karpathiotatis + * @throws RdbmsException + */ + public void clearGeoValues() throws RdbmsException { - try { - - String query = buildDeleteQuery("geo_values", null,null,null,null); + String query = buildDeleteQuery("geo_values", null, null, null, (RdbmsResource[]) null); PreparedStatement stmt = conn.prepareStatement(query); try { - setSelectQuery(stmt, null,null,null,null); - int count = stmt.executeUpdate(); - + setSelectQuery(stmt, null, null, null,(RdbmsResource[]) null); + stmt.executeUpdate(); } finally { stmt.close(); @@ -513,7 +513,6 @@ catch (SQLException e) { throw new RdbmsException(e); } - } } diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java Tue Mar 26 14:34:07 2013 +0200 @@ -239,26 +239,26 @@ /****************************************************/ public RdbmsLiteral asRdbmsLiteral(GeneralDBPolyhedron polyhedron) { - try { - URI wkt = new URIImpl(GeoConstants.WKT); - RdbmsLiteral literal = new RdbmsLiteral(polyhedron.getInternalId(), polyhedron.getVersion(),new LiteralImpl(polyhedron.stringValue(), wkt)); + try { + URI wkt = new URIImpl(GeoConstants.WKT); + RdbmsLiteral literal = new RdbmsLiteral(polyhedron.getInternalId(), polyhedron.getVersion(),new LiteralImpl(polyhedron.stringValue(), wkt)); - if (polyhedron instanceof GeneralDBPolyhedron) { - literals.cache(literal); - return (RdbmsLiteral)literal; - } + if (polyhedron instanceof GeneralDBPolyhedron) { + literals.cache(literal); + return (RdbmsLiteral)literal; + } - RdbmsLiteral lit = literals.findInCache(literal); - - if (lit == null) { - lit = new RdbmsLiteral(literal); - literals.cache(lit); - } - return lit; - } - catch (InterruptedException e) { - throw new RdbmsRuntimeException(e); - } + RdbmsLiteral lit = literals.findInCache(literal); + + if (lit == null) { + lit = new RdbmsLiteral(literal); + literals.cache(lit); + } + return lit; + } + catch (InterruptedException e) { + throw new RdbmsRuntimeException(e); + } } public RdbmsLiteral asRdbmsLiteral(StrabonPolyhedron polyhedron) { diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java Tue Mar 26 14:34:07 2013 +0200 @@ -15,6 +15,7 @@ import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.algebra.evaluation.QueryBindingSet; +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; import org.openrdf.sail.generaldb.GeneralDBSpatialFuncInfo; import org.openrdf.sail.generaldb.GeneralDBValueFactory; import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; @@ -29,7 +30,6 @@ * Converts a {@link ResultSet} into a {@link BindingSet} in an iteration. * * @author Manos Karpathiotakis - * */ public abstract class GeneralDBBindingIteration extends RdbmIterationBase { @@ -41,7 +41,6 @@ protected IdSequence ids; - //XXX addition protected HashMap geoNames = new HashMap(); //protected HashMap sp_ConstructIndexesAndNames = new HashMap(); @@ -63,8 +62,6 @@ super(stmt); } - //// - public HashMap getConstructIndexesAndNames() { return sp_ConstructIndexesAndNames; } @@ -97,7 +94,6 @@ this.ids = ids; } - //XXX Numerous additions here! @Override protected BindingSet convert(ResultSet rs) throws SQLException @@ -202,18 +198,22 @@ } /** - * XXX additions - */ - /** - * - * my addition - * + * FIXME the implementation of this function for PostGIS and MonetDB + * uses by default the {@link GeoConstants#WKT} datatype when creating WKT + * literals. What about geo:wktLiteral? + * However, this method is called by {@link convert} method only, which + * in turn is not called by any method! */ protected abstract RdbmsValue createGeoValue(ResultSet rs, int index) throws SQLException; - - + /** + * FIXME the implementation of this function for PostGIS and MonetDB + * uses by default the {@link GeoConstants#WKT} datatype when creating WKT + * literals. What about geo:wktLiteral? + * However, this method is called by {@link convert} method only, which + * in turn is not called by any method! + */ protected abstract RdbmsValue createBinaryGeoValueForSelectConstructs(ResultSet rs, int index) throws SQLException; @@ -253,26 +253,4 @@ return vf.asRdbmsLiteral(vf.createLiteral(spProperty)); } - - // protected RdbmsValue createGeoValueForSelectConstructs(ResultSet rs, int index) - // throws SQLException - // { - // double potentialMetric; - // try - // { - // //case of metrics - // potentialMetric = rs.getFloat(index + 1); - // - // return vf.asRdbmsLiteral(vf.createLiteral(potentialMetric)); - // - // } - // catch(SQLException e) - // { - // //Case of spatial constructs - // byte[] label = rs.getBytes(index + 1); - // return vf.getRdbmsPolyhedron(114, StrabonPolyhedron.ogcGeometry, label); - // } - // - // } - } diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Tue Mar 26 14:34:07 2013 +0200 @@ -17,8 +17,6 @@ import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; import org.openrdf.sail.generaldb.schema.LiteralTable; import org.openrdf.sail.rdbms.model.RdbmsLiteral; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Manages RDBMS Literals. Including creation, id lookup, and inserting them @@ -29,7 +27,7 @@ */ public class LiteralManager extends ValueManagerBase { - private static Logger logger = LoggerFactory.getLogger(org.openrdf.sail.generaldb.managers.LiteralManager.class); + //private static Logger logger = LoggerFactory.getLogger(org.openrdf.sail.generaldb.managers.LiteralManager.class); private static TimeZone Z = TimeZone.getTimeZone("GMT"); @@ -85,24 +83,18 @@ String label = literal.getLabel(); String language = literal.getLanguage(); URI datatype = literal.getDatatype(); + if (datatype == null && language == null) { table.insertSimple(id, label); } else if (datatype == null) { table.insertLanguage(id, label, language); } - else { + else { // literal with datatype String dt = datatype.stringValue(); - /**********************************************/ - //my additions - //http://stsparql.di.uoa.gr/SemiLinearPointSet - //System.out.println("the datatype i am gonna process is "+dt); - /**********************************************/ + try { if (XMLGSDatatypeUtil.isNumericDatatype(datatype)) { -// if (logger.isDebugEnabled()) { -// logger.debug("about to insert double value: {}", literal.doubleValue()); -// } table.insertNumeric(id, label, dt, literal.doubleValue()); } else if (XMLGSDatatypeUtil.isCalendarDatatype(datatype)) { diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TransTableManager.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TransTableManager.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TransTableManager.java Tue Mar 26 14:34:07 2013 +0200 @@ -6,14 +6,12 @@ package org.openrdf.sail.generaldb.managers; import java.sql.Connection; -import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.BlockingQueue; -import org.openrdf.sail.generaldb.GeneralDBSqlTable; import org.openrdf.sail.generaldb.schema.Batch; import org.openrdf.sail.generaldb.schema.IdSequence; import org.openrdf.sail.generaldb.schema.TransactionTable; @@ -308,7 +306,6 @@ private String getEmptyTableName() { StringBuilder sb = new StringBuilder(256); - GeneralDBSqlTable temp = (GeneralDBSqlTable)temporaryTable; sb.append("("); sb.append("SELECT "); sb.append(getZeroBigInt()).append(" AS ctx, "); diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleManager.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleManager.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleManager.java Tue Mar 26 14:34:07 2013 +0200 @@ -6,10 +6,8 @@ package org.openrdf.sail.generaldb.managers; import java.sql.SQLException; -import java.sql.Timestamp; import org.openrdf.generaldb.managers.base.ManagerBase; -import org.openrdf.sail.generaldb.managers.TransTableManager; /** * * @author James Leigh diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Tue Mar 26 14:34:07 2013 +0200 @@ -95,7 +95,8 @@ return false; } - return GeoConstants.WKT.equals(datatype.stringValue()); + return GeoConstants.WKT.equals(datatype.stringValue()) || + GeoConstants.WKTLITERAL.equals(datatype.stringValue()); } /** diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/AggregateOptimizer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/AggregateOptimizer.java Tue Mar 26 14:34:07 2013 +0200 @@ -0,0 +1,85 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (C) 2010, 2011, 2012, Pyravlos Team + * + * http://www.strabon.di.uoa.gr/ + */ +package org.openrdf.sail.generaldb.optimizers; + +import java.util.Iterator; + +import org.openrdf.query.algebra.Extension; +import org.openrdf.query.algebra.ExtensionElem; +import org.openrdf.query.algebra.FunctionCall; +import org.openrdf.query.algebra.Group; +import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.algebra.ValueExpr; +import org.openrdf.query.algebra.evaluation.function.Function; +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc; +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc; +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase; +/** + * + * @author Stella Giannakopoulou + */ + +public class AggregateOptimizer extends GeneralDBQueryModelVisitorBase +{ + public void optimize(TupleExpr tupleExpr) + { + tupleExpr.visit(this); + } + + @Override + public void meet(Extension node) throws RuntimeException + { + if(!(node.getArg() instanceof Group)) + { + Iterator iter = node.getElements().iterator(); + + while(iter.hasNext()) + { + ExtensionElem elem = iter.next(); + ValueExpr expr = elem.getExpr(); + + if(aggregateInQuery(expr) == true) //Union (or Extent) is used as an aggregate function on Select Clause! + { + Group group = new Group((TupleExpr) node.getArg()); + group.setParentNode(node.getArg().getParentNode()); + node.replaceChildNode(node.getArg(), group); + + break; + } + } + } + } + + + private boolean aggregateInQuery(ValueExpr expr) + { + if(expr instanceof FunctionCall) + { + Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI()); + if((!(function instanceof UnionFunc) || !(((FunctionCall) expr).getArgs().size()==1))&&!(function instanceof ExtentFunc)) + { + //Recursively check arguments + boolean unionPresent = false; + for(int i = 0 ; i< ((FunctionCall) expr).getArgs().size(); i++) + { + unionPresent = unionPresent || aggregateInQuery(((FunctionCall) expr).getArgs().get(i)); + } + return unionPresent; + } + else + return true; + } + else //var + { + return false; + } + } +} diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBQueryOptimizer.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBQueryOptimizer.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBQueryOptimizer.java Tue Mar 26 14:34:07 2013 +0200 @@ -16,7 +16,6 @@ import org.openrdf.query.algebra.evaluation.impl.BindingAssigner; import org.openrdf.query.algebra.evaluation.impl.CompareOptimizer; import org.openrdf.query.algebra.evaluation.impl.ConjunctiveConstraintSplitter; -import org.openrdf.query.algebra.evaluation.impl.ConstantOptimizer; import org.openrdf.query.algebra.evaluation.impl.DisjunctiveConstraintOptimizer; import org.openrdf.query.algebra.evaluation.impl.SameTermFilterOptimizer; import org.openrdf.query.algebra.evaluation.impl.SpatialJoinOptimizer; @@ -85,8 +84,8 @@ tupleExpr = new QueryRoot(tupleExpr); } + fixAggregates(tupleExpr); coreOptimizations(strategy, tupleExpr, dataset, bindings); - rdbmsOptimizations(tupleExpr, dataset, bindings); new GeneralDBSqlConstantOptimizer().optimize(tupleExpr, dataset, bindings); @@ -94,6 +93,12 @@ return tupleExpr; } + private void fixAggregates(TupleExpr expr) + { + AggregateOptimizer agg = new AggregateOptimizer(); + agg.optimize(expr); + } + private void coreOptimizations(EvaluationStrategy strategy, TupleExpr expr, Dataset dataset, BindingSet bindings) { diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java Tue Mar 26 14:34:07 2013 +0200 @@ -8,8 +8,8 @@ import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createCtx; import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createObj; import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createPred; +import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createSpatialColumn; import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createSubj; -import static org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar.createSpatialColumn; import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.coalesce; import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.eq; import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.isNull; @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -52,18 +51,16 @@ import org.openrdf.query.algebra.Projection; import org.openrdf.query.algebra.ProjectionElem; import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.QueryModelNode; import org.openrdf.query.algebra.Slice; import org.openrdf.query.algebra.StatementPattern; +import org.openrdf.query.algebra.StatementPattern.Scope; import org.openrdf.query.algebra.TupleExpr; import org.openrdf.query.algebra.UnaryValueOperator; import org.openrdf.query.algebra.Union; import org.openrdf.query.algebra.ValueExpr; import org.openrdf.query.algebra.Var; -import org.openrdf.query.algebra.StatementPattern.Scope; -import org.openrdf.query.algebra.evaluation.QueryOptimizer; import org.openrdf.query.algebra.evaluation.function.Function; -import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc; import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc; @@ -72,10 +69,8 @@ import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc; import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc; import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc; -import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc; import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.TransformFunc; import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc; -import org.openrdf.query.algebra.evaluation.iterator.SPARQLMinusIteration; import org.openrdf.sail.generaldb.GeneralDBValueFactory; import org.openrdf.sail.generaldb.algebra.GeneralDBBNodeColumn; import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; @@ -92,22 +87,17 @@ import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery; import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq; import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOr; -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary; -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary; import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn; import org.openrdf.sail.generaldb.algebra.GeneralDBUnionItem; -import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator; import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase; import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr; -import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator; import org.openrdf.sail.generaldb.algebra.factories.GeneralDBSqlExprFactory; +import org.openrdf.sail.generaldb.managers.TransTableManager; +import org.openrdf.sail.generaldb.schema.IdSequence; import org.openrdf.sail.rdbms.exceptions.RdbmsException; import org.openrdf.sail.rdbms.exceptions.RdbmsRuntimeException; import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException; -import org.openrdf.sail.generaldb.managers.TransTableManager; import org.openrdf.sail.rdbms.model.RdbmsResource; -import org.openrdf.sail.generaldb.schema.HashTable; -import org.openrdf.sail.generaldb.schema.IdSequence; /** * Rewrites the core algebra model with a relation optimised model, using SQL. diff -r 93d1b4ce44a6 -r f662352c3799 generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Sun Mar 10 22:14:24 2013 +0200 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Tue Mar 26 14:34:07 2013 +0200 @@ -5,16 +5,13 @@ */ package org.openrdf.sail.generaldb.schema; -import java.io.IOException; import java.sql.SQLException; import java.sql.Timestamp; -import java.lang.IllegalArgumentException; import javax.xml.bind.JAXBException; -import org.openrdf.sail.generaldb.exceptions.conversionException; +import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; -import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; import org.openrdf.query.algebra.evaluation.util.JTSWrapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -198,11 +195,12 @@ } //the new version will actually deal with WKB - public void insertWKT(Number id, String label, String datatype,Timestamp start,Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException + public void insertWKT(Number id, String label, String datatype, Timestamp start,Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException { try { - Geometry geom = JTSWrapper.getInstance().WKTread(label); - geoSpatialTable.insert(id, WKTHelper.getSRID(label),/* start,end,*/ JTSWrapper.getInstance().WKBwrite(geom)); + AbstractWKT awkt = new AbstractWKT(label, datatype); + Geometry geom = JTSWrapper.getInstance().WKTread(awkt.getWKT()); + geoSpatialTable.insert(id, awkt.getSRID(),/* start,end,*/ JTSWrapper.getInstance().WKBwrite(geom)); } catch (ParseException e) { throw new IllegalArgumentException(e); diff -r 93d1b4ce44a6 -r f662352c3799 monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java Sun Mar 10 22:14:24 2013 +0200 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java Tue Mar 26 14:34:07 2013 +0200 @@ -13,7 +13,6 @@ import org.openrdf.query.BindingSet; import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; import org.openrdf.sail.generaldb.iteration.GeneralDBBindingIteration; -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; import org.openrdf.sail.rdbms.model.RdbmsValue; /** @@ -30,14 +29,6 @@ super(stmt); } - /** - * XXX additions - */ - /** - * - * my addition - * - */ @Override protected RdbmsValue createGeoValue(ResultSet rs, int index) throws SQLException diff -r 93d1b4ce44a6 -r f662352c3799 postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java --- a/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Sun Mar 10 22:14:24 2013 +0200 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java Tue Mar 26 14:34:07 2013 +0200 @@ -5,7 +5,6 @@ */ package org.openrdf.sail.postgis.iteration; -import java.sql.Blob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +12,6 @@ import org.openrdf.query.BindingSet; import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; import org.openrdf.sail.generaldb.iteration.GeneralDBBindingIteration; -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; import org.openrdf.sail.rdbms.model.RdbmsValue; /** @@ -30,14 +28,6 @@ super(stmt); } - /** - * XXX additions - */ - /** - * - * my addition - * - */ @Override protected RdbmsValue createGeoValue(ResultSet rs, int index) throws SQLException @@ -54,7 +44,6 @@ return createResource(rs, index); } - @Override protected RdbmsValue createBinaryGeoValueForSelectConstructs(ResultSet rs, int index) throws SQLException diff -r 93d1b4ce44a6 -r f662352c3799 resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Sun Mar 10 22:14:24 2013 +0200 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Tue Mar 26 14:34:07 2013 +0200 @@ -28,6 +28,7 @@ import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.TupleQueryResultHandlerException; +import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; import org.openrdf.query.algebra.evaluation.util.JTSWrapper; import org.openrdf.query.resultio.TupleQueryResultFormat; @@ -159,13 +160,16 @@ } else { // spatial literal WKT or GML // get the textual representation of the geometry (WKT or GML) String geoText = value.stringValue(); + Literal literal = (Literal) value; - if (XMLGSDatatypeUtil.isWKTLiteral((Literal) value)) {// WKT + if (XMLGSDatatypeUtil.isWKTLiteral(literal)) {// WKT + AbstractWKT awkt = new AbstractWKT(geoText, literal.getDatatype().stringValue()); + // get its geometry - geom = jts.WKTread(WKTHelper.getWithoutSRID(geoText)); + geom = jts.WKTread(awkt.getWKT()); // get its SRID - srid = WKTHelper.getSRID(geoText); + srid = awkt.getSRID(); } else { // GML // get its geometry @@ -173,7 +177,6 @@ // get its SRID srid = geom.getSRID(); - } } diff -r 93d1b4ce44a6 -r f662352c3799 resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Sun Mar 10 22:14:24 2013 +0200 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Tue Mar 26 14:34:07 2013 +0200 @@ -25,8 +25,8 @@ import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.TupleQueryResultHandlerException; +import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; -import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; import org.openrdf.query.algebra.evaluation.util.JTSWrapper; import org.openrdf.query.resultio.TupleQueryResultFormat; import org.openrdf.query.resultio.TupleQueryResultWriter; @@ -63,16 +63,11 @@ private static final String PLACEMARK_TAG = "Placemark"; private static final String NAME_TAG = "name"; private static final String DESC_TAG = "description"; - private static final String STYLE_TAG = "Style"; - private static final String STYLEMAP_TAG = "StyleMap"; - private static final String LINESTYLE_TAG = "LineStyle"; - private static final String POLYSTYLE_TAG = "PolyStyle"; private static final String EXT_DATA_TAG = "ExtendedData"; private static final String DATA_TAG = "Data"; private static final String VALUE_TAG = "value"; private static final String NAME_ATTR = NAME_TAG; - private static final String STYLE_ID = "resultStyle"; private static final String TABLE_ROW_BEGIN = ""; private static final String TABLE_ROW_END = ""; private static final String TABLE_DATA_BEGIN = ""; @@ -84,34 +79,6 @@ private static final String GEOMETRY_NAME = "Geometry"; private static final String MULTIGEOMETRY = "MultiGeometry"; - /* - // Styling options - private static final int numOfStyles = 5; - private static final String[][] styles = { - // note that colors are encoded as "aabbggrr" strings where - // aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); - // rr=red - // (00 to ff). - // id, line width, line color, polygon fill, mouse over line width, - // mouse over line color mouse over polygon fill - // {STYLE_ID + "1", "1.5", "7d0000ff", "ad0000ff", "1.5", - // "7d0000ff", "ad0000ff"}, {STYLE_ID + "2", "1.5", "7d0000ff", - // "ad0000ff", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "3", - // "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", "ad0000ff"}, - // {STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", - // "7d0000ff", "ad0000ff"}, {STYLE_ID + "5", "1.5", "7d000055", - // "ad000055", "1.5", "7d0000ff", "ad0000ff"}}; - { STYLE_ID + "1", "1.5", "000000ff", "000000ff", "1.5", "000000ff", - "000000ff" }, - { STYLE_ID + "2", "1.5", "000000ff", "000000ff", "1.5", "000000ff", - "000000ff" }, - { STYLE_ID + "3", "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", - "ad0000ff" }, - { STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", "7d0000ff", - "ad0000ff" }, - { STYLE_ID + "5", "1.5", "7dff0000", "adff0000", "1.5", "7dff0000", - "adff0000" } }; - */ /** * The underlying XML formatter. */ @@ -176,65 +143,13 @@ } @Override - public void startQueryResult(List bindingNames) - throws TupleQueryResultHandlerException { + public void startQueryResult(List bindingNames) throws TupleQueryResultHandlerException { try { - xmlWriter.startDocument(); xmlWriter.setAttribute("xmlns", NAMESPACE); xmlWriter.startTag(ROOT_TAG); xmlWriter.startTag(RESULT_SET_TAG); - /* - // add default styles - for (String[] style : styles) { - String id = style[0]; - String lineWidth = style[1]; - String lineColor = style[2]; - String polygonFill = style[3]; - String mouseOverLineWidth = style[4]; - String mouseOverLineColor = style[5]; - String mouseOverPolygonFill = style[6]; - - // append normal style - xmlWriter.setAttribute("id", "normal_" + id); - xmlWriter.startTag(STYLE_TAG); - xmlWriter.startTag(LINESTYLE_TAG); - xmlWriter.textElement("width", lineWidth); - xmlWriter.textElement("color", lineColor); - xmlWriter.endTag(LINESTYLE_TAG); - xmlWriter.startTag(POLYSTYLE_TAG); - xmlWriter.textElement("color", polygonFill); - xmlWriter.endTag(POLYSTYLE_TAG); - xmlWriter.endTag(STYLE_TAG); - - // append highlight style - xmlWriter.setAttribute("id", "highlight_" + id); - xmlWriter.startTag(STYLE_TAG); - xmlWriter.startTag(LINESTYLE_TAG); - xmlWriter.textElement("width", mouseOverLineWidth); - xmlWriter.textElement("color", mouseOverLineColor); - xmlWriter.endTag(LINESTYLE_TAG); - xmlWriter.startTag(POLYSTYLE_TAG); - xmlWriter.textElement("color", mouseOverPolygonFill); - xmlWriter.endTag(POLYSTYLE_TAG); - xmlWriter.endTag(STYLE_TAG); - - // define map style combining the above styles - xmlWriter.setAttribute("id", id); - xmlWriter.startTag(STYLEMAP_TAG); - xmlWriter.startTag("Pair"); - xmlWriter.textElement("key", "normal"); - xmlWriter.textElement("styleUrl", "#normal_" + id); - xmlWriter.endTag("Pair"); - xmlWriter.startTag("Pair"); - xmlWriter.textElement("key", "highlight"); - xmlWriter.textElement("styleUrl", "#highlight_" + id); - xmlWriter.endTag("Pair"); - xmlWriter.endTag(STYLEMAP_TAG); - } - // end of default style definition - */ } catch (IOException e) { throw new TupleQueryResultHandlerException(e); } @@ -313,7 +228,6 @@ for (String geometry : geometries) { xmlWriter.startTag(PLACEMARK_TAG); xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); - //xmlWriter.textElement("styleUrl", "#"+ styles[geometries.indexOf(geometry) % (numOfStyles - 2)][0]); xmlWriter.startTag(MULTIGEOMETRY); xmlWriter.unescapedText(geometry); xmlWriter.endTag(MULTIGEOMETRY); @@ -324,7 +238,6 @@ // also write them in the same placemarks xmlWriter.startTag(PLACEMARK_TAG); xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); - //xmlWriter.textElement("styleUrl", "#" + styles[(numOfStyles - 1)][0]); xmlWriter.startTag(MULTIGEOMETRY); for (String geometry : geometries) { @@ -384,48 +297,69 @@ private String getGeometry(Value value) { String geometry = ""; + QName geometryType = null; + // the underlying geometry in value Geometry geom = null; + // the underlying SRID of the geometry int srid = -1; + // get the KML encoder Encoder encoder = null; + try { encoder = new Encoder(new KMLConfiguration()); encoder.setIndenting(true); + if (value instanceof GeneralDBPolyhedron) { GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; geom = dbpolyhedron.getPolyhedron().getGeometry(); srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID(); + } else { // spatial literal Literal spatial = (Literal) value; String geomRep = spatial.stringValue(); + if (XMLGSDatatypeUtil.isWKTLiteral(spatial)) { // WKT - geom = jts.WKTread(WKTHelper.getWithoutSRID(geomRep)); - srid = WKTHelper.getSRID(geomRep); + AbstractWKT awkt = new AbstractWKT(geomRep, spatial.getDatatype().stringValue()); + + geom = jts.WKTread(awkt.getWKT()); + srid = awkt.getSRID(); + } else { // GML geom = jts.GMLread(geomRep); srid = geom.getSRID(); } } + // transform the geometry to {@link GeoConstants#defaultSRID} geom = jts.transform(geom, srid, GeoConstants.defaultSRID); + if (geom instanceof Point) { geometryType = KML.Point; + } else if (geom instanceof Polygon) { geometryType = KML.Polygon; + } else if (geom instanceof LineString) { geometryType = KML.LineString; + } else if (geom instanceof MultiPoint) { geometryType = KML.MultiGeometry; + } else if (geom instanceof MultiLineString) { geometryType = KML.MultiGeometry; + } else if (geom instanceof MultiPolygon) { geometryType = KML.MultiGeometry; + } else if (geom instanceof GeometryCollection) { geometryType = KML.MultiGeometry; + } + if (geometryType == null) { logger.warn("[Strabon.KMLWriter] Found unknown geometry type."); @@ -433,11 +367,10 @@ encoder.encode(geom, geometryType, baos); geometry = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", ""); + /* if (geometryType == KML.MultiGeometry) { geometry = geometry.substring(geometry.indexOf("") + 15, geometry.indexOf("")); } - - /* * if(geom instanceof Point) { geometry = * geometry.substring(geometry.indexOf(""), * geometry.indexOf("") + 8); } else if(geom instanceof diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java Tue Mar 26 14:34:07 2013 +0200 @@ -19,7 +19,7 @@ public class GeosparqlRDFHandlerBase extends RDFHandlerBase { - public static String geonamespace = "http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/"; + public static String geonamespace = "http://www.opengis.net/ont/geosparql#"; public static String gml="http://www.opengis.net/def/geometryType/OGC-GML/3.2/"; public static String sf="http://www.opengis.net/def/geometryType/OGC-SF/1.0/"; public static String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; @@ -44,8 +44,8 @@ public static List geometryDomainList = Arrays.asList(dimension, coordinateDimension, spatialdimension,isEmpty, isSimple, is3D,asWKT, asGML); public static String WKTLiteral= geonamespace + "WKTLiteral"; public static String GMLLiteral= geonamespace + "GMLLiteral"; - public static List rcc8 = Arrays.asList(geonamespace+"rcc8-eq",geonamespace+"rcc8-dc",geonamespace+"rcc8-ec",geonamespace+"rcc8-po", - geonamespace+"rcc8-tppi", geonamespace+"rcc8-tpp",geonamespace+ "rcc8-ntpp", geonamespace+"rcc8-ntpp"); + public static List rcc8 = Arrays.asList(geonamespace+"rcc8eq",geonamespace+"rcc8dc",geonamespace+"rcc8ec",geonamespace+"rcc8po", + geonamespace+"rcc8tppi", geonamespace+"rcc8tpp",geonamespace+ "rcc8ntpp", geonamespace+"rcc8ntpp"); //loose check: tha elegxw an arxizei apo eh- i apo sf- i apo rcc8- (den einai ola tou rcc8) @@ -85,7 +85,7 @@ String predicate = st.getPredicate().toString(); String object = st.getObject().toString(); - if(predicate.startsWith("http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/sf-")||predicate.startsWith(geonamespace+"eh-")|| + if(predicate.startsWith("http://www.opengis.net/ont/geosparql#sf")||predicate.startsWith(geonamespace+"eh")|| rcc8.contains(predicate)) { String triple = "<"+subject+ "> <"+ type +"> <"+ SpatialObject+ "> .\n" + @@ -315,10 +315,10 @@ parser.setVerifyData(true); String text = - " . " + - " _:nai . \n"+ - " _:b2 . \n"+ - " . \n"; + " . " + + " _:nai . \n"+ + " _:b2 . \n"+ + " . \n"; String gmltext= " <"+type+"> <"+gml+"GM_Object> .\n"; String sftext= " <"+type+"> <"+sf+"Geometry> .\n"; diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Tue Mar 26 14:34:07 2013 +0200 @@ -59,9 +59,9 @@ public static final String FORMAT_KMZ = "KMZ"; public static final String FORMAT_GEOJSON = "GeoJSON"; public static final String FORMAT_EXP = "EXP"; - public static final String FORMAT_HTML = "HTML"; + public static final String FORMAT_HTML = "HTML"; - public static final String NEWLINE = "\n"; + public static final String NEWLINE = "\n"; /** * Connection details (shared with subclasses) @@ -171,23 +171,30 @@ try { con1.commit(); - con1.close(); - repo1.shutDown(); - - // delete the lock as well - checkAndDeleteLock(databaseName, user, password, port, serverName); } catch (RepositoryException e) { logger.error("[Strabon.close]", e); - } catch (SQLException e) { - logger.error("[Strabon.close] Error in deleting lock", e); + } finally { + try { + con1.close(); + repo1.shutDown(); + + // delete the lock as well + checkAndDeleteLock(databaseName, user, password, port, serverName); + + } catch (RepositoryException e) { + logger.error("[Strabon.close]", e); + + }catch (SQLException e) { + logger.error("[Strabon.close] Error in deleting lock", e); + + } catch (ClassNotFoundException e) { + logger.error("[Strabon.close] Error in deleting lock", e); + } - } catch (ClassNotFoundException e) { - logger.error("[Strabon.close] Error in deleting lock", e); + logger.info("[Strabon.close] Connection closed."); } - - logger.info("[Strabon.close] Connection closed."); } public Object query(String queryString, OutputStream out) diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java Tue Mar 26 14:34:07 2013 +0200 @@ -24,7 +24,7 @@ */ public static void main(String[] args) { - if (args.length < 6) { + if (args.length < 7) { System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); System.err.println(" where is the postgis database host to connect to"); System.err.println(" is the port to connect to on the database host"); @@ -32,7 +32,8 @@ System.err.println(" is the username to use when connecting to the database "); System.err.println(" is the password to use when connecting to the database"); System.err.println(" is the stSPARQL query to evaluate."); - System.err.println(" [] is the format of your results (XML)"); + System.err.println(" is true when deletion of \"locked\" table should be enforced (e.g., when Strabon has been ungracefully shutdown)."); + System.err.println(" [] is the format of your results (XML)"); System.exit(0); } @@ -42,14 +43,15 @@ String user = args[3]; String passwd = args[4]; String queryString = args[5]; + boolean forceDelete = Boolean.valueOf(args[6]); String resultsFormat = ""; - if ( args.length == 7 ) { - resultsFormat = args[6]; + if ( args.length == 8 ) { + resultsFormat = args[7]; } Strabon strabon = null; try { - strabon = new Strabon(db, user, passwd, port, host, false); + strabon = new Strabon(db, user, passwd, port, host, forceDelete); strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out); } catch (Exception e) { diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Tue Mar 26 14:34:07 2013 +0200 @@ -24,7 +24,7 @@ */ public static void main(String[] args) { - if (args.length < 6) { + if (args.length < 7) { System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon "); System.err.println(" where is the postgis database host to connect to"); System.err.println(" is the port to connect to on the database host"); @@ -32,6 +32,7 @@ System.err.println(" is the username to use when connecting to the database "); System.err.println(" is the password to use when connecting to the database"); System.err.println(" is the stSPARQL query to evaluate."); + System.err.println(" is true when deletion of \"locked\" table should be enforced (e.g., when Strabon has been ungracefully shutdown)."); System.err.println(" [] is the format of your results (default: XML)"); System.exit(0); } @@ -42,14 +43,15 @@ String user = args[3]; String passwd = args[4]; String queryString = args[5]; + boolean forceDelete = Boolean.valueOf(args[6]); String resultsFormat = ""; - if ( args.length == 7 ) { - resultsFormat = args[6]; + if ( args.length == 8 ) { + resultsFormat = args[7]; } Strabon strabon = null; try { - strabon = new Strabon(db, user, passwd, port, host, false); + strabon = new Strabon(db, user, passwd, port, host, forceDelete); strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out); } catch (Exception e) { diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/testCRS.java Tue Mar 26 14:34:07 2013 +0200 @@ -38,10 +38,10 @@ } String text = - " . \n" + - " . \n"+ - " . \n"+ - " . \n"; + " . \n" + + " . \n"+ + " . \n"+ + " . \n"; String statement1= " " + "\"POLYGON((34.80 19.37,41.74 19.37,41.74 29.64 ,34.80 29.64,34.80 19.37));http://www.opengis.net/def/crs/EPSG/0/4326" + diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SpatialTests.java --- a/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SpatialTests.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/SpatialTests.java Tue Mar 26 14:34:07 2013 +0200 @@ -29,7 +29,7 @@ public String STRDF_NS = "http://strdf.di.uoa.gr/ontology#", EX_NS = "http://example.org/", NOA_NS = "http://teleios.di.uoa.gr/ontologies/noaOntology.owl#", - GEOF_NS ="http://www.opengis.net/def/queryLanguage/OGC-GeoSPARQL/1.0/function/"; + GEOF_NS ="http://www.opengis.net/def/function/geosparql/"; protected String prefixes = "PREFIX rdf: <"+RDF.NAMESPACE+"> \n" + @@ -780,7 +780,7 @@ " ?s1 ex:geometry ?g1 . \n"+ " ?s2 ex:geometry ?g2 . \n" + " FILTER( str(?s1) < str(?s2) ) . \n"+ - " FILTER( geof:sf-equals(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfEquals(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -799,7 +799,7 @@ " ?s1 ex:geometry ?g1 . \n"+ " ?s2 ex:geometry ?g2 . \n" + " FILTER( str(?s1) < str(?s2) ) . \n"+ - " FILTER( geof:sf-disjoint(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfDisjoint(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -821,7 +821,7 @@ " FILTER( str(?id1) < str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-intersects(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfIntersects(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -846,7 +846,7 @@ " FILTER( str(?id1) < str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-touches(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfTouches(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -867,7 +867,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-crosses(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfCrosses(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -889,7 +889,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-within(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfWithin(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -911,7 +911,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-contains(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfContains(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -933,7 +933,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:sf-overlaps(?g1, ?g2 )) . \n"+ + " FILTER( geof:sfOverlaps(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -955,7 +955,7 @@ " ?s1 ex:geometry ?g1 . \n"+ " ?s2 ex:geometry ?g2 . \n" + " FILTER( str(?s1) < str(?s2) ) . \n"+ - " FILTER( geof:eh-equals(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehEquals(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -974,7 +974,7 @@ " ?s1 ex:geometry ?g1 . \n"+ " ?s2 ex:geometry ?g2 . \n" + " FILTER( str(?s1) < str(?s2) ) . \n"+ - " FILTER( geof:eh-disjoint(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehDisjoint(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -996,7 +996,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-meet(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehMeet(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1018,7 +1018,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-overlap(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehOverlap(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1040,7 +1040,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-covers(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehCovers(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1061,7 +1061,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-coveredBy(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehCoveredBy(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1082,7 +1082,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-inside(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehInside(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1103,7 +1103,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:eh-contains(?g1, ?g2 )) . \n"+ + " FILTER( geof:ehContains(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1124,7 +1124,7 @@ " ?s1 ex:geometry ?g1 . \n"+ " ?s2 ex:geometry ?g2 . \n" + " FILTER( str(?s1) < str(?s2) ) . \n"+ - " FILTER( geof:rcc8-dc(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8dc(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1146,7 +1146,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:rcc8-po(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8po(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1168,7 +1168,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:rcc8-tppi(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8tppi(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1189,7 +1189,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:rcc8-tpp(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8tpp(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1211,7 +1211,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:rcc8-ntpp(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8ntpp(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") @@ -1231,7 +1231,7 @@ " FILTER( str(?id1) != str(?id2) ) . \n"+ " ?s2 ex:geometry ?g2 . \n" + " ?s1 ex:geometry ?g1 . \n"+ - " FILTER( geof:rcc8-ntpp(?g1, ?g2 )) . \n"+ + " FILTER( geof:rcc8ntpp(?g1, ?g2 )) . \n"+ "}"; @SuppressWarnings("unchecked") diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/test/java/eu/earthobservatory/runtime/generaldb/TransformTests.java --- a/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/TransformTests.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/generaldb/TransformTests.java Tue Mar 26 14:34:07 2013 +0200 @@ -30,7 +30,7 @@ "PREFIX base: \n"+ "PREFIX ex: \n"+ "PREFIX rdfs: \n" + - "PREFIX geof: \n"; + "PREFIX geof: \n"; protected String query1 = prefixes + "SELECT ?H1 ?HAT1 ?HGEO1 " + diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java Tue Mar 26 14:34:07 2013 +0200 @@ -12,9 +12,12 @@ import java.io.IOException; import java.io.InputStream; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Connection; +import java.util.ArrayList; import java.util.Properties; import org.junit.AfterClass; @@ -23,60 +26,78 @@ import org.openrdf.rio.RDFHandlerException; import org.openrdf.rio.RDFParseException; + import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; import eu.earthobservatory.runtime.generaldb.SimpleTests; import eu.earthobservatory.runtime.generaldb.Strabon; +import static org.junit.Assert.assertNull; + /** * A set of simple tests on SPARQL query functionality * * @author George Garbis + * @author Panayiotis Smeros */ public class TemplateTests { - public static java.sql.Connection conn = null; - public static String databaseName = null; - - public static String jdbcDriver = null; + public static String databaseTemplateName = null; + public static String defaultUser = null; public static String serverName = null; public static String username = null; public static String password = null; public static Integer port = null; + public static Connection conn = null; + public static String databaseName = null; + @BeforeClass public static Strabon beforeClass(String inputFile) throws Exception { + String url=""; + ArrayList databases=new ArrayList(); + PreparedStatement pst = null; + // Read properties Properties properties = new Properties(); InputStream propertiesStream = SimpleTests.class.getResourceAsStream("/databases.properties"); properties.load(propertiesStream); + databaseTemplateName = properties.getProperty("postgis.databaseTemplateName");; + defaultUser = properties.getProperty("postgis.defaultUser"); serverName = properties.getProperty("postgis.serverName"); - databaseName = properties.getProperty("postgis.databaseName"); - port = Integer.parseInt(properties.getProperty("postgis.port")); username = properties.getProperty("postgis.username"); password = properties.getProperty("postgis.password"); - - // Connect to database - Class.forName("org.postgresql.Driver"); - String url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; + port = Integer.parseInt(properties.getProperty("postgis.port")); + + //Connect to server and create the temp database + url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; conn = DriverManager.getConnection(url, username, password); - -// // Clean database - Statement stmt = conn.createStatement(); - ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + - "table_schema='public' AND table_name <> 'spatial_ref_sys' " + - "AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " + - "AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " + - "AND table_name <> 'locked'" - ); - while (results.next()) { - String table_name = results.getString("table_name"); - Statement stmt2 = conn.createStatement(); - stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); - stmt2.close(); - } - stmt.close(); + assertNull(conn.getWarnings()); + + pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); + ResultSet rs = pst.executeQuery(); + + while (rs.next()) { + databases.add(rs.getString(1)); + } + rs.close(); + pst.close(); + + databaseName="teststrabon"+(int)(Math.random()*10000); + while(databases.contains(databaseName)){ + databaseName+="0"; + } + + + pst = conn.prepareStatement("CREATE DATABASE "+databaseName+" TEMPLATE " + databaseTemplateName); + pst.executeUpdate(); + pst.close(); + conn.close(); + + url = "jdbc:postgresql://"+serverName+":"+port+"/"+databaseName; + conn = DriverManager.getConnection(url, username, password); + assertNull(conn.getWarnings()); Strabon strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, username, password, port, serverName, true); @@ -85,10 +106,22 @@ return strabon; } + @AfterClass public static void afterClass(Strabon strabon) throws SQLException { strabon.close(); + + //Drop the temp database + conn.close(); + String url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; + conn = DriverManager.getConnection(url, username, password); + assertNull(conn.getWarnings()); + + PreparedStatement pst = conn.prepareStatement("DROP DATABASE "+databaseName); + pst.executeUpdate(); + pst.close(); + conn.close(); } protected static void loadTestData(String inputfile, Strabon strabon) @@ -96,6 +129,23 @@ { strabon.storeInRepo(inputfile, "NTRIPLES"); } + + + // Clean database +// Statement stmt = conn.createStatement(); +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + +// "table_schema='public' AND table_name <> 'spatial_ref_sys' " + +// "AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " + +// "AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " + +// "AND table_name <> 'locked'" +// ); +// while (results.next()) { +// String table_name = results.getString("table_name"); +// Statement stmt2 = conn.createStatement(); +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); +// stmt2.close(); +// } +// stmt.close(); // /** // * @throws java.lang.Exception diff -r 93d1b4ce44a6 -r f662352c3799 runtime/src/test/resources/databases.properties --- a/runtime/src/test/resources/databases.properties Sun Mar 10 22:14:24 2013 +0200 +++ b/runtime/src/test/resources/databases.properties Tue Mar 26 14:34:07 2013 +0200 @@ -1,5 +1,6 @@ # PostGIS -postgis.databaseName = strabon-test +postgis.databaseTemplateName = template_postgis +postgis.defaultUser = postgres postgis.serverName = localhost postgis.username = postgres postgis.password = postgres diff -r 93d1b4ce44a6 -r f662352c3799 scripts/strabon --- a/scripts/strabon Sun Mar 10 22:14:24 2013 +0200 +++ b/scripts/strabon Tue Mar 26 14:34:07 2013 +0200 @@ -55,11 +55,15 @@ # the RDF format of the files to store (defaults to ntriples) FORMAT="ntriples" +# true to force deletion of locked table, false otherwise +FORCE_DELETE="false" + # the URI of the named graph into which the RDF files shall be stored NAMED_GRAPH= # predefined queries QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}" +QUERY_GETALL="SELECT * WHERE {?s ?p ?o}" QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}" QUERY_HOTSPOT_SIZE="SELECT (COUNT(*) as ?C) WHERE {?h }" QUERY_EXPORT="CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" @@ -135,15 +139,20 @@ } function help_query() { - echo "Usage: ${CMD} query SPARQL_QUERY [RESULT_FORMAT]" + echo "Usage: ${CMD} query [OPTIONS] SPARQL_QUERY [RESULT_FORMAT]" echo echo "Execute a SPARQL query on Strabon." echo echo " SPARQL_QUERY : the SPARQL query to execute or an alias name such as the following:" echo " size: returns the number of triples" + echo " all: returns all triples" echo " hotspots: returns the number of hotspots" - echo " RESULT_FORMAT : the format of the result. Possible values are \`???' (default), \`xml'" + echo " RESULT_FORMAT : the format of the result. Possible values are \`???' (default), \`xml'" echo " \`html', \`kml', \`kmz', or \`geojson'" + echo + echo "OPTIONS can be one of the following" + echo " --force-delete : forces deletion of \"locked\" table (e.g., when Strabon has been" + echo " ungracefully shutdown)" } function help_update() { @@ -429,6 +438,13 @@ help_query exit 1 fi + + # check whether force deletion of locked table has been specified + if test "${1}" = "--force-delete"; then + shift + FORCE_DELETE="true" + fi + QUERY="${1}" shift @@ -440,6 +456,9 @@ hotspots) QUERY="${QUERY_HOTSPOT_SIZE}" ;; + all) + QUERY="${QUERY_GETALL}" + ;; esac # check for format of result @@ -583,6 +602,8 @@ STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" -f ${FORMAT} ${NAMED_GRAPH}); " done +elif test "${CLASS}" = "QueryOp"; then + STRABON_EXEC="(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${PREFIXES}${QUERY}\" ${FORCE_DELETE} ${RESULT_FORMAT})" else STRABON_EXEC="(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${PREFIXES}${QUERY}\" ${RESULT_FORMAT})" fi