Strabon

changeset 780:530257d4896e DiffDateTime

NOT WORKING: keep trying to implement diffDateTime for postgres
author George Garbis <ggarbis@di.uoa.gr>
date Tue Dec 04 16:31:03 2012 +0200 (2012-12-04)
parents bcf56f3e9988
children 69837cd17fb5
files generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDateTimeMetricBinary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDiffDateTime.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlExtDiffDateTime.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java.orig
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDateTimeMetricBinary.java	Tue Dec 04 16:31:03 2012 +0200
     1.3 @@ -0,0 +1,35 @@
     1.4 +package org.openrdf.sail.generaldb.algebra;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +
     1.8 +import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator;
     1.9 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
    1.10 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
    1.11 +import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator;
    1.12 +
    1.13 +/** Addition for datetime metric functions
    1.14 + * 
    1.15 + * @author George Garbis <ggarbis@di.uoa.gr>
    1.16 + * 
    1.17 + */
    1.18 +
    1.19 +public class GeneralDBSqlDateTimeMetricBinary extends BinaryGeneralDBOperator
    1.20 +{
    1.21 +
    1.22 +
    1.23 +	/*CONSTRUCTOR*/
    1.24 +
    1.25 +	public GeneralDBSqlDateTimeMetricBinary(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    1.26 +		super(left, right);
    1.27 +	}
    1.28 +
    1.29 +	@Override
    1.30 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
    1.31 +	throws X
    1.32 +	{
    1.33 +		visitor.meet(this);
    1.34 +	}
    1.35 +
    1.36 +}
    1.37 +
    1.38 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDiffDateTime.java	Tue Dec 04 16:31:03 2012 +0200
     2.3 @@ -0,0 +1,31 @@
     2.4 +/*
     2.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
     2.6 + *
     2.7 + * Licensed under the Aduna BSD-style license.
     2.8 + */
     2.9 +package org.openrdf.sail.generaldb.algebra;
    2.10 +
    2.11 +  
    2.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
    2.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
    2.14 +
    2.15 +/** Addition for datetime metric functions
    2.16 + * 
    2.17 + * @author George Garbis <ggarbis@di.uoa.gr>
    2.18 + * 
    2.19 + */
    2.20 +
    2.21 +public class GeneralDBSqlDiffDateTime extends GeneralDBSqlDateTimeMetricBinary{
    2.22 +	
    2.23 +	public GeneralDBSqlDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    2.24 +		super(left, right);
    2.25 +	}
    2.26 +
    2.27 +	@Override
    2.28 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
    2.29 +		throws X
    2.30 +	{
    2.31 +		visitor.meet(this);
    2.32 +	}
    2.33 +
    2.34 +}
    2.35 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlExtDiffDateTime.java	Tue Dec 04 16:31:03 2012 +0200
     3.3 @@ -0,0 +1,31 @@
     3.4 +/*
     3.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
     3.6 + *
     3.7 + * Licensed under the Aduna BSD-style license.
     3.8 + */
     3.9 +package org.openrdf.sail.generaldb.algebra;
    3.10 +
    3.11 +  
    3.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
    3.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
    3.14 +
    3.15 +/** Addition for datetime metric functions
    3.16 + * 
    3.17 + * @author George Garbis <ggarbis@di.uoa.gr>
    3.18 + * 
    3.19 + */
    3.20 +
    3.21 +public class GeneralDBSqlExtDiffDateTime extends GeneralDBSqlDateTimeMetricBinary {
    3.22 +
    3.23 +	public GeneralDBSqlExtDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    3.24 +		super(left, right);
    3.25 +	}
    3.26 +
    3.27 +	@Override
    3.28 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
    3.29 +		throws X
    3.30 +	{
    3.31 +		visitor.meet(this);
    3.32 +	}
    3.33 +
    3.34 +}
    3.35 \ No newline at end of file
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Fri Nov 30 20:09:20 2012 +0200
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Tue Dec 04 16:31:03 2012 +0200
     4.3 @@ -26,6 +26,7 @@
     4.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
     4.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
     4.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
     4.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
     4.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
     4.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
    4.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
    4.11 @@ -409,6 +410,19 @@
    4.12  	}
    4.13  	/***/
    4.14  	
    4.15 +	/** Addition for datetime metric functions
    4.16 +	 * 
    4.17 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    4.18 +	 * 
    4.19 +	 */
    4.20 +
    4.21 +	public static GeneralDBSqlExpr diffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
    4.22 +
    4.23 +		return new GeneralDBSqlDiffDateTime(left, right);
    4.24 +	}
    4.25 +	
    4.26 +	/***/
    4.27 +	
    4.28  	//XXX Spatial Metric Functions
    4.29  	public static GeneralDBSqlExpr geoArea(GeneralDBSqlExpr expr) {
    4.30  
     5.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Fri Nov 30 20:09:20 2012 +0200
     5.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Tue Dec 04 16:31:03 2012 +0200
     5.3 @@ -331,7 +331,7 @@
     5.4  	 {
     5.5  		 meetUnarySqlOperator(node);
     5.6  	 }
     5.7 -
     5.8 +	 
     5.9  	 public void meet(GeneralDBSqlSpatialMetricBinary node) throws X 
    5.10  	 {
    5.11  		 meetBinarySqlOperator(node);
     6.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Fri Nov 30 20:09:20 2012 +0200
     6.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Dec 04 16:31:03 2012 +0200
     6.3 @@ -1130,6 +1130,25 @@
     6.4  		return null;
     6.5  	}
     6.6  
     6.7 +	/** Addition for datetime metric functions
     6.8 +	 * 
     6.9 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    6.10 +	 * 
    6.11 +	 */
    6.12 +	
    6.13 +	GeneralDBSqlExpr dateTimeMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    6.14 +	{
    6.15 +		if(function.getURI().equals(GeoConstants.diffDateTime))
    6.16 +		{
    6.17 +			return diffDateTime(leftArg, rightArg);
    6.18 +		}
    6.19 +
    6.20 +		//Should never reach this place
    6.21 +		return null;
    6.22 +	}
    6.23 +	
    6.24 +	/***/
    6.25 +	
    6.26  	//TODO more to be added here probably
    6.27  	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
    6.28  	{
     7.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Fri Nov 30 20:09:20 2012 +0200
     7.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Tue Dec 04 16:31:03 2012 +0200
     7.3 @@ -42,6 +42,7 @@
     7.4  import org.openrdf.query.algebra.Var;
     7.5  import org.openrdf.query.algebra.evaluation.function.Function;
     7.6  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
     7.7 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
     7.8  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
     7.9  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    7.10  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
    7.11 @@ -250,7 +251,27 @@
    7.12  			return spatialPropertyPicker(function, leftArg);
    7.13  		}
    7.14  	}
    7.15 +	
    7.16 +	/** Addition for datetime metric functions
    7.17 +	 * 
    7.18 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    7.19 +	 * 
    7.20 +	 */
    7.21  
    7.22 +	public GeneralDBSqlExpr dateTimeFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
    7.23 +	{
    7.24 +		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
    7.25 +		if(function instanceof DateTimeMetricFunc)
    7.26 +		{
    7.27 +			return dateTimeMetricFunction(functionCall,function);	
    7.28 +		}
    7.29 +		
    7.30 +		return null;
    7.31 +	}
    7.32 +
    7.33 +	
    7.34 +	/***/
    7.35 +	
    7.36  	public GeneralDBSqlExpr spatialFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
    7.37  	{
    7.38  		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
    7.39 @@ -330,6 +351,31 @@
    7.40  
    7.41  	}
    7.42  
    7.43 +	/**
    7.44 +	 * Addition for datetime metric functions
    7.45 +	 * 
    7.46 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    7.47 +	 * 
    7.48 +	 */
    7.49 +	
    7.50 +	GeneralDBSqlExpr dateTimeMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
    7.51 +	{
    7.52 +		GeneralDBSqlExpr leftArg = null;
    7.53 +		GeneralDBSqlExpr rightArg = null;
    7.54 +
    7.55 +		ValueExpr left = functionCall.getArgs().get(0);
    7.56 +		ValueExpr right = functionCall.getArgs().get(1);
    7.57 +
    7.58 +		// TODO ti bazw edw??
    7.59 +		leftArg = null;
    7.60 +
    7.61 +		rightArg = null;
    7.62 +		return dateTimeMetricPicker(function, leftArg, rightArg);
    7.63 +
    7.64 +	}
    7.65 +		
    7.66 +	/***/
    7.67 +	
    7.68  	GeneralDBSqlExpr spatialMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
    7.69  	{
    7.70  		GeneralDBSqlExpr leftArg = null;
     8.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Fri Nov 30 20:09:20 2012 +0200
     8.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Dec 04 16:31:03 2012 +0200
     8.3 @@ -76,6 +76,7 @@
     8.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery;
     8.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery.OrderElem;
     8.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
     8.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDateTimeMetricBinary;
     8.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
     8.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
    8.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension;
    8.11 @@ -830,6 +831,17 @@
    8.12  		{
    8.13  			locateColumnVars(((GeneralDBSqlSpatialConstructUnary)expr).getArg(),allKnown);
    8.14  		}
    8.15 +		/** Addition for datetime metric functions
    8.16 +		 * 
    8.17 +		 * @author George Garbis <ggarbis@di.uoa.gr>
    8.18 +		 * 
    8.19 +		 */
    8.20 +		else if(expr instanceof GeneralDBSqlDateTimeMetricBinary)
    8.21 +		{
    8.22 +			locateColumnVars(((GeneralDBSqlDateTimeMetricBinary)expr).getLeftArg(),allKnown);
    8.23 +			locateColumnVars(((GeneralDBSqlDateTimeMetricBinary)expr).getRightArg(),allKnown);
    8.24 +		}
    8.25 +		/***/
    8.26  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary)
    8.27  		{
    8.28  			locateColumnVars(((GeneralDBSqlSpatialMetricBinary)expr).getLeftArg(),allKnown);
    8.29 @@ -989,7 +1001,14 @@
    8.30  		}
    8.31  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary ||
    8.32  				expr instanceof GeneralDBSqlSpatialMetricUnary ||
    8.33 -				expr instanceof GeneralDBSqlMathExpr)
    8.34 +				expr instanceof GeneralDBSqlMathExpr ||
    8.35 +				/** Addition for datetime metric functions
    8.36 +				 * 
    8.37 +				 * @author George Garbis <ggarbis@di.uoa.gr>
    8.38 +				 * 
    8.39 +				 */
    8.40 +				expr instanceof GeneralDBSqlDateTimeMetricBinary 
    8.41 +				/***/) 
    8.42  		{
    8.43  			return ResultType.DOUBLE;
    8.44  		}
     9.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Fri Nov 30 20:09:20 2012 +0200
     9.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Dec 04 16:31:03 2012 +0200
     9.3 @@ -197,6 +197,14 @@
     9.4  		; 
     9.5  	}
     9.6  
     9.7 +	/** Addition for datetime metric functions
     9.8 +	 * 
     9.9 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    9.10 +	 * 
    9.11 +	 */
    9.12 +	public enum DateTimeFunctionPostGIS { Difference; }
    9.13 +	/***/
    9.14 +	
    9.15  	public PostGISQueryBuilder() {
    9.16  		super();
    9.17  	}
    9.18 @@ -1251,7 +1259,147 @@
    9.19  
    9.20  			}
    9.21  
    9.22 +	/** Addition for datetime metric functions
    9.23 +	 * 
    9.24 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    9.25 +	 * 
    9.26 +	 */
    9.27 +	
    9.28 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionPostGIS func)
    9.29 +			throws UnsupportedRdbmsOperatorException
    9.30 +	{
    9.31 +		filter.openBracket();
    9.32  
    9.33 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    9.34 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
    9.35 +
    9.36 +		if(check1)
    9.37 +		{
    9.38 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
    9.39 +
    9.40 +		}
    9.41 +		else if(check2)
    9.42 +		{
    9.43 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
    9.44 +		}
    9.45 +		else
    9.46 +		{
    9.47 +
    9.48 +			GeneralDBSqlExpr tmp = expr;
    9.49 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
    9.50 +			{
    9.51 +				while(true)
    9.52 +				{
    9.53 +					GeneralDBSqlExpr child;
    9.54 +
    9.55 +					if(tmp instanceof BinaryGeneralDBOperator)
    9.56 +					{
    9.57 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
    9.58 +					}
    9.59 +					else //(tmp instanceof UnaryGeneralDBOperator)
    9.60 +					{
    9.61 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
    9.62 +					}
    9.63 +
    9.64 +					tmp = child;
    9.65 +					if(tmp instanceof GeneralDBLabelColumn)
    9.66 +					{
    9.67 +						//Reached the innermost left var -> need to capture its SRID
    9.68 +						String alias;
    9.69 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
    9.70 +							//Predicates used in triple patterns non-existent in db
    9.71 +							alias="NULL";
    9.72 +						}
    9.73 +						else
    9.74 +						{
    9.75 +							//Reached the innermost left var -> need to capture its SRID
    9.76 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
    9.77 +						}
    9.78 +						break;
    9.79 +					}
    9.80 +				}
    9.81 +			}
    9.82 +
    9.83 +			filter.openBracket();
    9.84 +
    9.85 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
    9.86 +			{
    9.87 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getLeftArg();
    9.88 +				String raw = arg.getValue();
    9.89 +				filter.append(" "+raw+" ");
    9.90 +			}
    9.91 +			else if(expr.getLeftArg() instanceof GeneralDBDoubleValue) //case met in buffer!
    9.92 +			{
    9.93 +				append(((GeneralDBDoubleValue)expr.getLeftArg()), filter);
    9.94 +			}
    9.95 +			else if(expr.getLeftArg() instanceof GeneralDBNumericColumn) //case met in buffer!
    9.96 +			{
    9.97 +				append(((GeneralDBNumericColumn)expr.getLeftArg()), filter);
    9.98 +			}
    9.99 +			else if(expr.getLeftArg() instanceof GeneralDBURIColumn) //case met in transform!
   9.100 +			{
   9.101 +				filter.keepSRID_part1();
   9.102 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
   9.103 +				filter.keepSRID_part2();
   9.104 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
   9.105 +				filter.keepSRID_part3();
   9.106 +			}
   9.107 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   9.108 +			else if(expr.getLeftArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getLeftArg()).isSpatial())
   9.109 +			{
   9.110 +				append(((GeneralDBLabelColumn)expr.getLeftArg()),filter);
   9.111 +				appendCastToDouble(filter);
   9.112 +			}
   9.113 +			else
   9.114 +			{
   9.115 +				// Den prepei na ftasei edw
   9.116 +			}
   9.117 +						
   9.118 +			switch(func)
   9.119 +			{
   9.120 +				case Difference: filter.append(" - "); break;			
   9.121 +			}
   9.122 +			
   9.123 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
   9.124 +			{
   9.125 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getRightArg();
   9.126 +				String raw = arg.getValue();
   9.127 +				filter.append(" "+raw+" ");
   9.128 +			}
   9.129 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
   9.130 +			{
   9.131 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
   9.132 +			}
   9.133 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
   9.134 +			{
   9.135 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
   9.136 +			}
   9.137 +			else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
   9.138 +			{
   9.139 +				filter.keepSRID_part1();
   9.140 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   9.141 +				filter.keepSRID_part2();
   9.142 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
   9.143 +				filter.keepSRID_part3();
   9.144 +			}
   9.145 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
   9.146 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
   9.147 +			{
   9.148 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
   9.149 +				appendCastToDouble(filter);
   9.150 +			}
   9.151 +			else
   9.152 +			{
   9.153 +				// Den prepei na ftasei edw
   9.154 +			}
   9.155 +
   9.156 +
   9.157 +			filter.closeBracket();
   9.158 +		}
   9.159 +		filter.closeBracket();
   9.160 +	}
   9.161 +	
   9.162 +	/***/
   9.163  
   9.164  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
   9.165  	//EXCEPT ST_Transform!!!
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java.orig	Tue Dec 04 16:31:03 2012 +0200
    10.3 @@ -0,0 +1,2150 @@
    10.4 +/*
    10.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    10.6 + *
    10.7 + * Licensed under the Aduna BSD-style license.
    10.8 + */
    10.9 +package org.openrdf.sail.postgis.evaluation;
   10.10 +
   10.11 +import java.util.ArrayList;
   10.12 +import java.util.List;
   10.13 +
   10.14 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   10.15 +import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar;
   10.16 +import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue;
   10.17 +import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn;
   10.18 +import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn;
   10.19 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbove;
   10.20 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd;
   10.21 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnyInteract;
   10.22 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlBelow;
   10.23 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
   10.24 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
   10.25 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
   10.26 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
   10.27 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
   10.28 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
   10.29 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   10.30 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
   10.31 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
   10.32 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
   10.33 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBoundary;
   10.34 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBuffer;
   10.35 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoConvexHull;
   10.36 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDifference;
   10.37 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension;
   10.38 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDistance;
   10.39 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoEnvelope;
   10.40 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoGeometryType;
   10.41 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIntersection;
   10.42 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsEmpty;
   10.43 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsSimple;
   10.44 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSrid;
   10.45 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSymDifference;
   10.46 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoTransform;
   10.47 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoUnion;
   10.48 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlInside;
   10.49 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIntersects;
   10.50 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
   10.51 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLeft;
   10.52 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr;
   10.53 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbEquals;
   10.54 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbInside;
   10.55 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbIntersects;
   10.56 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot;
   10.57 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull;
   10.58 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOverlap;
   10.59 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate;
   10.60 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight;
   10.61 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
   10.62 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
   10.63 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
   10.64 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
   10.65 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
   10.66 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouch;
   10.67 +import org.openrdf.sail.generaldb.algebra.GeneralDBStringValue;
   10.68 +import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
   10.69 +import org.openrdf.sail.generaldb.algebra.GeneralDBUnionItem;
   10.70 +import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator;
   10.71 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBFromItem;
   10.72 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   10.73 +import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator;
   10.74 +import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator;
   10.75 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Contains;
   10.76 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_CoveredBy;
   10.77 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Covers;
   10.78 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Disjoint;
   10.79 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Equals;
   10.80 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Inside;
   10.81 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Meet;
   10.82 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Overlap;
   10.83 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Dc;
   10.84 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ec;
   10.85 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Eq;
   10.86 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntpp;
   10.87 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntppi;
   10.88 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Po;
   10.89 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tpp;
   10.90 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tppi;
   10.91 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Contains;
   10.92 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Crosses;
   10.93 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Disjoint;
   10.94 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Equals;
   10.95 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Intersects;
   10.96 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Overlaps;
   10.97 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Touches;
   10.98 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Within;
   10.99 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilder;
  10.100 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder;
  10.101 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder;
  10.102 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlJoinBuilder;
  10.103 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlQueryBuilder;
  10.104 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
  10.105 +import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
  10.106 +
  10.107 +/**
  10.108 + * Constructs an SQL query from {@link GeneralDBSqlExpr}s and {@link GeneralDBFromItem}s.
  10.109 + * 
  10.110 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
  10.111 + * 
  10.112 + */
  10.113 +public class PostGISQueryBuilder extends GeneralDBQueryBuilder {
  10.114 +
  10.115 +	public static final String STRDFGEO_FIELD = "strdfgeo";
  10.116 +	public static final String SRID_FIELD = "srid";
  10.117 +	public static final String ST_TRANSFORM = "ST_Transform";
  10.118 +	public static final String ST_ASBINARY = "ST_AsBinary";
  10.119 +	/**
  10.120 +	 * If (spatial) label column met is null, I must not try to retrieve its srid. 
  10.121 +	 * Opting to ask for 'null' instead
  10.122 +	 */
  10.123 +	boolean nullLabel = false;
  10.124 +
  10.125 +	public enum SpatialOperandsPostGIS { anyInteract, equals, contains, left, right, above, inside, below; }
  10.126 +	public enum SpatialFunctionsPostGIS 
  10.127 +	{ 	//stSPARQL++
  10.128 +		//Spatial Relationships
  10.129 +		ST_Disjoint, 
  10.130 +		ST_Touches, 
  10.131 +		ST_Covers,
  10.132 +		ST_CoveredBy, 
  10.133 +		ST_Overlaps,
  10.134 +		ST_Intersects,
  10.135 +		ST_Equals,
  10.136 +		ST_Relate, 
  10.137 +		ST_Within,
  10.138 +		ST_Contains,
  10.139 +		
  10.140 +		
  10.141 +		//Spatial Constructs - Binary
  10.142 +		ST_Union, 
  10.143 +		ST_Intersection, 
  10.144 +		ST_Difference,
  10.145 +		ST_Buffer,
  10.146 +		ST_Transform,
  10.147 +		ST_SymDifference,
  10.148 +
  10.149 +
  10.150 +		//Spatial Constructs - Unary
  10.151 +		ST_Envelope,
  10.152 +		ST_ConvexHull,
  10.153 +		ST_Boundary,
  10.154 +
  10.155 +		//Spatial Metrics - Binary
  10.156 +		ST_Distance,
  10.157 +
  10.158 +		//Spatial Metrics - Unary
  10.159 +		ST_Area,
  10.160 +
  10.161 +		//Spatial Properties - All Unary
  10.162 +		ST_Dimension,
  10.163 +		ST_GeometryType,
  10.164 +		ST_AsGML,
  10.165 +		ST_AsText,
  10.166 +		ST_SRID,
  10.167 +		ST_IsEmpty,
  10.168 +		ST_IsSimple,
  10.169 +
  10.170 +		//GeoSPARQL
  10.171 +		//Simple Features
  10.172 +		SF_Equals,
  10.173 +		SF_Disjoint,
  10.174 +		SF_Intersects,
  10.175 +		SF_Touches,
  10.176 +		SF_Within,
  10.177 +		SF_Contains,
  10.178 +		SF_Overlaps,
  10.179 +		SF_Crosses,
  10.180 +
  10.181 +		//RCC8
  10.182 +		RCC8_Eq,
  10.183 +		RCC8_Dc,
  10.184 +		RCC8_Ec,
  10.185 +		RCC8_Po,
  10.186 +		RCC8_Tppi,
  10.187 +		RCC8_Tpp,
  10.188 +		RCC8_Ntppi,
  10.189 +		RCC8_Ntpp,
  10.190 +
  10.191 +		//Egenhofer
  10.192 +		EH_Equals,
  10.193 +		EH_Disjoint,
  10.194 +		EH_Meet,
  10.195 +		EH_Overlap,
  10.196 +		EH_Covers,
  10.197 +		EH_CoveredBy,
  10.198 +		EH_Inside,
  10.199 +		EH_Contains,
  10.200 +		; 
  10.201 +	}
  10.202 +	
  10.203 +	public enum DateTimeFunctionsPostGIS {
  10.204 +		Difference;
  10.205 +	}
  10.206 +
  10.207 +	public PostGISQueryBuilder() {
  10.208 +		super();
  10.209 +	}
  10.210 +
  10.211 +	public PostGISQueryBuilder(GeneralDBSqlQueryBuilder builder) {
  10.212 +		super(builder);
  10.213 +		this.query = builder;
  10.214 +	}
  10.215 +
  10.216 +	@Override
  10.217 +	protected void append(GeneralDBSqlNull expr, GeneralDBSqlExprBuilder filter) {
  10.218 +		filter.appendNull();
  10.219 +	}
  10.220 +
  10.221 +	@Override
  10.222 +	protected void append(GeneralDBSqlIsNull expr, GeneralDBSqlExprBuilder filter)
  10.223 +			throws UnsupportedRdbmsOperatorException
  10.224 +			{
  10.225 +		dispatch(expr.getArg(), filter);
  10.226 +		filter.isNull();
  10.227 +			}
  10.228 +
  10.229 +	@Override
  10.230 +	protected void append(GeneralDBSqlNot expr, GeneralDBSqlExprBuilder filter)
  10.231 +			throws UnsupportedRdbmsOperatorException
  10.232 +			{
  10.233 +		if (expr.getArg() instanceof GeneralDBSqlIsNull) {
  10.234 +			GeneralDBSqlIsNull arg = (GeneralDBSqlIsNull)expr.getArg();
  10.235 +			dispatch(arg.getArg(), filter);
  10.236 +			filter.isNotNull();
  10.237 +		}
  10.238 +		else {
  10.239 +			GeneralDBSqlBracketBuilder open = filter.not();
  10.240 +			dispatch(expr.getArg(), (GeneralDBSqlExprBuilder) open);
  10.241 +			open.close();
  10.242 +		}
  10.243 +			}
  10.244 +
  10.245 +	@Override
  10.246 +	protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) {
  10.247 +		if (var.getRdbmsVar().isResource()) {
  10.248 +			filter.appendNull();
  10.249 +			nullLabel = true;
  10.250 +		}
  10.251 +		else {
  10.252 +			if(var.isSpatial())
  10.253 +			{
  10.254 +				filter.appendFunction(ST_ASBINARY);
  10.255 +				filter.openBracket();
  10.256 +				//XXX SRID
  10.257 +				filter.appendFunction(ST_TRANSFORM);
  10.258 +				filter.openBracket();
  10.259 +				//
  10.260 +				String alias = getLabelAlias(var.getRdbmsVar());
  10.261 +
  10.262 +				filter.column(alias, STRDFGEO_FIELD);
  10.263 +				//XXX SRID
  10.264 +				filter.appendComma();
  10.265 +				filter.column(alias, SRID_FIELD);
  10.266 +				filter.closeBracket();
  10.267 +				//
  10.268 +				filter.closeBracket();
  10.269 +
  10.270 +				//Adding srid field explicitly for my StrabonPolyhedron constructor later on!
  10.271 +				filter.appendComma();
  10.272 +				filter.column(alias, SRID_FIELD);
  10.273 +			}
  10.274 +			else
  10.275 +			{
  10.276 +				//XXX original/default case
  10.277 +				String alias = getLabelAlias(var.getRdbmsVar());
  10.278 +				filter.column(alias, "value");
  10.279 +			}
  10.280 +		}
  10.281 +	}
  10.282 +
  10.283 +	@Override
  10.284 +	protected void append(GeneralDBSqlAnd expr, GeneralDBSqlExprBuilder filter)
  10.285 +			throws UnsupportedRdbmsOperatorException
  10.286 +			{
  10.287 +		dispatch(expr.getLeftArg(), filter);
  10.288 +		filter.and();
  10.289 +		dispatch(expr.getRightArg(), filter);
  10.290 +			}
  10.291 +
  10.292 +	protected GeneralDBSqlJoinBuilder subJoinAndFilter(GeneralDBSqlJoinBuilder query, GeneralDBFromItem from)
  10.293 +			throws RdbmsException, UnsupportedRdbmsOperatorException
  10.294 +			{
  10.295 +		if (from instanceof GeneralDBUnionItem) {
  10.296 +			GeneralDBUnionItem union = (GeneralDBUnionItem)from;
  10.297 +			List<String> names = union.getSelectVarNames();
  10.298 +			List<GeneralDBColumnVar> vars = union.appendVars(new ArrayList<GeneralDBColumnVar>());
  10.299 +			GeneralDBSqlQueryBuilder subquery = query.subquery();
  10.300 +			for (GeneralDBFromItem item : union.getUnion()) {
  10.301 +				for (int i = 0, n = names.size(); i < n; i++) {
  10.302 +					GeneralDBColumnVar var = item.getVar(names.get(i));
  10.303 +					GeneralDBSqlExprBuilder select = subquery.select();
  10.304 +					if (var == null) {
  10.305 +						select.appendNull();
  10.306 +					}
  10.307 +					else if (var.isImplied()) {
  10.308 +						select.appendNumeric(vf.getInternalId(var.getValue()));
  10.309 +					}
  10.310 +					else {
  10.311 +						select.column(var.getAlias(), var.getColumn());
  10.312 +					}
  10.313 +					select.as(vars.get(i).getColumn());
  10.314 +				}
  10.315 +				from(subquery, item);
  10.316 +				subquery = subquery.union();
  10.317 +			}
  10.318 +		}
  10.319 +		for (GeneralDBFromItem join : from.getJoins()) {
  10.320 +			join(query, join);
  10.321 +		}
  10.322 +		for (GeneralDBSqlExpr expr : from.getFilters()) {
  10.323 +			dispatch(expr, query.on().and());
  10.324 +		}
  10.325 +		return query;
  10.326 +			}
  10.327 +
  10.328 +	//FIXME my addition from here on
  10.329 +
  10.330 +	//Issue with this function: crashes when MathExpr is present in Select but does not
  10.331 +	//involve spatial variables! must escape this somehow
  10.332 +	@Override
  10.333 +	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException
  10.334 +	{
  10.335 +		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
  10.336 +				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
  10.337 +				&&!(expr instanceof GeneralDBSqlMathExpr)
  10.338 +				&&!(expr instanceof GeneralDBSqlSpatialProperty))
  10.339 +		{
  10.340 +			query.select().appendFunction(ST_ASBINARY);
  10.341 +		}
  10.342 +		else
  10.343 +		{
  10.344 +			query.select();
  10.345 +		}
  10.346 +		if(expr instanceof BinaryGeneralDBOperator)
  10.347 +		{
  10.348 +			dispatchBinarySqlOperator((BinaryGeneralDBOperator) expr, query.select);
  10.349 +		}
  10.350 +		else if(expr instanceof UnaryGeneralDBOperator)
  10.351 +		{
  10.352 +			dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select);
  10.353 +		}
  10.354 +		//SRID support must be explicitly added!
  10.355 +
  10.356 +		return this;
  10.357 +	}
  10.358 +
  10.359 +	//Spatial Relationship Functions
  10.360 +	@Override
  10.361 +	protected void append(GeneralDBSqlAnyInteract expr, GeneralDBSqlExprBuilder filter)
  10.362 +			throws UnsupportedRdbmsOperatorException
  10.363 +			{
  10.364 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects);
  10.365 +			}
  10.366 +
  10.367 +
  10.368 +	@Override
  10.369 +	protected void append(GeneralDBSqlIntersects expr, 	GeneralDBSqlExprBuilder filter)
  10.370 +			throws UnsupportedRdbmsOperatorException {
  10.371 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects);
  10.372 +	}
  10.373 +
  10.374 +	@Override
  10.375 +	protected void append(GeneralDBSqlContains expr, GeneralDBSqlExprBuilder filter)
  10.376 +			throws UnsupportedRdbmsOperatorException {
  10.377 +
  10.378 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Contains);
  10.379 +	}
  10.380 +
  10.381 +
  10.382 +
  10.383 +	
  10.384 +	@Override
  10.385 +	protected void append(GeneralDBSqlEqualsSpatial expr, GeneralDBSqlExprBuilder filter)
  10.386 +			throws UnsupportedRdbmsOperatorException {
  10.387 +
  10.388 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Equals);
  10.389 +	}
  10.390 +
  10.391 +	@Override
  10.392 +	protected void append(GeneralDBSqlInside expr, GeneralDBSqlExprBuilder filter)
  10.393 +			throws UnsupportedRdbmsOperatorException {
  10.394 +
  10.395 +		//appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside);
  10.396 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Within);
  10.397 +
  10.398 +	}
  10.399 +
  10.400 +	@Override
  10.401 +	protected void append(GeneralDBSqlCovers expr, GeneralDBSqlExprBuilder filter)
  10.402 +			throws UnsupportedRdbmsOperatorException {
  10.403 +
  10.404 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Covers);
  10.405 +	}
  10.406 +
  10.407 +	@Override
  10.408 +	protected void append(GeneralDBSqlCoveredBy expr, GeneralDBSqlExprBuilder filter)
  10.409 +			throws UnsupportedRdbmsOperatorException {
  10.410 +
  10.411 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_CoveredBy);
  10.412 +	}
  10.413 +
  10.414 +	@Override
  10.415 +	protected void append(GeneralDBSqlTouch expr, GeneralDBSqlExprBuilder filter)
  10.416 +			throws UnsupportedRdbmsOperatorException {
  10.417 +
  10.418 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Touches);
  10.419 +	}
  10.420 +
  10.421 +	@Override
  10.422 +	protected void append(GeneralDBSqlOverlap expr, GeneralDBSqlExprBuilder filter)
  10.423 +			throws UnsupportedRdbmsOperatorException {
  10.424 +
  10.425 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps);
  10.426 +	}
  10.427 +
  10.428 +	protected void append(GeneralDBSqlDisjoint expr, GeneralDBSqlExprBuilder filter)
  10.429 +			throws UnsupportedRdbmsOperatorException {
  10.430 +
  10.431 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Disjoint);
  10.432 +	}
  10.433 +
  10.434 +	@Override
  10.435 +	protected void append(GeneralDBSqlRelate expr, GeneralDBSqlExprBuilder filter)
  10.436 +			throws UnsupportedRdbmsOperatorException
  10.437 +			{
  10.438 +		appendGeneralDBSpatialFunctionTriple(expr, filter, SpatialFunctionsPostGIS.ST_Relate);
  10.439 +			}
  10.440 +
  10.441 +	@Override	
  10.442 +	protected void append(GeneralDBSqlLeft expr, GeneralDBSqlExprBuilder filter)
  10.443 +			throws UnsupportedRdbmsOperatorException
  10.444 +			{
  10.445 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.left);
  10.446 +			}
  10.447 +
  10.448 +	@Override
  10.449 +	protected void append(GeneralDBSqlRight expr, GeneralDBSqlExprBuilder filter)
  10.450 +			throws UnsupportedRdbmsOperatorException
  10.451 +			{
  10.452 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.right);
  10.453 +			}
  10.454 +
  10.455 +	@Override
  10.456 +	protected void append(GeneralDBSqlAbove expr, GeneralDBSqlExprBuilder filter)
  10.457 +			throws UnsupportedRdbmsOperatorException
  10.458 +			{
  10.459 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.above);
  10.460 +			}
  10.461 +
  10.462 +	@Override
  10.463 +	protected void append(GeneralDBSqlBelow expr, GeneralDBSqlExprBuilder filter)
  10.464 +			throws UnsupportedRdbmsOperatorException
  10.465 +			{
  10.466 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.below);
  10.467 +			}
  10.468 +
  10.469 +	@Override
  10.470 +	protected void append(GeneralDBSqlMbbIntersects expr, GeneralDBSqlExprBuilder filter)
  10.471 +			throws UnsupportedRdbmsOperatorException {
  10.472 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.anyInteract);
  10.473 +	}
  10.474 +
  10.475 +	@Override
  10.476 +	protected void append(GeneralDBSqlMbbInside expr, GeneralDBSqlExprBuilder filter)
  10.477 +			throws UnsupportedRdbmsOperatorException {
  10.478 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside);
  10.479 +	}
  10.480 +
  10.481 +	
  10.482 +	@Override
  10.483 +	protected void append(GeneralDBSqlContainsMBB expr, GeneralDBSqlExprBuilder filter)
  10.484 +			throws UnsupportedRdbmsOperatorException {
  10.485 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.contains);
  10.486 +	}
  10.487 +
  10.488 +	
  10.489 +	@Override
  10.490 +	protected void append(GeneralDBSqlMbbEquals expr, GeneralDBSqlExprBuilder filter)
  10.491 +			throws UnsupportedRdbmsOperatorException {
  10.492 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.equals);
  10.493 +	}
  10.494 +
  10.495 +	//GeoSPARQL - Spatial Relationship Functions 
  10.496 +	//Simple Features
  10.497 +	@Override
  10.498 +	protected void append(GeneralDBSqlSF_Contains expr, GeneralDBSqlExprBuilder filter)
  10.499 +			throws UnsupportedRdbmsOperatorException
  10.500 +			{
  10.501 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Contains);
  10.502 +			}
  10.503 +
  10.504 +	@Override
  10.505 +	protected void append(GeneralDBSqlSF_Crosses expr, GeneralDBSqlExprBuilder filter)
  10.506 +			throws UnsupportedRdbmsOperatorException
  10.507 +			{
  10.508 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Crosses);
  10.509 +			}
  10.510 +
  10.511 +	@Override
  10.512 +	protected void append(GeneralDBSqlSF_Disjoint expr, GeneralDBSqlExprBuilder filter)
  10.513 +			throws UnsupportedRdbmsOperatorException
  10.514 +			{
  10.515 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Disjoint);
  10.516 +			}
  10.517 +
  10.518 +	@Override
  10.519 +	protected void append(GeneralDBSqlSF_Equals expr, GeneralDBSqlExprBuilder filter)
  10.520 +			throws UnsupportedRdbmsOperatorException
  10.521 +			{
  10.522 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Equals);
  10.523 +			}
  10.524 +
  10.525 +	@Override
  10.526 +	protected void append(GeneralDBSqlSF_Intersects expr, GeneralDBSqlExprBuilder filter)
  10.527 +			throws UnsupportedRdbmsOperatorException
  10.528 +			{
  10.529 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Intersects);
  10.530 +			}
  10.531 +
  10.532 +	@Override
  10.533 +	protected void append(GeneralDBSqlSF_Overlaps expr, GeneralDBSqlExprBuilder filter)
  10.534 +			throws UnsupportedRdbmsOperatorException
  10.535 +			{
  10.536 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Overlaps);
  10.537 +			}
  10.538 +
  10.539 +	@Override
  10.540 +	protected void append(GeneralDBSqlSF_Touches expr, GeneralDBSqlExprBuilder filter)
  10.541 +			throws UnsupportedRdbmsOperatorException
  10.542 +			{
  10.543 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Touches);
  10.544 +			}
  10.545 +
  10.546 +	@Override
  10.547 +	protected void append(GeneralDBSqlSF_Within expr, GeneralDBSqlExprBuilder filter)
  10.548 +			throws UnsupportedRdbmsOperatorException
  10.549 +			{
  10.550 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Within);
  10.551 +			}
  10.552 +
  10.553 +	//Egenhofer
  10.554 +	@Override
  10.555 +	protected void append(GeneralDBSqlEgenhofer_CoveredBy expr, GeneralDBSqlExprBuilder filter)
  10.556 +			throws UnsupportedRdbmsOperatorException
  10.557 +			{
  10.558 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_CoveredBy);
  10.559 +			}
  10.560 +
  10.561 +	@Override
  10.562 +	protected void append(GeneralDBSqlEgenhofer_Covers expr, GeneralDBSqlExprBuilder filter)
  10.563 +			throws UnsupportedRdbmsOperatorException
  10.564 +			{
  10.565 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Covers);
  10.566 +			}
  10.567 +
  10.568 +	@Override
  10.569 +	protected void append(GeneralDBSqlEgenhofer_Contains expr, GeneralDBSqlExprBuilder filter)
  10.570 +			throws UnsupportedRdbmsOperatorException
  10.571 +			{
  10.572 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Contains);
  10.573 +			}
  10.574 +
  10.575 +	@Override
  10.576 +	protected void append(GeneralDBSqlEgenhofer_Disjoint expr, GeneralDBSqlExprBuilder filter)
  10.577 +			throws UnsupportedRdbmsOperatorException
  10.578 +			{
  10.579 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Disjoint);
  10.580 +			}
  10.581 +
  10.582 +	@Override
  10.583 +	protected void append(GeneralDBSqlEgenhofer_Equals expr, GeneralDBSqlExprBuilder filter)
  10.584 +			throws UnsupportedRdbmsOperatorException
  10.585 +			{
  10.586 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Equals);
  10.587 +			}
  10.588 +
  10.589 +	@Override
  10.590 +	protected void append(GeneralDBSqlEgenhofer_Inside expr, GeneralDBSqlExprBuilder filter)
  10.591 +			throws UnsupportedRdbmsOperatorException
  10.592 +			{
  10.593 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Inside);
  10.594 +			}
  10.595 +
  10.596 +	@Override
  10.597 +	protected void append(GeneralDBSqlEgenhofer_Meet expr, GeneralDBSqlExprBuilder filter)
  10.598 +			throws UnsupportedRdbmsOperatorException
  10.599 +			{
  10.600 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Meet);
  10.601 +			}
  10.602 +
  10.603 +	@Override
  10.604 +	protected void append(GeneralDBSqlEgenhofer_Overlap expr, GeneralDBSqlExprBuilder filter)
  10.605 +			throws UnsupportedRdbmsOperatorException
  10.606 +			{
  10.607 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Overlap);
  10.608 +			}
  10.609 +
  10.610 +	//RCC8
  10.611 +	@Override
  10.612 +	protected void append(GeneralDBSqlRCC8_Dc expr, GeneralDBSqlExprBuilder filter)
  10.613 +			throws UnsupportedRdbmsOperatorException
  10.614 +			{
  10.615 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Dc);
  10.616 +			}
  10.617 +
  10.618 +	@Override
  10.619 +	protected void append(GeneralDBSqlRCC8_Eq expr, GeneralDBSqlExprBuilder filter)
  10.620 +			throws UnsupportedRdbmsOperatorException
  10.621 +			{
  10.622 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Eq);
  10.623 +			}
  10.624 +
  10.625 +	@Override
  10.626 +	protected void append(GeneralDBSqlRCC8_Ec expr, GeneralDBSqlExprBuilder filter)
  10.627 +			throws UnsupportedRdbmsOperatorException
  10.628 +			{
  10.629 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ec);
  10.630 +			}
  10.631 +
  10.632 +	@Override
  10.633 +	protected void append(GeneralDBSqlRCC8_Po expr, GeneralDBSqlExprBuilder filter)
  10.634 +			throws UnsupportedRdbmsOperatorException
  10.635 +			{
  10.636 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Po);
  10.637 +			}
  10.638 +
  10.639 +	@Override
  10.640 +	protected void append(GeneralDBSqlRCC8_Tppi expr, GeneralDBSqlExprBuilder filter)
  10.641 +			throws UnsupportedRdbmsOperatorException
  10.642 +			{
  10.643 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tppi);
  10.644 +			}
  10.645 +
  10.646 +	@Override
  10.647 +	protected void append(GeneralDBSqlRCC8_Tpp expr, GeneralDBSqlExprBuilder filter)
  10.648 +			throws UnsupportedRdbmsOperatorException
  10.649 +			{
  10.650 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tpp);
  10.651 +			}
  10.652 +
  10.653 +	@Override
  10.654 +	protected void append(GeneralDBSqlRCC8_Ntpp expr, GeneralDBSqlExprBuilder filter)
  10.655 +			throws UnsupportedRdbmsOperatorException
  10.656 +			{
  10.657 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntpp);
  10.658 +			}
  10.659 +
  10.660 +	@Override
  10.661 +	protected void append(GeneralDBSqlRCC8_Ntppi expr, GeneralDBSqlExprBuilder filter)
  10.662 +			throws UnsupportedRdbmsOperatorException
  10.663 +			{
  10.664 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntppi);
  10.665 +			}
  10.666 +
  10.667 +	//Spatial Construct Functions
  10.668 +	@Override
  10.669 +	protected void append(GeneralDBSqlGeoUnion expr, GeneralDBSqlExprBuilder filter)
  10.670 +			throws UnsupportedRdbmsOperatorException
  10.671 +			{
  10.672 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Union);
  10.673 +			}
  10.674 +
  10.675 +	@Override
  10.676 +	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter)
  10.677 +			throws UnsupportedRdbmsOperatorException
  10.678 +			{
  10.679 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Buffer);
  10.680 +			}
  10.681 +
  10.682 +	//XXX Different Behavior
  10.683 +	@Override
  10.684 +	protected void append(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
  10.685 +			throws UnsupportedRdbmsOperatorException
  10.686 +			{
  10.687 +		appendTransformFunc(expr, filter);
  10.688 +			}
  10.689 +
  10.690 +	@Override
  10.691 +	protected void append(GeneralDBSqlGeoEnvelope expr, GeneralDBSqlExprBuilder filter)
  10.692 +			throws UnsupportedRdbmsOperatorException
  10.693 +			{
  10.694 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Envelope);
  10.695 +			}
  10.696 +
  10.697 +	@Override
  10.698 +	protected void append(GeneralDBSqlGeoConvexHull expr, GeneralDBSqlExprBuilder filter)
  10.699 +			throws UnsupportedRdbmsOperatorException
  10.700 +			{
  10.701 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_ConvexHull);
  10.702 +			}
  10.703 +
  10.704 +	@Override
  10.705 +	protected void append(GeneralDBSqlGeoBoundary expr, GeneralDBSqlExprBuilder filter)
  10.706 +			throws UnsupportedRdbmsOperatorException
  10.707 +			{
  10.708 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Boundary);
  10.709 +			}
  10.710 +
  10.711 +	@Override
  10.712 +	protected void append(GeneralDBSqlGeoIntersection expr, GeneralDBSqlExprBuilder filter)
  10.713 +			throws UnsupportedRdbmsOperatorException
  10.714 +			{
  10.715 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersection);
  10.716 +			}
  10.717 +
  10.718 +	@Override
  10.719 +	protected void append(GeneralDBSqlGeoDifference expr, GeneralDBSqlExprBuilder filter)
  10.720 +			throws UnsupportedRdbmsOperatorException
  10.721 +			{
  10.722 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Difference);
  10.723 +			}
  10.724 +
  10.725 +	@Override
  10.726 +	protected void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter)
  10.727 +			throws UnsupportedRdbmsOperatorException
  10.728 +			{
  10.729 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference);
  10.730 +			}
  10.731 +
  10.732 +	//Spatial Metric Functions
  10.733 +	@Override
  10.734 +	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
  10.735 +			throws UnsupportedRdbmsOperatorException
  10.736 +			{
  10.737 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Distance);
  10.738 +			}
  10.739 +
  10.740 +	@Override
  10.741 +	protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter)
  10.742 +			throws UnsupportedRdbmsOperatorException
  10.743 +			{
  10.744 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Area);
  10.745 +			}
  10.746 +
  10.747 +	//Spatial Property Functions
  10.748 +	@Override
  10.749 +	protected void append(GeneralDBSqlGeoDimension expr, GeneralDBSqlExprBuilder filter)
  10.750 +			throws UnsupportedRdbmsOperatorException
  10.751 +			{
  10.752 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Dimension);
  10.753 +			}
  10.754 +
  10.755 +	@Override
  10.756 +	protected void append(GeneralDBSqlGeoGeometryType expr, GeneralDBSqlExprBuilder filter)
  10.757 +			throws UnsupportedRdbmsOperatorException
  10.758 +			{
  10.759 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_GeometryType);
  10.760 +			}
  10.761 +
  10.762 +	@Override
  10.763 +	protected void append(GeneralDBSqlGeoAsText expr, GeneralDBSqlExprBuilder filter)
  10.764 +			throws UnsupportedRdbmsOperatorException
  10.765 +			{
  10.766 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsText);
  10.767 +			}
  10.768 +
  10.769 +	@Override
  10.770 +	protected void append(GeneralDBSqlGeoAsGML expr, GeneralDBSqlExprBuilder filter)
  10.771 +			throws UnsupportedRdbmsOperatorException
  10.772 +			{
  10.773 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsGML);
  10.774 +			}
  10.775 +
  10.776 +	//	@Override
  10.777 +	//	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
  10.778 +	//	throws UnsupportedRdbmsOperatorException
  10.779 +	//	{
  10.780 +	//		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID);
  10.781 +	//	}
  10.782 +
  10.783 +	/**
  10.784 +	 * Special Case because I need to retrieve a single different column from geo_values when this function occurs
  10.785 +	 * in the select clause
  10.786 +	 */
  10.787 +	@Override
  10.788 +	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
  10.789 +			throws UnsupportedRdbmsOperatorException
  10.790 +			{
  10.791 +		boolean sridNeeded = true;
  10.792 +		filter.openBracket();
  10.793 +
  10.794 +		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  10.795 +		boolean check2 = false;
  10.796 +		if(expr.getArg() instanceof GeneralDBLabelColumn)
  10.797 +		{
  10.798 +			if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource())
  10.799 +			{
  10.800 +				check2 = true;
  10.801 +			}
  10.802 +		}
  10.803 +		if(check1)
  10.804 +		{
  10.805 +			this.append((GeneralDBSqlNull)expr.getArg(), filter);
  10.806 +
  10.807 +		}
  10.808 +		else if (check2)
  10.809 +		{
  10.810 +			appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
  10.811 +		}
  10.812 +		else
  10.813 +		{
  10.814 +			//XXX Incorporating SRID
  10.815 +			GeneralDBSqlExpr tmp = expr;
  10.816 +			if(tmp.getParentNode() == null)
  10.817 +			{
  10.818 +				String sridExpr;
  10.819 +				while(true)
  10.820 +				{
  10.821 +					GeneralDBSqlExpr child = null;
  10.822 +
  10.823 +					if(tmp instanceof BinaryGeneralDBOperator)
  10.824 +					{
  10.825 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  10.826 +					}
  10.827 +					else if(tmp instanceof UnaryGeneralDBOperator)
  10.828 +					{
  10.829 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
  10.830 +					}
  10.831 +					else if(tmp instanceof GeneralDBStringValue)
  10.832 +					{
  10.833 +						//Constant!!
  10.834 +						sridNeeded  = false;
  10.835 +						break;
  10.836 +					}
  10.837 +
  10.838 +					tmp = child;
  10.839 +					if(tmp instanceof GeneralDBLabelColumn)
  10.840 +					{
  10.841 +						//Reached the innermost left var -> need to capture its SRID
  10.842 +						String alias;
  10.843 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
  10.844 +							//Predicates used in triple patterns non-existent in db
  10.845 +							alias="NULL";
  10.846 +						}
  10.847 +						else
  10.848 +						{
  10.849 +							//Reached the innermost left var -> need to capture its SRID
  10.850 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  10.851 +							alias=alias+".srid";
  10.852 +						}
  10.853 +						sridExpr = alias;
  10.854 +						filter.append(sridExpr);
  10.855 +						filter.closeBracket();
  10.856 +						return;
  10.857 +						//break;
  10.858 +					}
  10.859 +					else if(tmp instanceof GeneralDBStringValue)
  10.860 +					{
  10.861 +						//Constant!!
  10.862 +						sridNeeded  = false;
  10.863 +						break;
  10.864 +					}
  10.865 +
  10.866 +				}
  10.867 +			}
  10.868 +
  10.869 +			if(sridNeeded)
  10.870 +			{
  10.871 +				filter.appendFunction("ST_SRID");
  10.872 +				filter.openBracket();
  10.873 +				if(expr.getArg() instanceof GeneralDBStringValue)
  10.874 +				{
  10.875 +					appendWKT(expr.getArg(),filter);
  10.876 +				}
  10.877 +				else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary)
  10.878 +				{
  10.879 +					appendConstructFunction(expr.getArg(), filter);
  10.880 +				}
  10.881 +				else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary)
  10.882 +				{
  10.883 +					appendConstructFunction(expr.getArg(), filter);
  10.884 +				}
  10.885 +				else if(expr.getArg() instanceof GeneralDBSqlCase)
  10.886 +				{
  10.887 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
  10.888 +					appendMBB(onlyLabel,filter); 
  10.889 +				}
  10.890 +				else
  10.891 +				{
  10.892 +					appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
  10.893 +				}
  10.894 +
  10.895 +				filter.closeBracket();
  10.896 +			}
  10.897 +			else
  10.898 +			{
  10.899 +				//4326 by default - Software House additions
  10.900 +				filter.append("4326");
  10.901 +			}
  10.902 +		}
  10.903 +
  10.904 +		filter.closeBracket();
  10.905 +			}
  10.906 +
  10.907 +	@Override
  10.908 +	protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter)
  10.909 +			throws UnsupportedRdbmsOperatorException
  10.910 +			{
  10.911 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsSimple);
  10.912 +			}
  10.913 +
  10.914 +	@Override
  10.915 +	protected void append(GeneralDBSqlGeoIsEmpty expr, GeneralDBSqlExprBuilder filter)
  10.916 +			throws UnsupportedRdbmsOperatorException
  10.917 +			{
  10.918 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty);
  10.919 +			}
  10.920 +
  10.921 +
  10.922 +	/**
  10.923 +	 * 'helper' functions
  10.924 +	 */
  10.925 +
  10.926 +	@Override
  10.927 +	protected String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter)
  10.928 +	{
  10.929 +		GeneralDBStringValue arg = (GeneralDBStringValue) expr;
  10.930 +		String raw = arg.getValue();
  10.931 +
  10.932 +		StrabonPolyhedron poly = null;
  10.933 +		try{
  10.934 +			poly = new StrabonPolyhedron(raw);
  10.935 +		} catch (Exception e) {
  10.936 +			e.printStackTrace();
  10.937 +		}
  10.938 +
  10.939 +		filter.append(" ST_GeomFromText('"+poly.toWKT() +"',4326)");
  10.940 +
  10.941 +		return raw;
  10.942 +	}
  10.943 +
  10.944 +	//Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 
  10.945 +	//	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
  10.946 +	//	{
  10.947 +	//		filter.openBracket();
  10.948 +	//
  10.949 +	//		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  10.950 +	//		//boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  10.951 +	//
  10.952 +	//		if(check1a)
  10.953 +	//		{
  10.954 +	//			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  10.955 +	//
  10.956 +	//		}
  10.957 +	////		else if(check2a)
  10.958 +	////		{
  10.959 +	////			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
  10.960 +	////		}
  10.961 +	//		else
  10.962 +	//		{
  10.963 +	//			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  10.964 +	//			{
  10.965 +	//				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
  10.966 +	//			}
  10.967 +	//			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
  10.968 +	//			{
  10.969 +	//				appendWKT(expr.getLeftArg(),filter);
  10.970 +	//			}
  10.971 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
  10.972 +	//			{
  10.973 +	//				appendConstructFunction(expr.getLeftArg(), filter);
  10.974 +	//			}
  10.975 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
  10.976 +	//			{
  10.977 +	//				appendConstructFunction(expr.getLeftArg(), filter);
  10.978 +	//			}
  10.979 +	//			else
  10.980 +	//			{
  10.981 +	//				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
  10.982 +	//			}
  10.983 +	//
  10.984 +	//			switch(operand)
  10.985 +	//			{
  10.986 +	//			case anyInteract: filter.anyInteract(); break;
  10.987 +	//			case equals: filter.equals(); break;
  10.988 +	//			case contains: filter.contains(); break;
  10.989 +	//			case inside: filter.inside(); break;
  10.990 +	//			case left: filter.left(); break;
  10.991 +	//			case right: filter.right(); break;
  10.992 +	//			case above: filter.above(); break;
  10.993 +	//			case below: filter.below(); break;
  10.994 +	//			}
  10.995 +	//
  10.996 +	//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  10.997 +	//
  10.998 +	//			if(check2a)
  10.999 +	//			{
 10.1000 +	//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1001 +	//			}
 10.1002 +	//			else
 10.1003 +	//			{
 10.1004 +	//
 10.1005 +	//				if(expr.getRightArg() instanceof GeneralDBSqlCase)
 10.1006 +	//				{
 10.1007 +	//					this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
 10.1008 +	//				}
 10.1009 +	//				else if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.1010 +	//				{
 10.1011 +	//					appendWKT(expr.getRightArg(),filter);
 10.1012 +	//				}
 10.1013 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1014 +	//				{
 10.1015 +	//					appendConstructFunction(expr.getRightArg(), filter);
 10.1016 +	//				}
 10.1017 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1018 +	//				{
 10.1019 +	//					appendConstructFunction(expr.getRightArg(), filter);
 10.1020 +	//				}
 10.1021 +	//				else
 10.1022 +	//				{
 10.1023 +	//					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 10.1024 +	//				}
 10.1025 +	//
 10.1026 +	//			}
 10.1027 +	//		}
 10.1028 +	//		filter.closeBracket();
 10.1029 +	//	}
 10.1030 +
 10.1031 +
 10.1032 +	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
 10.1033 +	{
 10.1034 +		filter.openBracket();
 10.1035 +
 10.1036 +		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1037 +		boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1038 +
 10.1039 +		if(check1a)
 10.1040 +		{
 10.1041 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1042 +
 10.1043 +		}
 10.1044 +		else if(check2a)
 10.1045 +		{
 10.1046 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1047 +		}
 10.1048 +		else
 10.1049 +		{
 10.1050 +			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 10.1051 +			{
 10.1052 +				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
 10.1053 +			}
 10.1054 +			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
 10.1055 +			{
 10.1056 +				appendWKT(expr.getLeftArg(),filter);
 10.1057 +			}
 10.1058 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1059 +			{
 10.1060 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1061 +			}
 10.1062 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1063 +			{
 10.1064 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1065 +			}
 10.1066 +			else
 10.1067 +			{
 10.1068 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 10.1069 +			}
 10.1070 +
 10.1071 +			switch(operand)
 10.1072 +			{
 10.1073 +			case anyInteract: filter.intersectsMBB(); break;
 10.1074 +			case equals: filter.equalsMBB(); break;
 10.1075 +			case contains: filter.containsMBB(); break;
 10.1076 +			case inside: filter.insideMBB(); break;
 10.1077 +			case left: filter.leftMBB(); break;
 10.1078 +			case right: filter.rightMBB(); break;
 10.1079 +			case above: filter.aboveMBB(); break;
 10.1080 +			case below: filter.belowMBB(); break;
 10.1081 +			}
 10.1082 +
 10.1083 +			//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1084 +			//
 10.1085 +			//			if(check2a)
 10.1086 +			//			{
 10.1087 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1088 +			//			}
 10.1089 +			//			else
 10.1090 +			//			{
 10.1091 +
 10.1092 +			if(expr.getRightArg() instanceof GeneralDBSqlCase)
 10.1093 +			{
 10.1094 +				this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
 10.1095 +			}
 10.1096 +			else if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.1097 +			{
 10.1098 +				appendWKT(expr.getRightArg(),filter);
 10.1099 +			}
 10.1100 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1101 +			{
 10.1102 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1103 +			}
 10.1104 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1105 +			{
 10.1106 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1107 +			}
 10.1108 +			else
 10.1109 +			{
 10.1110 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 10.1111 +			}
 10.1112 +
 10.1113 +			//}
 10.1114 +		}
 10.1115 +		filter.closeBracket();
 10.1116 +	}
 10.1117 +
 10.1118 +	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
 10.1119 +	protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
 10.1120 +			throws UnsupportedRdbmsOperatorException
 10.1121 +			{
 10.1122 +		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
 10.1123 +		boolean sridNeeded = true;
 10.1124 +		//XXX Incorporating SRID
 10.1125 +		String sridExpr = null;
 10.1126 +
 10.1127 +		filter.openBracket();
 10.1128 +		filter.appendFunction(ST_TRANSFORM);
 10.1129 +		filter.openBracket();
 10.1130 +
 10.1131 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1132 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1133 +
 10.1134 +		if(check1)
 10.1135 +		{
 10.1136 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1137 +
 10.1138 +		}
 10.1139 +		else if(check2)
 10.1140 +		{
 10.1141 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1142 +		}
 10.1143 +		else
 10.1144 +		{
 10.1145 +			GeneralDBSqlExpr tmp = expr;
 10.1146 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
 10.1147 +			{
 10.1148 +				while(true)
 10.1149 +				{
 10.1150 +					GeneralDBSqlExpr child;
 10.1151 +
 10.1152 +					if(tmp instanceof BinaryGeneralDBOperator)
 10.1153 +					{
 10.1154 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
 10.1155 +					}
 10.1156 +					else //(tmp instanceof UnaryGeneralDBOperator)
 10.1157 +					{
 10.1158 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
 10.1159 +					}
 10.1160 +
 10.1161 +					tmp = child;
 10.1162 +					if(tmp instanceof GeneralDBLabelColumn)
 10.1163 +					{
 10.1164 +						String alias;
 10.1165 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
 10.1166 +							//Predicates used in triple patterns non-existent in db
 10.1167 +							alias="NULL";
 10.1168 +						}
 10.1169 +						else
 10.1170 +						{
 10.1171 +							//Reached the innermost left var -> need to capture its SRID
 10.1172 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
 10.1173 +							alias=alias+".srid";
 10.1174 +						}
 10.1175 +						sridExpr = alias;
 10.1176 +						break;
 10.1177 +					}
 10.1178 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
 10.1179 +					{
 10.1180 +						sridNeeded  = false;
 10.1181 +						break;
 10.1182 +					}
 10.1183 +
 10.1184 +				}
 10.1185 +				if(sridNeeded)
 10.1186 +				{
 10.1187 +					filter.appendFunction(ST_TRANSFORM);
 10.1188 +					filter.openBracket();
 10.1189 +				}
 10.1190 +			}
 10.1191 +
 10.1192 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 10.1193 +			{
 10.1194 +				appendWKT(expr.getLeftArg(),filter);
 10.1195 +			}
 10.1196 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1197 +			{
 10.1198 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1199 +			}
 10.1200 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1201 +			{
 10.1202 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1203 +			}
 10.1204 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 10.1205 +			{
 10.1206 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 10.1207 +				appendMBB(onlyLabel,filter); 
 10.1208 +			}
 10.1209 +			else
 10.1210 +			{
 10.1211 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 10.1212 +			}
 10.1213 +
 10.1214 +			//SRID Support
 10.1215 +			if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
 10.1216 +			{
 10.1217 +				filter.appendComma();
 10.1218 +				//filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid());
 10.1219 +				filter.append(sridExpr);
 10.1220 +				filter.closeBracket();
 10.1221 +			}
 10.1222 +
 10.1223 +			filter.appendComma();
 10.1224 +
 10.1225 +			if(expr.getRightArg() instanceof GeneralDBSqlCase) //case met in transform!
 10.1226 +			{
 10.1227 +				GeneralDBURIColumn plainURI = (GeneralDBURIColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 10.1228 +
 10.1229 +				//XXX This case would be met if we recovered the SRID URI from the db!!!
 10.1230 +				//Need to set sridExpr to the value of this new URI, otherwise the appended uri
 10.1231 +				//to the spatial object will be the wrong one!!!! (Seee following case)
 10.1232 +				filter.keepSRID_part1();
 10.1233 +				append(plainURI, filter);
 10.1234 +				filter.keepSRID_part2();
 10.1235 +				append(plainURI, filter);
 10.1236 +				filter.keepSRID_part3();
 10.1237 +			}
 10.1238 +			else if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.1239 +			{
 10.1240 +				String unparsedSRID = ((GeneralDBStringValue)expr.getRightArg()).getValue();
 10.1241 +				//				int srid = Integer.parseInt(unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1));
 10.1242 +				sridExpr = unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1);
 10.1243 +				filter.append(sridExpr);
 10.1244 +				filter.closeBracket();
 10.1245 +			}
 10.1246 +
 10.1247 +
 10.1248 +		}
 10.1249 +		filter.closeBracket();
 10.1250 +		//In this case, SRID is the one that has been provided by the user!! 
 10.1251 +		//I am including this extra binding to be used in subsequent (Aggregate) steps
 10.1252 +		if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
 10.1253 +		{
 10.1254 +			filter.appendComma();
 10.1255 +			filter.append(sridExpr);
 10.1256 +		}
 10.1257 +
 10.1258 +			}
 10.1259 +
 10.1260 +	/** Addition for datetime metric functions
 10.1261 +	 * 
 10.1262 +	 * @author George Garbis <ggarbis@di.uoa.gr>
 10.1263 +	 * 
 10.1264 +	 */
 10.1265 +	
 10.1266 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionsPostGIS func)
 10.1267 +	throws UnsupportedRdbmsOperatorException
 10.1268 +	{
 10.1269 +
 10.1270 +		filter.openBracket();
 10.1271 +
 10.1272 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1273 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1274 +
 10.1275 +		if(check1)
 10.1276 +		{
 10.1277 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1278 +
 10.1279 +		}
 10.1280 +		else if(check2)
 10.1281 +		{
 10.1282 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1283 +		}
 10.1284 +		else
 10.1285 +		{			
 10.1286 +			switch (func){
 10.1287 +			case Difference:
 10.1288 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 10.1289 +				filter.append(" - ");
 10.1290 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 10.1291 +				break;
 10.1292 +			}
 10.1293 +			
 10.1294 +		}
 10.1295 +	}
 10.1296 +
 10.1297 +	// Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1, ?GEO2)
 10.1298 +	// EXCEPT ST_Transform!!! 
 10.1299 +	protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 10.1300 +			throws UnsupportedRdbmsOperatorException
 10.1301 +			{
 10.1302 +		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
 10.1303 +		boolean sridNeeded = true;
 10.1304 +		String sridExpr = null;
 10.1305 +
 10.1306 +		filter.openBracket();
 10.1307 +
 10.1308 +		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1309 +		boolean check2 = false;
 10.1310 +		if(expr.getArg() instanceof GeneralDBLabelColumn)
 10.1311 +		{
 10.1312 +			if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource())
 10.1313 +			{
 10.1314 +				check2 = true;
 10.1315 +			}
 10.1316 +		}
 10.1317 +		if(check1)
 10.1318 +		{
 10.1319 +			this.append((GeneralDBSqlNull)expr.getArg(), filter);
 10.1320 +
 10.1321 +		}
 10.1322 +		else if (check2)
 10.1323 +		{
 10.1324 +			appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
 10.1325 +		}
 10.1326 +		else
 10.1327 +		{
 10.1328 +
 10.1329 +			GeneralDBSqlExpr tmp = expr;
 10.1330 +
 10.1331 +
 10.1332 +			if(tmp instanceof GeneralDBSqlSpatialConstructUnary && tmp.getParentNode() == null)
 10.1333 +			{
 10.1334 +				while(true)
 10.1335 +				{
 10.1336 +					GeneralDBSqlExpr child = null;
 10.1337 +
 10.1338 +					if(tmp instanceof BinaryGeneralDBOperator)
 10.1339 +					{
 10.1340 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
 10.1341 +					}
 10.1342 +					else if(tmp instanceof UnaryGeneralDBOperator)
 10.1343 +					{
 10.1344 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
 10.1345 +					}
 10.1346 +					else if(tmp instanceof GeneralDBStringValue)
 10.1347 +					{
 10.1348 +						sridNeeded  = false;
 10.1349 +						break;
 10.1350 +					}
 10.1351 +
 10.1352 +					tmp = child;
 10.1353 +					if(tmp instanceof GeneralDBLabelColumn)
 10.1354 +					{
 10.1355 +						//Reached the innermost left var -> need to capture its SRID
 10.1356 +						String alias;
 10.1357 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
 10.1358 +							//Predicates used in triple patterns non-existent in db
 10.1359 +							alias="NULL";
 10.1360 +						}
 10.1361 +						else
 10.1362 +						{
 10.1363 +							//Reached the innermost left var -> need to capture its SRID
 10.1364 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
 10.1365 +							alias=alias+".srid";
 10.1366 +						}
 10.1367 +						sridExpr = alias;
 10.1368 +						break;
 10.1369 +					}
 10.1370 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
 10.1371 +					{
 10.1372 +						sridNeeded  = false;
 10.1373 +						break;
 10.1374 +					}
 10.1375 +
 10.1376 +				}
 10.1377 +				if(sridNeeded)
 10.1378 +				{
 10.1379 +					filter.appendFunction(ST_TRANSFORM);
 10.1380 +					filter.openBracket();
 10.1381 +				}
 10.1382 +			}
 10.1383 +			/////
 10.1384 +
 10.1385 +			switch(func)
 10.1386 +			{
 10.1387 +			case ST_Envelope: filter.appendFunction("ST_Envelope"); break;
 10.1388 +			case ST_ConvexHull: filter.appendFunction("ST_ConvexHull"); break;
 10.1389 +			case ST_Boundary: filter.appendFunction("ST_Boundary"); break;
 10.1390 +			case ST_Area: filter.appendFunction("ST_Area"); break;
 10.1391 +			case ST_Dimension: filter.appendFunction("ST_Dimension"); break;
 10.1392 +			case ST_GeometryType: filter.appendFunction("ST_GeometryType"); break;
 10.1393 +			case ST_AsText: filter.appendFunction("ST_AsText"); break;
 10.1394 +			case ST_AsGML: filter.appendFunction("ST_AsGML"); break;
 10.1395 +			case ST_SRID: filter.appendFunction("ST_SRID"); break;
 10.1396 +			case ST_IsEmpty: filter.appendFunction("ST_IsEmpty"); break;
 10.1397 +			case ST_IsSimple: filter.appendFunction("ST_IsSimple"); break;
 10.1398 +			}
 10.1399 +			filter.openBracket();
 10.1400 +			if(expr.getArg() instanceof GeneralDBStringValue)
 10.1401 +			{
 10.1402 +				appendWKT(expr.getArg(),filter);
 10.1403 +			}
 10.1404 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1405 +			{
 10.1406 +				appendConstructFunction(expr.getArg(), filter);
 10.1407 +			}
 10.1408 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1409 +			{
 10.1410 +				appendConstructFunction(expr.getArg(), filter);
 10.1411 +			}
 10.1412 +			else if(expr.getArg() instanceof GeneralDBSqlCase)
 10.1413 +			{
 10.1414 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
 10.1415 +				appendMBB(onlyLabel,filter); 
 10.1416 +			}
 10.1417 +			else
 10.1418 +			{
 10.1419 +				appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
 10.1420 +			}
 10.1421 +
 10.1422 +			filter.closeBracket();
 10.1423 +			//			//SRID Support
 10.1424 +			if(sridNeeded)
 10.1425 +			{
 10.1426 +				if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
 10.1427 +				{
 10.1428 +					filter.appendComma();
 10.1429 +					//				filter.append(((GeneralDBSqlSpatialConstructUnary)expr).getSrid());
 10.1430 +					filter.append(sridExpr);
 10.1431 +					filter.closeBracket();
 10.1432 +				}
 10.1433 +			}
 10.1434 +			///
 10.1435 +		}
 10.1436 +
 10.1437 +		filter.closeBracket();
 10.1438 +		//Used to explicitly include SRID
 10.1439 +		if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
 10.1440 +		{
 10.1441 +			filter.appendComma();
 10.1442 +			filter.append(sridExpr);
 10.1443 +		}
 10.1444 +			}
 10.1445 +
 10.1446 +	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
 10.1447 +	protected void appendGeneralDBSpatialFunctionTriple(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 10.1448 +			throws UnsupportedRdbmsOperatorException
 10.1449 +			{
 10.1450 +		filter.openBracket();
 10.1451 +
 10.1452 +		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1453 +		boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1454 +		boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1455 +
 10.1456 +		if(check1a)
 10.1457 +		{
 10.1458 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1459 +
 10.1460 +		}
 10.1461 +		else if(check2a)
 10.1462 +		{
 10.1463 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1464 +		}
 10.1465 +		else if(check3)
 10.1466 +		{
 10.1467 +			this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
 10.1468 +		}
 10.1469 +		else
 10.1470 +		{
 10.1471 +			switch(func)
 10.1472 +			{
 10.1473 +			case ST_Relate: filter.appendFunction("ST_Relate"); break;
 10.1474 +			}
 10.1475 +			filter.openBracket();
 10.1476 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 10.1477 +			{
 10.1478 +				appendWKT(expr.getLeftArg(),filter);
 10.1479 +			}
 10.1480 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1481 +			{
 10.1482 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1483 +			}
 10.1484 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1485 +			{
 10.1486 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1487 +			}
 10.1488 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 10.1489 +			{
 10.1490 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 10.1491 +				appendMBB(onlyLabel,filter); 
 10.1492 +			}
 10.1493 +			else
 10.1494 +			{
 10.1495 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 10.1496 +			}
 10.1497 +			filter.appendComma();
 10.1498 +			//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1499 +			//			if(check2)
 10.1500 +			//			{
 10.1501 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1502 +			//			}
 10.1503 +			//			else
 10.1504 +			//			{
 10.1505 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.1506 +			{
 10.1507 +				appendWKT(expr.getRightArg(),filter);
 10.1508 +			}
 10.1509 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1510 +			{
 10.1511 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1512 +			}
 10.1513 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1514 +			{
 10.1515 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1516 +			}
 10.1517 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 10.1518 +			{
 10.1519 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 10.1520 +				appendMBB(onlyLabel,filter);					 
 10.1521 +			}
 10.1522 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 10.1523 +			{
 10.1524 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 10.1525 +			}
 10.1526 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 10.1527 +			{
 10.1528 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 10.1529 +			}
 10.1530 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 10.1531 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 10.1532 +			{
 10.1533 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 10.1534 +				appendCastToDouble(filter);
 10.1535 +			}
 10.1536 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 10.1537 +			{
 10.1538 +				appendMetricFunction(expr.getRightArg(), filter);
 10.1539 +			}
 10.1540 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 10.1541 +			{
 10.1542 +				appendMetricFunction(expr.getRightArg(), filter);
 10.1543 +			}
 10.1544 +			else
 10.1545 +			{
 10.1546 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 10.1547 +			}
 10.1548 +
 10.1549 +			//			}
 10.1550 +			//3rd arg
 10.1551 +			filter.appendComma();
 10.1552 +			//			boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1553 +			//			if(check3)
 10.1554 +			//			{
 10.1555 +			//				this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
 10.1556 +			//			}
 10.1557 +			//			else
 10.1558 +			//			{
 10.1559 +
 10.1560 +			if(expr.getThirdArg() instanceof GeneralDBStringValue)
 10.1561 +			{
 10.1562 +				append(((GeneralDBStringValue)expr.getThirdArg()),filter);	
 10.1563 +			}
 10.1564 +			else if(expr.getThirdArg() instanceof GeneralDBSqlCase)
 10.1565 +			{
 10.1566 +				append(((GeneralDBSqlCase)expr.getThirdArg()),filter);				 
 10.1567 +			}
 10.1568 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 10.1569 +			else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial())
 10.1570 +			{
 10.1571 +
 10.1572 +				append(((GeneralDBLabelColumn)expr.getThirdArg()),filter);
 10.1573 +			}
 10.1574 +
 10.1575 +
 10.1576 +			//			}
 10.1577 +			filter.closeBracket();
 10.1578 +		}
 10.1579 +
 10.1580 +		filter.closeBracket();
 10.1581 +			}
 10.1582 +
 10.1583 +
 10.1584 +	//GeoSPARQL
 10.1585 +	//XXX
 10.1586 +	protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern)
 10.1587 +			throws UnsupportedRdbmsOperatorException
 10.1588 +			{
 10.1589 +		filter.openBracket();
 10.1590 +
 10.1591 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1592 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1593 +
 10.1594 +		if(check1)
 10.1595 +		{
 10.1596 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1597 +
 10.1598 +		}
 10.1599 +		else if(check2)
 10.1600 +		{
 10.1601 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.1602 +		}
 10.1603 +		else
 10.1604 +		{	
 10.1605 +			filter.appendFunction("ST_Relate");
 10.1606 +
 10.1607 +
 10.1608 +			filter.openBracket();
 10.1609 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 10.1610 +			{
 10.1611 +				appendWKT(expr.getLeftArg(),filter);
 10.1612 +			}
 10.1613 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1614 +			{
 10.1615 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1616 +			}
 10.1617 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1618 +			{
 10.1619 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.1620 +			}
 10.1621 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 10.1622 +			{
 10.1623 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 10.1624 +				appendMBB(onlyLabel,filter); 
 10.1625 +			}
 10.1626 +			else
 10.1627 +			{
 10.1628 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 10.1629 +			}
 10.1630 +			filter.appendComma();
 10.1631 +
 10.1632 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.1633 +			{
 10.1634 +				appendWKT(expr.getRightArg(),filter);
 10.1635 +			}
 10.1636 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.1637 +			{
 10.1638 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1639 +			}
 10.1640 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.1641 +			{
 10.1642 +				appendConstructFunction(expr.getRightArg(), filter);
 10.1643 +			}
 10.1644 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 10.1645 +			{
 10.1646 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 10.1647 +				appendMBB(onlyLabel,filter);					 
 10.1648 +			}
 10.1649 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 10.1650 +			{
 10.1651 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 10.1652 +			}
 10.1653 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 10.1654 +			{
 10.1655 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 10.1656 +			}
 10.1657 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 10.1658 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 10.1659 +			{
 10.1660 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 10.1661 +				appendCastToDouble(filter);
 10.1662 +			}
 10.1663 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 10.1664 +			{
 10.1665 +				appendMetricFunction(expr.getRightArg(), filter);
 10.1666 +			}
 10.1667 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 10.1668 +			{
 10.1669 +				appendMetricFunction(expr.getRightArg(), filter);
 10.1670 +			}
 10.1671 +			else
 10.1672 +			{
 10.1673 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 10.1674 +			}
 10.1675 +
 10.1676 +			//3rd arg
 10.1677 +			filter.appendComma();
 10.1678 +
 10.1679 +			//must turn the table of characters I have to a valid sql value!
 10.1680 +			filter.append("'");
 10.1681 +			for(int i = 0; i< intersectionPattern.length; i++)
 10.1682 +			{
 10.1683 +				filter.append(intersectionPattern[i]+"");
 10.1684 +			}
 10.1685 +			filter.append("'");
 10.1686 +
 10.1687 +			filter.closeBracket();
 10.1688 +
 10.1689 +		}
 10.1690 +
 10.1691 +		filter.closeBracket();
 10.1692 +			}
 10.1693 +
 10.1694 +
 10.1695 +	protected void appendgeoSPARQLSpatialRelation(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 10.1696 +			throws UnsupportedRdbmsOperatorException
 10.1697 +			{
 10.1698 +		filter.openBracket();
 10.1699 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.1700 +		if(check1)
 10.1701 +		{
 10.1702 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.1703 +
 10.1704 +		}
 10.1705 +		else
 10.1706 +		{
 10.1707 +			char[][] intersectionPattern = null;
 10.1708 +			switch(func)
 10.1709 +			{
 10.1710 +			case ST_Covers: 
 10.1711 +				intersectionPattern = new char[1][9];
 10.1712 +				intersectionPattern[0][0] = 'T';
 10.1713 +				intersectionPattern[0][1] = '*';
 10.1714 +				intersectionPattern[0][2] = 'T';
 10.1715 +				intersectionPattern[0][3] = 'F';
 10.1716 +				intersectionPattern[0][4] = 'T';
 10.1717 +				intersectionPattern[0][5] = '*';
 10.1718 +				intersectionPattern[0][6] = 'F';
 10.1719 +				intersectionPattern[0][7] = 'F';
 10.1720 +				intersectionPattern[0][8] = '*';
 10.1721 +				break;
 10.1722 +			case ST_CoveredBy: 
 10.1723 +				intersectionPattern = new char[1][9];
 10.1724 +				intersectionPattern[0][0] = 'T';
 10.1725 +				intersectionPattern[0][1] = 'F';
 10.1726 +				intersectionPattern[0][2] = 'F';
 10.1727 +				intersectionPattern[0][3] = '*';
 10.1728 +				intersectionPattern[0][4] = 'T';
 10.1729 +				intersectionPattern[0][5] = 'F';
 10.1730 +				intersectionPattern[0][6] = 'T';
 10.1731 +				intersectionPattern[0][7] = '*';
 10.1732 +				intersectionPattern[0][8] = '*';
 10.1733 +				break;
 10.1734 +			case SF_Contains:  
 10.1735 +				intersectionPattern = new char[1][9];
 10.1736 +				intersectionPattern[0][0] = 'T';
 10.1737 +				intersectionPattern[0][1] = '*';
 10.1738 +				intersectionPattern[0][2] = '*';
 10.1739 +				intersectionPattern[0][3] = '*';
 10.1740 +				intersectionPattern[0][4] = '*';
 10.1741 +				intersectionPattern[0][5] = '*';
 10.1742 +				intersectionPattern[0][6] = 'F';
 10.1743 +				intersectionPattern[0][7] = 'F';
 10.1744 +				intersectionPattern[0][8] = '*';
 10.1745 +				break;
 10.1746 +			case SF_Crosses:  
 10.1747 +				intersectionPattern = new char[1][9];
 10.1748 +				intersectionPattern[0][0] = 'T';
 10.1749 +				intersectionPattern[0][1] = '*';
 10.1750 +				intersectionPattern[0][2] = 'T';
 10.1751 +				intersectionPattern[0][3] = '*';
 10.1752 +				intersectionPattern[0][4] = '*';
 10.1753 +				intersectionPattern[0][5] = '*';
 10.1754 +				intersectionPattern[0][6] = '*';
 10.1755 +				intersectionPattern[0][7] = '*';
 10.1756 +				intersectionPattern[0][8] = '*';
 10.1757 +				break;
 10.1758 +			case SF_Disjoint:
 10.1759 +			case EH_Disjoint:
 10.1760 +				intersectionPattern = new char[1][9];
 10.1761 +				intersectionPattern[0][0] = 'F';
 10.1762 +				intersectionPattern[0][1] = 'F';
 10.1763 +				intersectionPattern[0][2] = '*';
 10.1764 +				intersectionPattern[0][3] = 'F';
 10.1765 +				intersectionPattern[0][4] = 'F';
 10.1766 +				intersectionPattern[0][5] = '*';
 10.1767 +				intersectionPattern[0][6] = '*';
 10.1768 +				intersectionPattern[0][7] = '*';
 10.1769 +				intersectionPattern[0][8] = '*';
 10.1770 +				break;
 10.1771 +			case SF_Equals: 
 10.1772 +			case EH_Equals:
 10.1773 +			case RCC8_Eq:	
 10.1774 +				intersectionPattern = new char[1][9];
 10.1775 +				intersectionPattern[0][0] = 'T';
 10.1776 +				intersectionPattern[0][1] = 'F';
 10.1777 +				intersectionPattern[0][2] = 'F';
 10.1778 +				intersectionPattern[0][3] = 'F';
 10.1779 +				intersectionPattern[0][4] = 'T';
 10.1780 +				intersectionPattern[0][5] = 'F';
 10.1781 +				intersectionPattern[0][6] = 'F';
 10.1782 +				intersectionPattern[0][7] = 'F';
 10.1783 +				intersectionPattern[0][8] = 'T';
 10.1784 +				break;
 10.1785 +			case SF_Overlaps:
 10.1786 +			case EH_Overlap:
 10.1787 +				intersectionPattern = new char[1][9];
 10.1788 +				intersectionPattern[0][0] = 'T';
 10.1789 +				intersectionPattern[0][1] = '*';
 10.1790 +				intersectionPattern[0][2] = 'T';
 10.1791 +				intersectionPattern[0][3] = '*';
 10.1792 +				intersectionPattern[0][4] = '*';
 10.1793 +				intersectionPattern[0][5] = '*';
 10.1794 +				intersectionPattern[0][6] = 'T';
 10.1795 +				intersectionPattern[0][7] = '*';
 10.1796 +				intersectionPattern[0][8] = '*';
 10.1797 +				break;
 10.1798 +			case SF_Within: 
 10.1799 +				intersectionPattern = new char[1][9];
 10.1800 +				intersectionPattern[0][0] = 'T';
 10.1801 +				intersectionPattern[0][1] = '*';
 10.1802 +				intersectionPattern[0][2] = 'F';
 10.1803 +				intersectionPattern[0][3] = '*';
 10.1804 +				intersectionPattern[0][4] = '*';
 10.1805 +				intersectionPattern[0][5] = 'F';
 10.1806 +				intersectionPattern[0][6] = '*';
 10.1807 +				intersectionPattern[0][7] = '*';
 10.1808 +				intersectionPattern[0][8] = '*';
 10.1809 +				break;
 10.1810 +			case EH_Covers: 
 10.1811 +				intersectionPattern = new char[1][9];
 10.1812 +				intersectionPattern[0][0] = 'T';
 10.1813 +				intersectionPattern[0][1] = '*';
 10.1814 +				intersectionPattern[0][2] = 'T';
 10.1815 +				intersectionPattern[0][3] = 'F';
 10.1816 +				intersectionPattern[0][4] = 'T';
 10.1817 +				intersectionPattern[0][5] = '*';
 10.1818 +				intersectionPattern[0][6] = 'F';
 10.1819 +				intersectionPattern[0][7] = 'F';
 10.1820 +				intersectionPattern[0][8] = '*';
 10.1821 +				break;
 10.1822 +			case EH_CoveredBy: 
 10.1823 +				intersectionPattern = new char[1][9];
 10.1824 +				intersectionPattern[0][0] = 'T';
 10.1825 +				intersectionPattern[0][1] = 'F';
 10.1826 +				intersectionPattern[0][2] = 'F';
 10.1827 +				intersectionPattern[0][3] = '*';
 10.1828 +				intersectionPattern[0][4] = 'T';
 10.1829 +				intersectionPattern[0][5] = 'F';
 10.1830 +				intersectionPattern[0][6] = 'T';
 10.1831 +				intersectionPattern[0][7] = '*';
 10.1832 +				intersectionPattern[0][8] = '*';
 10.1833 +				break;
 10.1834 +			case EH_Inside: 
 10.1835 +				intersectionPattern = new char[1][9];
 10.1836 +				intersectionPattern[0][0] = 'T';
 10.1837 +				intersectionPattern[0][1] = 'F';
 10.1838 +				intersectionPattern[0][2] = 'F';
 10.1839 +				intersectionPattern[0][3] = '*';
 10.1840 +				intersectionPattern[0][4] = 'F';
 10.1841 +				intersectionPattern[0][5] = 'F';
 10.1842 +				intersectionPattern[0][6] = 'T';
 10.1843 +				intersectionPattern[0][7] = '*';
 10.1844 +				intersectionPattern[0][8] = '*';
 10.1845 +				break;
 10.1846 +			case EH_Contains: 
 10.1847 +				intersectionPattern = new char[1][9];
 10.1848 +				intersectionPattern[0][0] = 'T';
 10.1849 +				intersectionPattern[0][1] = '*';
 10.1850 +				intersectionPattern[0][2] = 'T';
 10.1851 +				intersectionPattern[0][3] = 'F';
 10.1852 +				intersectionPattern[0][4] = 'F';
 10.1853 +				intersectionPattern[0][5] = '*';
 10.1854 +				intersectionPattern[0][6] = 'F';
 10.1855 +				intersectionPattern[0][7] = 'F';
 10.1856 +				intersectionPattern[0][8] = '*';
 10.1857 +				break;
 10.1858 +			case RCC8_Dc:	
 10.1859 +				intersectionPattern = new char[1][9];
 10.1860 +				intersectionPattern[0][0] = 'F';
 10.1861 +				intersectionPattern[0][1] = 'F';
 10.1862 +				intersectionPattern[0][2] = 'T';
 10.1863 +				intersectionPattern[0][3] = 'F';
 10.1864 +				intersectionPattern[0][4] = 'F';
 10.1865 +				intersectionPattern[0][5] = 'T';
 10.1866 +				intersectionPattern[0][6] = 'T';
 10.1867 +				intersectionPattern[0][7] = 'T';
 10.1868 +				intersectionPattern[0][8] = 'T';
 10.1869 +				break;
 10.1870 +			case RCC8_Ec:	
 10.1871 +				intersectionPattern = new char[1][9];
 10.1872 +				intersectionPattern[0][0] = 'F';
 10.1873 +				intersectionPattern[0][1] = 'F';
 10.1874 +				intersectionPattern[0][2] = 'T';
 10.1875 +				intersectionPattern[0][3] = 'F';
 10.1876 +				intersectionPattern[0][4] = 'T';
 10.1877 +				intersectionPattern[0][5] = 'T';
 10.1878 +				intersectionPattern[0][6] = 'T';
 10.1879 +				intersectionPattern[0][7] = 'T';
 10.1880 +				intersectionPattern[0][8] = 'T';
 10.1881 +				break;
 10.1882 +			case RCC8_Po:	
 10.1883 +				intersectionPattern = new char[1][9];
 10.1884 +				intersectionPattern[0][0] = 'T';
 10.1885 +				intersectionPattern[0][1] = 'T';
 10.1886 +				intersectionPattern[0][2] = 'T';
 10.1887 +				intersectionPattern[0][3] = 'T';
 10.1888 +				intersectionPattern[0][4] = 'T';
 10.1889 +				intersectionPattern[0][5] = 'T';
 10.1890 +				intersectionPattern[0][6] = 'T';
 10.1891 +				intersectionPattern[0][7] = 'T';
 10.1892 +				intersectionPattern[0][8] = 'T';
 10.1893 +				break;
 10.1894 +			case RCC8_Tppi:	
 10.1895 +				intersectionPattern = new char[1][9];
 10.1896 +				intersectionPattern[0][0] = 'T';
 10.1897 +				intersectionPattern[0][1] = 'T';
 10.1898 +				intersectionPattern[0][2] = 'T';
 10.1899 +				intersectionPattern[0][3] = 'F';
 10.1900 +				intersectionPattern[0][4] = 'T';
 10.1901 +				intersectionPattern[0][5] = 'T';
 10.1902 +				intersectionPattern[0][6] = 'F';
 10.1903 +				intersectionPattern[0][7] = 'F';
 10.1904 +				intersectionPattern[0][8] = 'T';
 10.1905 +				break;
 10.1906 +			case RCC8_Tpp:	
 10.1907 +				intersectionPattern = new char[1][9];
 10.1908 +				intersectionPattern[0][0] = 'T';
 10.1909 +				intersectionPattern[0][1] = 'F';
 10.1910 +				intersectionPattern[0][2] = 'F';
 10.1911 +				intersectionPattern[0][3] = 'T';
 10.1912 +				intersectionPattern[0][4] = 'T';
 10.1913 +				intersectionPattern[0][5] = 'F';
 10.1914 +				intersectionPattern[0][6] = 'T';
 10.1915 +				intersectionPattern[0][7] = 'T';
 10.1916 +				intersectionPattern[0][8] = 'T';
 10.1917 +				break;
 10.1918 +			case RCC8_Ntpp:	
 10.1919 +				intersectionPattern = new char[1][9];
 10.1920 +				intersectionPattern[0][0] = 'T';
 10.1921 +				intersectionPattern[0][1] = 'F';
 10.1922 +				intersectionPattern[0][2] = 'F';
 10.1923 +				intersectionPattern[0][3] = 'T';
 10.1924 +				intersectionPattern[0][4] = 'F';
 10.1925 +				intersectionPattern[0][5] = 'F';
 10.1926 +				intersectionPattern[0][6] = 'T';
 10.1927 +				intersectionPattern[0][7] = 'T';
 10.1928 +				intersectionPattern[0][8] = 'T';
 10.1929 +				break;
 10.1930 +			case RCC8_Ntppi:	
 10.1931 +				intersectionPattern = new char[1][9];
 10.1932 +				intersectionPattern[0][0] = 'T';
 10.1933 +				intersectionPattern[0][1] = 'T';
 10.1934 +				intersectionPattern[0][2] = 'T';
 10.1935 +				intersectionPattern[0][3] = 'F';
 10.1936 +				intersectionPattern[0][4] = 'F';
 10.1937 +				intersectionPattern[0][5] = 'T';
 10.1938 +				intersectionPattern[0][6] = 'F';
 10.1939 +				intersectionPattern[0][7] = 'F';
 10.1940 +				intersectionPattern[0][8] = 'T';
 10.1941 +				break;
 10.1942 +			case SF_Intersects:   
 10.1943 +				intersectionPattern = new char[4][9];
 10.1944 +				intersectionPattern[0][0] = 'T';
 10.1945 +				intersectionPattern[0][1] = '*';
 10.1946 +				intersectionPattern[0][2] = '*';
 10.1947 +				intersectionPattern[0][3] = '*';
 10.1948 +				intersectionPattern[0][4] = '*';
 10.1949 +				intersectionPattern[0][5] = '*';
 10.1950 +				intersectionPattern[0][6] = '*';
 10.1951 +				intersectionPattern[0][7] = '*';
 10.1952 +				intersectionPattern[0][8] = '*';
 10.1953 +				//
 10.1954 +				intersectionPattern[1][0] = '*';
 10.1955 +				intersectionPattern[1][1] = 'T';
 10.1956 +				intersectionPattern[1][2] = '*';
 10.1957 +				intersectionPattern[1][3] = '*';
 10.1958 +				intersectionPattern[1][4] = '*';
 10.1959 +				intersectionPattern[1][5] = '*';
 10.1960 +				intersectionPattern[1][6] = '*';
 10.1961 +				intersectionPattern[1][7] = '*';
 10.1962 +				intersectionPattern[1][8] = '*';
 10.1963 +				//
 10.1964 +				intersectionPattern[2][0] = '*';
 10.1965 +				intersectionPattern[2][1] = '*';
 10.1966 +				intersectionPattern[2][2] = '*';
 10.1967 +				intersectionPattern[2][3] = 'T';
 10.1968 +				intersectionPattern[2][4] = '*';
 10.1969 +				intersectionPattern[2][5] = '*';
 10.1970 +				intersectionPattern[2][6] = '*';
 10.1971 +				intersectionPattern[2][7] = '*';
 10.1972 +				intersectionPattern[2][8] = '*';
 10.1973 +				//
 10.1974 +				intersectionPattern[3][0] = '*';
 10.1975 +				intersectionPattern[3][1] = '*';
 10.1976 +				intersectionPattern[3][2] = '*';
 10.1977 +				intersectionPattern[3][3] = '*';
 10.1978 +				intersectionPattern[3][4] = 'T';
 10.1979 +				intersectionPattern[3][5] = '*';
 10.1980 +				intersectionPattern[3][6] = '*';
 10.1981 +				intersectionPattern[3][7] = '*';
 10.1982 +				intersectionPattern[3][8] = '*';
 10.1983 +				break;
 10.1984 +
 10.1985 +			case SF_Touches: 
 10.1986 +			case EH_Meet:
 10.1987 +				intersectionPattern = new char[3][9];
 10.1988 +				intersectionPattern[0][0] = 'F';
 10.1989 +				intersectionPattern[0][1] = 'T';
 10.1990 +				intersectionPattern[0][2] = '*';
 10.1991 +				intersectionPattern[0][3] = '*';
 10.1992 +				intersectionPattern[0][4] = '*';
 10.1993 +				intersectionPattern[0][5] = '*';
 10.1994 +				intersectionPattern[0][6] = '*';
 10.1995 +				intersectionPattern[0][7] = '*';
 10.1996 +				intersectionPattern[0][8] = '*';
 10.1997 +				//
 10.1998 +				intersectionPattern[1][0] = 'F';
 10.1999 +				intersectionPattern[1][1] = '*';
 10.2000 +				intersectionPattern[1][2] = '*';
 10.2001 +				intersectionPattern[1][3] = 'T';
 10.2002 +				intersectionPattern[1][4] = '*';
 10.2003 +				intersectionPattern[1][5] = '*';
 10.2004 +				intersectionPattern[1][6] = '*';
 10.2005 +				intersectionPattern[1][7] = '*';
 10.2006 +				intersectionPattern[1][8] = '*';
 10.2007 +				//
 10.2008 +				intersectionPattern[2][0] = 'F';
 10.2009 +				intersectionPattern[2][1] = '*';
 10.2010 +				intersectionPattern[2][2] = '*';
 10.2011 +				intersectionPattern[2][3] = '*';
 10.2012 +				intersectionPattern[2][4] = 'T';
 10.2013 +				intersectionPattern[2][5] = '*';
 10.2014 +				intersectionPattern[2][6] = '*';
 10.2015 +				intersectionPattern[2][7] = '*';
 10.2016 +				intersectionPattern[2][8] = '*';
 10.2017 +				//
 10.2018 +
 10.2019 +			}
 10.2020 +
 10.2021 +			for(int i = 0; i < intersectionPattern.length ; i++)
 10.2022 +			{
 10.2023 +				appendRelate(expr, filter, intersectionPattern[i]);
 10.2024 +				if(i < intersectionPattern.length - 1)
 10.2025 +				{
 10.2026 +					//append OR and continue
 10.2027 +					filter.or();
 10.2028 +				}
 10.2029 +			}
 10.2030 +
 10.2031 +			//Also need bounding box intersection query to enable the usage of the Gist R-tree index
 10.2032 +			if(func != SpatialFunctionsPostGIS.SF_Disjoint && func != SpatialFunctionsPostGIS.EH_Disjoint && func != SpatialFunctionsPostGIS.RCC8_Dc)
 10.2033 +			{
 10.2034 +				filter.and();
 10.2035 +				appendGeneralDBSpatialFunctionBinary(expr, filter,SpatialFunctionsPostGIS.ST_Intersects);
 10.2036 +			}
 10.2037 +		}
 10.2038 +		filter.closeBracket();
 10.2039 +			}
 10.2040 +
 10.2041 +	@Override
 10.2042 +	//GeoSPARQL
 10.2043 +	//XXX
 10.2044 +
 10.2045 +	protected void appendRelate(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, char[] intersectionPattern)
 10.2046 +			throws UnsupportedRdbmsOperatorException
 10.2047 +			{
 10.2048 +		filter.openBracket();
 10.2049 +		System.out.println(expr.getLeftArg().getClass().getCanonicalName());
 10.2050 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.2051 +		if(check1)
 10.2052 +		{
 10.2053 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 10.2054 +
 10.2055 +		}
 10.2056 +		else
 10.2057 +		{	
 10.2058 +			filter.appendFunction("ST_Relate");
 10.2059 +
 10.2060 +
 10.2061 +			filter.openBracket();
 10.2062 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 10.2063 +			{
 10.2064 +				appendWKT(expr.getLeftArg(),filter);
 10.2065 +			}
 10.2066 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.2067 +			{
 10.2068 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.2069 +			}
 10.2070 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.2071 +			{
 10.2072 +				appendConstructFunction(expr.getLeftArg(), filter);
 10.2073 +			}
 10.2074 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 10.2075 +			{
 10.2076 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 10.2077 +				appendMBB(onlyLabel,filter); 
 10.2078 +			}
 10.2079 +			else
 10.2080 +			{
 10.2081 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 10.2082 +			}
 10.2083 +			filter.appendComma();
 10.2084 +			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 10.2085 +			if(check2)
 10.2086 +			{
 10.2087 +				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 10.2088 +			}
 10.2089 +			else
 10.2090 +			{
 10.2091 +				if(expr.getRightArg() instanceof GeneralDBStringValue)
 10.2092 +				{
 10.2093 +					appendWKT(expr.getRightArg(),filter);
 10.2094 +				}
 10.2095 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 10.2096 +				{
 10.2097 +					appendConstructFunction(expr.getRightArg(), filter);
 10.2098 +				}
 10.2099 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 10.2100 +				{
 10.2101 +					appendConstructFunction(expr.getRightArg(), filter);
 10.2102 +				}
 10.2103 +				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 10.2104 +				{
 10.2105 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 10.2106 +					appendMBB(onlyLabel,filter);					 
 10.2107 +				}
 10.2108 +				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 10.2109 +				{
 10.2110 +					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 10.2111 +				}
 10.2112 +				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 10.2113 +				{
 10.2114 +					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 10.2115 +				}
 10.2116 +				//case met in buffer when in select -> buffer(?spatial,?thematic)
 10.2117 +				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 10.2118 +				{
 10.2119 +					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 10.2120 +					appendCastToDouble(filter);
 10.2121 +				}
 10.2122 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 10.2123 +				{
 10.2124 +					appendMetricFunction(expr.getRightArg(), filter);
 10.2125 +				}
 10.2126 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 10.2127 +				{
 10.2128 +					appendMetricFunction(expr.getRightArg(), filter);
 10.2129 +				}
 10.2130 +				else
 10.2131 +				{
 10.2132 +					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 10.2133 +				}
 10.2134 +
 10.2135 +			}
 10.2136 +			//3rd arg
 10.2137 +			filter.appendComma();
 10.2138 +
 10.2139 +			//must turn the table of characters I have to a valid sql value!
 10.2140 +			filter.append("'");
 10.2141 +			for(int i = 0; i< intersectionPattern.length; i++)
 10.2142 +			{
 10.2143 +				filter.append(intersectionPattern[i]+"");
 10.2144 +			}
 10.2145 +			filter.append("'");
 10.2146 +
 10.2147 +			filter.closeBracket();
 10.2148 +		}
 10.2149 +
 10.2150 +		filter.closeBracket();
 10.2151 +			}
 10.2152 +
 10.2153 +}