Strabon

changeset 21:8b551eacb5d6

PostGISQueryBuilder
author Konstantina Mpereta <grad1110@di.uoa.gr>
date Mon Feb 20 18:04:00 2012 +0200 (2012-02-20)
parents 0e07f8eba6bc
children b11832da5ee5
files postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java
line diff
     1.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Mon Feb 20 14:10:52 2012 +0200
     1.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Mon Feb 20 18:04:00 2012 +0200
     1.3 @@ -167,7 +167,7 @@
     1.4  	public PostGISQueryBuilder() {
     1.5  		super();
     1.6  	}
     1.7 -	
     1.8 +
     1.9  	public PostGISQueryBuilder(GeneralDBSqlQueryBuilder builder) {
    1.10  		super(builder);
    1.11  		this.query = builder;
    1.12 @@ -177,7 +177,7 @@
    1.13  	protected void append(GeneralDBSqlNull expr, GeneralDBSqlExprBuilder filter) {
    1.14  		filter.appendNull();
    1.15  	}
    1.16 -	
    1.17 +
    1.18  	@Override
    1.19  	protected void append(GeneralDBSqlIsNull expr, GeneralDBSqlExprBuilder filter)
    1.20  	throws UnsupportedRdbmsOperatorException
    1.21 @@ -185,7 +185,7 @@
    1.22  		dispatch(expr.getArg(), filter);
    1.23  		filter.isNull();
    1.24  	}
    1.25 -	
    1.26 +
    1.27  	@Override
    1.28  	protected void append(GeneralDBSqlNot expr, GeneralDBSqlExprBuilder filter)
    1.29  	throws UnsupportedRdbmsOperatorException
    1.30 @@ -201,7 +201,7 @@
    1.31  			open.close();
    1.32  		}
    1.33  	}
    1.34 -	
    1.35 +
    1.36  	@Override
    1.37  	protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) {
    1.38  		if (var.getRdbmsVar().isResource()) {
    1.39 @@ -210,12 +210,20 @@
    1.40  		else {
    1.41  			if(var.isSpatial())
    1.42  			{
    1.43 -//				filter.appendFunction("ST_AsBinary");
    1.44 -				filter.appendFunction("ST_AsEWKB");
    1.45 +				filter.appendFunction("ST_AsBinary");
    1.46  				filter.openBracket();
    1.47 +				//XXX SRID
    1.48 +				filter.appendFunction("ST_Transform");
    1.49 +				filter.openBracket();
    1.50 +				//
    1.51  				String alias = getLabelAlias(var.getRdbmsVar());
    1.52  
    1.53  				filter.column(alias, "strdfgeo");
    1.54 +				//XXX SRID
    1.55 +				filter.appendComma();
    1.56 +				filter.column(alias, "srid");
    1.57 +				filter.closeBracket();
    1.58 +				//
    1.59  				filter.closeBracket();
    1.60  
    1.61  			}
    1.62 @@ -272,7 +280,7 @@
    1.63  		}
    1.64  		return query;
    1.65  	}
    1.66 -	
    1.67 +
    1.68  	//FIXME my addition from here on
    1.69  	@Override
    1.70  	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr)
    1.71 @@ -283,8 +291,7 @@
    1.72  				&&!(expr instanceof GeneralDBSqlMathExpr)
    1.73  				&&!(expr instanceof GeneralDBSqlSpatialProperty))
    1.74  		{
    1.75 -//			query.select().appendFunction("ST_AsBinary");
    1.76 -			query.select().appendFunction("ST_AsEWKB");
    1.77 +			query.select().appendFunction("ST_AsBinary");
    1.78  		}
    1.79  		else
    1.80  		{
    1.81 @@ -514,7 +521,7 @@
    1.82  	{
    1.83  		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Overlap);
    1.84  	}
    1.85 -	
    1.86 +
    1.87  	//RCC8
    1.88  	@Override
    1.89  	protected void append(GeneralDBSqlRCC8_Dc expr, GeneralDBSqlExprBuilder filter)
    1.90 @@ -666,11 +673,105 @@
    1.91  		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsText);
    1.92  	}
    1.93  
    1.94 +	//	@Override
    1.95 +	//	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
    1.96 +	//	throws UnsupportedRdbmsOperatorException
    1.97 +	//	{
    1.98 +	//		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID);
    1.99 +	//	}
   1.100 +
   1.101 +	/**
   1.102 +	 * Special Case because I need to retrieve a single different column from geo_values when this function occurs
   1.103 +	 * in the select clause
   1.104 +	 */
   1.105  	@Override
   1.106  	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
   1.107  	throws UnsupportedRdbmsOperatorException
   1.108  	{
   1.109 -		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID);
   1.110 +		filter.openBracket();
   1.111 +
   1.112 +		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.113 +		boolean check2 = false;
   1.114 +		if(expr.getArg() instanceof GeneralDBLabelColumn)
   1.115 +		{
   1.116 +			if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource())
   1.117 +			{
   1.118 +				check2 = true;
   1.119 +			}
   1.120 +		}
   1.121 +		if(check1)
   1.122 +		{
   1.123 +			this.append((GeneralDBSqlNull)expr.getArg(), filter);
   1.124 +
   1.125 +		}
   1.126 +		else if (check2)
   1.127 +		{
   1.128 +			appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
   1.129 +		}
   1.130 +		else
   1.131 +		{
   1.132 +			//XXX Incorporating SRID
   1.133 +			GeneralDBSqlExpr tmp = expr;
   1.134 +			if(tmp.getParentNode() == null)
   1.135 +			{
   1.136 +				String sridExpr;
   1.137 +				while(true)
   1.138 +				{
   1.139 +					GeneralDBSqlExpr child;
   1.140 +
   1.141 +					if(tmp instanceof BinaryGeneralDBOperator)
   1.142 +					{
   1.143 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
   1.144 +					}
   1.145 +					else //(tmp instanceof UnaryGeneralDBOperator)
   1.146 +					{
   1.147 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
   1.148 +					}
   1.149 +
   1.150 +					tmp = child;
   1.151 +					if(tmp instanceof GeneralDBLabelColumn)
   1.152 +					{
   1.153 +						//Reached the innermost left var -> need to capture its SRID
   1.154 +						String alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
   1.155 +						alias=alias+".srid";
   1.156 +						sridExpr = alias;
   1.157 +						filter.append(sridExpr);
   1.158 +						filter.closeBracket();
   1.159 +						return;
   1.160 +						//break;
   1.161 +					}
   1.162 +
   1.163 +				}
   1.164 +			}
   1.165 +
   1.166 +			filter.appendFunction("ST_SRID");
   1.167 +			filter.openBracket();
   1.168 +			if(expr.getArg() instanceof GeneralDBStringValue)
   1.169 +			{
   1.170 +				appendWKT(expr.getArg(),filter);
   1.171 +			}
   1.172 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.173 +			{
   1.174 +				appendConstructFunction(expr.getArg(), filter);
   1.175 +			}
   1.176 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.177 +			{
   1.178 +				appendConstructFunction(expr.getArg(), filter);
   1.179 +			}
   1.180 +			else if(expr.getArg() instanceof GeneralDBSqlCase)
   1.181 +			{
   1.182 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
   1.183 +				appendMBB(onlyLabel,filter); 
   1.184 +			}
   1.185 +			else
   1.186 +			{
   1.187 +				appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
   1.188 +			}
   1.189 +
   1.190 +			filter.closeBracket();
   1.191 +		}
   1.192 +
   1.193 +		filter.closeBracket();
   1.194  	}
   1.195  
   1.196  	@Override
   1.197 @@ -711,93 +812,93 @@
   1.198  	}
   1.199  
   1.200  	//Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 
   1.201 -//	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
   1.202 -//	{
   1.203 -//		filter.openBracket();
   1.204 -//
   1.205 -//		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.206 -//		//boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.207 -//
   1.208 -//		if(check1a)
   1.209 -//		{
   1.210 -//			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   1.211 -//
   1.212 -//		}
   1.213 -////		else if(check2a)
   1.214 -////		{
   1.215 -////			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.216 -////		}
   1.217 -//		else
   1.218 -//		{
   1.219 -//			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
   1.220 -//			{
   1.221 -//				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
   1.222 -//			}
   1.223 -//			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
   1.224 -//			{
   1.225 -//				appendWKT(expr.getLeftArg(),filter);
   1.226 -//			}
   1.227 -//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.228 -//			{
   1.229 -//				appendConstructFunction(expr.getLeftArg(), filter);
   1.230 -//			}
   1.231 -//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.232 -//			{
   1.233 -//				appendConstructFunction(expr.getLeftArg(), filter);
   1.234 -//			}
   1.235 -//			else
   1.236 -//			{
   1.237 -//				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   1.238 -//			}
   1.239 -//
   1.240 -//			switch(operand)
   1.241 -//			{
   1.242 -//			case anyInteract: filter.anyInteract(); break;
   1.243 -//			case equals: filter.equals(); break;
   1.244 -//			case contains: filter.contains(); break;
   1.245 -//			case inside: filter.inside(); break;
   1.246 -//			case left: filter.left(); break;
   1.247 -//			case right: filter.right(); break;
   1.248 -//			case above: filter.above(); break;
   1.249 -//			case below: filter.below(); break;
   1.250 -//			}
   1.251 -//
   1.252 -//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.253 -//
   1.254 -//			if(check2a)
   1.255 -//			{
   1.256 -//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.257 -//			}
   1.258 -//			else
   1.259 -//			{
   1.260 -//
   1.261 -//				if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.262 -//				{
   1.263 -//					this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
   1.264 -//				}
   1.265 -//				else if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.266 -//				{
   1.267 -//					appendWKT(expr.getRightArg(),filter);
   1.268 -//				}
   1.269 -//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.270 -//				{
   1.271 -//					appendConstructFunction(expr.getRightArg(), filter);
   1.272 -//				}
   1.273 -//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.274 -//				{
   1.275 -//					appendConstructFunction(expr.getRightArg(), filter);
   1.276 -//				}
   1.277 -//				else
   1.278 -//				{
   1.279 -//					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.280 -//				}
   1.281 -//
   1.282 -//			}
   1.283 -//		}
   1.284 -//		filter.closeBracket();
   1.285 -//	}
   1.286 +	//	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
   1.287 +	//	{
   1.288 +	//		filter.openBracket();
   1.289 +	//
   1.290 +	//		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.291 +	//		//boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.292 +	//
   1.293 +	//		if(check1a)
   1.294 +	//		{
   1.295 +	//			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   1.296 +	//
   1.297 +	//		}
   1.298 +	////		else if(check2a)
   1.299 +	////		{
   1.300 +	////			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.301 +	////		}
   1.302 +	//		else
   1.303 +	//		{
   1.304 +	//			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
   1.305 +	//			{
   1.306 +	//				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
   1.307 +	//			}
   1.308 +	//			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
   1.309 +	//			{
   1.310 +	//				appendWKT(expr.getLeftArg(),filter);
   1.311 +	//			}
   1.312 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.313 +	//			{
   1.314 +	//				appendConstructFunction(expr.getLeftArg(), filter);
   1.315 +	//			}
   1.316 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.317 +	//			{
   1.318 +	//				appendConstructFunction(expr.getLeftArg(), filter);
   1.319 +	//			}
   1.320 +	//			else
   1.321 +	//			{
   1.322 +	//				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   1.323 +	//			}
   1.324 +	//
   1.325 +	//			switch(operand)
   1.326 +	//			{
   1.327 +	//			case anyInteract: filter.anyInteract(); break;
   1.328 +	//			case equals: filter.equals(); break;
   1.329 +	//			case contains: filter.contains(); break;
   1.330 +	//			case inside: filter.inside(); break;
   1.331 +	//			case left: filter.left(); break;
   1.332 +	//			case right: filter.right(); break;
   1.333 +	//			case above: filter.above(); break;
   1.334 +	//			case below: filter.below(); break;
   1.335 +	//			}
   1.336 +	//
   1.337 +	//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.338 +	//
   1.339 +	//			if(check2a)
   1.340 +	//			{
   1.341 +	//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.342 +	//			}
   1.343 +	//			else
   1.344 +	//			{
   1.345 +	//
   1.346 +	//				if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.347 +	//				{
   1.348 +	//					this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
   1.349 +	//				}
   1.350 +	//				else if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.351 +	//				{
   1.352 +	//					appendWKT(expr.getRightArg(),filter);
   1.353 +	//				}
   1.354 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.355 +	//				{
   1.356 +	//					appendConstructFunction(expr.getRightArg(), filter);
   1.357 +	//				}
   1.358 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.359 +	//				{
   1.360 +	//					appendConstructFunction(expr.getRightArg(), filter);
   1.361 +	//				}
   1.362 +	//				else
   1.363 +	//				{
   1.364 +	//					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.365 +	//				}
   1.366 +	//
   1.367 +	//			}
   1.368 +	//		}
   1.369 +	//		filter.closeBracket();
   1.370 +	//	}
   1.371  
   1.372 -	
   1.373 +
   1.374  	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
   1.375  	{
   1.376  		filter.openBracket();
   1.377 @@ -849,41 +950,41 @@
   1.378  			case below: filter.below(); break;
   1.379  			}
   1.380  
   1.381 -//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.382 -//
   1.383 -//			if(check2a)
   1.384 -//			{
   1.385 -//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.386 -//			}
   1.387 -//			else
   1.388 -//			{
   1.389 +			//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.390 +			//
   1.391 +			//			if(check2a)
   1.392 +			//			{
   1.393 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.394 +			//			}
   1.395 +			//			else
   1.396 +			//			{
   1.397  
   1.398 -				if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.399 -				{
   1.400 -					this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
   1.401 -				}
   1.402 -				else if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.403 -				{
   1.404 -					appendWKT(expr.getRightArg(),filter);
   1.405 -				}
   1.406 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.407 -				{
   1.408 -					appendConstructFunction(expr.getRightArg(), filter);
   1.409 -				}
   1.410 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.411 -				{
   1.412 -					appendConstructFunction(expr.getRightArg(), filter);
   1.413 -				}
   1.414 -				else
   1.415 -				{
   1.416 -					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.417 -				}
   1.418 +			if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.419 +			{
   1.420 +				this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
   1.421 +			}
   1.422 +			else if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.423 +			{
   1.424 +				appendWKT(expr.getRightArg(),filter);
   1.425 +			}
   1.426 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.427 +			{
   1.428 +				appendConstructFunction(expr.getRightArg(), filter);
   1.429 +			}
   1.430 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.431 +			{
   1.432 +				appendConstructFunction(expr.getRightArg(), filter);
   1.433 +			}
   1.434 +			else
   1.435 +			{
   1.436 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.437 +			}
   1.438  
   1.439  			//}
   1.440  		}
   1.441  		filter.closeBracket();
   1.442  	}
   1.443 -//	
   1.444 +	//	
   1.445  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
   1.446  	protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
   1.447  	throws UnsupportedRdbmsOperatorException
   1.448 @@ -892,7 +993,7 @@
   1.449  
   1.450  		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.451  		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.452 -		
   1.453 +
   1.454  		if(check1)
   1.455  		{
   1.456  			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   1.457 @@ -904,6 +1005,43 @@
   1.458  		}
   1.459  		else
   1.460  		{
   1.461 +			//XXX Incorporating SRID
   1.462 +			String sridExpr = null;
   1.463 +			GeneralDBSqlExpr tmp = expr;
   1.464 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
   1.465 +			{
   1.466 +				while(true)
   1.467 +				{
   1.468 +					GeneralDBSqlExpr child;
   1.469 +
   1.470 +					if(tmp instanceof BinaryGeneralDBOperator)
   1.471 +					{
   1.472 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
   1.473 +					}
   1.474 +					else //(tmp instanceof UnaryGeneralDBOperator)
   1.475 +					{
   1.476 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
   1.477 +					}
   1.478 +
   1.479 +					tmp = child;
   1.480 +					if(tmp instanceof GeneralDBLabelColumn)
   1.481 +					{
   1.482 +						//Reached the innermost left var -> need to capture its SRID
   1.483 +						String alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
   1.484 +						alias=alias+".srid";
   1.485 +						sridExpr = alias;
   1.486 +//						((GeneralDBSqlSpatialConstructBinary)expr).setSrid(alias);
   1.487 +						break;
   1.488 +					}
   1.489 +
   1.490 +				}
   1.491 +				filter.appendFunction("ST_Transform");
   1.492 +				filter.openBracket();
   1.493 +			}
   1.494 +			/////
   1.495 +
   1.496 +
   1.497 +
   1.498  			switch(func)
   1.499  			{
   1.500  			case ST_Difference: filter.appendFunction("ST_Difference"); break;
   1.501 @@ -918,7 +1056,6 @@
   1.502  			case ST_CoveredBy: filter.appendFunction("ST_CoveredBy"); break;
   1.503  			case ST_Overlaps: filter.appendFunction("ST_Overlaps"); break;
   1.504  			}
   1.505 -			//filter.appendFunction("ST_Union");
   1.506  			filter.openBracket();
   1.507  			if(expr.getLeftArg() instanceof GeneralDBStringValue)
   1.508  			{
   1.509 @@ -942,57 +1079,65 @@
   1.510  				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   1.511  			}
   1.512  			filter.appendComma();
   1.513 -			
   1.514 -			
   1.515 -				if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.516 -				{
   1.517 -					appendWKT(expr.getRightArg(),filter);
   1.518 -				}
   1.519 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.520 -				{
   1.521 -					appendConstructFunction(expr.getRightArg(), filter);
   1.522 -				}
   1.523 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.524 -				{
   1.525 -					appendConstructFunction(expr.getRightArg(), filter);
   1.526 -				}
   1.527 -				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.528 -				{
   1.529 -					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.530 -					appendMBB(onlyLabel,filter);					 
   1.531 -				}
   1.532 -				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.533 -				{
   1.534 -					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.535 -				}
   1.536 -				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.537 -				{
   1.538 -					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.539 -				}
   1.540 -				//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.541 -				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.542 -				{
   1.543 -					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.544 -					appendCastToDouble(filter);
   1.545 -				}
   1.546 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.547 -				{
   1.548 -					appendMetricFunction(expr.getRightArg(), filter);
   1.549 -				}
   1.550 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.551 -				{
   1.552 -					appendMetricFunction(expr.getRightArg(), filter);
   1.553 -				}
   1.554 -				else
   1.555 -				{
   1.556 -					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.557 -				}
   1.558  
   1.559 -			
   1.560 +
   1.561 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.562 +			{
   1.563 +				appendWKT(expr.getRightArg(),filter);
   1.564 +			}
   1.565 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.566 +			{
   1.567 +				appendConstructFunction(expr.getRightArg(), filter);
   1.568 +			}
   1.569 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.570 +			{
   1.571 +				appendConstructFunction(expr.getRightArg(), filter);
   1.572 +			}
   1.573 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.574 +			{
   1.575 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.576 +				appendMBB(onlyLabel,filter);					 
   1.577 +			}
   1.578 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.579 +			{
   1.580 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.581 +			}
   1.582 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.583 +			{
   1.584 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.585 +			}
   1.586 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.587 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.588 +			{
   1.589 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.590 +				appendCastToDouble(filter);
   1.591 +			}
   1.592 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.593 +			{
   1.594 +				appendMetricFunction(expr.getRightArg(), filter);
   1.595 +			}
   1.596 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.597 +			{
   1.598 +				appendMetricFunction(expr.getRightArg(), filter);
   1.599 +			}
   1.600 +			else
   1.601 +			{
   1.602 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.603 +			}
   1.604 +
   1.605 +
   1.606  			filter.closeBracket();
   1.607 +			//SRID Support
   1.608 +			if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
   1.609 +			{
   1.610 +				filter.appendComma();
   1.611 +				//filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid());
   1.612 +				filter.append(sridExpr);
   1.613 +				filter.closeBracket();
   1.614  			}
   1.615 +			///
   1.616 +		}
   1.617  		//}
   1.618 -
   1.619  		filter.closeBracket();
   1.620  	}
   1.621  
   1.622 @@ -1022,6 +1167,41 @@
   1.623  		}
   1.624  		else
   1.625  		{
   1.626 +			//XXX Incorporating SRID
   1.627 +			String sridExpr = null;
   1.628 +			GeneralDBSqlExpr tmp = expr;
   1.629 +			if(tmp instanceof GeneralDBSqlSpatialConstructUnary && tmp.getParentNode() == null)
   1.630 +			{
   1.631 +				while(true)
   1.632 +				{
   1.633 +					GeneralDBSqlExpr child;
   1.634 +
   1.635 +					if(tmp instanceof BinaryGeneralDBOperator)
   1.636 +					{
   1.637 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
   1.638 +					}
   1.639 +					else //(tmp instanceof UnaryGeneralDBOperator)
   1.640 +					{
   1.641 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
   1.642 +					}
   1.643 +
   1.644 +					tmp = child;
   1.645 +					if(tmp instanceof GeneralDBLabelColumn)
   1.646 +					{
   1.647 +						//Reached the innermost left var -> need to capture its SRID
   1.648 +						String alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
   1.649 +						alias=alias+".srid";
   1.650 +//						((GeneralDBSqlSpatialConstructUnary)expr).setSrid(alias);
   1.651 +						sridExpr = alias;
   1.652 +						break;
   1.653 +					}
   1.654 +
   1.655 +				}
   1.656 +				filter.appendFunction("ST_Transform");
   1.657 +				filter.openBracket();
   1.658 +			}
   1.659 +			/////
   1.660 +
   1.661  			switch(func)
   1.662  			{
   1.663  			case ST_Envelope: filter.appendFunction("ST_Envelope"); break;
   1.664 @@ -1035,7 +1215,6 @@
   1.665  			case ST_IsEmpty: filter.appendFunction("ST_IsEmpty"); break;
   1.666  			case ST_IsSimple: filter.appendFunction("ST_IsSimple"); break;
   1.667  			}
   1.668 -			//filter.appendFunction("ST_Union");
   1.669  			filter.openBracket();
   1.670  			if(expr.getArg() instanceof GeneralDBStringValue)
   1.671  			{
   1.672 @@ -1060,11 +1239,22 @@
   1.673  			}
   1.674  
   1.675  			filter.closeBracket();
   1.676 +			//SRID Support
   1.677 +			if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
   1.678 +			{
   1.679 +				filter.appendComma();
   1.680 +//				filter.append(((GeneralDBSqlSpatialConstructUnary)expr).getSrid());
   1.681 +				filter.append(sridExpr);
   1.682 +				filter.closeBracket();
   1.683 +			}
   1.684 +			///
   1.685  		}
   1.686  
   1.687  		filter.closeBracket();
   1.688  	}
   1.689  
   1.690 +
   1.691 +
   1.692  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
   1.693  	protected void appendGeneralDBSpatialFunctionTriple(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
   1.694  	throws UnsupportedRdbmsOperatorException
   1.695 @@ -1074,7 +1264,7 @@
   1.696  		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.697  		boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.698  		boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.699 -		
   1.700 +
   1.701  		if(check1a)
   1.702  		{
   1.703  			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   1.704 @@ -1117,92 +1307,92 @@
   1.705  				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   1.706  			}
   1.707  			filter.appendComma();
   1.708 -//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.709 -//			if(check2)
   1.710 -//			{
   1.711 -//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.712 -//			}
   1.713 -//			else
   1.714 -//			{
   1.715 -				if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.716 -				{
   1.717 -					appendWKT(expr.getRightArg(),filter);
   1.718 -				}
   1.719 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.720 -				{
   1.721 -					appendConstructFunction(expr.getRightArg(), filter);
   1.722 -				}
   1.723 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.724 -				{
   1.725 -					appendConstructFunction(expr.getRightArg(), filter);
   1.726 -				}
   1.727 -				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.728 -				{
   1.729 -					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.730 -					appendMBB(onlyLabel,filter);					 
   1.731 -				}
   1.732 -				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.733 -				{
   1.734 -					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.735 -				}
   1.736 -				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.737 -				{
   1.738 -					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.739 -				}
   1.740 -				//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.741 -				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.742 -				{
   1.743 -					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.744 -					appendCastToDouble(filter);
   1.745 -				}
   1.746 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.747 -				{
   1.748 -					appendMetricFunction(expr.getRightArg(), filter);
   1.749 -				}
   1.750 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.751 -				{
   1.752 -					appendMetricFunction(expr.getRightArg(), filter);
   1.753 -				}
   1.754 -				else
   1.755 -				{
   1.756 -					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.757 -				}
   1.758 +			//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.759 +			//			if(check2)
   1.760 +			//			{
   1.761 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.762 +			//			}
   1.763 +			//			else
   1.764 +			//			{
   1.765 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.766 +			{
   1.767 +				appendWKT(expr.getRightArg(),filter);
   1.768 +			}
   1.769 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.770 +			{
   1.771 +				appendConstructFunction(expr.getRightArg(), filter);
   1.772 +			}
   1.773 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.774 +			{
   1.775 +				appendConstructFunction(expr.getRightArg(), filter);
   1.776 +			}
   1.777 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.778 +			{
   1.779 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.780 +				appendMBB(onlyLabel,filter);					 
   1.781 +			}
   1.782 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.783 +			{
   1.784 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.785 +			}
   1.786 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.787 +			{
   1.788 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.789 +			}
   1.790 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.791 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.792 +			{
   1.793 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.794 +				appendCastToDouble(filter);
   1.795 +			}
   1.796 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.797 +			{
   1.798 +				appendMetricFunction(expr.getRightArg(), filter);
   1.799 +			}
   1.800 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.801 +			{
   1.802 +				appendMetricFunction(expr.getRightArg(), filter);
   1.803 +			}
   1.804 +			else
   1.805 +			{
   1.806 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.807 +			}
   1.808  
   1.809 -//			}
   1.810 +			//			}
   1.811  			//3rd arg
   1.812  			filter.appendComma();
   1.813 -//			boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.814 -//			if(check3)
   1.815 -//			{
   1.816 -//				this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
   1.817 -//			}
   1.818 -//			else
   1.819 -//			{
   1.820 +			//			boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   1.821 +			//			if(check3)
   1.822 +			//			{
   1.823 +			//				this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
   1.824 +			//			}
   1.825 +			//			else
   1.826 +			//			{
   1.827  
   1.828 -				if(expr.getThirdArg() instanceof GeneralDBStringValue)
   1.829 -				{
   1.830 -					append(((GeneralDBStringValue)expr.getThirdArg()),filter);	
   1.831 -				}
   1.832 -				else if(expr.getThirdArg() instanceof GeneralDBSqlCase)
   1.833 -				{
   1.834 -					append(((GeneralDBSqlCase)expr.getThirdArg()),filter);				 
   1.835 -				}
   1.836 -				//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.837 -				else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial())
   1.838 -				{
   1.839 +			if(expr.getThirdArg() instanceof GeneralDBStringValue)
   1.840 +			{
   1.841 +				append(((GeneralDBStringValue)expr.getThirdArg()),filter);	
   1.842 +			}
   1.843 +			else if(expr.getThirdArg() instanceof GeneralDBSqlCase)
   1.844 +			{
   1.845 +				append(((GeneralDBSqlCase)expr.getThirdArg()),filter);				 
   1.846 +			}
   1.847 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.848 +			else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial())
   1.849 +			{
   1.850  
   1.851 -					append(((GeneralDBLabelColumn)expr.getThirdArg()),filter);
   1.852 -				}
   1.853 +				append(((GeneralDBLabelColumn)expr.getThirdArg()),filter);
   1.854 +			}
   1.855  
   1.856  
   1.857 -//			}
   1.858 +			//			}
   1.859  			filter.closeBracket();
   1.860  		}
   1.861  
   1.862  		filter.closeBracket();
   1.863  	}
   1.864  
   1.865 -	
   1.866 +
   1.867  	//GeoSPARQL
   1.868  	//XXX
   1.869  	protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern)
   1.870 @@ -1212,7 +1402,7 @@
   1.871  
   1.872  		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.GeneralDBSqlNull");
   1.873  		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.GeneralDBSqlNull");
   1.874 -		
   1.875 +
   1.876  		if(check1)
   1.877  		{
   1.878  			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   1.879 @@ -1250,58 +1440,58 @@
   1.880  				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
   1.881  			}
   1.882  			filter.appendComma();
   1.883 -//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.GeneralDBSqlNull");
   1.884 -//			if(check2)
   1.885 -//			{
   1.886 -//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.887 -//			}
   1.888 -//			else
   1.889 -//			{
   1.890 -				if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.891 -				{
   1.892 -					appendWKT(expr.getRightArg(),filter);
   1.893 -				}
   1.894 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.895 -				{
   1.896 -					appendConstructFunction(expr.getRightArg(), filter);
   1.897 -				}
   1.898 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.899 -				{
   1.900 -					appendConstructFunction(expr.getRightArg(), filter);
   1.901 -				}
   1.902 -				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.903 -				{
   1.904 -					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.905 -					appendMBB(onlyLabel,filter);					 
   1.906 -				}
   1.907 -				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.908 -				{
   1.909 -					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.910 -				}
   1.911 -				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.912 -				{
   1.913 -					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.914 -				}
   1.915 -				//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.916 -				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.917 -				{
   1.918 -					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.919 -					appendCastToDouble(filter);
   1.920 -				}
   1.921 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.922 -				{
   1.923 -					appendMetricFunction(expr.getRightArg(), filter);
   1.924 -				}
   1.925 -				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.926 -				{
   1.927 -					appendMetricFunction(expr.getRightArg(), filter);
   1.928 -				}
   1.929 -				else
   1.930 -				{
   1.931 -					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.932 -				}
   1.933 +			//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.monetdb.algebra.GeneralDBSqlNull");
   1.934 +			//			if(check2)
   1.935 +			//			{
   1.936 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   1.937 +			//			}
   1.938 +			//			else
   1.939 +			//			{
   1.940 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   1.941 +			{
   1.942 +				appendWKT(expr.getRightArg(),filter);
   1.943 +			}
   1.944 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
   1.945 +			{
   1.946 +				appendConstructFunction(expr.getRightArg(), filter);
   1.947 +			}
   1.948 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
   1.949 +			{
   1.950 +				appendConstructFunction(expr.getRightArg(), filter);
   1.951 +			}
   1.952 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
   1.953 +			{
   1.954 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
   1.955 +				appendMBB(onlyLabel,filter);					 
   1.956 +			}
   1.957 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   1.958 +			{
   1.959 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   1.960 +			}
   1.961 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   1.962 +			{
   1.963 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   1.964 +			}
   1.965 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   1.966 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   1.967 +			{
   1.968 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   1.969 +				appendCastToDouble(filter);
   1.970 +			}
   1.971 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
   1.972 +			{
   1.973 +				appendMetricFunction(expr.getRightArg(), filter);
   1.974 +			}
   1.975 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
   1.976 +			{
   1.977 +				appendMetricFunction(expr.getRightArg(), filter);
   1.978 +			}
   1.979 +			else
   1.980 +			{
   1.981 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
   1.982 +			}
   1.983  
   1.984 -//			}
   1.985 +			//			}
   1.986  			//3rd arg
   1.987  			filter.appendComma();
   1.988  
   1.989 @@ -1318,8 +1508,8 @@
   1.990  
   1.991  		filter.closeBracket();
   1.992  	}
   1.993 -	
   1.994 -	
   1.995 +
   1.996 +
   1.997  	protected void appendgeoSPARQLSpatialRelation(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
   1.998  	throws UnsupportedRdbmsOperatorException
   1.999  	{
  1.1000 @@ -1666,7 +1856,7 @@
  1.1001  	@Override
  1.1002  	//GeoSPARQL
  1.1003  	//XXX
  1.1004 -	
  1.1005 +
  1.1006  	protected void appendRelate(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, char[] intersectionPattern)
  1.1007  	throws UnsupportedRdbmsOperatorException
  1.1008  	{
  1.1009 @@ -1774,4 +1964,4 @@
  1.1010  
  1.1011  		filter.closeBracket();
  1.1012  	}
  1.1013 -}
  1.1014 \ No newline at end of file
  1.1015 +}