Strabon
changeset 1203:5fe95b6e25fc
fixed NULL pointer exception that was from StrabonPolyhedron when one passed a WKT representation containing the URI for the CRS (stRDF/wktLiteral). In this case, parsing of WKT using JTS was failing causing StrabonPolyhedron to continue parsing for GML, which was failing as well
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Sat Jul 13 20:11:01 2013 +0300 (2013-07-13) |
parents | 7ad711e19d01 |
children | d928a2a245f5 |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java.orig runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java |
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Sat Jul 13 19:28:12 2013 +0300 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Sat Jul 13 20:11:01 2013 +0300 1.3 @@ -81,6 +81,39 @@ 1.4 } 1.5 1.6 /** 1.7 + * This constructor tries to guess the datatype of the WKT literal. 1.8 + * It should be used only when one does not have such information 1.9 + * available. 1.10 + * 1.11 + * NOTICE: it is not guaranteed that guessing will fill-in the 1.12 + * datatype, but it is guaranteed that parsing will be done 1.13 + * correctly in any case (well, except for illegal cases). 1.14 + * 1.15 + * @param literalValue 1.16 + */ 1.17 + public AbstractWKT(String literalValue) { 1.18 + datatype = null; 1.19 + 1.20 + if (literalValue.indexOf(WKTHelper.STRDF_SRID_DELIM) > 0) { // strdf:WKT 1.21 + datatype = GeoConstants.WKT; 1.22 + 1.23 + isstRDFWKT = true; 1.24 + parsestRDFWKT(literalValue); 1.25 + 1.26 + } else { // wktLiteral or plain WKT 1.27 + if (literalValue.charAt(0) == '<') { // starts with a URI, assume wktLiteral 1.28 + datatype = GeoConstants.WKTLITERAL; 1.29 + 1.30 + isstRDFWKT = false; 1.31 + parseWKTLITERAL(literalValue); 1.32 + 1.33 + } else { // cannot guess, only WKT representation was given 1.34 + parsestRDFWKT(literalValue); 1.35 + } 1.36 + } 1.37 + } 1.38 + 1.39 + /** 1.40 * Parses a WKT literal according to the specification of stRDF/stSPARQL. 1.41 * The literal value may (not) specify the URI of a spatial reference system. 1.42 *
2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Sat Jul 13 19:28:12 2013 +0300 2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java Sat Jul 13 20:11:01 2013 +0300 2.3 @@ -53,6 +53,7 @@ 2.4 * {@link StrabonPolyhedron} instance through any kind of representation and of course 2.5 * getting a {@link StrabonPolyhedron} instance in a specific representation. 2.6 * 2.7 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 2.8 * @author Manos Karpathiotakis <mk@di.uoa.gr> 2.9 * @author Kostis Kyzirakos <kk@di.uoa.gr> 2.10 * 2.11 @@ -104,6 +105,10 @@ 2.12 * in the representation of the argument. The representation could be 2.13 * either in WKT or in GML. 2.14 * 2.15 + * NOTICE: whoever creates StrabonPolyhedron objects is responsible 2.16 + * for cleaning the representation of the geometry by removing any 2.17 + * stRDF/GeoSPARQL specific information, such as the SRID. 2.18 + * 2.19 * @param representation 2.20 * @throws Exception 2.21 */
3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Sat Jul 13 19:28:12 2013 +0300 3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Sat Jul 13 20:11:01 2013 +0300 3.3 @@ -24,7 +24,7 @@ 3.4 3.5 private static Logger logger = LoggerFactory.getLogger(org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper.class); 3.6 3.7 - private static String SRID_DELIM = ";"; 3.8 + public static String STRDF_SRID_DELIM = ";"; 3.9 private static String CUT_DELIM = "/"; 3.10 private static String URI_ENDING = ">"; 3.11 3.12 @@ -37,7 +37,7 @@ 3.13 public static String getWithoutSRID(String wkt) { 3.14 if (wkt == null) return wkt; 3.15 3.16 - int pos = wkt.indexOf(SRID_DELIM); 3.17 + int pos = wkt.indexOf(STRDF_SRID_DELIM); 3.18 if (pos != -1) { 3.19 return wkt.substring(0, pos); 3.20 3.21 @@ -59,7 +59,7 @@ 3.22 3.23 if (wkt == null) return srid; 3.24 3.25 - int pos = wkt.indexOf(SRID_DELIM); 3.26 + int pos = wkt.indexOf(STRDF_SRID_DELIM); 3.27 if (pos != -1) { 3.28 try { 3.29 srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, ""));
4.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Sat Jul 13 19:28:12 2013 +0300 4.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java Sat Jul 13 20:11:01 2013 +0300 4.3 @@ -12,6 +12,7 @@ 4.4 import java.util.ArrayList; 4.5 import java.util.List; 4.6 4.7 +import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT; 4.8 import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 4.9 import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 4.10 import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 4.11 @@ -986,13 +987,17 @@ 4.12 4.13 StrabonPolyhedron poly = null; 4.14 try{ 4.15 - poly = new StrabonPolyhedron(raw); 4.16 + // have to parse it before and clean it from possible appearance of CRS 4.17 + AbstractWKT wkt = new AbstractWKT(raw); 4.18 + 4.19 + poly = new StrabonPolyhedron(wkt.getWKT()); 4.20 + 4.21 + filter.append(" ST_GeomFromText('"+poly.toWKT() +"',"+String.valueOf(wkt.getSRID())+")"); 4.22 + 4.23 } catch (Exception e) { 4.24 e.printStackTrace(); 4.25 } 4.26 4.27 - filter.append(" ST_GeomFromText('"+poly.toWKT() +"',"+String.valueOf(GeoConstants.defaultSRID)+")"); 4.28 - 4.29 return raw; 4.30 } 4.31
5.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java.orig Sat Jul 13 19:28:12 2013 +0300 5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 5.3 @@ -1,2150 +0,0 @@ 5.4 -/* 5.5 - * Copyright Aduna (http://www.aduna-software.com/) (c) 2008. 5.6 - * 5.7 - * Licensed under the Aduna BSD-style license. 5.8 - */ 5.9 -package org.openrdf.sail.postgis.evaluation; 5.10 - 5.11 -import java.util.ArrayList; 5.12 -import java.util.List; 5.13 - 5.14 -import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 5.15 -import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 5.16 -import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue; 5.17 -import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn; 5.18 -import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn; 5.19 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbove; 5.20 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd; 5.21 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnyInteract; 5.22 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlBelow; 5.23 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase; 5.24 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains; 5.25 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB; 5.26 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy; 5.27 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers; 5.28 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint; 5.29 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial; 5.30 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea; 5.31 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML; 5.32 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText; 5.33 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBoundary; 5.34 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBuffer; 5.35 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoConvexHull; 5.36 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDifference; 5.37 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension; 5.38 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDistance; 5.39 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoEnvelope; 5.40 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoGeometryType; 5.41 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIntersection; 5.42 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsEmpty; 5.43 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsSimple; 5.44 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSrid; 5.45 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSymDifference; 5.46 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoTransform; 5.47 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoUnion; 5.48 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlInside; 5.49 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIntersects; 5.50 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull; 5.51 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLeft; 5.52 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr; 5.53 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbEquals; 5.54 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbInside; 5.55 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbIntersects; 5.56 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot; 5.57 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull; 5.58 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOverlap; 5.59 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate; 5.60 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight; 5.61 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary; 5.62 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary; 5.63 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary; 5.64 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary; 5.65 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty; 5.66 -import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouch; 5.67 -import org.openrdf.sail.generaldb.algebra.GeneralDBStringValue; 5.68 -import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn; 5.69 -import org.openrdf.sail.generaldb.algebra.GeneralDBUnionItem; 5.70 -import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator; 5.71 -import org.openrdf.sail.generaldb.algebra.base.GeneralDBFromItem; 5.72 -import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr; 5.73 -import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator; 5.74 -import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator; 5.75 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Contains; 5.76 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_CoveredBy; 5.77 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Covers; 5.78 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Disjoint; 5.79 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Equals; 5.80 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Inside; 5.81 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Meet; 5.82 -import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Overlap; 5.83 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Dc; 5.84 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ec; 5.85 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Eq; 5.86 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntpp; 5.87 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntppi; 5.88 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Po; 5.89 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tpp; 5.90 -import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tppi; 5.91 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Contains; 5.92 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Crosses; 5.93 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Disjoint; 5.94 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Equals; 5.95 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Intersects; 5.96 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Overlaps; 5.97 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Touches; 5.98 -import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Within; 5.99 -import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilder; 5.100 -import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder; 5.101 -import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 5.102 -import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlJoinBuilder; 5.103 -import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlQueryBuilder; 5.104 -import org.openrdf.sail.rdbms.exceptions.RdbmsException; 5.105 -import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException; 5.106 - 5.107 -/** 5.108 - * Constructs an SQL query from {@link GeneralDBSqlExpr}s and {@link GeneralDBFromItem}s. 5.109 - * 5.110 - * @author Manos Karpathiotakis <mk@di.uoa.gr> 5.111 - * 5.112 - */ 5.113 -public class PostGISQueryBuilder extends GeneralDBQueryBuilder { 5.114 - 5.115 - public static final String STRDFGEO_FIELD = "strdfgeo"; 5.116 - public static final String SRID_FIELD = "srid"; 5.117 - public static final String ST_TRANSFORM = "ST_Transform"; 5.118 - public static final String ST_ASBINARY = "ST_AsBinary"; 5.119 - /** 5.120 - * If (spatial) label column met is null, I must not try to retrieve its srid. 5.121 - * Opting to ask for 'null' instead 5.122 - */ 5.123 - boolean nullLabel = false; 5.124 - 5.125 - public enum SpatialOperandsPostGIS { anyInteract, equals, contains, left, right, above, inside, below; } 5.126 - public enum SpatialFunctionsPostGIS 5.127 - { //stSPARQL++ 5.128 - //Spatial Relationships 5.129 - ST_Disjoint, 5.130 - ST_Touches, 5.131 - ST_Covers, 5.132 - ST_CoveredBy, 5.133 - ST_Overlaps, 5.134 - ST_Intersects, 5.135 - ST_Equals, 5.136 - ST_Relate, 5.137 - ST_Within, 5.138 - ST_Contains, 5.139 - 5.140 - 5.141 - //Spatial Constructs - Binary 5.142 - ST_Union, 5.143 - ST_Intersection, 5.144 - ST_Difference, 5.145 - ST_Buffer, 5.146 - ST_Transform, 5.147 - ST_SymDifference, 5.148 - 5.149 - 5.150 - //Spatial Constructs - Unary 5.151 - ST_Envelope, 5.152 - ST_ConvexHull, 5.153 - ST_Boundary, 5.154 - 5.155 - //Spatial Metrics - Binary 5.156 - ST_Distance, 5.157 - 5.158 - //Spatial Metrics - Unary 5.159 - ST_Area, 5.160 - 5.161 - //Spatial Properties - All Unary 5.162 - ST_Dimension, 5.163 - ST_GeometryType, 5.164 - ST_AsGML, 5.165 - ST_AsText, 5.166 - ST_SRID, 5.167 - ST_IsEmpty, 5.168 - ST_IsSimple, 5.169 - 5.170 - //GeoSPARQL 5.171 - //Simple Features 5.172 - SF_Equals, 5.173 - SF_Disjoint, 5.174 - SF_Intersects, 5.175 - SF_Touches, 5.176 - SF_Within, 5.177 - SF_Contains, 5.178 - SF_Overlaps, 5.179 - SF_Crosses, 5.180 - 5.181 - //RCC8 5.182 - RCC8_Eq, 5.183 - RCC8_Dc, 5.184 - RCC8_Ec, 5.185 - RCC8_Po, 5.186 - RCC8_Tppi, 5.187 - RCC8_Tpp, 5.188 - RCC8_Ntppi, 5.189 - RCC8_Ntpp, 5.190 - 5.191 - //Egenhofer 5.192 - EH_Equals, 5.193 - EH_Disjoint, 5.194 - EH_Meet, 5.195 - EH_Overlap, 5.196 - EH_Covers, 5.197 - EH_CoveredBy, 5.198 - EH_Inside, 5.199 - EH_Contains, 5.200 - ; 5.201 - } 5.202 - 5.203 - public enum DateTimeFunctionsPostGIS { 5.204 - Difference; 5.205 - } 5.206 - 5.207 - public PostGISQueryBuilder() { 5.208 - super(); 5.209 - } 5.210 - 5.211 - public PostGISQueryBuilder(GeneralDBSqlQueryBuilder builder) { 5.212 - super(builder); 5.213 - this.query = builder; 5.214 - } 5.215 - 5.216 - @Override 5.217 - protected void append(GeneralDBSqlNull expr, GeneralDBSqlExprBuilder filter) { 5.218 - filter.appendNull(); 5.219 - } 5.220 - 5.221 - @Override 5.222 - protected void append(GeneralDBSqlIsNull expr, GeneralDBSqlExprBuilder filter) 5.223 - throws UnsupportedRdbmsOperatorException 5.224 - { 5.225 - dispatch(expr.getArg(), filter); 5.226 - filter.isNull(); 5.227 - } 5.228 - 5.229 - @Override 5.230 - protected void append(GeneralDBSqlNot expr, GeneralDBSqlExprBuilder filter) 5.231 - throws UnsupportedRdbmsOperatorException 5.232 - { 5.233 - if (expr.getArg() instanceof GeneralDBSqlIsNull) { 5.234 - GeneralDBSqlIsNull arg = (GeneralDBSqlIsNull)expr.getArg(); 5.235 - dispatch(arg.getArg(), filter); 5.236 - filter.isNotNull(); 5.237 - } 5.238 - else { 5.239 - GeneralDBSqlBracketBuilder open = filter.not(); 5.240 - dispatch(expr.getArg(), (GeneralDBSqlExprBuilder) open); 5.241 - open.close(); 5.242 - } 5.243 - } 5.244 - 5.245 - @Override 5.246 - protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) { 5.247 - if (var.getRdbmsVar().isResource()) { 5.248 - filter.appendNull(); 5.249 - nullLabel = true; 5.250 - } 5.251 - else { 5.252 - if(var.isSpatial()) 5.253 - { 5.254 - filter.appendFunction(ST_ASBINARY); 5.255 - filter.openBracket(); 5.256 - //XXX SRID 5.257 - filter.appendFunction(ST_TRANSFORM); 5.258 - filter.openBracket(); 5.259 - // 5.260 - String alias = getLabelAlias(var.getRdbmsVar()); 5.261 - 5.262 - filter.column(alias, STRDFGEO_FIELD); 5.263 - //XXX SRID 5.264 - filter.appendComma(); 5.265 - filter.column(alias, SRID_FIELD); 5.266 - filter.closeBracket(); 5.267 - // 5.268 - filter.closeBracket(); 5.269 - 5.270 - //Adding srid field explicitly for my StrabonPolyhedron constructor later on! 5.271 - filter.appendComma(); 5.272 - filter.column(alias, SRID_FIELD); 5.273 - } 5.274 - else 5.275 - { 5.276 - //XXX original/default case 5.277 - String alias = getLabelAlias(var.getRdbmsVar()); 5.278 - filter.column(alias, "value"); 5.279 - } 5.280 - } 5.281 - } 5.282 - 5.283 - @Override 5.284 - protected void append(GeneralDBSqlAnd expr, GeneralDBSqlExprBuilder filter) 5.285 - throws UnsupportedRdbmsOperatorException 5.286 - { 5.287 - dispatch(expr.getLeftArg(), filter); 5.288 - filter.and(); 5.289 - dispatch(expr.getRightArg(), filter); 5.290 - } 5.291 - 5.292 - protected GeneralDBSqlJoinBuilder subJoinAndFilter(GeneralDBSqlJoinBuilder query, GeneralDBFromItem from) 5.293 - throws RdbmsException, UnsupportedRdbmsOperatorException 5.294 - { 5.295 - if (from instanceof GeneralDBUnionItem) { 5.296 - GeneralDBUnionItem union = (GeneralDBUnionItem)from; 5.297 - List<String> names = union.getSelectVarNames(); 5.298 - List<GeneralDBColumnVar> vars = union.appendVars(new ArrayList<GeneralDBColumnVar>()); 5.299 - GeneralDBSqlQueryBuilder subquery = query.subquery(); 5.300 - for (GeneralDBFromItem item : union.getUnion()) { 5.301 - for (int i = 0, n = names.size(); i < n; i++) { 5.302 - GeneralDBColumnVar var = item.getVar(names.get(i)); 5.303 - GeneralDBSqlExprBuilder select = subquery.select(); 5.304 - if (var == null) { 5.305 - select.appendNull(); 5.306 - } 5.307 - else if (var.isImplied()) { 5.308 - select.appendNumeric(vf.getInternalId(var.getValue())); 5.309 - } 5.310 - else { 5.311 - select.column(var.getAlias(), var.getColumn()); 5.312 - } 5.313 - select.as(vars.get(i).getColumn()); 5.314 - } 5.315 - from(subquery, item); 5.316 - subquery = subquery.union(); 5.317 - } 5.318 - } 5.319 - for (GeneralDBFromItem join : from.getJoins()) { 5.320 - join(query, join); 5.321 - } 5.322 - for (GeneralDBSqlExpr expr : from.getFilters()) { 5.323 - dispatch(expr, query.on().and()); 5.324 - } 5.325 - return query; 5.326 - } 5.327 - 5.328 - //FIXME my addition from here on 5.329 - 5.330 - //Issue with this function: crashes when MathExpr is present in Select but does not 5.331 - //involve spatial variables! must escape this somehow 5.332 - @Override 5.333 - public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException 5.334 - { 5.335 - if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 5.336 - &&!(expr instanceof GeneralDBSqlSpatialMetricUnary) 5.337 - &&!(expr instanceof GeneralDBSqlMathExpr) 5.338 - &&!(expr instanceof GeneralDBSqlSpatialProperty)) 5.339 - { 5.340 - query.select().appendFunction(ST_ASBINARY); 5.341 - } 5.342 - else 5.343 - { 5.344 - query.select(); 5.345 - } 5.346 - if(expr instanceof BinaryGeneralDBOperator) 5.347 - { 5.348 - dispatchBinarySqlOperator((BinaryGeneralDBOperator) expr, query.select); 5.349 - } 5.350 - else if(expr instanceof UnaryGeneralDBOperator) 5.351 - { 5.352 - dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select); 5.353 - } 5.354 - //SRID support must be explicitly added! 5.355 - 5.356 - return this; 5.357 - } 5.358 - 5.359 - //Spatial Relationship Functions 5.360 - @Override 5.361 - protected void append(GeneralDBSqlAnyInteract expr, GeneralDBSqlExprBuilder filter) 5.362 - throws UnsupportedRdbmsOperatorException 5.363 - { 5.364 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects); 5.365 - } 5.366 - 5.367 - 5.368 - @Override 5.369 - protected void append(GeneralDBSqlIntersects expr, GeneralDBSqlExprBuilder filter) 5.370 - throws UnsupportedRdbmsOperatorException { 5.371 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects); 5.372 - } 5.373 - 5.374 - @Override 5.375 - protected void append(GeneralDBSqlContains expr, GeneralDBSqlExprBuilder filter) 5.376 - throws UnsupportedRdbmsOperatorException { 5.377 - 5.378 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Contains); 5.379 - } 5.380 - 5.381 - 5.382 - 5.383 - 5.384 - @Override 5.385 - protected void append(GeneralDBSqlEqualsSpatial expr, GeneralDBSqlExprBuilder filter) 5.386 - throws UnsupportedRdbmsOperatorException { 5.387 - 5.388 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Equals); 5.389 - } 5.390 - 5.391 - @Override 5.392 - protected void append(GeneralDBSqlInside expr, GeneralDBSqlExprBuilder filter) 5.393 - throws UnsupportedRdbmsOperatorException { 5.394 - 5.395 - //appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside); 5.396 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Within); 5.397 - 5.398 - } 5.399 - 5.400 - @Override 5.401 - protected void append(GeneralDBSqlCovers expr, GeneralDBSqlExprBuilder filter) 5.402 - throws UnsupportedRdbmsOperatorException { 5.403 - 5.404 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Covers); 5.405 - } 5.406 - 5.407 - @Override 5.408 - protected void append(GeneralDBSqlCoveredBy expr, GeneralDBSqlExprBuilder filter) 5.409 - throws UnsupportedRdbmsOperatorException { 5.410 - 5.411 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_CoveredBy); 5.412 - } 5.413 - 5.414 - @Override 5.415 - protected void append(GeneralDBSqlTouch expr, GeneralDBSqlExprBuilder filter) 5.416 - throws UnsupportedRdbmsOperatorException { 5.417 - 5.418 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Touches); 5.419 - } 5.420 - 5.421 - @Override 5.422 - protected void append(GeneralDBSqlOverlap expr, GeneralDBSqlExprBuilder filter) 5.423 - throws UnsupportedRdbmsOperatorException { 5.424 - 5.425 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps); 5.426 - } 5.427 - 5.428 - protected void append(GeneralDBSqlDisjoint expr, GeneralDBSqlExprBuilder filter) 5.429 - throws UnsupportedRdbmsOperatorException { 5.430 - 5.431 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Disjoint); 5.432 - } 5.433 - 5.434 - @Override 5.435 - protected void append(GeneralDBSqlRelate expr, GeneralDBSqlExprBuilder filter) 5.436 - throws UnsupportedRdbmsOperatorException 5.437 - { 5.438 - appendGeneralDBSpatialFunctionTriple(expr, filter, SpatialFunctionsPostGIS.ST_Relate); 5.439 - } 5.440 - 5.441 - @Override 5.442 - protected void append(GeneralDBSqlLeft expr, GeneralDBSqlExprBuilder filter) 5.443 - throws UnsupportedRdbmsOperatorException 5.444 - { 5.445 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.left); 5.446 - } 5.447 - 5.448 - @Override 5.449 - protected void append(GeneralDBSqlRight expr, GeneralDBSqlExprBuilder filter) 5.450 - throws UnsupportedRdbmsOperatorException 5.451 - { 5.452 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.right); 5.453 - } 5.454 - 5.455 - @Override 5.456 - protected void append(GeneralDBSqlAbove expr, GeneralDBSqlExprBuilder filter) 5.457 - throws UnsupportedRdbmsOperatorException 5.458 - { 5.459 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.above); 5.460 - } 5.461 - 5.462 - @Override 5.463 - protected void append(GeneralDBSqlBelow expr, GeneralDBSqlExprBuilder filter) 5.464 - throws UnsupportedRdbmsOperatorException 5.465 - { 5.466 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.below); 5.467 - } 5.468 - 5.469 - @Override 5.470 - protected void append(GeneralDBSqlMbbIntersects expr, GeneralDBSqlExprBuilder filter) 5.471 - throws UnsupportedRdbmsOperatorException { 5.472 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.anyInteract); 5.473 - } 5.474 - 5.475 - @Override 5.476 - protected void append(GeneralDBSqlMbbInside expr, GeneralDBSqlExprBuilder filter) 5.477 - throws UnsupportedRdbmsOperatorException { 5.478 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside); 5.479 - } 5.480 - 5.481 - 5.482 - @Override 5.483 - protected void append(GeneralDBSqlContainsMBB expr, GeneralDBSqlExprBuilder filter) 5.484 - throws UnsupportedRdbmsOperatorException { 5.485 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.contains); 5.486 - } 5.487 - 5.488 - 5.489 - @Override 5.490 - protected void append(GeneralDBSqlMbbEquals expr, GeneralDBSqlExprBuilder filter) 5.491 - throws UnsupportedRdbmsOperatorException { 5.492 - appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.equals); 5.493 - } 5.494 - 5.495 - //GeoSPARQL - Spatial Relationship Functions 5.496 - //Simple Features 5.497 - @Override 5.498 - protected void append(GeneralDBSqlSF_Contains expr, GeneralDBSqlExprBuilder filter) 5.499 - throws UnsupportedRdbmsOperatorException 5.500 - { 5.501 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Contains); 5.502 - } 5.503 - 5.504 - @Override 5.505 - protected void append(GeneralDBSqlSF_Crosses expr, GeneralDBSqlExprBuilder filter) 5.506 - throws UnsupportedRdbmsOperatorException 5.507 - { 5.508 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Crosses); 5.509 - } 5.510 - 5.511 - @Override 5.512 - protected void append(GeneralDBSqlSF_Disjoint expr, GeneralDBSqlExprBuilder filter) 5.513 - throws UnsupportedRdbmsOperatorException 5.514 - { 5.515 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Disjoint); 5.516 - } 5.517 - 5.518 - @Override 5.519 - protected void append(GeneralDBSqlSF_Equals expr, GeneralDBSqlExprBuilder filter) 5.520 - throws UnsupportedRdbmsOperatorException 5.521 - { 5.522 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Equals); 5.523 - } 5.524 - 5.525 - @Override 5.526 - protected void append(GeneralDBSqlSF_Intersects expr, GeneralDBSqlExprBuilder filter) 5.527 - throws UnsupportedRdbmsOperatorException 5.528 - { 5.529 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Intersects); 5.530 - } 5.531 - 5.532 - @Override 5.533 - protected void append(GeneralDBSqlSF_Overlaps expr, GeneralDBSqlExprBuilder filter) 5.534 - throws UnsupportedRdbmsOperatorException 5.535 - { 5.536 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Overlaps); 5.537 - } 5.538 - 5.539 - @Override 5.540 - protected void append(GeneralDBSqlSF_Touches expr, GeneralDBSqlExprBuilder filter) 5.541 - throws UnsupportedRdbmsOperatorException 5.542 - { 5.543 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Touches); 5.544 - } 5.545 - 5.546 - @Override 5.547 - protected void append(GeneralDBSqlSF_Within expr, GeneralDBSqlExprBuilder filter) 5.548 - throws UnsupportedRdbmsOperatorException 5.549 - { 5.550 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Within); 5.551 - } 5.552 - 5.553 - //Egenhofer 5.554 - @Override 5.555 - protected void append(GeneralDBSqlEgenhofer_CoveredBy expr, GeneralDBSqlExprBuilder filter) 5.556 - throws UnsupportedRdbmsOperatorException 5.557 - { 5.558 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_CoveredBy); 5.559 - } 5.560 - 5.561 - @Override 5.562 - protected void append(GeneralDBSqlEgenhofer_Covers expr, GeneralDBSqlExprBuilder filter) 5.563 - throws UnsupportedRdbmsOperatorException 5.564 - { 5.565 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Covers); 5.566 - } 5.567 - 5.568 - @Override 5.569 - protected void append(GeneralDBSqlEgenhofer_Contains expr, GeneralDBSqlExprBuilder filter) 5.570 - throws UnsupportedRdbmsOperatorException 5.571 - { 5.572 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Contains); 5.573 - } 5.574 - 5.575 - @Override 5.576 - protected void append(GeneralDBSqlEgenhofer_Disjoint expr, GeneralDBSqlExprBuilder filter) 5.577 - throws UnsupportedRdbmsOperatorException 5.578 - { 5.579 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Disjoint); 5.580 - } 5.581 - 5.582 - @Override 5.583 - protected void append(GeneralDBSqlEgenhofer_Equals expr, GeneralDBSqlExprBuilder filter) 5.584 - throws UnsupportedRdbmsOperatorException 5.585 - { 5.586 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Equals); 5.587 - } 5.588 - 5.589 - @Override 5.590 - protected void append(GeneralDBSqlEgenhofer_Inside expr, GeneralDBSqlExprBuilder filter) 5.591 - throws UnsupportedRdbmsOperatorException 5.592 - { 5.593 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Inside); 5.594 - } 5.595 - 5.596 - @Override 5.597 - protected void append(GeneralDBSqlEgenhofer_Meet expr, GeneralDBSqlExprBuilder filter) 5.598 - throws UnsupportedRdbmsOperatorException 5.599 - { 5.600 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Meet); 5.601 - } 5.602 - 5.603 - @Override 5.604 - protected void append(GeneralDBSqlEgenhofer_Overlap expr, GeneralDBSqlExprBuilder filter) 5.605 - throws UnsupportedRdbmsOperatorException 5.606 - { 5.607 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Overlap); 5.608 - } 5.609 - 5.610 - //RCC8 5.611 - @Override 5.612 - protected void append(GeneralDBSqlRCC8_Dc expr, GeneralDBSqlExprBuilder filter) 5.613 - throws UnsupportedRdbmsOperatorException 5.614 - { 5.615 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Dc); 5.616 - } 5.617 - 5.618 - @Override 5.619 - protected void append(GeneralDBSqlRCC8_Eq expr, GeneralDBSqlExprBuilder filter) 5.620 - throws UnsupportedRdbmsOperatorException 5.621 - { 5.622 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Eq); 5.623 - } 5.624 - 5.625 - @Override 5.626 - protected void append(GeneralDBSqlRCC8_Ec expr, GeneralDBSqlExprBuilder filter) 5.627 - throws UnsupportedRdbmsOperatorException 5.628 - { 5.629 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ec); 5.630 - } 5.631 - 5.632 - @Override 5.633 - protected void append(GeneralDBSqlRCC8_Po expr, GeneralDBSqlExprBuilder filter) 5.634 - throws UnsupportedRdbmsOperatorException 5.635 - { 5.636 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Po); 5.637 - } 5.638 - 5.639 - @Override 5.640 - protected void append(GeneralDBSqlRCC8_Tppi expr, GeneralDBSqlExprBuilder filter) 5.641 - throws UnsupportedRdbmsOperatorException 5.642 - { 5.643 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tppi); 5.644 - } 5.645 - 5.646 - @Override 5.647 - protected void append(GeneralDBSqlRCC8_Tpp expr, GeneralDBSqlExprBuilder filter) 5.648 - throws UnsupportedRdbmsOperatorException 5.649 - { 5.650 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tpp); 5.651 - } 5.652 - 5.653 - @Override 5.654 - protected void append(GeneralDBSqlRCC8_Ntpp expr, GeneralDBSqlExprBuilder filter) 5.655 - throws UnsupportedRdbmsOperatorException 5.656 - { 5.657 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntpp); 5.658 - } 5.659 - 5.660 - @Override 5.661 - protected void append(GeneralDBSqlRCC8_Ntppi expr, GeneralDBSqlExprBuilder filter) 5.662 - throws UnsupportedRdbmsOperatorException 5.663 - { 5.664 - appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntppi); 5.665 - } 5.666 - 5.667 - //Spatial Construct Functions 5.668 - @Override 5.669 - protected void append(GeneralDBSqlGeoUnion expr, GeneralDBSqlExprBuilder filter) 5.670 - throws UnsupportedRdbmsOperatorException 5.671 - { 5.672 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Union); 5.673 - } 5.674 - 5.675 - @Override 5.676 - protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter) 5.677 - throws UnsupportedRdbmsOperatorException 5.678 - { 5.679 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Buffer); 5.680 - } 5.681 - 5.682 - //XXX Different Behavior 5.683 - @Override 5.684 - protected void append(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter) 5.685 - throws UnsupportedRdbmsOperatorException 5.686 - { 5.687 - appendTransformFunc(expr, filter); 5.688 - } 5.689 - 5.690 - @Override 5.691 - protected void append(GeneralDBSqlGeoEnvelope expr, GeneralDBSqlExprBuilder filter) 5.692 - throws UnsupportedRdbmsOperatorException 5.693 - { 5.694 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Envelope); 5.695 - } 5.696 - 5.697 - @Override 5.698 - protected void append(GeneralDBSqlGeoConvexHull expr, GeneralDBSqlExprBuilder filter) 5.699 - throws UnsupportedRdbmsOperatorException 5.700 - { 5.701 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_ConvexHull); 5.702 - } 5.703 - 5.704 - @Override 5.705 - protected void append(GeneralDBSqlGeoBoundary expr, GeneralDBSqlExprBuilder filter) 5.706 - throws UnsupportedRdbmsOperatorException 5.707 - { 5.708 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Boundary); 5.709 - } 5.710 - 5.711 - @Override 5.712 - protected void append(GeneralDBSqlGeoIntersection expr, GeneralDBSqlExprBuilder filter) 5.713 - throws UnsupportedRdbmsOperatorException 5.714 - { 5.715 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersection); 5.716 - } 5.717 - 5.718 - @Override 5.719 - protected void append(GeneralDBSqlGeoDifference expr, GeneralDBSqlExprBuilder filter) 5.720 - throws UnsupportedRdbmsOperatorException 5.721 - { 5.722 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Difference); 5.723 - } 5.724 - 5.725 - @Override 5.726 - protected void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter) 5.727 - throws UnsupportedRdbmsOperatorException 5.728 - { 5.729 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference); 5.730 - } 5.731 - 5.732 - //Spatial Metric Functions 5.733 - @Override 5.734 - protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter) 5.735 - throws UnsupportedRdbmsOperatorException 5.736 - { 5.737 - appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Distance); 5.738 - } 5.739 - 5.740 - @Override 5.741 - protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter) 5.742 - throws UnsupportedRdbmsOperatorException 5.743 - { 5.744 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Area); 5.745 - } 5.746 - 5.747 - //Spatial Property Functions 5.748 - @Override 5.749 - protected void append(GeneralDBSqlGeoDimension expr, GeneralDBSqlExprBuilder filter) 5.750 - throws UnsupportedRdbmsOperatorException 5.751 - { 5.752 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Dimension); 5.753 - } 5.754 - 5.755 - @Override 5.756 - protected void append(GeneralDBSqlGeoGeometryType expr, GeneralDBSqlExprBuilder filter) 5.757 - throws UnsupportedRdbmsOperatorException 5.758 - { 5.759 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_GeometryType); 5.760 - } 5.761 - 5.762 - @Override 5.763 - protected void append(GeneralDBSqlGeoAsText expr, GeneralDBSqlExprBuilder filter) 5.764 - throws UnsupportedRdbmsOperatorException 5.765 - { 5.766 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsText); 5.767 - } 5.768 - 5.769 - @Override 5.770 - protected void append(GeneralDBSqlGeoAsGML expr, GeneralDBSqlExprBuilder filter) 5.771 - throws UnsupportedRdbmsOperatorException 5.772 - { 5.773 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsGML); 5.774 - } 5.775 - 5.776 - // @Override 5.777 - // protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter) 5.778 - // throws UnsupportedRdbmsOperatorException 5.779 - // { 5.780 - // appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID); 5.781 - // } 5.782 - 5.783 - /** 5.784 - * Special Case because I need to retrieve a single different column from geo_values when this function occurs 5.785 - * in the select clause 5.786 - */ 5.787 - @Override 5.788 - protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter) 5.789 - throws UnsupportedRdbmsOperatorException 5.790 - { 5.791 - boolean sridNeeded = true; 5.792 - filter.openBracket(); 5.793 - 5.794 - boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.795 - boolean check2 = false; 5.796 - if(expr.getArg() instanceof GeneralDBLabelColumn) 5.797 - { 5.798 - if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource()) 5.799 - { 5.800 - check2 = true; 5.801 - } 5.802 - } 5.803 - if(check1) 5.804 - { 5.805 - this.append((GeneralDBSqlNull)expr.getArg(), filter); 5.806 - 5.807 - } 5.808 - else if (check2) 5.809 - { 5.810 - appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 5.811 - } 5.812 - else 5.813 - { 5.814 - //XXX Incorporating SRID 5.815 - GeneralDBSqlExpr tmp = expr; 5.816 - if(tmp.getParentNode() == null) 5.817 - { 5.818 - String sridExpr; 5.819 - while(true) 5.820 - { 5.821 - GeneralDBSqlExpr child = null; 5.822 - 5.823 - if(tmp instanceof BinaryGeneralDBOperator) 5.824 - { 5.825 - child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 5.826 - } 5.827 - else if(tmp instanceof UnaryGeneralDBOperator) 5.828 - { 5.829 - child = ((UnaryGeneralDBOperator) tmp).getArg(); 5.830 - } 5.831 - else if(tmp instanceof GeneralDBStringValue) 5.832 - { 5.833 - //Constant!! 5.834 - sridNeeded = false; 5.835 - break; 5.836 - } 5.837 - 5.838 - tmp = child; 5.839 - if(tmp instanceof GeneralDBLabelColumn) 5.840 - { 5.841 - //Reached the innermost left var -> need to capture its SRID 5.842 - String alias; 5.843 - if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 5.844 - //Predicates used in triple patterns non-existent in db 5.845 - alias="NULL"; 5.846 - } 5.847 - else 5.848 - { 5.849 - //Reached the innermost left var -> need to capture its SRID 5.850 - alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 5.851 - alias=alias+".srid"; 5.852 - } 5.853 - sridExpr = alias; 5.854 - filter.append(sridExpr); 5.855 - filter.closeBracket(); 5.856 - return; 5.857 - //break; 5.858 - } 5.859 - else if(tmp instanceof GeneralDBStringValue) 5.860 - { 5.861 - //Constant!! 5.862 - sridNeeded = false; 5.863 - break; 5.864 - } 5.865 - 5.866 - } 5.867 - } 5.868 - 5.869 - if(sridNeeded) 5.870 - { 5.871 - filter.appendFunction("ST_SRID"); 5.872 - filter.openBracket(); 5.873 - if(expr.getArg() instanceof GeneralDBStringValue) 5.874 - { 5.875 - appendWKT(expr.getArg(),filter); 5.876 - } 5.877 - else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.878 - { 5.879 - appendConstructFunction(expr.getArg(), filter); 5.880 - } 5.881 - else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.882 - { 5.883 - appendConstructFunction(expr.getArg(), filter); 5.884 - } 5.885 - else if(expr.getArg() instanceof GeneralDBSqlCase) 5.886 - { 5.887 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult(); 5.888 - appendMBB(onlyLabel,filter); 5.889 - } 5.890 - else 5.891 - { 5.892 - appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 5.893 - } 5.894 - 5.895 - filter.closeBracket(); 5.896 - } 5.897 - else 5.898 - { 5.899 - //4326 by default - Software House additions 5.900 - filter.append("4326"); 5.901 - } 5.902 - } 5.903 - 5.904 - filter.closeBracket(); 5.905 - } 5.906 - 5.907 - @Override 5.908 - protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter) 5.909 - throws UnsupportedRdbmsOperatorException 5.910 - { 5.911 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsSimple); 5.912 - } 5.913 - 5.914 - @Override 5.915 - protected void append(GeneralDBSqlGeoIsEmpty expr, GeneralDBSqlExprBuilder filter) 5.916 - throws UnsupportedRdbmsOperatorException 5.917 - { 5.918 - appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty); 5.919 - } 5.920 - 5.921 - 5.922 - /** 5.923 - * 'helper' functions 5.924 - */ 5.925 - 5.926 - @Override 5.927 - protected String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter) 5.928 - { 5.929 - GeneralDBStringValue arg = (GeneralDBStringValue) expr; 5.930 - String raw = arg.getValue(); 5.931 - 5.932 - StrabonPolyhedron poly = null; 5.933 - try{ 5.934 - poly = new StrabonPolyhedron(raw); 5.935 - } catch (Exception e) { 5.936 - e.printStackTrace(); 5.937 - } 5.938 - 5.939 - filter.append(" ST_GeomFromText('"+poly.toWKT() +"',4326)"); 5.940 - 5.941 - return raw; 5.942 - } 5.943 - 5.944 - //Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 5.945 - // protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException 5.946 - // { 5.947 - // filter.openBracket(); 5.948 - // 5.949 - // boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.950 - // //boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.951 - // 5.952 - // if(check1a) 5.953 - // { 5.954 - // this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.955 - // 5.956 - // } 5.957 - //// else if(check2a) 5.958 - //// { 5.959 - //// this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.960 - //// } 5.961 - // else 5.962 - // { 5.963 - // if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.964 - // { 5.965 - // this.append((GeneralDBSqlCase)expr.getLeftArg(), filter); 5.966 - // } 5.967 - // else if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.968 - // { 5.969 - // appendWKT(expr.getLeftArg(),filter); 5.970 - // } 5.971 - // else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.972 - // { 5.973 - // appendConstructFunction(expr.getLeftArg(), filter); 5.974 - // } 5.975 - // else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.976 - // { 5.977 - // appendConstructFunction(expr.getLeftArg(), filter); 5.978 - // } 5.979 - // else 5.980 - // { 5.981 - // appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.982 - // } 5.983 - // 5.984 - // switch(operand) 5.985 - // { 5.986 - // case anyInteract: filter.anyInteract(); break; 5.987 - // case equals: filter.equals(); break; 5.988 - // case contains: filter.contains(); break; 5.989 - // case inside: filter.inside(); break; 5.990 - // case left: filter.left(); break; 5.991 - // case right: filter.right(); break; 5.992 - // case above: filter.above(); break; 5.993 - // case below: filter.below(); break; 5.994 - // } 5.995 - // 5.996 - // boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.997 - // 5.998 - // if(check2a) 5.999 - // { 5.1000 - // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1001 - // } 5.1002 - // else 5.1003 - // { 5.1004 - // 5.1005 - // if(expr.getRightArg() instanceof GeneralDBSqlCase) 5.1006 - // { 5.1007 - // this.append((GeneralDBSqlCase)expr.getRightArg(), filter); 5.1008 - // } 5.1009 - // else if(expr.getRightArg() instanceof GeneralDBStringValue) 5.1010 - // { 5.1011 - // appendWKT(expr.getRightArg(),filter); 5.1012 - // } 5.1013 - // else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1014 - // { 5.1015 - // appendConstructFunction(expr.getRightArg(), filter); 5.1016 - // } 5.1017 - // else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1018 - // { 5.1019 - // appendConstructFunction(expr.getRightArg(), filter); 5.1020 - // } 5.1021 - // else 5.1022 - // { 5.1023 - // appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.1024 - // } 5.1025 - // 5.1026 - // } 5.1027 - // } 5.1028 - // filter.closeBracket(); 5.1029 - // } 5.1030 - 5.1031 - 5.1032 - protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException 5.1033 - { 5.1034 - filter.openBracket(); 5.1035 - 5.1036 - boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1037 - boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1038 - 5.1039 - if(check1a) 5.1040 - { 5.1041 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1042 - 5.1043 - } 5.1044 - else if(check2a) 5.1045 - { 5.1046 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1047 - } 5.1048 - else 5.1049 - { 5.1050 - if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.1051 - { 5.1052 - this.append((GeneralDBSqlCase)expr.getLeftArg(), filter); 5.1053 - } 5.1054 - else if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.1055 - { 5.1056 - appendWKT(expr.getLeftArg(),filter); 5.1057 - } 5.1058 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1059 - { 5.1060 - appendConstructFunction(expr.getLeftArg(), filter); 5.1061 - } 5.1062 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1063 - { 5.1064 - appendConstructFunction(expr.getLeftArg(), filter); 5.1065 - } 5.1066 - else 5.1067 - { 5.1068 - appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.1069 - } 5.1070 - 5.1071 - switch(operand) 5.1072 - { 5.1073 - case anyInteract: filter.intersectsMBB(); break; 5.1074 - case equals: filter.equalsMBB(); break; 5.1075 - case contains: filter.containsMBB(); break; 5.1076 - case inside: filter.insideMBB(); break; 5.1077 - case left: filter.leftMBB(); break; 5.1078 - case right: filter.rightMBB(); break; 5.1079 - case above: filter.aboveMBB(); break; 5.1080 - case below: filter.belowMBB(); break; 5.1081 - } 5.1082 - 5.1083 - // boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1084 - // 5.1085 - // if(check2a) 5.1086 - // { 5.1087 - // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1088 - // } 5.1089 - // else 5.1090 - // { 5.1091 - 5.1092 - if(expr.getRightArg() instanceof GeneralDBSqlCase) 5.1093 - { 5.1094 - this.append((GeneralDBSqlCase)expr.getRightArg(), filter); 5.1095 - } 5.1096 - else if(expr.getRightArg() instanceof GeneralDBStringValue) 5.1097 - { 5.1098 - appendWKT(expr.getRightArg(),filter); 5.1099 - } 5.1100 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1101 - { 5.1102 - appendConstructFunction(expr.getRightArg(), filter); 5.1103 - } 5.1104 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1105 - { 5.1106 - appendConstructFunction(expr.getRightArg(), filter); 5.1107 - } 5.1108 - else 5.1109 - { 5.1110 - appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.1111 - } 5.1112 - 5.1113 - //} 5.1114 - } 5.1115 - filter.closeBracket(); 5.1116 - } 5.1117 - 5.1118 - //Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 5.1119 - protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter) 5.1120 - throws UnsupportedRdbmsOperatorException 5.1121 - { 5.1122 - //In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))") 5.1123 - boolean sridNeeded = true; 5.1124 - //XXX Incorporating SRID 5.1125 - String sridExpr = null; 5.1126 - 5.1127 - filter.openBracket(); 5.1128 - filter.appendFunction(ST_TRANSFORM); 5.1129 - filter.openBracket(); 5.1130 - 5.1131 - boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1132 - boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1133 - 5.1134 - if(check1) 5.1135 - { 5.1136 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1137 - 5.1138 - } 5.1139 - else if(check2) 5.1140 - { 5.1141 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1142 - } 5.1143 - else 5.1144 - { 5.1145 - GeneralDBSqlExpr tmp = expr; 5.1146 - if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null) 5.1147 - { 5.1148 - while(true) 5.1149 - { 5.1150 - GeneralDBSqlExpr child; 5.1151 - 5.1152 - if(tmp instanceof BinaryGeneralDBOperator) 5.1153 - { 5.1154 - child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 5.1155 - } 5.1156 - else //(tmp instanceof UnaryGeneralDBOperator) 5.1157 - { 5.1158 - child = ((UnaryGeneralDBOperator) tmp).getArg(); 5.1159 - } 5.1160 - 5.1161 - tmp = child; 5.1162 - if(tmp instanceof GeneralDBLabelColumn) 5.1163 - { 5.1164 - String alias; 5.1165 - if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 5.1166 - //Predicates used in triple patterns non-existent in db 5.1167 - alias="NULL"; 5.1168 - } 5.1169 - else 5.1170 - { 5.1171 - //Reached the innermost left var -> need to capture its SRID 5.1172 - alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 5.1173 - alias=alias+".srid"; 5.1174 - } 5.1175 - sridExpr = alias; 5.1176 - break; 5.1177 - } 5.1178 - else if (tmp instanceof GeneralDBStringValue) //Constant!! 5.1179 - { 5.1180 - sridNeeded = false; 5.1181 - break; 5.1182 - } 5.1183 - 5.1184 - } 5.1185 - if(sridNeeded) 5.1186 - { 5.1187 - filter.appendFunction(ST_TRANSFORM); 5.1188 - filter.openBracket(); 5.1189 - } 5.1190 - } 5.1191 - 5.1192 - if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.1193 - { 5.1194 - appendWKT(expr.getLeftArg(),filter); 5.1195 - } 5.1196 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1197 - { 5.1198 - appendConstructFunction(expr.getLeftArg(), filter); 5.1199 - } 5.1200 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1201 - { 5.1202 - appendConstructFunction(expr.getLeftArg(), filter); 5.1203 - } 5.1204 - else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.1205 - { 5.1206 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 5.1207 - appendMBB(onlyLabel,filter); 5.1208 - } 5.1209 - else 5.1210 - { 5.1211 - appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.1212 - } 5.1213 - 5.1214 - //SRID Support 5.1215 - if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 5.1216 - { 5.1217 - filter.appendComma(); 5.1218 - //filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid()); 5.1219 - filter.append(sridExpr); 5.1220 - filter.closeBracket(); 5.1221 - } 5.1222 - 5.1223 - filter.appendComma(); 5.1224 - 5.1225 - if(expr.getRightArg() instanceof GeneralDBSqlCase) //case met in transform! 5.1226 - { 5.1227 - GeneralDBURIColumn plainURI = (GeneralDBURIColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 5.1228 - 5.1229 - //XXX This case would be met if we recovered the SRID URI from the db!!! 5.1230 - //Need to set sridExpr to the value of this new URI, otherwise the appended uri 5.1231 - //to the spatial object will be the wrong one!!!! (Seee following case) 5.1232 - filter.keepSRID_part1(); 5.1233 - append(plainURI, filter); 5.1234 - filter.keepSRID_part2(); 5.1235 - append(plainURI, filter); 5.1236 - filter.keepSRID_part3(); 5.1237 - } 5.1238 - else if(expr.getRightArg() instanceof GeneralDBStringValue) 5.1239 - { 5.1240 - String unparsedSRID = ((GeneralDBStringValue)expr.getRightArg()).getValue(); 5.1241 - // int srid = Integer.parseInt(unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1)); 5.1242 - sridExpr = unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1); 5.1243 - filter.append(sridExpr); 5.1244 - filter.closeBracket(); 5.1245 - } 5.1246 - 5.1247 - 5.1248 - } 5.1249 - filter.closeBracket(); 5.1250 - //In this case, SRID is the one that has been provided by the user!! 5.1251 - //I am including this extra binding to be used in subsequent (Aggregate) steps 5.1252 - if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 5.1253 - { 5.1254 - filter.appendComma(); 5.1255 - filter.append(sridExpr); 5.1256 - } 5.1257 - 5.1258 - } 5.1259 - 5.1260 - /** Addition for datetime metric functions 5.1261 - * 5.1262 - * @author George Garbis <ggarbis@di.uoa.gr> 5.1263 - * 5.1264 - */ 5.1265 - 5.1266 - protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionsPostGIS func) 5.1267 - throws UnsupportedRdbmsOperatorException 5.1268 - { 5.1269 - 5.1270 - filter.openBracket(); 5.1271 - 5.1272 - boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1273 - boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1274 - 5.1275 - if(check1) 5.1276 - { 5.1277 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1278 - 5.1279 - } 5.1280 - else if(check2) 5.1281 - { 5.1282 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1283 - } 5.1284 - else 5.1285 - { 5.1286 - switch (func){ 5.1287 - case Difference: 5.1288 - append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 5.1289 - filter.append(" - "); 5.1290 - append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 5.1291 - break; 5.1292 - } 5.1293 - 5.1294 - } 5.1295 - } 5.1296 - 5.1297 - // Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1, ?GEO2) 5.1298 - // EXCEPT ST_Transform!!! 5.1299 - protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 5.1300 - throws UnsupportedRdbmsOperatorException 5.1301 - { 5.1302 - //In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))") 5.1303 - boolean sridNeeded = true; 5.1304 - String sridExpr = null; 5.1305 - 5.1306 - filter.openBracket(); 5.1307 - 5.1308 - boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1309 - boolean check2 = false; 5.1310 - if(expr.getArg() instanceof GeneralDBLabelColumn) 5.1311 - { 5.1312 - if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource()) 5.1313 - { 5.1314 - check2 = true; 5.1315 - } 5.1316 - } 5.1317 - if(check1) 5.1318 - { 5.1319 - this.append((GeneralDBSqlNull)expr.getArg(), filter); 5.1320 - 5.1321 - } 5.1322 - else if (check2) 5.1323 - { 5.1324 - appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 5.1325 - } 5.1326 - else 5.1327 - { 5.1328 - 5.1329 - GeneralDBSqlExpr tmp = expr; 5.1330 - 5.1331 - 5.1332 - if(tmp instanceof GeneralDBSqlSpatialConstructUnary && tmp.getParentNode() == null) 5.1333 - { 5.1334 - while(true) 5.1335 - { 5.1336 - GeneralDBSqlExpr child = null; 5.1337 - 5.1338 - if(tmp instanceof BinaryGeneralDBOperator) 5.1339 - { 5.1340 - child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 5.1341 - } 5.1342 - else if(tmp instanceof UnaryGeneralDBOperator) 5.1343 - { 5.1344 - child = ((UnaryGeneralDBOperator) tmp).getArg(); 5.1345 - } 5.1346 - else if(tmp instanceof GeneralDBStringValue) 5.1347 - { 5.1348 - sridNeeded = false; 5.1349 - break; 5.1350 - } 5.1351 - 5.1352 - tmp = child; 5.1353 - if(tmp instanceof GeneralDBLabelColumn) 5.1354 - { 5.1355 - //Reached the innermost left var -> need to capture its SRID 5.1356 - String alias; 5.1357 - if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 5.1358 - //Predicates used in triple patterns non-existent in db 5.1359 - alias="NULL"; 5.1360 - } 5.1361 - else 5.1362 - { 5.1363 - //Reached the innermost left var -> need to capture its SRID 5.1364 - alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 5.1365 - alias=alias+".srid"; 5.1366 - } 5.1367 - sridExpr = alias; 5.1368 - break; 5.1369 - } 5.1370 - else if (tmp instanceof GeneralDBStringValue) //Constant!! 5.1371 - { 5.1372 - sridNeeded = false; 5.1373 - break; 5.1374 - } 5.1375 - 5.1376 - } 5.1377 - if(sridNeeded) 5.1378 - { 5.1379 - filter.appendFunction(ST_TRANSFORM); 5.1380 - filter.openBracket(); 5.1381 - } 5.1382 - } 5.1383 - ///// 5.1384 - 5.1385 - switch(func) 5.1386 - { 5.1387 - case ST_Envelope: filter.appendFunction("ST_Envelope"); break; 5.1388 - case ST_ConvexHull: filter.appendFunction("ST_ConvexHull"); break; 5.1389 - case ST_Boundary: filter.appendFunction("ST_Boundary"); break; 5.1390 - case ST_Area: filter.appendFunction("ST_Area"); break; 5.1391 - case ST_Dimension: filter.appendFunction("ST_Dimension"); break; 5.1392 - case ST_GeometryType: filter.appendFunction("ST_GeometryType"); break; 5.1393 - case ST_AsText: filter.appendFunction("ST_AsText"); break; 5.1394 - case ST_AsGML: filter.appendFunction("ST_AsGML"); break; 5.1395 - case ST_SRID: filter.appendFunction("ST_SRID"); break; 5.1396 - case ST_IsEmpty: filter.appendFunction("ST_IsEmpty"); break; 5.1397 - case ST_IsSimple: filter.appendFunction("ST_IsSimple"); break; 5.1398 - } 5.1399 - filter.openBracket(); 5.1400 - if(expr.getArg() instanceof GeneralDBStringValue) 5.1401 - { 5.1402 - appendWKT(expr.getArg(),filter); 5.1403 - } 5.1404 - else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1405 - { 5.1406 - appendConstructFunction(expr.getArg(), filter); 5.1407 - } 5.1408 - else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1409 - { 5.1410 - appendConstructFunction(expr.getArg(), filter); 5.1411 - } 5.1412 - else if(expr.getArg() instanceof GeneralDBSqlCase) 5.1413 - { 5.1414 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult(); 5.1415 - appendMBB(onlyLabel,filter); 5.1416 - } 5.1417 - else 5.1418 - { 5.1419 - appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 5.1420 - } 5.1421 - 5.1422 - filter.closeBracket(); 5.1423 - // //SRID Support 5.1424 - if(sridNeeded) 5.1425 - { 5.1426 - if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null) 5.1427 - { 5.1428 - filter.appendComma(); 5.1429 - // filter.append(((GeneralDBSqlSpatialConstructUnary)expr).getSrid()); 5.1430 - filter.append(sridExpr); 5.1431 - filter.closeBracket(); 5.1432 - } 5.1433 - } 5.1434 - /// 5.1435 - } 5.1436 - 5.1437 - filter.closeBracket(); 5.1438 - //Used to explicitly include SRID 5.1439 - if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null) 5.1440 - { 5.1441 - filter.appendComma(); 5.1442 - filter.append(sridExpr); 5.1443 - } 5.1444 - } 5.1445 - 5.1446 - //Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 5.1447 - protected void appendGeneralDBSpatialFunctionTriple(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 5.1448 - throws UnsupportedRdbmsOperatorException 5.1449 - { 5.1450 - filter.openBracket(); 5.1451 - 5.1452 - boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1453 - boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1454 - boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1455 - 5.1456 - if(check1a) 5.1457 - { 5.1458 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1459 - 5.1460 - } 5.1461 - else if(check2a) 5.1462 - { 5.1463 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1464 - } 5.1465 - else if(check3) 5.1466 - { 5.1467 - this.append((GeneralDBSqlNull)expr.getThirdArg(), filter); 5.1468 - } 5.1469 - else 5.1470 - { 5.1471 - switch(func) 5.1472 - { 5.1473 - case ST_Relate: filter.appendFunction("ST_Relate"); break; 5.1474 - } 5.1475 - filter.openBracket(); 5.1476 - if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.1477 - { 5.1478 - appendWKT(expr.getLeftArg(),filter); 5.1479 - } 5.1480 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1481 - { 5.1482 - appendConstructFunction(expr.getLeftArg(), filter); 5.1483 - } 5.1484 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1485 - { 5.1486 - appendConstructFunction(expr.getLeftArg(), filter); 5.1487 - } 5.1488 - else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.1489 - { 5.1490 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 5.1491 - appendMBB(onlyLabel,filter); 5.1492 - } 5.1493 - else 5.1494 - { 5.1495 - appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.1496 - } 5.1497 - filter.appendComma(); 5.1498 - // boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1499 - // if(check2) 5.1500 - // { 5.1501 - // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1502 - // } 5.1503 - // else 5.1504 - // { 5.1505 - if(expr.getRightArg() instanceof GeneralDBStringValue) 5.1506 - { 5.1507 - appendWKT(expr.getRightArg(),filter); 5.1508 - } 5.1509 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1510 - { 5.1511 - appendConstructFunction(expr.getRightArg(), filter); 5.1512 - } 5.1513 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1514 - { 5.1515 - appendConstructFunction(expr.getRightArg(), filter); 5.1516 - } 5.1517 - else if(expr.getRightArg() instanceof GeneralDBSqlCase) 5.1518 - { 5.1519 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 5.1520 - appendMBB(onlyLabel,filter); 5.1521 - } 5.1522 - else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 5.1523 - { 5.1524 - append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 5.1525 - } 5.1526 - else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 5.1527 - { 5.1528 - append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 5.1529 - } 5.1530 - //case met in buffer when in select -> buffer(?spatial,?thematic) 5.1531 - else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 5.1532 - { 5.1533 - append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 5.1534 - appendCastToDouble(filter); 5.1535 - } 5.1536 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 5.1537 - { 5.1538 - appendMetricFunction(expr.getRightArg(), filter); 5.1539 - } 5.1540 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 5.1541 - { 5.1542 - appendMetricFunction(expr.getRightArg(), filter); 5.1543 - } 5.1544 - else 5.1545 - { 5.1546 - appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.1547 - } 5.1548 - 5.1549 - // } 5.1550 - //3rd arg 5.1551 - filter.appendComma(); 5.1552 - // boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1553 - // if(check3) 5.1554 - // { 5.1555 - // this.append((GeneralDBSqlNull)expr.getThirdArg(), filter); 5.1556 - // } 5.1557 - // else 5.1558 - // { 5.1559 - 5.1560 - if(expr.getThirdArg() instanceof GeneralDBStringValue) 5.1561 - { 5.1562 - append(((GeneralDBStringValue)expr.getThirdArg()),filter); 5.1563 - } 5.1564 - else if(expr.getThirdArg() instanceof GeneralDBSqlCase) 5.1565 - { 5.1566 - append(((GeneralDBSqlCase)expr.getThirdArg()),filter); 5.1567 - } 5.1568 - //case met in buffer when in select -> buffer(?spatial,?thematic) 5.1569 - else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial()) 5.1570 - { 5.1571 - 5.1572 - append(((GeneralDBLabelColumn)expr.getThirdArg()),filter); 5.1573 - } 5.1574 - 5.1575 - 5.1576 - // } 5.1577 - filter.closeBracket(); 5.1578 - } 5.1579 - 5.1580 - filter.closeBracket(); 5.1581 - } 5.1582 - 5.1583 - 5.1584 - //GeoSPARQL 5.1585 - //XXX 5.1586 - protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern) 5.1587 - throws UnsupportedRdbmsOperatorException 5.1588 - { 5.1589 - filter.openBracket(); 5.1590 - 5.1591 - boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1592 - boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1593 - 5.1594 - if(check1) 5.1595 - { 5.1596 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1597 - 5.1598 - } 5.1599 - else if(check2) 5.1600 - { 5.1601 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.1602 - } 5.1603 - else 5.1604 - { 5.1605 - filter.appendFunction("ST_Relate"); 5.1606 - 5.1607 - 5.1608 - filter.openBracket(); 5.1609 - if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.1610 - { 5.1611 - appendWKT(expr.getLeftArg(),filter); 5.1612 - } 5.1613 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1614 - { 5.1615 - appendConstructFunction(expr.getLeftArg(), filter); 5.1616 - } 5.1617 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1618 - { 5.1619 - appendConstructFunction(expr.getLeftArg(), filter); 5.1620 - } 5.1621 - else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.1622 - { 5.1623 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 5.1624 - appendMBB(onlyLabel,filter); 5.1625 - } 5.1626 - else 5.1627 - { 5.1628 - appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.1629 - } 5.1630 - filter.appendComma(); 5.1631 - 5.1632 - if(expr.getRightArg() instanceof GeneralDBStringValue) 5.1633 - { 5.1634 - appendWKT(expr.getRightArg(),filter); 5.1635 - } 5.1636 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.1637 - { 5.1638 - appendConstructFunction(expr.getRightArg(), filter); 5.1639 - } 5.1640 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.1641 - { 5.1642 - appendConstructFunction(expr.getRightArg(), filter); 5.1643 - } 5.1644 - else if(expr.getRightArg() instanceof GeneralDBSqlCase) 5.1645 - { 5.1646 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 5.1647 - appendMBB(onlyLabel,filter); 5.1648 - } 5.1649 - else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 5.1650 - { 5.1651 - append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 5.1652 - } 5.1653 - else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 5.1654 - { 5.1655 - append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 5.1656 - } 5.1657 - //case met in buffer when in select -> buffer(?spatial,?thematic) 5.1658 - else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 5.1659 - { 5.1660 - append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 5.1661 - appendCastToDouble(filter); 5.1662 - } 5.1663 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 5.1664 - { 5.1665 - appendMetricFunction(expr.getRightArg(), filter); 5.1666 - } 5.1667 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 5.1668 - { 5.1669 - appendMetricFunction(expr.getRightArg(), filter); 5.1670 - } 5.1671 - else 5.1672 - { 5.1673 - appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.1674 - } 5.1675 - 5.1676 - //3rd arg 5.1677 - filter.appendComma(); 5.1678 - 5.1679 - //must turn the table of characters I have to a valid sql value! 5.1680 - filter.append("'"); 5.1681 - for(int i = 0; i< intersectionPattern.length; i++) 5.1682 - { 5.1683 - filter.append(intersectionPattern[i]+""); 5.1684 - } 5.1685 - filter.append("'"); 5.1686 - 5.1687 - filter.closeBracket(); 5.1688 - 5.1689 - } 5.1690 - 5.1691 - filter.closeBracket(); 5.1692 - } 5.1693 - 5.1694 - 5.1695 - protected void appendgeoSPARQLSpatialRelation(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 5.1696 - throws UnsupportedRdbmsOperatorException 5.1697 - { 5.1698 - filter.openBracket(); 5.1699 - boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.1700 - if(check1) 5.1701 - { 5.1702 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.1703 - 5.1704 - } 5.1705 - else 5.1706 - { 5.1707 - char[][] intersectionPattern = null; 5.1708 - switch(func) 5.1709 - { 5.1710 - case ST_Covers: 5.1711 - intersectionPattern = new char[1][9]; 5.1712 - intersectionPattern[0][0] = 'T'; 5.1713 - intersectionPattern[0][1] = '*'; 5.1714 - intersectionPattern[0][2] = 'T'; 5.1715 - intersectionPattern[0][3] = 'F'; 5.1716 - intersectionPattern[0][4] = 'T'; 5.1717 - intersectionPattern[0][5] = '*'; 5.1718 - intersectionPattern[0][6] = 'F'; 5.1719 - intersectionPattern[0][7] = 'F'; 5.1720 - intersectionPattern[0][8] = '*'; 5.1721 - break; 5.1722 - case ST_CoveredBy: 5.1723 - intersectionPattern = new char[1][9]; 5.1724 - intersectionPattern[0][0] = 'T'; 5.1725 - intersectionPattern[0][1] = 'F'; 5.1726 - intersectionPattern[0][2] = 'F'; 5.1727 - intersectionPattern[0][3] = '*'; 5.1728 - intersectionPattern[0][4] = 'T'; 5.1729 - intersectionPattern[0][5] = 'F'; 5.1730 - intersectionPattern[0][6] = 'T'; 5.1731 - intersectionPattern[0][7] = '*'; 5.1732 - intersectionPattern[0][8] = '*'; 5.1733 - break; 5.1734 - case SF_Contains: 5.1735 - intersectionPattern = new char[1][9]; 5.1736 - intersectionPattern[0][0] = 'T'; 5.1737 - intersectionPattern[0][1] = '*'; 5.1738 - intersectionPattern[0][2] = '*'; 5.1739 - intersectionPattern[0][3] = '*'; 5.1740 - intersectionPattern[0][4] = '*'; 5.1741 - intersectionPattern[0][5] = '*'; 5.1742 - intersectionPattern[0][6] = 'F'; 5.1743 - intersectionPattern[0][7] = 'F'; 5.1744 - intersectionPattern[0][8] = '*'; 5.1745 - break; 5.1746 - case SF_Crosses: 5.1747 - intersectionPattern = new char[1][9]; 5.1748 - intersectionPattern[0][0] = 'T'; 5.1749 - intersectionPattern[0][1] = '*'; 5.1750 - intersectionPattern[0][2] = 'T'; 5.1751 - intersectionPattern[0][3] = '*'; 5.1752 - intersectionPattern[0][4] = '*'; 5.1753 - intersectionPattern[0][5] = '*'; 5.1754 - intersectionPattern[0][6] = '*'; 5.1755 - intersectionPattern[0][7] = '*'; 5.1756 - intersectionPattern[0][8] = '*'; 5.1757 - break; 5.1758 - case SF_Disjoint: 5.1759 - case EH_Disjoint: 5.1760 - intersectionPattern = new char[1][9]; 5.1761 - intersectionPattern[0][0] = 'F'; 5.1762 - intersectionPattern[0][1] = 'F'; 5.1763 - intersectionPattern[0][2] = '*'; 5.1764 - intersectionPattern[0][3] = 'F'; 5.1765 - intersectionPattern[0][4] = 'F'; 5.1766 - intersectionPattern[0][5] = '*'; 5.1767 - intersectionPattern[0][6] = '*'; 5.1768 - intersectionPattern[0][7] = '*'; 5.1769 - intersectionPattern[0][8] = '*'; 5.1770 - break; 5.1771 - case SF_Equals: 5.1772 - case EH_Equals: 5.1773 - case RCC8_Eq: 5.1774 - intersectionPattern = new char[1][9]; 5.1775 - intersectionPattern[0][0] = 'T'; 5.1776 - intersectionPattern[0][1] = 'F'; 5.1777 - intersectionPattern[0][2] = 'F'; 5.1778 - intersectionPattern[0][3] = 'F'; 5.1779 - intersectionPattern[0][4] = 'T'; 5.1780 - intersectionPattern[0][5] = 'F'; 5.1781 - intersectionPattern[0][6] = 'F'; 5.1782 - intersectionPattern[0][7] = 'F'; 5.1783 - intersectionPattern[0][8] = 'T'; 5.1784 - break; 5.1785 - case SF_Overlaps: 5.1786 - case EH_Overlap: 5.1787 - intersectionPattern = new char[1][9]; 5.1788 - intersectionPattern[0][0] = 'T'; 5.1789 - intersectionPattern[0][1] = '*'; 5.1790 - intersectionPattern[0][2] = 'T'; 5.1791 - intersectionPattern[0][3] = '*'; 5.1792 - intersectionPattern[0][4] = '*'; 5.1793 - intersectionPattern[0][5] = '*'; 5.1794 - intersectionPattern[0][6] = 'T'; 5.1795 - intersectionPattern[0][7] = '*'; 5.1796 - intersectionPattern[0][8] = '*'; 5.1797 - break; 5.1798 - case SF_Within: 5.1799 - intersectionPattern = new char[1][9]; 5.1800 - intersectionPattern[0][0] = 'T'; 5.1801 - intersectionPattern[0][1] = '*'; 5.1802 - intersectionPattern[0][2] = 'F'; 5.1803 - intersectionPattern[0][3] = '*'; 5.1804 - intersectionPattern[0][4] = '*'; 5.1805 - intersectionPattern[0][5] = 'F'; 5.1806 - intersectionPattern[0][6] = '*'; 5.1807 - intersectionPattern[0][7] = '*'; 5.1808 - intersectionPattern[0][8] = '*'; 5.1809 - break; 5.1810 - case EH_Covers: 5.1811 - intersectionPattern = new char[1][9]; 5.1812 - intersectionPattern[0][0] = 'T'; 5.1813 - intersectionPattern[0][1] = '*'; 5.1814 - intersectionPattern[0][2] = 'T'; 5.1815 - intersectionPattern[0][3] = 'F'; 5.1816 - intersectionPattern[0][4] = 'T'; 5.1817 - intersectionPattern[0][5] = '*'; 5.1818 - intersectionPattern[0][6] = 'F'; 5.1819 - intersectionPattern[0][7] = 'F'; 5.1820 - intersectionPattern[0][8] = '*'; 5.1821 - break; 5.1822 - case EH_CoveredBy: 5.1823 - intersectionPattern = new char[1][9]; 5.1824 - intersectionPattern[0][0] = 'T'; 5.1825 - intersectionPattern[0][1] = 'F'; 5.1826 - intersectionPattern[0][2] = 'F'; 5.1827 - intersectionPattern[0][3] = '*'; 5.1828 - intersectionPattern[0][4] = 'T'; 5.1829 - intersectionPattern[0][5] = 'F'; 5.1830 - intersectionPattern[0][6] = 'T'; 5.1831 - intersectionPattern[0][7] = '*'; 5.1832 - intersectionPattern[0][8] = '*'; 5.1833 - break; 5.1834 - case EH_Inside: 5.1835 - intersectionPattern = new char[1][9]; 5.1836 - intersectionPattern[0][0] = 'T'; 5.1837 - intersectionPattern[0][1] = 'F'; 5.1838 - intersectionPattern[0][2] = 'F'; 5.1839 - intersectionPattern[0][3] = '*'; 5.1840 - intersectionPattern[0][4] = 'F'; 5.1841 - intersectionPattern[0][5] = 'F'; 5.1842 - intersectionPattern[0][6] = 'T'; 5.1843 - intersectionPattern[0][7] = '*'; 5.1844 - intersectionPattern[0][8] = '*'; 5.1845 - break; 5.1846 - case EH_Contains: 5.1847 - intersectionPattern = new char[1][9]; 5.1848 - intersectionPattern[0][0] = 'T'; 5.1849 - intersectionPattern[0][1] = '*'; 5.1850 - intersectionPattern[0][2] = 'T'; 5.1851 - intersectionPattern[0][3] = 'F'; 5.1852 - intersectionPattern[0][4] = 'F'; 5.1853 - intersectionPattern[0][5] = '*'; 5.1854 - intersectionPattern[0][6] = 'F'; 5.1855 - intersectionPattern[0][7] = 'F'; 5.1856 - intersectionPattern[0][8] = '*'; 5.1857 - break; 5.1858 - case RCC8_Dc: 5.1859 - intersectionPattern = new char[1][9]; 5.1860 - intersectionPattern[0][0] = 'F'; 5.1861 - intersectionPattern[0][1] = 'F'; 5.1862 - intersectionPattern[0][2] = 'T'; 5.1863 - intersectionPattern[0][3] = 'F'; 5.1864 - intersectionPattern[0][4] = 'F'; 5.1865 - intersectionPattern[0][5] = 'T'; 5.1866 - intersectionPattern[0][6] = 'T'; 5.1867 - intersectionPattern[0][7] = 'T'; 5.1868 - intersectionPattern[0][8] = 'T'; 5.1869 - break; 5.1870 - case RCC8_Ec: 5.1871 - intersectionPattern = new char[1][9]; 5.1872 - intersectionPattern[0][0] = 'F'; 5.1873 - intersectionPattern[0][1] = 'F'; 5.1874 - intersectionPattern[0][2] = 'T'; 5.1875 - intersectionPattern[0][3] = 'F'; 5.1876 - intersectionPattern[0][4] = 'T'; 5.1877 - intersectionPattern[0][5] = 'T'; 5.1878 - intersectionPattern[0][6] = 'T'; 5.1879 - intersectionPattern[0][7] = 'T'; 5.1880 - intersectionPattern[0][8] = 'T'; 5.1881 - break; 5.1882 - case RCC8_Po: 5.1883 - intersectionPattern = new char[1][9]; 5.1884 - intersectionPattern[0][0] = 'T'; 5.1885 - intersectionPattern[0][1] = 'T'; 5.1886 - intersectionPattern[0][2] = 'T'; 5.1887 - intersectionPattern[0][3] = 'T'; 5.1888 - intersectionPattern[0][4] = 'T'; 5.1889 - intersectionPattern[0][5] = 'T'; 5.1890 - intersectionPattern[0][6] = 'T'; 5.1891 - intersectionPattern[0][7] = 'T'; 5.1892 - intersectionPattern[0][8] = 'T'; 5.1893 - break; 5.1894 - case RCC8_Tppi: 5.1895 - intersectionPattern = new char[1][9]; 5.1896 - intersectionPattern[0][0] = 'T'; 5.1897 - intersectionPattern[0][1] = 'T'; 5.1898 - intersectionPattern[0][2] = 'T'; 5.1899 - intersectionPattern[0][3] = 'F'; 5.1900 - intersectionPattern[0][4] = 'T'; 5.1901 - intersectionPattern[0][5] = 'T'; 5.1902 - intersectionPattern[0][6] = 'F'; 5.1903 - intersectionPattern[0][7] = 'F'; 5.1904 - intersectionPattern[0][8] = 'T'; 5.1905 - break; 5.1906 - case RCC8_Tpp: 5.1907 - intersectionPattern = new char[1][9]; 5.1908 - intersectionPattern[0][0] = 'T'; 5.1909 - intersectionPattern[0][1] = 'F'; 5.1910 - intersectionPattern[0][2] = 'F'; 5.1911 - intersectionPattern[0][3] = 'T'; 5.1912 - intersectionPattern[0][4] = 'T'; 5.1913 - intersectionPattern[0][5] = 'F'; 5.1914 - intersectionPattern[0][6] = 'T'; 5.1915 - intersectionPattern[0][7] = 'T'; 5.1916 - intersectionPattern[0][8] = 'T'; 5.1917 - break; 5.1918 - case RCC8_Ntpp: 5.1919 - intersectionPattern = new char[1][9]; 5.1920 - intersectionPattern[0][0] = 'T'; 5.1921 - intersectionPattern[0][1] = 'F'; 5.1922 - intersectionPattern[0][2] = 'F'; 5.1923 - intersectionPattern[0][3] = 'T'; 5.1924 - intersectionPattern[0][4] = 'F'; 5.1925 - intersectionPattern[0][5] = 'F'; 5.1926 - intersectionPattern[0][6] = 'T'; 5.1927 - intersectionPattern[0][7] = 'T'; 5.1928 - intersectionPattern[0][8] = 'T'; 5.1929 - break; 5.1930 - case RCC8_Ntppi: 5.1931 - intersectionPattern = new char[1][9]; 5.1932 - intersectionPattern[0][0] = 'T'; 5.1933 - intersectionPattern[0][1] = 'T'; 5.1934 - intersectionPattern[0][2] = 'T'; 5.1935 - intersectionPattern[0][3] = 'F'; 5.1936 - intersectionPattern[0][4] = 'F'; 5.1937 - intersectionPattern[0][5] = 'T'; 5.1938 - intersectionPattern[0][6] = 'F'; 5.1939 - intersectionPattern[0][7] = 'F'; 5.1940 - intersectionPattern[0][8] = 'T'; 5.1941 - break; 5.1942 - case SF_Intersects: 5.1943 - intersectionPattern = new char[4][9]; 5.1944 - intersectionPattern[0][0] = 'T'; 5.1945 - intersectionPattern[0][1] = '*'; 5.1946 - intersectionPattern[0][2] = '*'; 5.1947 - intersectionPattern[0][3] = '*'; 5.1948 - intersectionPattern[0][4] = '*'; 5.1949 - intersectionPattern[0][5] = '*'; 5.1950 - intersectionPattern[0][6] = '*'; 5.1951 - intersectionPattern[0][7] = '*'; 5.1952 - intersectionPattern[0][8] = '*'; 5.1953 - // 5.1954 - intersectionPattern[1][0] = '*'; 5.1955 - intersectionPattern[1][1] = 'T'; 5.1956 - intersectionPattern[1][2] = '*'; 5.1957 - intersectionPattern[1][3] = '*'; 5.1958 - intersectionPattern[1][4] = '*'; 5.1959 - intersectionPattern[1][5] = '*'; 5.1960 - intersectionPattern[1][6] = '*'; 5.1961 - intersectionPattern[1][7] = '*'; 5.1962 - intersectionPattern[1][8] = '*'; 5.1963 - // 5.1964 - intersectionPattern[2][0] = '*'; 5.1965 - intersectionPattern[2][1] = '*'; 5.1966 - intersectionPattern[2][2] = '*'; 5.1967 - intersectionPattern[2][3] = 'T'; 5.1968 - intersectionPattern[2][4] = '*'; 5.1969 - intersectionPattern[2][5] = '*'; 5.1970 - intersectionPattern[2][6] = '*'; 5.1971 - intersectionPattern[2][7] = '*'; 5.1972 - intersectionPattern[2][8] = '*'; 5.1973 - // 5.1974 - intersectionPattern[3][0] = '*'; 5.1975 - intersectionPattern[3][1] = '*'; 5.1976 - intersectionPattern[3][2] = '*'; 5.1977 - intersectionPattern[3][3] = '*'; 5.1978 - intersectionPattern[3][4] = 'T'; 5.1979 - intersectionPattern[3][5] = '*'; 5.1980 - intersectionPattern[3][6] = '*'; 5.1981 - intersectionPattern[3][7] = '*'; 5.1982 - intersectionPattern[3][8] = '*'; 5.1983 - break; 5.1984 - 5.1985 - case SF_Touches: 5.1986 - case EH_Meet: 5.1987 - intersectionPattern = new char[3][9]; 5.1988 - intersectionPattern[0][0] = 'F'; 5.1989 - intersectionPattern[0][1] = 'T'; 5.1990 - intersectionPattern[0][2] = '*'; 5.1991 - intersectionPattern[0][3] = '*'; 5.1992 - intersectionPattern[0][4] = '*'; 5.1993 - intersectionPattern[0][5] = '*'; 5.1994 - intersectionPattern[0][6] = '*'; 5.1995 - intersectionPattern[0][7] = '*'; 5.1996 - intersectionPattern[0][8] = '*'; 5.1997 - // 5.1998 - intersectionPattern[1][0] = 'F'; 5.1999 - intersectionPattern[1][1] = '*'; 5.2000 - intersectionPattern[1][2] = '*'; 5.2001 - intersectionPattern[1][3] = 'T'; 5.2002 - intersectionPattern[1][4] = '*'; 5.2003 - intersectionPattern[1][5] = '*'; 5.2004 - intersectionPattern[1][6] = '*'; 5.2005 - intersectionPattern[1][7] = '*'; 5.2006 - intersectionPattern[1][8] = '*'; 5.2007 - // 5.2008 - intersectionPattern[2][0] = 'F'; 5.2009 - intersectionPattern[2][1] = '*'; 5.2010 - intersectionPattern[2][2] = '*'; 5.2011 - intersectionPattern[2][3] = '*'; 5.2012 - intersectionPattern[2][4] = 'T'; 5.2013 - intersectionPattern[2][5] = '*'; 5.2014 - intersectionPattern[2][6] = '*'; 5.2015 - intersectionPattern[2][7] = '*'; 5.2016 - intersectionPattern[2][8] = '*'; 5.2017 - // 5.2018 - 5.2019 - } 5.2020 - 5.2021 - for(int i = 0; i < intersectionPattern.length ; i++) 5.2022 - { 5.2023 - appendRelate(expr, filter, intersectionPattern[i]); 5.2024 - if(i < intersectionPattern.length - 1) 5.2025 - { 5.2026 - //append OR and continue 5.2027 - filter.or(); 5.2028 - } 5.2029 - } 5.2030 - 5.2031 - //Also need bounding box intersection query to enable the usage of the Gist R-tree index 5.2032 - if(func != SpatialFunctionsPostGIS.SF_Disjoint && func != SpatialFunctionsPostGIS.EH_Disjoint && func != SpatialFunctionsPostGIS.RCC8_Dc) 5.2033 - { 5.2034 - filter.and(); 5.2035 - appendGeneralDBSpatialFunctionBinary(expr, filter,SpatialFunctionsPostGIS.ST_Intersects); 5.2036 - } 5.2037 - } 5.2038 - filter.closeBracket(); 5.2039 - } 5.2040 - 5.2041 - @Override 5.2042 - //GeoSPARQL 5.2043 - //XXX 5.2044 - 5.2045 - protected void appendRelate(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, char[] intersectionPattern) 5.2046 - throws UnsupportedRdbmsOperatorException 5.2047 - { 5.2048 - filter.openBracket(); 5.2049 - System.out.println(expr.getLeftArg().getClass().getCanonicalName()); 5.2050 - boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.2051 - if(check1) 5.2052 - { 5.2053 - this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 5.2054 - 5.2055 - } 5.2056 - else 5.2057 - { 5.2058 - filter.appendFunction("ST_Relate"); 5.2059 - 5.2060 - 5.2061 - filter.openBracket(); 5.2062 - if(expr.getLeftArg() instanceof GeneralDBStringValue) 5.2063 - { 5.2064 - appendWKT(expr.getLeftArg(),filter); 5.2065 - } 5.2066 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.2067 - { 5.2068 - appendConstructFunction(expr.getLeftArg(), filter); 5.2069 - } 5.2070 - else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.2071 - { 5.2072 - appendConstructFunction(expr.getLeftArg(), filter); 5.2073 - } 5.2074 - else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 5.2075 - { 5.2076 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 5.2077 - appendMBB(onlyLabel,filter); 5.2078 - } 5.2079 - else 5.2080 - { 5.2081 - appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 5.2082 - } 5.2083 - filter.appendComma(); 5.2084 - boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 5.2085 - if(check2) 5.2086 - { 5.2087 - this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 5.2088 - } 5.2089 - else 5.2090 - { 5.2091 - if(expr.getRightArg() instanceof GeneralDBStringValue) 5.2092 - { 5.2093 - appendWKT(expr.getRightArg(),filter); 5.2094 - } 5.2095 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 5.2096 - { 5.2097 - appendConstructFunction(expr.getRightArg(), filter); 5.2098 - } 5.2099 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 5.2100 - { 5.2101 - appendConstructFunction(expr.getRightArg(), filter); 5.2102 - } 5.2103 - else if(expr.getRightArg() instanceof GeneralDBSqlCase) 5.2104 - { 5.2105 - GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 5.2106 - appendMBB(onlyLabel,filter); 5.2107 - } 5.2108 - else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 5.2109 - { 5.2110 - append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 5.2111 - } 5.2112 - else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 5.2113 - { 5.2114 - append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 5.2115 - } 5.2116 - //case met in buffer when in select -> buffer(?spatial,?thematic) 5.2117 - else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 5.2118 - { 5.2119 - append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 5.2120 - appendCastToDouble(filter); 5.2121 - } 5.2122 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 5.2123 - { 5.2124 - appendMetricFunction(expr.getRightArg(), filter); 5.2125 - } 5.2126 - else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 5.2127 - { 5.2128 - appendMetricFunction(expr.getRightArg(), filter); 5.2129 - } 5.2130 - else 5.2131 - { 5.2132 - appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 5.2133 - } 5.2134 - 5.2135 - } 5.2136 - //3rd arg 5.2137 - filter.appendComma(); 5.2138 - 5.2139 - //must turn the table of characters I have to a valid sql value! 5.2140 - filter.append("'"); 5.2141 - for(int i = 0; i< intersectionPattern.length; i++) 5.2142 - { 5.2143 - filter.append(intersectionPattern[i]+""); 5.2144 - } 5.2145 - filter.append("'"); 5.2146 - 5.2147 - filter.closeBracket(); 5.2148 - } 5.2149 - 5.2150 - filter.closeBracket(); 5.2151 - } 5.2152 - 5.2153 -}
6.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java Sat Jul 13 19:28:12 2013 +0300 6.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java Sat Jul 13 20:11:01 2013 +0300 6.3 @@ -9,14 +9,15 @@ 6.4 */ 6.5 package eu.earthobservatory.runtime.postgis; 6.6 6.7 +import static org.junit.Assert.assertNull; 6.8 + 6.9 import java.io.IOException; 6.10 import java.io.InputStream; 6.11 +import java.sql.Connection; 6.12 import java.sql.DriverManager; 6.13 import java.sql.PreparedStatement; 6.14 import java.sql.ResultSet; 6.15 import java.sql.SQLException; 6.16 -import java.sql.Statement; 6.17 -import java.sql.Connection; 6.18 import java.util.ArrayList; 6.19 import java.util.Properties; 6.20 6.21 @@ -26,13 +27,10 @@ 6.22 import org.openrdf.rio.RDFHandlerException; 6.23 import org.openrdf.rio.RDFParseException; 6.24 6.25 - 6.26 import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 6.27 import eu.earthobservatory.runtime.generaldb.SimpleTests; 6.28 import eu.earthobservatory.runtime.generaldb.Strabon; 6.29 6.30 -import static org.junit.Assert.assertNull; 6.31 - 6.32 /** 6.33 * A set of simple tests on SPARQL query functionality 6.34 *