Strabon

changeset 845:250d177995ca

merge with DiffDateTime
author George Garbis <ggarbis@di.uoa.gr>
date Tue Jan 08 12:30:51 2013 +0200 (2013-01-08)
parents 674f8f91162b 5e4a561d0a11
children 150e7578f7e2
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function 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/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java
line diff
     1.1 --- a/endpoint/src/log4j.properties	Mon Dec 24 14:14:08 2012 +0100
     1.2 +++ b/endpoint/src/log4j.properties	Tue Jan 08 12:30:51 2013 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  # logger level values: OFF, ERROR, WARN, INFO, DEBUG, ALL
     1.5 -log4j.rootLogger=INFO, CA
     1.6 -#log4j.rootLogger=INFO, CA, FA
     1.7 +#log4j.rootLogger=INFO, CA
     1.8 +log4j.rootLogger=DEBUG, CA, FA
     1.9  
    1.10  # Console Appender
    1.11  log4j.appender.CA=org.apache.log4j.ConsoleAppender
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/datetime/stsparql/metric/DiffDateTime.java	Tue Jan 08 12:30:51 2013 +0200
     2.3 @@ -0,0 +1,72 @@
     2.4 +/**
     2.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.8 + *
     2.9 + * Copyright (C) 2012, Pyravlos Team
    2.10 + *
    2.11 + * http://www.strabon.di.uoa.gr/
    2.12 + */
    2.13 +package org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric;
    2.14 +
    2.15 +import java.text.SimpleDateFormat;
    2.16 +import java.util.Calendar;
    2.17 +import java.util.GregorianCalendar;
    2.18 +
    2.19 +import org.openrdf.model.Value;
    2.20 +import org.openrdf.model.ValueFactory;
    2.21 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    2.22 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
    2.23 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    2.24 +
    2.25 +/**
    2.26 + * Addition for datetime metric functions
    2.27 + * 
    2.28 + * 
    2.29 + * @author George Garbis <ggarbis@di.uoa.gr>
    2.30 + * 
    2.31 + */
    2.32 +public class DiffDateTime extends DateTimeMetricFunc {
    2.33 +
    2.34 +	// This functions returns the difference in msecs of two xsd:dateTimes
    2.35 +	
    2.36 +	@Override
    2.37 +	public String getURI() {
    2.38 +		return GeoConstants.diffDateTime;
    2.39 +	}
    2.40 +	
    2.41 +//	@Override
    2.42 +//	public Value evaluate(ValueFactory valueFactory, Value... args)
    2.43 +//            throws ValueExprEvaluationException {
    2.44 +//        if (args.length != 2) {
    2.45 +//            throw new ValueExprEvaluationException(this.getURI()
    2.46 +//                    + " requires exactly 2 arguments, got " + args.length);
    2.47 +//        }
    2.48 +//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'hh:mm:ss"); //the format of xsd:Datetime
    2.49 +//		
    2.50 +//		long diff = 0;
    2.51 +//    	try {
    2.52 +//    	    String date1 = args[0].toString();
    2.53 +//    	    date1 = date1.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    2.54 +//    	    date1 = date1.replace("\"", "");
    2.55 +//    	    Calendar cal1 = new GregorianCalendar();
    2.56 +//    		cal1.setTime(sdf.parse(date1));
    2.57 +//    		
    2.58 +//    		String date2 = args[1].toString();
    2.59 +//    		date2 = date2.replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "");
    2.60 +//    	    date2 = date2.replace("\"", "");
    2.61 +//    	    Calendar cal2 = new GregorianCalendar();
    2.62 +//    		cal2.setTime(sdf.parse(date2));
    2.63 +//    		
    2.64 +//    		diff = cal2.getTimeInMillis() - cal1.getTimeInMillis();
    2.65 +//    		
    2.66 +//    	} catch (java.text.ParseException e) {
    2.67 +//			// TODO Auto-generated catch block
    2.68 +//			e.printStackTrace();
    2.69 +//		}
    2.70 +//		
    2.71 +//		
    2.72 +//        return valueFactory.createLiteral(diff);
    2.73 +//    }
    2.74 +
    2.75 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/DateTimeMetricFunc.java	Tue Jan 08 12:30:51 2013 +0200
     3.3 @@ -0,0 +1,35 @@
     3.4 +/**
     3.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.8 + * 
     3.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team
    3.10 + * 
    3.11 + * http://www.strabon.di.uoa.gr/
    3.12 + */
    3.13 +package org.openrdf.query.algebra.evaluation.function.spatial;
    3.14 +
    3.15 +import org.openrdf.model.Value;
    3.16 +import org.openrdf.model.ValueFactory;
    3.17 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    3.18 +import org.openrdf.query.algebra.evaluation.function.Function;
    3.19 +
    3.20 +/**
    3.21 + * This class represents a function doing a metric computation on xsd:dateTime values
    3.22 + * (e.g., calculating the difference between two xsd:dateTime values).
    3.23 + * 
    3.24 + * @see package {@link org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric}
    3.25 + * 
    3.26 + * @author George Garbis <ggarbis@di.uoa.gr>
    3.27 + */
    3.28 +public abstract class DateTimeMetricFunc implements Function {
    3.29 +
    3.30 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    3.31 +	public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
    3.32 +
    3.33 +		return null;
    3.34 +	}
    3.35 +
    3.36 +	// charnik: made method (and hence the class) abstract
    3.37 +	public abstract String getURI();
    3.38 +}
     4.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Mon Dec 24 14:14:08 2012 +0100
     4.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Tue Jan 08 12:30:51 2013 +0200
     4.3 @@ -176,5 +176,13 @@
     4.4  	
     4.5  	// The generic relate function
     4.6  	public static final String geoSparqlRelate 					 = geof + "relate";
     4.7 -	
     4.8 +
     4.9 +	/**
    4.10 +	 * Addition for datetime metric functions
    4.11 +	 * 
    4.12 +	 * @author George Garbis <ggarbis@di.uoa.gr>
    4.13 +	 * 
    4.14 +	 */
    4.15 +	public static final String diffDateTime = "http://strdf.di.uoa.gr/extensions/ontology#diffDateTime";
    4.16 +	/** End of addition **/
    4.17  }
     5.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/stSPARQLConstantOptimizer.java	Mon Dec 24 14:14:08 2012 +0100
     5.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/stSPARQLConstantOptimizer.java	Tue Jan 08 12:30:51 2013 +0200
     5.3 @@ -34,6 +34,7 @@
     5.4  import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     5.5  import org.openrdf.query.algebra.evaluation.function.Function;
     5.6  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
     5.7 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
     5.8  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
     5.9  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
    5.10  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
    5.11 @@ -189,7 +190,15 @@
    5.12  			if(!(function instanceof SpatialConstructFunc) && 
    5.13  					!(function instanceof SpatialMetricFunc) &&
    5.14  					!(function instanceof SpatialPropertyFunc) &&
    5.15 -					!(function instanceof SpatialRelationshipFunc) )
    5.16 +					!(function instanceof SpatialRelationshipFunc) 
    5.17 +					/**
    5.18 +					 * Addition for datetime metric functions
    5.19 +					 * 
    5.20 +					 * @author George Garbis <ggarbis@di.uoa.gr>
    5.21 +					 * 
    5.22 +					 */
    5.23 +					&& !(function instanceof DateTimeMetricFunc)
    5.24 +				)
    5.25  			{
    5.26  				super.meet(functionCall);
    5.27  
     6.1 --- a/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function	Mon Dec 24 14:14:08 2012 +0100
     6.2 +++ b/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function	Tue Jan 08 12:30:51 2013 +0200
     6.3 @@ -78,3 +78,5 @@
     6.4  org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesOverlapsFunc
     6.5  org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesWithinFunc
     6.6  org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeatureTouchesFunc
     6.7 +
     6.8 +org.openrdf.query.algebra.evaluation.function.datetime.stsparql.metric.DiffDateTime
     6.9 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/examples/teleios/deleteReflections.rq	Tue Jan 08 12:30:51 2013 +0200
     7.3 @@ -0,0 +1,52 @@
     7.4 +# Θεωρούμε ότι εαν ένα πολύγωνο παραμένει ενεργό για μεγάλο χρονικό
     7.5 +# διάστημα, χωρίς παράλληλα να ενεργοποιείται κάποιο γειτονικό του, τότε
     7.6 +# αυτό το πολύγωνο είναι θόρυβος.
     7.7 +# Συγκεκριμένα, για όλο το χρονικό διάστημα ενδιαφέροντος και για κάθε grid:
     7.8 +# - Υπολογίζω την χρονική διαφορά της τελευταίας από την πρώτη καταγραφή.
     7.9 +# - Εαν αυτή είναι μεγαλύτερη της μίας ώρας &
    7.10 +# - Για όλο αυτό το διάστημα δεν υπάρχουν γειτονικα πολύγωνα ενεργά
    7.11 +# (adjacent polygons)
    7.12 +# - Τότε οι συγκεκριμένες καταγραφές διαγράφονται
    7.13 +
    7.14 +PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>
    7.15 +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    7.16 +PREFIX strdf: <http://strdf.di.uoa.gr/ontology#>
    7.17 +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    7.18 +
    7.19 +INSERT {?h1 noa:isDiscarded "1"^^xsd:int ;
    7.20 +			noa:refinedBy noa:reflections .
    7.21 +}
    7.22 +WHERE {
    7.23 +    SELECT ?h1 (count(?h2) as ?h2Count)
    7.24 +    WHERE {
    7.25 +        # Retrieve a hotspot of the current acquisition
    7.26 +        ?h1 noa:hasAcquisitionTime "TIMESTAMP"^^xsd:dateTime ; #"2007-08-23T13:00:00"^^xsd:dateTime ; 
    7.27 +            noa:hasGeometry ?geo ;
    7.28 +		    noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ; #"StaticThresholds"^^xsd:string ;
    7.29 +         	noa:isDerivedFromSensor "SENSOR"^^xsd:string . # "MSG2"^^xsd:string .
    7.30 +
    7.31 +        # Retrieve all hotspots with the same geometry detected at most an hour ago
    7.32 +        ?h2	noa:hasAcquisitionTime ?h2Time ;
    7.33 +	        noa:hasGeometry ?geo ;
    7.34 +	        noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ; #"StaticThresholds"^^xsd:string ;
    7.35 +         	noa:isDerivedFromSensor "SENSOR"^^xsd:string . # "MSG2"^^xsd:string .
    7.36 +    	FILTER("MIN_ACQUISITION_TIME"^^xsd:dateTime <= ?h2Time && ?h2Time <= "TIMESTAMP"^^xsd:dateTime ) .
    7.37 +#        FILTER("2007-08-23T12:00:00"^^xsd:dateTime <= ?h2Time && ?h2Time <= "2007-08-23T13:00:00"^^xsd:dateTime) .
    7.38 +
    7.39 +		# Filter the results so that the above hotspots have no neighbours
    7.40 +        OPTIONAL {
    7.41 +            ?h3	noa:hasAcquisitionTime ?h3Time ;
    7.42 +	            noa:hasGeometry ?h3Geo ;
    7.43 +	            noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ; #"StaticThresholds"^^xsd:string ;
    7.44 +             	noa:isDerivedFromSensor "SENSOR"^^xsd:string . # "MSG2"^^xsd:string .
    7.45 +        	FILTER("MIN_ACQUISITION_TIME"^^xsd:dateTime <= ?h3Time && ?h3Time <= "TIMESTAMP"^^xsd:dateTime ) .
    7.46 +#            FILTER("2007-08-23T12:00:00"^^xsd:dateTime <= ?h3Time && ?h3Time <= "2007-08-23T13:00:00"^^xsd:dateTime) .
    7.47 +	        FILTER(strdf:touch(?geo, ?h3Geo)).
    7.48 +        }
    7.49 +        FILTER(!bound(?h3)) .
    7.50 +    }
    7.51 +	# Select every hotspot of the current acquisition which has no neighbours since an hour ago until now
    7.52 +	# and is "on" during all this time (MSG2 can have 333 detections during an hour)
    7.53 +    GROUP BY ?h1
    7.54 +    HAVING (?h2Count >= ACQUISITIONS_IN_AN_HOUR)
    7.55 +}
     8.1 --- a/examples/teleios/deleteSeaHotspots.rq	Mon Dec 24 14:14:08 2012 +0100
     8.2 +++ b/examples/teleios/deleteSeaHotspots.rq	Tue Jan 08 12:30:51 2013 +0200
     8.3 @@ -8,11 +8,11 @@
     8.4             noa:refinedBy noa:seaInconsistency .
     8.5  } 
     8.6  WHERE {
     8.7 -?h   noa:hasAcquisitionTime "TIMESTAMP"^^xsd:dateTime ;
     8.8 -     noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ;
     8.9 -     noa:isDerivedFromSensor "SENSOR"^^xsd:string .
    8.10 -       OPTIONAL {
    8.11 -    ?h	gag:hasMunicipality ?muni .
    8.12 -  } 
    8.13 -  FILTER(!bound(?muni)) .
    8.14 +	?h   noa:hasAcquisitionTime "TIMESTAMP"^^xsd:dateTime ;
    8.15 +	     noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ;
    8.16 +	     noa:isDerivedFromSensor "SENSOR"^^xsd:string .
    8.17 +	OPTIONAL {
    8.18 +		?h	gag:hasMunicipality ?muni .
    8.19 +	} 
    8.20 +	FILTER(!bound(?muni)) .
    8.21  }
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/examples/teleios/discoverFires.rq	Tue Jan 08 12:30:51 2013 +0200
     9.3 @@ -0,0 +1,67 @@
     9.4 +#Το πρώτο query εφαρμόζεται  με σκοπό τον περιορισμό τoυ θορύβου,
     9.5 +#εντοπίζοντας την χρονική αστάθεια ("αναλαμπές") σε πολύγωνα
     9.6 +#καμένων εκτάσεων. Υλοποιήσαμε και εφαρμόσαμε το ακόλουθο  χρονικό φίλτρο
     9.7 +#στα δεδομένα (με αναφορές στον πηγαίο κώδικα):
     9.8 +#- Στις γραμμές 1574..1614, για κάθε πολύγωνο, ομαδοποιούμε τις
     9.9 +#καταγραφές οι οποίες δεν απέχουν μεταξύ τους (επόμενη-προηγούμενη)
    9.10 +#περισσότερο από την τιμή της μεταβλητής persistence.
    9.11 +#- Στην συνέχεια εξετάζουμε κάθε τέτοια ομάδα (κοντινών στο χώρο
    9.12 +#καταγραφών), και ελέγχουμε εάν το πλήθος τους (για κάθε τέτοια ομάδα)
    9.13 +#είναι μικρότερο ή ίσο από την τιμή της μεταβλητής repeat_in_persistence
    9.14 +#(γραμμές 1614..1630).
    9.15 +#- Αυτές τις καταγραφές τις διαγράφουμε θεωρώντας τις θόρυβο
    9.16 +
    9.17 +PREFIX noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>
    9.18 +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    9.19 +PREFIX strdf: <http://strdf.di.uoa.gr/ontology#>
    9.20 +PREFIX strdf-ext: <http://strdf.di.uoa.gr/extensions/ontology#>
    9.21 +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    9.22 +PREFIX gag: <http://geo.linkedopendata.gr/greekadministrativeregion/ontology#>
    9.23 +
    9.24 +# The ending time of a fire (identificated by its starting time) is the latest
    9.25 +# hotspot attributed to this fire
    9.26 +SELECT ?start (max(?hTime) as ?end) ?geo 
    9.27 +WHERE
    9.28 +{
    9.29 +    {
    9.30 +		# Each hotspots is finally grouped only with the latest fire starting
    9.31 +		# time found
    9.32 +        SELECT (max(?hStartTime) as ?start) ?hTime ?geo ?h
    9.33 +#        SELECT (count(distinct ?hStartTime) as ?c) ?geo
    9.34 +        WHERE {
    9.35 +	        # -- FIND HOTSPOTS THAT DEFINE THE START OF A FIRE (GROUP ALA THEMOS) -- 
    9.36 +	        # Retrieve all hotstpots in time range...  
    9.37 +	        ?hStart	noa:hasAcquisitionTime ?hStartTime ;
    9.38 +                    noa:hasGeometry ?geo ;
    9.39 +			        noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ;
    9.40 +			        noa:isDerivedFromSensor "SENSOR"^^xsd:string .
    9.41 +            OPTIONAL {?hStart noa:isDiscarded ?hStartDisc }. FILTER (!bound(?hStartDisc)) .
    9.42 +            FILTER(strdf-ext:diffDateTime("MIN_ACQUISITION_TIME"^^xsd:dateTime,?hStartTime)<=0 && strdf-ext:diffDateTime("MAX_ACQUISITION_TIME"^^xsd:dateTime,?hStartTime)>=0).
    9.43 +	        # ... narrow down results so that any previous hotspots is detected at least PERSISTENCE mins earlier
    9.44 +            OPTIONAL {
    9.45 +                ?hPrevious	noa:hasAcquisitionTime ?hPreviousTime ;
    9.46 +                			noa:hasGeometry ?geo ;
    9.47 +					        noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ;
    9.48 +					        noa:isDerivedFromSensor "SENSOR"^^xsd:string .
    9.49 +                OPTIONAL {?hPrevious noa:isDiscarded ?hPreviousDisc }. FILTER (!bound(?hPreviousDisc)) .
    9.50 +         		FILTER(strdf-ext:diffDateTime("MIN_ACQUISITION_TIME"^^xsd:dateTime,?hPreviousTime)<=0 && strdf-ext:diffDateTime("MAX_ACQUISITION_TIME"^^xsd:dateTime,?hPreviousTime)>=0).                
    9.51 +		        FILTER(strdf-ext:diffDateTime(?hStartTime, ?hPreviousTime) <= PERSISTENCE*60000 && strdf-ext:diffDateTime(?hStartTime, ?hPreviousTime) > 0).
    9.52 +            } 
    9.53 +            FILTER(!bound(?hPrevious)) .
    9.54 +
    9.55 +            # FIND HOTSPOTS AFTER A FIRE STARTING TIME
    9.56 +            ?h  noa:hasAcquisitionTime ?hTime;
    9.57 +                noa:hasGeometry ?geo;
    9.58 +		        noa:producedFromProcessingChain "PROCESSING_CHAIN"^^xsd:string ;
    9.59 +		        noa:isDerivedFromSensor "SENSOR"^^xsd:string .
    9.60 +            OPTIONAL {?h noa:isDiscarded ?hDisc }. FILTER (!bound(?hDisc)) .
    9.61 +        	FILTER(strdf-ext:diffDateTime("MIN_ACQUISITION_TIME"^^xsd:dateTime,?hTime)<=0 && strdf-ext:diffDateTime("MAX_ACQUISITION_TIME"^^xsd:dateTime,?hTime)>=0).   
    9.62 +	 	    FILTER(strdf-ext:diffDateTime(?hTime, ?hStartTime) >= 0).
    9.63 +        }
    9.64 +#		group by ?geo
    9.65 +        group by ?h ?hTime ?geo
    9.66 +    }.
    9.67 +}
    9.68 +group by ?start ?geo
    9.69 +having (count(?h) >= REPEAT_IN_PERS)
    9.70 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/examples/teleios/exampleFires.ttl	Tue Jan 08 12:30:51 2013 +0200
    10.3 @@ -0,0 +1,51 @@
    10.4 +# Παράδειγμα για το deleteReflections.rq
    10.5 +# Έχει 4 ομάδες hotspot.
    10.6 +# Η δύο πρώτες ομάδες (h111,h112,h121) απέχουν 10 λεπτά (persistence=10') άρα πάνε μαζί.
    10.7 +# Η δύο τελευταίες (h211, h221, h222) απέχουν πάλι δέκα λεπτά και πάνε μαζί.
    10.8 +# Άρα η επερώτηση θα μου απαντήσει τις δύο ομάδες (με την ίδια γεωμετριά και διαφορετικά start και end times)
    10.9 +
   10.10 +@prefix lgd: <http://linkedgeodata.org/triplify/> .
   10.11 +@prefix lgdgeo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
   10.12 +@prefix lgdont: <http://linkedgeodata.org/ontology/> .
   10.13 +@prefix geonames: <http://www.geonames.org/ontology#> .
   10.14 +@prefix clc: <http://geo.linkedopendata.gr/corine/ontology#> .
   10.15 +@prefix gag: <http://teleios.di.uoa.gr/ontologies/gagKallikratis.rdf#> .
   10.16 +@prefix noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> .
   10.17 +@prefix dlr: <http://www.earthobservatory.eu/ontologies/dlrOntology-v2.owl#> .
   10.18 +@prefix strdf: <http://strdf.di.uoa.gr/ontology#> .
   10.19 +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
   10.20 +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
   10.21 +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
   10.22 +
   10.23 +noa:h111	noa:hasAcquisitionTime "2012-08-24T12:00:00"^^xsd:dateTime ;
   10.24 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.25 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.26 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.27 +
   10.28 +
   10.29 +noa:h112	noa:hasAcquisitionTime "2012-08-24T12:05:00"^^xsd:dateTime ;
   10.30 +        	noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.31 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.32 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.33 +
   10.34 +noa:h121		noa:hasAcquisitionTime "2012-08-24T12:15:00"^^xsd:dateTime ;
   10.35 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.36 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.37 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.38 +
   10.39 +noa:h211	noa:hasAcquisitionTime "2012-08-24T12:30:00"^^xsd:dateTime ;
   10.40 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.41 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.42 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.43 +
   10.44 +noa:h221	noa:hasAcquisitionTime "2012-08-24T12:40:00"^^xsd:dateTime ;
   10.45 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.46 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.47 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.48 +
   10.49 +noa:h222	noa:hasAcquisitionTime "2012-08-24T12:45:00"^^xsd:dateTime ;
   10.50 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   10.51 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   10.52 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   10.53 +
   10.54 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/examples/teleios/exampleReflections.ttl	Tue Jan 08 12:30:51 2013 +0200
    11.3 @@ -0,0 +1,74 @@
    11.4 +# Παράδειγμα για το deleteReflections.rq
    11.5 +# Έχει hotspots σε 4 περιοχές.
    11.6 +# Το πρώτο (h11-h14) δεν έχει γείτονες και είναι αναμένο για μία ώρα. Συνεπώς θεωρείται αντανάκλαση και διαγράφεται.
    11.7 +# Το δεύτερο (h21-h22) δεν έχει γείτονες αλλά ανάβει μόνο δύο φορές σε μία ώρα. Συνεπώς δεν θεωρείται αντανακλαση.
    11.8 +# Το τρίτο (h31-h34) είναι αναμένο επί μία ώρα αλλά έχει ένα γείτονα -το τέταρτο hotspots(h41)- άρα επίσης δεν θεωρείται αντανάκλαση.
    11.9 +
   11.10 +@prefix lgd: <http://linkedgeodata.org/triplify/> .
   11.11 +@prefix lgdgeo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
   11.12 +@prefix lgdont: <http://linkedgeodata.org/ontology/> .
   11.13 +@prefix geonames: <http://www.geonames.org/ontology#> .
   11.14 +@prefix clc: <http://geo.linkedopendata.gr/corine/ontology#> .
   11.15 +@prefix gag: <http://teleios.di.uoa.gr/ontologies/gagKallikratis.rdf#> .
   11.16 +@prefix noa: <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#> .
   11.17 +@prefix dlr: <http://www.earthobservatory.eu/ontologies/dlrOntology-v2.owl#> .
   11.18 +@prefix strdf: <http://strdf.di.uoa.gr/ontology#> .
   11.19 +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
   11.20 +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
   11.21 +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
   11.22 +
   11.23 +noa:h11	 	noa:hasAcquisitionTime "2007-08-23T12:00:00"^^xsd:dateTime ;
   11.24 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.25 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.26 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.27 +
   11.28 +
   11.29 +noa:h12		noa:hasAcquisitionTime "2007-08-23T12:15:00"^^xsd:dateTime ;
   11.30 +        	noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.31 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.32 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.33 +
   11.34 +noa:h13		noa:hasAcquisitionTime "2007-08-23T12:30:00"^^xsd:dateTime ;
   11.35 +			noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.36 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.37 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.38 +
   11.39 +noa:h14		noa:hasAcquisitionTime "2007-08-23T13:00:00"^^xsd:dateTime ;
   11.40 +	        noa:hasGeometry "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.41 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.42 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.43 +
   11.44 +noa:h21		noa:hasAcquisitionTime "2007-08-23T12:00:00"^^xsd:dateTime ;
   11.45 +	        noa:hasGeometry "POLYGON ((20 0, 30 0, 30 10, 20 10, 20 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.46 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.47 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.48 +
   11.49 +noa:h22		noa:hasAcquisitionTime "2007-08-23T13:00:00"^^xsd:dateTime ;
   11.50 +			noa:hasGeometry "POLYGON ((20 0, 30 0, 30 10, 20 10, 20 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.51 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.52 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.53 +
   11.54 +noa:h31		noa:hasAcquisitionTime "2007-08-23T12:15:00"^^xsd:dateTime ;
   11.55 +	        noa:hasGeometry "POLYGON ((40 10, 50 10, 50 20, 40 20, 40 10))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.56 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.57 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.58 +
   11.59 +noa:h41		noa:hasAcquisitionTime "2007-08-23T12:00:00"^^xsd:dateTime ;
   11.60 +	     	noa:hasGeometry "POLYGON ((40 0, 50 0, 50 10, 40 10, 40 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.61 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.62 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.63 +
   11.64 +noa:h42	 	noa:hasAcquisitionTime "2007-08-23T12:15:00"^^xsd:dateTime ;
   11.65 +	        noa:hasGeometry "POLYGON ((40 0, 50 0, 50 10, 40 10, 40 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.66 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.67 +    	 	noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.68 +
   11.69 +noa:h43	 	noa:hasAcquisitionTime "2007-08-23T12:30:00"^^xsd:dateTime ;
   11.70 +        	noa:hasGeometry "POLYGON ((40 0, 50 0, 50 10, 40 10, 40 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.71 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.72 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
   11.73 +
   11.74 +noa:h44	 	noa:hasAcquisitionTime "2007-08-23T13:00:00"^^xsd:dateTime ;
   11.75 +	        noa:hasGeometry "POLYGON ((40 0, 50 0, 50 10, 40 10, 40 0))"^^<http://strdf.di.uoa.gr/ontology#WKT> ;
   11.76 +			noa:producedFromProcessingChain "StaticThresholds"^^xsd:string ;
   11.77 +     		noa:isDerivedFromSensor "MSG2"^^xsd:string .
    12.1 --- a/examples/teleios/instantiate.sh	Mon Dec 24 14:14:08 2012 +0100
    12.2 +++ b/examples/teleios/instantiate.sh	Tue Jan 08 12:30:51 2013 +0200
    12.3 @@ -36,6 +36,8 @@
    12.4  	echo "	-t, --timestamp		: the timestamp to use, e.g., \`2010-08-21T19:50:00'"
    12.5  	echo "	-m, --min_acq_time	: the minimum acquisition time (used in a persistence query only)"
    12.6  	echo "	-M, --max_acq_time	: the maximum acquisition time (used in a discovery query only)"
    12.7 +	echo "	-p, --persistence	: "
    12.8 +	echo "	-r, --repeat_in_persistence	: "
    12.9  	echo
   12.10  	echo "Example run:"
   12.11  	echo "	./instantiate.sh -s MSG1 -t '2010-08-21T19:50:00' -c "DynamicThresholds" -m '2010-08-21T19:50:00' -M '2010-08-21T19:50:00' *.rq"
   12.12 @@ -45,9 +47,12 @@
   12.13  CHAIN=
   12.14  SAT=
   12.15  N_ACQUISITIONS=
   12.16 +N_ACQUISITIONS_PER_HOUR=
   12.17  TIMESTAMP=
   12.18  MIN_ACQ_TIME=
   12.19  MAX_ACQ_TIME=
   12.20 +PERSISTENCE=
   12.21 +REPEAT_IN_PERS= 
   12.22  
   12.23  if test $# -eq 0; then
   12.24  	help
   12.25 @@ -69,10 +74,12 @@
   12.26  			if test "${SENSOR}" = "MSG2"; then
   12.27  				SAT="METEOSAT9"
   12.28  				N_ACQUISITIONS=3.0
   12.29 +				N_ACQUISITIONS_PER_HOUR=5.0
   12.30  			else
   12.31  				SAT="METEOSAT8"
   12.32  				N_ACQUISITIONS=7.0
   12.33 -
   12.34 +				N_ACQUISITIONS_PER_HOUR=13.0 
   12.35 +				
   12.36  				# change MSG1 to MSG1_RSS (for whatever reason NOA uses it :-))
   12.37  				SENSOR="MSG1_RSS"
   12.38  			fi
   12.39 @@ -98,6 +105,16 @@
   12.40  			MAX_ACQ_TIME="${1}"
   12.41  			shift
   12.42  			;;
   12.43 +		-p|--persistence)
   12.44 +			shift
   12.45 +			PERSISTENCE="${1}"
   12.46 +			shift
   12.47 +			;;
   12.48 +		-r|--repeat_in_persistence)
   12.49 +			shift
   12.50 +			REPEAT_IN_PERS="${1}"
   12.51 +			shift
   12.52 +			;;
   12.53  		-*)
   12.54  			echo "${CMD}: unknown option \"${1}\""
   12.55  			help
   12.56 @@ -125,6 +142,10 @@
   12.57  	ARGS="${ARGS} -e 's/ACQUISITIONS_IN_HALF_AN_HOUR/${N_ACQUISITIONS}/g'"
   12.58  fi
   12.59  
   12.60 +if test ! -z "${N_ACQUISITIONS_PER_HOUR}"; then
   12.61 +	ARGS="${ARGS} -e 's/ACQUISITIONS_IN_AN_HOUR/${N_ACQUISITIONS_PER_HOUR}/g'"
   12.62 +fi
   12.63 +
   12.64  if test ! -z "${TIMESTAMP}"; then
   12.65  	ARGS="${ARGS} -e 's/TIMESTAMP/${TIMESTAMP}/g'"
   12.66  fi
   12.67 @@ -137,6 +158,14 @@
   12.68  	ARGS="${ARGS} -e 's/MAX_ACQUISITION_TIME/${MAX_ACQ_TIME}/g'"
   12.69  fi
   12.70  
   12.71 +if test ! -z "${PERSISTENCE}"; then
   12.72 +	ARGS="${ARGS} -e 's/PERSISTENCE/${PERSISTENCE}/g'"
   12.73 +fi
   12.74 +
   12.75 +if test ! -z "${REPEAT_IN_PERS}"; then
   12.76 +	ARGS="${ARGS} -e 's/REPEAT_IN_PERS/${REPEAT_IN_PERS}/g'"
   12.77 +fi
   12.78 +
   12.79  if test -z "${ARGS}"; then
   12.80  	echo "${CMD}: You would be so kind to provide at least one OPTION."
   12.81  	help
   12.82 @@ -148,10 +177,10 @@
   12.83  #echo eval sed ${ARGS} ${@}
   12.84  
   12.85  # check for unbounded variables
   12.86 -GREP_RESULT=`echo "${QUERY}" | egrep -o 'PROCESSING_CHAIN|SENSOR|"SAT"|ACQUISITIONS_IN_HALF_AN_HOUR|TIMESTAMP|MIN_ACQUISITION_TIME|MAX_ACQUISITION_TIME'`
   12.87 +GREP_RESULT=`echo "${QUERY}" | egrep -o 'PROCESSING_CHAIN|SENSOR|"SAT"|ACQUISITIONS_IN_HALF_AN_HOUR|TIMESTAMP|MIN_ACQUISITION_TIME|MAX_ACQUISITION_TIME|PERSISTENCE|REPEAT_IN_PERS'`
   12.88 +
   12.89  if ! test $? -eq 0; then
   12.90  	echo "${QUERY}"
   12.91 -
   12.92  else
   12.93  	echo -e "${CMD}: WARNING: found unbounded variables "$(echo "${GREP_RESULT}"|sort -u)""
   12.94  	echo
    13.1 --- a/examples/teleios/runChain.sh	Mon Dec 24 14:14:08 2012 +0100
    13.2 +++ b/examples/teleios/runChain.sh	Tue Jan 08 12:30:51 2013 +0200
    13.3 @@ -1,25 +1,45 @@
    13.4  #! /bin/bash
    13.5 -
    13.6 +# 
    13.7 +# This Source Code Form is subject to the terms of the Mozilla Public 
    13.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, you
    13.9 +# can obtain one at http://mozilla.org/MPL/2.0/. 
   13.10 +# 
   13.11 +# Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team 
   13.12 +# 
   13.13 +# http://www.strabon.di.uoa.gr/ 
   13.14  #
   13.15 -# This Source Code Form is subject to the terms of the Mozilla Public
   13.16 -# License, v. 2.0. If a copy of the MPL was not distributed with this
   13.17 -# file, You can obtain one at http://mozilla.org/MPL/2.0/.
   13.18 -#
   13.19 -# Copyright (C) 2010, 2011, 2012, Pyravlos Team
   13.20 -#
   13.21 -# http://www.strabon.di.uoa.gr/
   13.22 +# Author: George Garbis <ggarbis@di.uoa.gr>
   13.23 +# Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
   13.24 +# Author: Manos Karpathiotakis <mk@di.uoa.gr>
   13.25 +# Author: Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
   13.26  #
   13.27  
   13.28 -LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
   13.29 +# Example run command: examples/teleios/runChain.sh -b http://dev.strabon.di.uoa.gr/rdf/data-dump-postgres-9.tgz  -l /home/ggarbis/runChain.log -e http://pathway.di.uoa.gr:8080/endpoint
   13.30  
   13.31 -ENDPOINT="http://teleios4.di.uoa.gr:8080/NOA"
   13.32 -DB="NOA2012"
   13.33 +# Command name
   13.34 +cmd="$(basename ${0})" 
   13.35 +# Get the directory where the script resides
   13.36 +loc="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
   13.37  
   13.38 -HOTSPOTS_URL="http://challenge.strabon.di.uoa.gr/MSG1"
   13.39 -ENDPOINT_SCRIPT=../../scripts/endpoint
   13.40 +function help() {                                                               
   13.41 +    echo "Usage: ${cmd} [OPTIONS] "                        
   13.42 +    echo                                                                        
   13.43 +    echo "Execute NOA chain with refinements and measure time."
   13.44 +    echo                                                                        
   13.45 +    echo "OPTIONS can be any of the following"                                  
   13.46 +    echo "  -d,--db   					: PostGIS database"                
   13.47 +    echo "  -e,--endpoint   			: Strabon Endpoint"
   13.48 +    echo "  -h,--hotposts				: URL where hotspots are stored"
   13.49 +	echo "  -b,--background         	: Background data"                                           
   13.50 +	echo "  -l,--log		            : Log file"                                           
   13.51 +	echo "  -c,--chain		            : Processing chain of hotspots"
   13.52 +	echo "  -p,--persistence            : Value of persistence of discoverFires query"
   13.53 +	echo "  -r,--repeat_in_persistence  : Value of repeat_in_persistence of discoverFires query"     
   13.54 +}
   13.55  
   13.56 -logFile="chain.log"
   13.57 -
   13.58 +# If no arguments are given it returns miliseconds from 1970-01-01 00:00:00 UTC
   13.59 +# Else if a time (miliseconds form ...) is given it returns the delta between
   13.60 +# given time and current time
   13.61  function timer()
   13.62  {
   13.63     if [[ $# -eq 0 ]]; then
   13.64 @@ -42,12 +62,72 @@
   13.65     fi
   13.66  }
   13.67  
   13.68 -# find out the postgres service to use
   13.69 -postgres=$(ls -1 /etc/init.d/| grep postgres | head -1)
   13.70 +# Handle the postgres service
   13.71 +# -$1: Command for the service
   13.72 +function handlePostgresService()
   13.73 +{
   13.74 +	# find out the postgres service to use
   13.75 +	postgres=$(ls -1 /etc/init.d/| grep postgres | head -1)
   13.76  
   13.77 -tomcat=
   13.78 -function chooseTomcat()
   13.79 +	echo "Service ${postgres} received command: $1"
   13.80 +	sudo service ${postgres} $1
   13.81 +}
   13.82 +
   13.83 +# Handled a postgres database
   13.84 +# -$1: Command (create/drop/store)
   13.85 +# -$2: Dump file to store (if runscript is given as command)
   13.86 +#	   or 'spatial' to create a spatial database (if create is given as command)
   13.87 +function handlePostgresDatabase() {
   13.88 +	local command=$1
   13.89 +	local db=$2
   13.90 +	shift; shift
   13.91 +	local options="$*"
   13.92 +	case "${command}" in
   13.93 +		create)
   13.94 +            if test "${options}" = "spatial"; then
   13.95 +                options="-T template_postgis"
   13.96 +            elif test ! -z "${options}"; then
   13.97 +				echo "ERROR: only spatial is allowed for create option"
   13.98 +				echo "options: ${options}"
   13.99 +				exit -1
  13.100 +			fi
  13.101 +			echo "Creating database ${db}... with options ${options}"
  13.102 +			createdb -U postgres ${db} ${options}	
  13.103 +			;;
  13.104 +		drop)
  13.105 +			if test ! -z "${options}"; then
  13.106 +				echo "ERROR: dropdb takes no extra options"
  13.107 +				echo "options: ${options}"
  13.108 +				exit -1
  13.109 +			fi
  13.110 +			echo "Dropping database ${db}..."
  13.111 +			dropdb -U postgres ${db} 
  13.112 +			;;
  13.113 +		vacuum)
  13.114 +			if test "${options}" = "analyze"; then
  13.115 +				psql -U postgres ${db} -c 'VACUUM ANALYZE' 
  13.116 +                echo "VACUUM ANALYZE ${db}"
  13.117 +			else
  13.118 +				psql -U postgres ${db} -c 'VACUUM' 
  13.119 +                echo "VACUUM ${db}"
  13.120 +			fi
  13.121 +			;;
  13.122 +		runscript)
  13.123 +			if test ! -f "${options}"; then
  13.124 +				echo "ERROR: No dump file to run"
  13.125 +				exit -1
  13.126 +			fi
  13.127 +			echo "Storing dump file ${options} in database ${db}..."
  13.128 +			psql ${db} -f ${options}
  13.129 +			;;
  13.130 +	esac
  13.131 +}
  13.132 +
  13.133 +# Handle the tomcat service
  13.134 +# -$1: Command for the service
  13.135 +function handleTomcatService()
  13.136  {
  13.137 +	# find out the tomcat service to use
  13.138  	if test -s /etc/fedora-release ; then
  13.139  		tomcat="tomcat"
  13.140  	#elif test -s /etc/centos-release ; then
  13.141 @@ -56,89 +136,206 @@
  13.142  	#elif test -s /etc/SuSE-release ; then
  13.143  	#elif test -s /etc/gentoo-release ; then
  13.144  	elif test -s /etc/lsb-release ; then # Ubuntu
  13.145 -			tomcat=$(ls -1 /etc/init.d/| grep tomcat | head -1)
  13.146 +		tomcat=$(ls -1 /etc/init.d/| grep tomcat | head -1)
  13.147  	elif test -s /etc/debian_version ; then
  13.148  		tomcat="tomcat"
  13.149  	fi
  13.150  
  13.151  	# check for service availability
  13.152  	if ! test -e "/etc/init.d/${tomcat}"; then
  13.153 -		tomcat=
  13.154 +		echo "ERROR: No tomcat service found"
  13.155 +		exit -1
  13.156  	fi
  13.157 +
  13.158 +	echo "Service ${tomcat} received command: $1"
  13.159 +	sudo service ${tomcat} $1
  13.160  }
  13.161  
  13.162 -insertMunicipalities=`cat ${LOC}/insertMunicipalities.rq`
  13.163 -deleteSeaHotspots=`cat ${LOC}/deleteSeaHotspots.rq` # | sed 's/\"/\\\"/g'`
  13.164 -refinePartialSeaHotspots=`cat ${LOC}/refinePartialSeaHotspots.rq` # | sed 's/\"/\\\"/g'`
  13.165 -invalidForFires=`cat ${LOC}/landUseInvalidForFires.rq`
  13.166 -refineTimePersistence=`cat ${LOC}/refineTimePersistence.rq` # | sed 's/\"/\\\"/g'`
  13.167 -discover=`cat ${LOC}/discover.rq`
  13.168 -#InsertMunicipalities =`cat ${LOC}/InsertMunicipalities.sparql` # | sed 's/\"/\\\"/g'`
  13.169 +# get the main version of postgres
  13.170 +function getPostgresMainVersion() {
  13.171 +	echo $(sudo service ${postgres} status | grep -o '.\..' | cut -b 1)
  13.172 +}
  13.173  
  13.174 -# Initialize (stop tomcat, restart postgres, drop/create database, start tomcat)
  13.175 -chooseTomcat
  13.176 -echo "stopping tomcat"
  13.177 -if test -z "${tomcat}"; then
  13.178 -	# work-around for babis (standalone tomcat, with start_tomcat.sh and stop_tomcat.sh scripts)
  13.179 -	stop_tomcat.sh
  13.180 -else
  13.181 -	sudo service ${tomcat} stop
  13.182 -fi
  13.183 +# It stores the backgroud data
  13.184 +# - $1: database
  13.185 +# - $2: backgound data file
  13.186 +function storeBackgroundData() {
  13.187 +	local db=$1
  13.188 +	local bgFile=$2
  13.189  
  13.190 -sudo service ${postgres} restart
  13.191 +	if test -f ${bgFile}; then
  13.192 +		handlePostgresDatabase runscript ${db} ${bgFile}	
  13.193 +	elif test "${bgFile:0:7}" = "http://"; then
  13.194 +		curl -s ${bgFile} | tar xzf - -O > /tmp/bgFiles$$.sql
  13.195 +#		wget ${bgFile} -O /tmp/bgFile$$.tar.gz
  13.196 +#		tar xzf /tmp/bgFile$$.tar.gz		
  13.197 +		handlePostgresDatabase runscript ${db} /tmp/bgFiles$$.sql
  13.198 +#		rm /tmp/bgFile$$.tar.gz
  13.199 +		rm /tmp/bgFiles$$.sql
  13.200 +	else
  13.201 +		echo "Backgound file not foung"
  13.202 +		exit -1
  13.203 +	fi
  13.204 +	handlePostgresDatabase vacuum ${db} analyze
  13.205 +}
  13.206  
  13.207 -# get the main version of postgres
  13.208 -POSTGRES_MAIN_VERSION=$(sudo service ${postgres} status | grep -o '.\..' | cut -b 1)
  13.209 +# Handle Stabon Endpoint
  13.210 +# - $1: endpoint
  13.211 +# - $2: command (store/query)
  13.212 +# - $2: file/query
  13.213 +function handleStrabonEndpoint(){
  13.214 +	endpoint=$1
  13.215 +	command=$2
  13.216 +	options=$3
  13.217  
  13.218 -#echo "Dropping endpoint database";
  13.219 -dropdb -U postgres ${DB}
  13.220 +	endpointScript=${loc}/../../scripts/endpoint
  13.221 +	case ${command} in
  13.222 +		store)
  13.223 +			url=${options}
  13.224  
  13.225 -#echo "Creating endpoint database"
  13.226 -createdb -U postgres ${DB} 
  13.227 +			tmr1=$(timer)
  13.228 +			${endpointScript} store ${endpoint} N-Triples -u ${url}
  13.229 +			tmr2=$(timer)
  13.230  
  13.231 -# load data
  13.232 -#curl -s http://dev.strabon.di.uoa.gr/rdf/Kallikratis-Coastline-Corine-dump-postgres-${POSTGRES_MAIN_VERSION}.tgz | tar xz -O | psql -d ${DB}
  13.233 -psql -U postgres -d ${DB} -f /tmp/Kallikratis-Coastline-ExcludeArea-dump.sql
  13.234 -#psql -U postgres ${DB} -c 'VACUUM ANALYZE' 
  13.235 +    		# execute an explicit VACUUM ANALYZE when a query takes longer than it should
  13.236 +    		duration=$((tmr2-tmr1))
  13.237 +    		if test ${duration} -ge 30000; then
  13.238 +                handlePostgresDatabase vacuum ${db} analyze
  13.239 +#    			psql -U postgres ${DB} -c 'VACUUM ANALYZE' 
  13.240 +#    			echo "Explicit VACUUM ANALYZE"
  13.241 +        	    tmr2=$(timer)
  13.242 +    		fi
  13.243 +			printf '%s ' $((tmr2-tmr1)) >> ${logFile}
  13.244 +			;;
  13.245 +		query)
  13.246 +			query=${options}
  13.247 +			tmr1=$(timer)
  13.248 +			${endpointScript} query ${endpoint} "${query}"
  13.249 +			tmr2=$(timer)
  13.250 +			printf '%s ' $((tmr2-tmr1)) >> ${logFile} 
  13.251 +			;;
  13.252 +		update)
  13.253 +			update=${options}
  13.254 +			tmr1=$(timer)
  13.255 +			${endpointScript} update ${endpoint} "${update}"
  13.256 +			tmr2=$(timer)
  13.257 +			printf '%s ' $((tmr2-tmr1)) >> ${logFile}
  13.258 +			;;
  13.259 +		*)
  13.260 +			echo "ERROR: Unknown endpoint command"
  13.261 +			exit -1
  13.262 +			;;
  13.263 +	esac
  13.264 +}
  13.265  
  13.266 -echo "starting tomcat"
  13.267 -if test -z "${tomcat}"; then
  13.268 -	# work-around for babis (standalone tomcat, with start_tomcat.sh and stop_tomcat.sh scripts)
  13.269 -	start_tomcat.sh
  13.270 -	sleep 2
  13.271 -else
  13.272 -	sudo service ${tomcat} start
  13.273 -fi
  13.274 +# default values
  13.275 +endpoint="http://pathway.di.uoa.gr:8080/endpoint"
  13.276 +db="NOA2012"
  13.277 +hotspotsURL="http://jose.di.uoa.gr/rdf/hotspots/MSG1"
  13.278 +#                                 ./examples/teleios/data/data-dump-9.sql
  13.279 +bgFile="http://dev.strabon.di.uoa.gr/rdf/Kallikratis-Coastline-ExcludeArea-dump.tgz"
  13.280 +logFile="runChain.log"
  13.281  
  13.282 -echo "initializing database"
  13.283 -echo "Timestamp Store Municipalities DeleteInSea InvalidForFires RefineInCoast TimePersistence" > stderr.txt
  13.284 +chain="DynamicThresholds"
  13.285 +persistence=10
  13.286 +repeatInPers=3
  13.287  
  13.288 +# read script options
  13.289 +while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
  13.290 +    case "${1}" in
  13.291 +        --help)
  13.292 +            help
  13.293 +            exit 0
  13.294 +            ;;
  13.295 +        -e|--endpoint)
  13.296 +            shift
  13.297 +			endpoint=${1}
  13.298 +            shift
  13.299 +            ;;
  13.300 +        -d|--db)
  13.301 +            shift
  13.302 +			db=${1}
  13.303 +			shift
  13.304 +			;;
  13.305 +		-h|--hotspots)
  13.306 +            shift
  13.307 +			hotspots_url=${1}
  13.308 +			shift
  13.309 +			;;
  13.310 +		-b|--background)
  13.311 +            shift
  13.312 +			bgFile=${1}
  13.313 +			shift
  13.314 +			;;
  13.315 +		-l|--log)
  13.316 +            shift
  13.317 +			logFile=${1}
  13.318 +			shift
  13.319 +			;;
  13.320 +        -c|--chain)
  13.321 +            shift
  13.322 +            chain=${1}
  13.323 +            shift
  13.324 +            ;;
  13.325 +        -p|--persistence)
  13.326 +            shift
  13.327 +            persistence=${1}
  13.328 +            shift
  13.329 +            ;;
  13.330 +        -r|--repeat_in_persistence)
  13.331 +            shift
  13.332 +            repeat_in_persistence=${1}
  13.333 +            shift
  13.334 +            ;;
  13.335 +		*)
  13.336 +			echo "unknown argument ${1}"
  13.337 +			help
  13.338 +			exit -1
  13.339 +			;;
  13.340 +	esac
  13.341 +done
  13.342  
  13.343 -#./scripts/endpoint query ${ENDPOINT} "SELECT (COUNT(*) AS ?C) WHERE {?s ?p ?o}"
  13.344 -#sudo -u postgres psql -d endpoint -c 'CREATE INDEX datetime_values_idx_value ON datetime_values USING btree(value)';
  13.345 -#sudo -u postgres psql -d endpoint -c 'VACUUM ANALYZE;';
  13.346 +echo "endpoint: ${endpoint}"
  13.347 +echo "db: ${db}"
  13.348 +echo "hotspots: ${hotspotsURL}"
  13.349 +echo "background: ${bgFile}"
  13.350 +echo "logFile: ${logFile}"
  13.351  
  13.352 -#for y in 2007 2008 2010 2011; do
  13.353 -for y in 2012; do
  13.354 +instantiate=${loc}/instantiate.sh
  13.355 +
  13.356 +#Initialize (stop tomcat, restart postgres, drop/create database, start tomcat)
  13.357 +handleTomcatService stop
  13.358 +handlePostgresService restart
  13.359 +
  13.360 +handlePostgresDatabase drop ${db}
  13.361 +handlePostgresDatabase create ${db}
  13.362 +
  13.363 +storeBackgroundData ${db} ${bgFile} # ~/Temp/Kallikratis-Coastline-Corine-postgres-9.sql
  13.364 +
  13.365 +handleTomcatService start
  13.366 +
  13.367 +#${loc}/../../scripts/endpoint query ${endpoint} size 
  13.368 +#exit -1
  13.369 +echo "Timestamp Store Municipalities DeleteInSea InvalidForFires DeleteReflections RefineInCoast TimePersistence DiscoverHotspots DiscoverFires" > ${logFile}
  13.370 +echo > /home/ggarbis/discoverFires.log
  13.371 +echo > /home/ggarbis/discover.log
  13.372 +
  13.373 +years="2012" #"2007 2008 2010 2011"
  13.374 +for y in ${years}; do
  13.375 +#    hotspots="`ls /var/www/hotspots/${y} | sort | grep -o 'HMSG.*\.nt'`"
  13.376  	# get hotpost URLS
  13.377 -	for hot in $(curl -s ${HOTSPOTS_URL}/${y}/ | grep -o '>HMSG.*\.nt' | colrm 1 1); do
  13.378 -		file="${HOTSPOTS_URL}/${y}/${hot}"
  13.379 +	for hot in $(curl -s ${hotspotsURL}/${y}/ | grep -o '>HMSG.*\.nt' | colrm 1 1); do
  13.380 +#	for hot in ${hotspots}; do
  13.381 +		file="${hotspotsURL}/${y}/${hot}"
  13.382  
  13.383  		time_status=$(echo ${hot} | egrep -o '[[:digit:]]{6}_[[:digit:]]{4}')
  13.384  		
  13.385  		# get sensor
  13.386 -		SENSOR=$(echo ${hot} | grep -o 'MSG.')
  13.387 +		sensor=$(echo ${hot} | grep -o 'MSG.')
  13.388  
  13.389  		# get satellite and set number of acquisitions per hour
  13.390 -		if test "${SENSOR}" = "MSG2"; then
  13.391 -			SAT="METEOSAT9"
  13.392 -
  13.393 -			N_ACQUISITIONS=3.0
  13.394 -		else
  13.395 -			SAT="METEOSAT8"
  13.396 -			SENSOR="MSG1_RSS"
  13.397 -
  13.398 -			N_ACQUISITIONS=7.0
  13.399 +		if test "${sensor}" = "MSG1"; then
  13.400 +			sensor="MSG1_RSS"
  13.401  		fi
  13.402  
  13.403  		# get time information for acquisition and construct timestamp
  13.404 @@ -149,127 +346,62 @@
  13.405  		time2="${time2}:$(expr substr ${time_status} 10 2)"
  13.406  
  13.407  		# construct timestamp
  13.408 -		TIMESTAMP="${year}-${month}-${day}T${time2}:00"
  13.409 +		timestamp="${year}-${month}-${day}T${time2}:00"
  13.410 +		# print timestamp
  13.411 +		echo -n "${timestamp} " >> ${logFile}
  13.412 +        
  13.413 +		handleStrabonEndpoint ${endpoint} store ${file}
  13.414 +        echo "Processing File ${file}" ; # read t
  13.415  
  13.416 -		# store file
  13.417 -		echo -n "storing " $file; echo; echo; 
  13.418 -		# ${countTime} ./strabon -db endpoint store $file
  13.419 +		# Insert Municipalities	
  13.420 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} ${loc}/insertMunicipalities.rq`"
  13.421 +#        echo "Insert Municipalities: ${update}" ; read t
  13.422 +        handleStrabonEndpoint ${endpoint} update "${update}"
  13.423  
  13.424 -		# print timestamp
  13.425 -		echo -n "${TIMESTAMP} " >> stderr.txt
  13.426  
  13.427 -		tmr1=$(timer)
  13.428 -		${ENDPOINT_SCRIPT} store ${ENDPOINT} N-Triples -u ${file}
  13.429 -		tmr2=$(timer)
  13.430 -		printf '%s ' $((tmr2-tmr1)) >> stderr.txt
  13.431 +		# Delete Sea Hotspots
  13.432 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} ${loc}/deleteSeaHotspots.rq`"
  13.433 +#       echo "Delete Sea Hotspots: ${update}" ; read t
  13.434 +		handleStrabonEndpoint ${endpoint} update "${update}"
  13.435  
  13.436 -		# sudo -u postgres psql -d endpoint -c 'VACUUM ANALYZE;';
  13.437 +		# Invalid For Fires
  13.438 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} ${loc}/landUseInvalidForFires.rq`"
  13.439 +#       echo "Invalid For Fires: ${update}" ; read t
  13.440 +		handleStrabonEndpoint ${endpoint} update "${update}"
  13.441 + 
  13.442 +        # Delete Reflections
  13.443 +    	minTime=`date --date="${year}-${month}-${day} ${time2}:00 EEST -60 minutes" +%Y-%m-%dT%H:%M:00`
  13.444 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} -m ${minTime} ${loc}/deleteReflections.rq`"
  13.445 +#        echo "Delete Reflections: ${update}" ;
  13.446 +		handleStrabonEndpoint ${endpoint} update "${update}"
  13.447  
  13.448 -		echo;echo;echo;echo "File ${file} stored!" >> ${logFile}
  13.449 +		# Refine Partial Sea Hotspots
  13.450 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} ${loc}/refinePartialSeaHotspots.rq`"
  13.451 +#       echo "Refine Partial Sea Hotspots: ${update}" ; read t
  13.452 +		handleStrabonEndpoint ${endpoint} update "${update}"
  13.453  
  13.454 -		# insertMunicipalities
  13.455 -		echo -n "inserting Municipalities " ;echo; echo; echo;
  13.456 -		# query=`echo "${insertMunicipalities}" `
  13.457 -		# ${countTime} ./strabon -db endpoint update "${query}"
  13.458 -
  13.459 -		tmr1=$(timer)
  13.460 -
  13.461 -		query=`echo "${insertMunicipalities}" | sed "s/TIMESTAMP/${TIMESTAMP}/g" | \
  13.462 -		sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.463 -		sed "s/SENSOR/${SENSOR}/g"`
  13.464 -
  13.465 -		${ENDPOINT_SCRIPT} update ${ENDPOINT} "${query}"
  13.466 -		
  13.467 -		tmr2=$(timer)
  13.468 -		printf '%s ' $((tmr2-tmr1)) >>stderr.txt
  13.469 -		echo;echo;echo;echo "File ${file} inserted Municipalities!"
  13.470 -
  13.471 -		# execute an explicit VACUUM ANALYZE when a query takes longer than it should
  13.472 -		duration=$((tmr2-tmr1))
  13.473 -		if test ${duration} -ge 30000; then
  13.474 -			psql -U postgres ${DB} -c 'VACUUM ANALYZE' 
  13.475 -			echo "Explicit VACUUM ANALYZE"
  13.476 -		fi
  13.477 -		
  13.478 -		# deleteSeaHotspots
  13.479 -		echo -n "Going to deleteSeaHotspots ${TIMESTAMP} " ;echo; echo; echo;
  13.480 -		query=`echo "${deleteSeaHotspots}" | sed "s/TIMESTAMP/${TIMESTAMP}/g" | \
  13.481 -		sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.482 -		sed "s/SENSOR/${SENSOR}/g"`
  13.483 -		# ${countTime} ./strabon -db endpoint update "${query}"
  13.484 -
  13.485 -		tmr1=$(timer)
  13.486 -		${ENDPOINT_SCRIPT} update ${ENDPOINT} "${query}"
  13.487 -
  13.488 -		tmr2=$(timer)
  13.489 -		printf '%s ' $((tmr2-tmr1)) >>stderr.txt
  13.490 -		echo;echo;echo;echo "File ${file} deleteSeaHotspots done!"
  13.491 -
  13.492 -		# invalidForFires
  13.493 -		echo -n "invalidForFires ${TIMESTAMP} "  ; echo; echo ; echo;
  13.494 -		query=`echo "${invalidForFires}" | sed "s/TIMESTAMP/${TIMESTAMP}/g" | \
  13.495 -		sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.496 -		sed "s/SENSOR/${SENSOR}/g"` 
  13.497 -
  13.498 -		# ${countTime} ./strabon -db endpoint update "${query}"
  13.499 -		tmr1=$(timer)
  13.500 -		${ENDPOINT_SCRIPT} update ${ENDPOINT} "${query}"
  13.501 -		tmr2=$(timer)
  13.502 -		printf '%s ' $((tmr2-tmr1)) >>stderr.txt
  13.503 -		echo "File ${file} invalidForFires done!"
  13.504 - 
  13.505 -		# refinePartialSeaHotspots
  13.506 -		echo -n "refinePartialSeaHotspots ${TIMESTAMP} "  ; echo; echo ; echo;
  13.507 -		query=`echo "${refinePartialSeaHotspots}" | sed "s/TIMESTAMP/${TIMESTAMP}/g" | \
  13.508 -		sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.509 -		sed "s/SENSOR/${SENSOR}/g" |\
  13.510 -		sed "s/SAT/${SAT}/g"`
  13.511 -		# ${countTime} ./strabon -db endpoint update "${query}"
  13.512 -		tmr1=$(timer)
  13.513 -		${ENDPOINT_SCRIPT} update ${ENDPOINT} "${query}"
  13.514 -		tmr2=$(timer)
  13.515 -		printf '%s ' $((tmr2-tmr1)) >>stderr.txt
  13.516 -
  13.517 -		echo "File ${file} refinePartialSeaHotspots done!"
  13.518 -		# echo "Continue?"
  13.519 -		# read a
  13.520 -
  13.521 -		# refineTimePersistence
  13.522 -		echo -n "Going to refineTimePersistence ${TIMESTAMP} ";echo;echo;echo; 
  13.523 -		min_acquisition_time=`date --date="${year}-${month}-${day} ${time2}:00 EEST -30 minutes" +%Y-%m-%dT%H:%M:00`
  13.524 -		query=`echo "${refineTimePersistence}" | sed "s/TIMESTAMP/${TIMESTAMP}/g" | \
  13.525 -		sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.526 -		sed "s/SENSOR/${SENSOR}/g" | \
  13.527 -		sed "s/ACQUISITIONS_IN_HALF_AN_HOUR/${N_ACQUISITIONS}/g" | \
  13.528 -		sed "s/MIN_ACQUISITION_TIME/${min_acquisition_time}/g" |\
  13.529 -		sed "s/SAT/${SAT}/g"`
  13.530 +		# Refine Time Persistence
  13.531 +		minTime=`date --date="${year}-${month}-${day} ${time2}:00 EEST -30 minutes" +%Y-%m-%dT%H:%M:00`
  13.532 +		update="`${instantiate} -t ${timestamp} -c ${chain} -s ${sensor} -m ${minTime} ${loc}/refineTimePersistence.rq`"
  13.533 +#       echo "Refine Time Persistence: ${update}" ; read t
  13.534 +		handleStrabonEndpoint ${endpoint} update "${update}" #2>&1 | tee /home/ggarbis/timePersistence.log
  13.535  
  13.536  		#sudo -u postgres psql -d ${DB} -c 'VACUUM ANALYZE;';
  13.537 +        
  13.538 +		# Discover
  13.539 +		minTime=`date --date="${year}-${month}-${day} 00:00 EEST" +%Y-%m-%dT%H:%M:00`
  13.540 +		maxTime=`date --date="${year}-${month}-${day} 23:59 EEST" +%Y-%m-%dT%H:%M:00`
  13.541 +        query="`${instantiate} -c ${chain} -s ${sensor} -m ${minTime} -M ${maxTime} ${loc}/discover.rq`"
  13.542 +#        echo "Discover: ${query}" ; #read t
  13.543 +		handleStrabonEndpoint ${endpoint} query "${query}" &>> /home/ggarbis/discover.log
  13.544 +    
  13.545 +		# Discover Fires
  13.546 +		minTime=`date --date="${year}-${month}-${day} 00:00 EEST" +%Y-%m-%dT%H:%M:00`
  13.547 +		maxTime=`date --date="${year}-${month}-${day} 23:59 EEST" +%Y-%m-%dT%H:%M:00`
  13.548 +        query="`${instantiate} -c ${chain} -s ${sensor} -m ${minTime} -M ${maxTime} -p 10 -r 3 ${loc}/discoverFires.rq`"
  13.549 +#        echo "Discover Fires: ${query}" ; #read t
  13.550 +		handleStrabonEndpoint ${endpoint} query "${query}" &>> /home/ggarbis/discoverFires.log
  13.551  
  13.552 -		tmr1=$(timer)
  13.553 -		${ENDPOINT_SCRIPT} update ${ENDPOINT} "${query}"
  13.554 -		 tmr2=$(timer)
  13.555 -		printf '%s \n' $((tmr2-tmr1)) >>stderr.txt
  13.556 -		echo;echo;echo;echo "File ${file} timePersistence done!"
  13.557 -		# echo "Continue?"
  13.558 -		# read a
  13.559 -
  13.560 -
  13.561 -		# discover
  13.562 -		echo -n "Going to discover ${TIMESTAMP} ";echo;echo;echo; 
  13.563 -		min_acquisition_time=`date --date="${year}-${month}-${day} 00:00 EEST" +%Y-%m-%dT%H:%M:00`
  13.564 -		max_acquisition_time=`date --date="${year}-${month}-${day} 23:59 EEST" +%Y-%m-%dT%H:%M:00`
  13.565 -		query=`echo "${discover}" | \
  13.566 -			sed "s/PROCESSING_CHAIN/DynamicThresholds/g" | \
  13.567 -			sed "s/SENSOR/${SENSOR}/g" | \
  13.568 -			sed "s/MIN_ACQUISITION_TIME/${min_acquisition_time}/g" |\
  13.569 -			sed "s/MAX_ACQUISITION_TIME/${max_acquisition_time}/g"`
  13.570 -			
  13.571 -		tmr1=$(timer)
  13.572 -		${ENDPOINT_SCRIPT} query ${ENDPOINT} "${query}"
  13.573 -		tmr2=$(timer)
  13.574 -		printf '%s \n' $((tmr2-tmr1)) >>discover.txt
  13.575 -		echo;echo;echo;echo "Discovered hotspots done!"
  13.576 +        echo >> ${logFile}    
  13.577  	done
  13.578  done
  13.579 -
    14.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Mon Dec 24 14:14:08 2012 +0100
    14.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Tue Jan 08 12:30:51 2013 +0200
    14.3 @@ -211,6 +211,7 @@
    14.4  			EvaluationStrategy strategy;
    14.5  			strategy = factory.createRdbmsEvaluation(dataset);
    14.6  			tupleExpr = optimizer.optimize(expr, dataset, bindings, strategy);
    14.7 +			// Mexri edw to GeneralDBSqlDiffDateTime ftanei kanonika
    14.8  			return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance());
    14.9  		}
   14.10  		catch (QueryEvaluationException e) {
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDateTimeMetricBinary.java	Tue Jan 08 12:30:51 2013 +0200
    15.3 @@ -0,0 +1,35 @@
    15.4 +package org.openrdf.sail.generaldb.algebra;
    15.5 +
    15.6 +import java.util.ArrayList;
    15.7 +
    15.8 +import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator;
    15.9 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
   15.10 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   15.11 +import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator;
   15.12 +
   15.13 +/** Addition for datetime metric functions
   15.14 + * 
   15.15 + * @author George Garbis <ggarbis@di.uoa.gr>
   15.16 + * 
   15.17 + */
   15.18 +
   15.19 +public class GeneralDBSqlDateTimeMetricBinary extends BinaryGeneralDBOperator
   15.20 +{
   15.21 +
   15.22 +
   15.23 +	/*CONSTRUCTOR*/
   15.24 +
   15.25 +	public GeneralDBSqlDateTimeMetricBinary(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   15.26 +		super(left, right);
   15.27 +	}
   15.28 +
   15.29 +	@Override
   15.30 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
   15.31 +	throws X
   15.32 +	{
   15.33 +		visitor.meet(this);
   15.34 +	}
   15.35 +
   15.36 +}
   15.37 +
   15.38 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDiffDateTime.java	Tue Jan 08 12:30:51 2013 +0200
    16.3 @@ -0,0 +1,31 @@
    16.4 +/*
    16.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    16.6 + *
    16.7 + * Licensed under the Aduna BSD-style license.
    16.8 + */
    16.9 +package org.openrdf.sail.generaldb.algebra;
   16.10 +
   16.11 +  
   16.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
   16.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   16.14 +
   16.15 +/** Addition for datetime metric functions
   16.16 + * 
   16.17 + * @author George Garbis <ggarbis@di.uoa.gr>
   16.18 + * 
   16.19 + */
   16.20 +
   16.21 +public class GeneralDBSqlDiffDateTime extends GeneralDBSqlDateTimeMetricBinary {
   16.22 +	
   16.23 +	public GeneralDBSqlDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   16.24 +		super(left, right);
   16.25 +	}
   16.26 +
   16.27 +	@Override
   16.28 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
   16.29 +		throws X
   16.30 +	{
   16.31 +		visitor.meet(this);
   16.32 +	}
   16.33 +
   16.34 +}
   16.35 \ No newline at end of file
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlExtDiffDateTime.java	Tue Jan 08 12:30:51 2013 +0200
    17.3 @@ -0,0 +1,31 @@
    17.4 +/*
    17.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    17.6 + *
    17.7 + * Licensed under the Aduna BSD-style license.
    17.8 + */
    17.9 +package org.openrdf.sail.generaldb.algebra;
   17.10 +
   17.11 +  
   17.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
   17.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   17.14 +
   17.15 +/** Addition for datetime metric functions
   17.16 + * 
   17.17 + * @author George Garbis <ggarbis@di.uoa.gr>
   17.18 + * 
   17.19 + */
   17.20 +
   17.21 +public class GeneralDBSqlExtDiffDateTime extends GeneralDBSqlDateTimeMetricBinary {
   17.22 +
   17.23 +	public GeneralDBSqlExtDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   17.24 +		super(left, right);
   17.25 +	}
   17.26 +
   17.27 +	@Override
   17.28 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
   17.29 +		throws X
   17.30 +	{
   17.31 +		visitor.meet(this);
   17.32 +	}
   17.33 +
   17.34 +}
   17.35 \ No newline at end of file
    18.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Mon Dec 24 14:14:08 2012 +0100
    18.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java	Tue Jan 08 12:30:51 2013 +0200
    18.3 @@ -9,7 +9,7 @@
    18.4  import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
    18.5  import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
    18.6  
    18.7 -public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricBinary{
    18.8 +public class GeneralDBSqlGeoDistance extends GeneralDBSqlSpatialMetricBinary {
    18.9  
   18.10  	public GeneralDBSqlGeoDistance(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   18.11  		super(left, right);
    19.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java	Mon Dec 24 14:14:08 2012 +0100
    19.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java	Tue Jan 08 12:30:51 2013 +0200
    19.3 @@ -27,7 +27,7 @@
    19.4  	}
    19.5  
    19.6  	public BinaryGeneralDBOperator(GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg) {
    19.7 -		super();
    19.8 +		super(); // Edw to this(distance) exei ginei GeneralDBSqlGeoDistance
    19.9  		setLeftArg(leftArg);
   19.10  		setRightArg(rightArg);
   19.11  	}
    20.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Mon Dec 24 14:14:08 2012 +0100
    20.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java	Tue Jan 08 12:30:51 2013 +0200
    20.3 @@ -24,9 +24,11 @@
    20.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
    20.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbContains;
    20.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCrosses;
    20.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
    20.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
    20.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
   20.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   20.11 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlExtDiffDateTime;
   20.12  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
   20.13  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
   20.14  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
   20.15 @@ -391,6 +393,30 @@
   20.16  		return new GeneralDBSqlGeoSymDifference(left, right);
   20.17  	}
   20.18  	
   20.19 +	/** Addition for datetime metric functions
   20.20 +	 * 
   20.21 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   20.22 +	 * 
   20.23 +	 */
   20.24 +	public static GeneralDBSqlExpr extDiffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   20.25 +
   20.26 +		return new GeneralDBSqlExtDiffDateTime(left, right);
   20.27 +	}
   20.28 +	/***/
   20.29 +	
   20.30 +	/** Addition for datetime metric functions
   20.31 +	 * 
   20.32 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   20.33 +	 * 
   20.34 +	 */
   20.35 +
   20.36 +	public static GeneralDBSqlExpr diffDateTime(GeneralDBSqlExpr left, GeneralDBSqlExpr right) {
   20.37 +
   20.38 +		return new GeneralDBSqlDiffDateTime(left, right);
   20.39 +	}
   20.40 +	
   20.41 +	/***/
   20.42 +	
   20.43  	//XXX Spatial Metric Functions
   20.44  	public static GeneralDBSqlExpr geoArea(GeneralDBSqlExpr expr) {
   20.45  
    21.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Mon Dec 24 14:14:08 2012 +0100
    21.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java	Tue Jan 08 12:30:51 2013 +0200
    21.3 @@ -29,6 +29,7 @@
    21.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCast;
    21.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCompare;
    21.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlConcat;
    21.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDateTimeMetricBinary;
    21.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
    21.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSpatial;
   21.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
   21.11 @@ -330,7 +331,7 @@
   21.12  	 {
   21.13  		 meetUnarySqlOperator(node);
   21.14  	 }
   21.15 -
   21.16 +	 
   21.17  	 public void meet(GeneralDBSqlSpatialMetricBinary node) throws X 
   21.18  	 {
   21.19  		 meetBinarySqlOperator(node);
   21.20 @@ -364,7 +365,18 @@
   21.21  		 meetNode(node);
   21.22  	 }
   21.23  
   21.24 -	 //	public void meet(GeneralDBSqlmbbIntersects node) throws X
   21.25 +	 /** Addition for datetime metric functions
   21.26 +	  * 
   21.27 +	  * @author George Garbis <ggarbis@di.uoa.gr>
   21.28 +	  * 
   21.29 +	  */ 
   21.30 +	public void meet(GeneralDBSqlDateTimeMetricBinary node) 
   21.31 +	throws X {
   21.32 +		meetBinarySqlOperator(node);
   21.33 +	}
   21.34 +	/***/
   21.35 +	
   21.36 +	 //	public void meet(GeneralDBSqlAnyInteract node) throws X
   21.37  	 //	{
   21.38  	 //		meetBinarySqlOperator(node);
   21.39  	 //	}
    22.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Mon Dec 24 14:14:08 2012 +0100
    22.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java	Tue Jan 08 12:30:51 2013 +0200
    22.3 @@ -32,6 +32,7 @@
    22.4  import org.openrdf.query.algebra.evaluation.function.Function;
    22.5  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
    22.6  import org.openrdf.query.algebra.evaluation.function.link.AddDateTimeFunc;
    22.7 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
    22.8  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    22.9  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   22.10  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   22.11 @@ -105,7 +106,7 @@
   22.12  	@Override
   22.13  	public void meet(Compare compare)
   22.14  			throws UnsupportedRdbmsOperatorException
   22.15 -			{
   22.16 +	{
   22.17  		ValueExpr left = compare.getLeftArg();
   22.18  		ValueExpr right = compare.getRightArg();
   22.19  		CompareOp op = compare.getOperator();
   22.20 @@ -114,7 +115,9 @@
   22.21  		 * 
   22.22  		 */
   22.23  		boolean leftIsSpatial = false;
   22.24 +		boolean leftIsDateTime = false;
   22.25  		boolean rightIsSpatial = false;
   22.26 +		boolean rightIsDateTime = false;
   22.27  		GeneralDBSqlExpr leftSql = null;
   22.28  		GeneralDBSqlExpr rightSql = null;
   22.29  
   22.30 @@ -124,12 +127,25 @@
   22.31  			if(function instanceof SpatialMetricFunc)
   22.32  			{
   22.33  				leftSql = spatialMetricFunction((FunctionCall) left, function);
   22.34 +				leftIsSpatial = true;
   22.35  			}
   22.36 +			/**
   22.37 +			 * Addition for datetime metric functions
   22.38 +			 * 
   22.39 +			 * @author George Garbis <ggarbis@di.uoa.gr>
   22.40 +			 * 
   22.41 +			 */
   22.42 +			else if (function instanceof DateTimeMetricFunc){
   22.43 +				// Edw prepei na epistrafei ena GenearalDBSqlDiffDateTime me parent=null
   22.44 +				leftSql = dateTimeMetricFunction((FunctionCall)left, function);
   22.45 +				leftIsDateTime = true;
   22.46 +			}
   22.47 +			/***/
   22.48  			else //spatial property
   22.49  			{
   22.50  				leftSql = spatialPropertyFunction((FunctionCall) left, function);
   22.51 +				leftIsSpatial = true;
   22.52  			}
   22.53 -			leftIsSpatial = true;
   22.54  		}
   22.55  		else if(left instanceof MathExpr)
   22.56  		{
   22.57 @@ -143,30 +159,35 @@
   22.58  
   22.59  		if(right instanceof FunctionCall)
   22.60  		{
   22.61 -			System.out.println("FUNCTION:"+right.toString());
   22.62  			Function function = FunctionRegistry.getInstance().get(((FunctionCall)right).getURI());
   22.63  			if(function instanceof SpatialMetricFunc)
   22.64  			{
   22.65  				rightSql = spatialMetricFunction((FunctionCall) right, function);
   22.66 +				rightIsSpatial = true;
   22.67  			}
   22.68 -			else if(((FunctionCall) right).getURI().toString().equalsIgnoreCase("http://example.org/custom-function/addDatetime"))
   22.69 -			{
   22.70 -				System.out.println("ADD DATE TIME FUNC!");
   22.71 -				FunctionRegistry fr =  FunctionRegistry.getInstance();
   22.72 -				Function f = fr.get("http://example.org/custom-function/addDatetime");
   22.73 -				if (f == null){System.out.println("COULD NOT GET DA FUNCTION!");}
   22.74 +			/**
   22.75 +			 * Addition for datetime metric functions
   22.76 +			 * 
   22.77 +			 * @author George Garbis <ggarbis@di.uoa.gr>
   22.78 +			 * 
   22.79 +			 */
   22.80 +			else if (function instanceof DateTimeMetricFunc){
   22.81 +				// Edw prepei na epistrafei ena GenearalDBSqlDiffDateTime me parent=null
   22.82 +				rightSql = dateTimeMetricFunction((FunctionCall)right, function);
   22.83 +				rightIsDateTime = true;
   22.84  			}
   22.85 +			/***/
   22.86  			else //spatial property
   22.87  			{
   22.88  				System.out.println("SPATIAL PROPERTY!!!");
   22.89  				rightSql = spatialPropertyFunction((FunctionCall) right, function);
   22.90 +				rightIsSpatial = true;
   22.91  			}
   22.92 -			rightIsSpatial = true;
   22.93  		}
   22.94  		else if(right instanceof MathExpr)
   22.95  		{
   22.96  			//some recursive function plainly to find out whether there is some nested metric
   22.97 -			rightIsSpatial = containsMetric((MathExpr)left);
   22.98 +			rightIsSpatial = containsMetric((MathExpr)right);
   22.99  			if(rightIsSpatial)
  22.100  			{
  22.101  				rightSql = numeric(right);
  22.102 @@ -179,7 +200,7 @@
  22.103  
  22.104  		switch (op) {
  22.105  		case EQ:
  22.106 -			if(!rightIsSpatial&&!leftIsSpatial)
  22.107 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
  22.108  			{
  22.109  				//default cases
  22.110  				if (isTerm(left) && isTerm(right)) {
  22.111 @@ -193,12 +214,12 @@
  22.112  			else
  22.113  			{
  22.114  				//more complicated cases
  22.115 -				if(!rightIsSpatial)
  22.116 +				if(!rightIsSpatial && !rightIsDateTime)
  22.117  				{
  22.118  					rightSql = numeric(right);
  22.119  				}
  22.120  
  22.121 -				if(!leftIsSpatial)
  22.122 +				if(!leftIsSpatial && !leftIsDateTime)
  22.123  				{
  22.124  					leftSql = numeric(right);
  22.125  				}
  22.126 @@ -206,7 +227,7 @@
  22.127  			}
  22.128  			break;
  22.129  		case NE:
  22.130 -			if(!rightIsSpatial&&!leftIsSpatial)
  22.131 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
  22.132  			{
  22.133  				//default cases
  22.134  				if (isTerm(left) && isTerm(right)) {
  22.135 @@ -220,12 +241,12 @@
  22.136  			else
  22.137  			{
  22.138  				//more complicated cases
  22.139 -				if(!rightIsSpatial)
  22.140 +				if(!rightIsSpatial && !rightIsDateTime)
  22.141  				{
  22.142  					rightSql = numeric(right);
  22.143  				}
  22.144  
  22.145 -				if(!leftIsSpatial)
  22.146 +				if(!leftIsSpatial && !leftIsSpatial)
  22.147  				{
  22.148  					leftSql = numeric(right);
  22.149  				}
  22.150 @@ -237,7 +258,7 @@
  22.151  		case LE:
  22.152  		case LT:
  22.153  
  22.154 -			if(!rightIsSpatial&&!leftIsSpatial)
  22.155 +			if( (!rightIsSpatial && !rightIsDateTime) && (!leftIsSpatial && !leftIsDateTime) )
  22.156  			{
  22.157  				//default cases
  22.158  				GeneralDBSqlExpr simple = and(simple(type(left)), simple(type(right)));
  22.159 @@ -257,12 +278,12 @@
  22.160  			else
  22.161  			{
  22.162  				//more complicated cases
  22.163 -				if(!rightIsSpatial)
  22.164 +				if(!rightIsSpatial && !rightIsDateTime)
  22.165  				{
  22.166  					rightSql = numeric(right);
  22.167  				}
  22.168  
  22.169 -				if(!leftIsSpatial)
  22.170 +				if(!leftIsSpatial && !leftIsDateTime)
  22.171  				{
  22.172  					leftSql = numeric(right);
  22.173  				}
  22.174 @@ -271,7 +292,7 @@
  22.175  
  22.176  			break;
  22.177  		}
  22.178 -			}
  22.179 +	}
  22.180  
  22.181  	@Override
  22.182  	public void meet(IsBNode node)
  22.183 @@ -687,6 +708,24 @@
  22.184  
  22.185  			}
  22.186  
  22.187 +	/**
  22.188 +	 * Addition for datetime metric functions
  22.189 +	 * 
  22.190 +	 * @author George Garbis <ggarbis@di.uoa.gr>
  22.191 +	 * 
  22.192 +	 */
  22.193 +	public GeneralDBSqlExpr dateTimeFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
  22.194 +	{
  22.195 +		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
  22.196 +		if(function instanceof DateTimeMetricFunc) //1 argument
  22.197 +		{
  22.198 +			return dateTimeMetricFunction(functionCall,function);	
  22.199 +		}
  22.200 +		return null;
  22.201 +	}
  22.202 +
  22.203 +	/***/
  22.204 +	
  22.205  	public GeneralDBSqlExpr spatialFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
  22.206  	{
  22.207  		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
  22.208 @@ -808,6 +847,45 @@
  22.209  
  22.210  	}
  22.211  
  22.212 +	/**
  22.213 +	 * Addition for datetime metric functions
  22.214 +	 * 
  22.215 +	 * @author George Garbis <ggarbis@di.uoa.gr>
  22.216 +	 * 
  22.217 +	 */
  22.218 +	GeneralDBSqlExpr dateTimeMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
  22.219 +	{
  22.220 +		GeneralDBSqlExpr leftArg = null;
  22.221 +		GeneralDBSqlExpr rightArg = null;
  22.222 +
  22.223 +		ValueExpr left = functionCall.getArgs().get(0);
  22.224 +		ValueExpr right = functionCall.getArgs().get(1);
  22.225 +
  22.226 +		if(left instanceof FunctionCall)
  22.227 +		{
  22.228 +			leftArg = dateTimeFunction((FunctionCall) left);
  22.229 +		}
  22.230 +		else
  22.231 +		{
  22.232 +			leftArg = time(left);
  22.233 +		}
  22.234 +
  22.235 +		if(right instanceof FunctionCall)
  22.236 +		{
  22.237 +			rightArg = spatialFunction((FunctionCall) right);
  22.238 +			rightArg = dateTimeFunction((FunctionCall) right);
  22.239 +		}
  22.240 +		else
  22.241 +		{
  22.242 +			rightArg = time(right);
  22.243 +		}
  22.244 +		
  22.245 +		return dateTimeMetricPicker(function, leftArg, rightArg);
  22.246 +
  22.247 +	}
  22.248 +
  22.249 +	/***/
  22.250 +	
  22.251  	GeneralDBSqlExpr spatialMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
  22.252  	{
  22.253  		GeneralDBSqlExpr leftArg = null;
  22.254 @@ -1120,6 +1198,25 @@
  22.255  		return null;
  22.256  	}
  22.257  
  22.258 +	/** Addition for datetime metric functions
  22.259 +	 * 
  22.260 +	 * @author George Garbis <ggarbis@di.uoa.gr>
  22.261 +	 * 
  22.262 +	 */
  22.263 +	
  22.264 +	GeneralDBSqlExpr dateTimeMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
  22.265 +	{
  22.266 +		if(function.getURI().equals(GeoConstants.diffDateTime))
  22.267 +		{
  22.268 +			return diffDateTime(leftArg, rightArg);
  22.269 +		}
  22.270 +
  22.271 +		//Should never reach this place
  22.272 +		return null;
  22.273 +	}
  22.274 +	
  22.275 +	/***/
  22.276 +	
  22.277  	//TODO more to be added here probably
  22.278  	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
  22.279  	{
    23.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Mon Dec 24 14:14:08 2012 +0100
    23.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java	Tue Jan 08 12:30:51 2013 +0200
    23.3 @@ -12,6 +12,7 @@
    23.4  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoBuffer;
    23.5  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoConvexHull;
    23.6  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoDifference;
    23.7 +import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.extDiffDateTime;
    23.8  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoDistance;
    23.9  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoEnvelope;
   23.10  import static org.openrdf.sail.generaldb.algebra.base.GeneralDBExprSupport.geoIntersection;
   23.11 @@ -41,6 +42,7 @@
   23.12  import org.openrdf.query.algebra.Var;
   23.13  import org.openrdf.query.algebra.evaluation.function.Function;
   23.14  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
   23.15 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
   23.16  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
   23.17  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   23.18  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   23.19 @@ -249,7 +251,27 @@
   23.20  			return spatialPropertyPicker(function, leftArg);
   23.21  		}
   23.22  	}
   23.23 +	
   23.24 +	/** Addition for datetime metric functions
   23.25 +	 * 
   23.26 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   23.27 +	 * 
   23.28 +	 */
   23.29  
   23.30 +	public GeneralDBSqlExpr dateTimeFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
   23.31 +	{
   23.32 +		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
   23.33 +		if(function instanceof DateTimeMetricFunc)
   23.34 +		{
   23.35 +			return dateTimeMetricFunction(functionCall,function);	
   23.36 +		}
   23.37 +		
   23.38 +		return null;
   23.39 +	}
   23.40 +
   23.41 +	
   23.42 +	/***/
   23.43 +	
   23.44  	public GeneralDBSqlExpr spatialFunction(FunctionCall functionCall) throws UnsupportedRdbmsOperatorException
   23.45  	{
   23.46  		Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
   23.47 @@ -329,6 +351,31 @@
   23.48  
   23.49  	}
   23.50  
   23.51 +	/**
   23.52 +	 * Addition for datetime metric functions
   23.53 +	 * 
   23.54 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   23.55 +	 * 
   23.56 +	 */
   23.57 +	
   23.58 +	GeneralDBSqlExpr dateTimeMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
   23.59 +	{
   23.60 +		GeneralDBSqlExpr leftArg = null;
   23.61 +		GeneralDBSqlExpr rightArg = null;
   23.62 +
   23.63 +		ValueExpr left = functionCall.getArgs().get(0);
   23.64 +		ValueExpr right = functionCall.getArgs().get(1);
   23.65 +
   23.66 +		// TODO ti bazw edw??
   23.67 +		leftArg = null;
   23.68 +
   23.69 +		rightArg = null;
   23.70 +		return dateTimeMetricPicker(function, leftArg, rightArg);
   23.71 +
   23.72 +	}
   23.73 +		
   23.74 +	/***/
   23.75 +	
   23.76  	GeneralDBSqlExpr spatialMetricFunction(FunctionCall functionCall, Function function) throws UnsupportedRdbmsOperatorException
   23.77  	{
   23.78  		GeneralDBSqlExpr leftArg = null;
   23.79 @@ -458,6 +505,24 @@
   23.80  		return null;
   23.81  	}
   23.82  
   23.83 +	/**
   23.84 +	 * Addition for datetime metric functions
   23.85 +	 * 
   23.86 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   23.87 +	 * 
   23.88 +	 */
   23.89 +	GeneralDBSqlExpr dateTimeMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
   23.90 +	{
   23.91 +		if(function.getURI().equals(GeoConstants.diffDateTime))
   23.92 +		{
   23.93 +			return extDiffDateTime(leftArg, rightArg);
   23.94 +		}
   23.95 +
   23.96 +		//Should never reach this place
   23.97 +		return null;
   23.98 +	}
   23.99 +	/***/
  23.100 +	
  23.101  	//TODO more to be added here probably
  23.102  	GeneralDBSqlExpr spatialMetricPicker(Function function,GeneralDBSqlExpr leftArg, GeneralDBSqlExpr rightArg)
  23.103  	{
    24.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Mon Dec 24 14:14:08 2012 +0100
    24.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java	Tue Jan 08 12:30:51 2013 +0200
    24.3 @@ -74,6 +74,7 @@
    24.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery;
    24.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery.OrderElem;
    24.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
    24.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDateTimeMetricBinary;
    24.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
    24.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
   24.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension;
   24.11 @@ -813,6 +814,17 @@
   24.12  		{
   24.13  			locateColumnVars(((GeneralDBSqlSpatialConstructUnary)expr).getArg(),allKnown);
   24.14  		}
   24.15 +		/** Addition for datetime metric functions
   24.16 +		 * 
   24.17 +		 * @author George Garbis <ggarbis@di.uoa.gr>
   24.18 +		 * 
   24.19 +		 */
   24.20 +		else if(expr instanceof GeneralDBSqlDateTimeMetricBinary)
   24.21 +		{
   24.22 +			locateColumnVars(((GeneralDBSqlDateTimeMetricBinary)expr).getLeftArg(),allKnown);
   24.23 +			locateColumnVars(((GeneralDBSqlDateTimeMetricBinary)expr).getRightArg(),allKnown);
   24.24 +		}
   24.25 +		/***/
   24.26  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary)
   24.27  		{
   24.28  			locateColumnVars(((GeneralDBSqlSpatialMetricBinary)expr).getLeftArg(),allKnown);
   24.29 @@ -972,7 +984,14 @@
   24.30  		}
   24.31  		else if(expr instanceof GeneralDBSqlSpatialMetricBinary ||
   24.32  				expr instanceof GeneralDBSqlSpatialMetricUnary ||
   24.33 -				expr instanceof GeneralDBSqlMathExpr)
   24.34 +				expr instanceof GeneralDBSqlMathExpr ||
   24.35 +				/** Addition for datetime metric functions
   24.36 +				 * 
   24.37 +				 * @author George Garbis <ggarbis@di.uoa.gr>
   24.38 +				 * 
   24.39 +				 */
   24.40 +				expr instanceof GeneralDBSqlDateTimeMetricBinary 
   24.41 +				/***/) 
   24.42  		{
   24.43  			return ResultType.DOUBLE;
   24.44  		}
    25.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Mon Dec 24 14:14:08 2012 +0100
    25.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java	Tue Jan 08 12:30:51 2013 +0200
    25.3 @@ -37,6 +37,7 @@
    25.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
    25.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbContains;
    25.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCrosses;
    25.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
    25.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
    25.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEq;
   25.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   25.11 @@ -679,7 +680,9 @@
   25.12  		else if (expr instanceof GeneralDBSqlGeoDistance) {
   25.13  			append((GeneralDBSqlGeoDistance)expr, filter);
   25.14  		}
   25.15 -
   25.16 +		else if (expr instanceof GeneralDBSqlDiffDateTime) {
   25.17 +			append((GeneralDBSqlDiffDateTime)expr, filter);
   25.18 +		}
   25.19  		/**
   25.20  		 * end of my addition
   25.21  		 */
   25.22 @@ -1092,6 +1095,15 @@
   25.23  	protected abstract void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter)
   25.24  			throws UnsupportedRdbmsOperatorException;
   25.25  
   25.26 +	/** Addition for datetime metric functions
   25.27 +	 * 
   25.28 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   25.29 +	 * 
   25.30 +	 */
   25.31 +	protected abstract void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
   25.32 +			throws UnsupportedRdbmsOperatorException;
   25.33 +	/***/
   25.34 +	
   25.35  	//Spatial Metric Functions
   25.36  	protected abstract void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
   25.37  			throws UnsupportedRdbmsOperatorException;
   25.38 @@ -1201,6 +1213,18 @@
   25.39  
   25.40  			}
   25.41  
   25.42 +	/** Addition for datetime metric functions
   25.43 +	 * 
   25.44 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   25.45 +	 * 
   25.46 +	 */
   25.47 +	protected void appendCastToEpoch(GeneralDBSqlExprBuilder filter)
   25.48 +	{
   25.49 +//		filter.epochCastBefore();
   25.50 +//		filter.epochCastAfter();
   25.51 +	}	
   25.52 +	/***/
   25.53 +	
   25.54  	protected void appendCastToDouble(GeneralDBSqlExprBuilder filter)
   25.55  	{
   25.56  		filter.doubleCast();
    26.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Mon Dec 24 14:14:08 2012 +0100
    26.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java	Tue Jan 08 12:30:51 2013 +0200
    26.3 @@ -64,6 +64,7 @@
    26.4  import org.openrdf.query.algebra.evaluation.QueryOptimizer;
    26.5  import org.openrdf.query.algebra.evaluation.function.Function;
    26.6  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; 
    26.7 +import org.openrdf.query.algebra.evaluation.function.spatial.DateTimeMetricFunc;
    26.8  import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    26.9  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   26.10  import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   26.11 @@ -798,7 +799,7 @@
   26.12  							//					}
   26.13  							//					else //DEFAULT CASE
   26.14  							//					{
   26.15 -							query.addFilter(sql.createBooleanExpr(expr));
   26.16 + 							query.addFilter(sql.createBooleanExpr(expr));
   26.17  							//					}
   26.18  
   26.19  						}
   26.20 @@ -878,6 +879,7 @@
   26.21  			throws RuntimeException
   26.22  			{
   26.23  		super.meet(node);
   26.24 +		// Edw ftanei to Filter GeneralDBSqlDiffDateTime!
   26.25  		if (node.getArg() instanceof GeneralDBSelectQuery) {
   26.26  			GeneralDBSelectQuery query = (GeneralDBSelectQuery)node.getArg();
   26.27  
   26.28 @@ -905,13 +907,13 @@
   26.29  	@Override
   26.30  	public void meet(FunctionCall node)
   26.31  			throws RuntimeException
   26.32 -			{
   26.33 +	{
   26.34  		Function function = FunctionRegistry.getInstance().get(node.getURI());
   26.35  
   26.36  		super.meet(node);
   26.37  
   26.38  		if(function instanceof SpatialRelationshipFunc || function instanceof SpatialConstructFunc 
   26.39 -				|| function instanceof SpatialMetricFunc || function instanceof SpatialPropertyFunc)
   26.40 +				|| function instanceof SpatialMetricFunc || function instanceof SpatialPropertyFunc )
   26.41  		{
   26.42  			List<ValueExpr> allArgs = node.getArgs();
   26.43  
   26.44 @@ -966,8 +968,31 @@
   26.45  			//				
   26.46  			//			}
   26.47  		}
   26.48 +		/**
   26.49 +		 * Addition for datetime metric functions
   26.50 +		 * 
   26.51 +		 * @author George Garbis <ggarbis@di.uoa.gr>
   26.52 +		 * 
   26.53 +		 */
   26.54 +		else if (function instanceof DateTimeMetricFunc)
   26.55 +		{
   26.56 +			List<ValueExpr> allArgs = node.getArgs();
   26.57  
   26.58 +			int argNo = 0; 
   26.59 +			//Used so that the second argument of buffer func is not 
   26.60 +			//mistakenly confused with a spatial variable
   26.61 +			for(ValueExpr arg : allArgs)
   26.62 +			{	
   26.63 +				argNo++;
   26.64 +				if(arg instanceof Var && argNo!=2)
   26.65 +				{
   26.66 +					String originalName = ((Var)arg).getName();
   26.67 +					((Var)arg).setName(originalName);
   26.68 +				}
   26.69  			}
   26.70 +		}
   26.71 +		/***/
   26.72 +	}
   26.73  
   26.74  	//
   26.75  	@Override
    27.1 --- a/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Mon Dec 24 14:14:08 2012 +0100
    27.2 +++ b/monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java	Tue Jan 08 12:30:51 2013 +0200
    27.3 @@ -21,6 +21,7 @@
    27.4  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
    27.5  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbContains;
    27.6  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCrosses;
    27.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
    27.8  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
    27.9  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   27.10  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
   27.11 @@ -192,6 +193,15 @@
   27.12  		; 
   27.13  	}
   27.14  
   27.15 +	/** Addition for datetime metric functions
   27.16 +	 * 
   27.17 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   27.18 +	 * 
   27.19 +	 */
   27.20 +	public enum DateTimeFunctionMonetDB { Difference; }
   27.21 +	/***/
   27.22 +
   27.23 +	
   27.24  	public MonetDBQueryBuilder() {
   27.25  		super();
   27.26  	}
   27.27 @@ -738,6 +748,19 @@
   27.28  		appendMonetDBSpatialFunctionBinary(expr, filter, SpatialFunctionsMonetDB.ST_SymDifference);
   27.29  			}
   27.30  
   27.31 +	/** Addition for datetime metric functions
   27.32 +	 * 
   27.33 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   27.34 +	 * 
   27.35 +	 */
   27.36 +	@Override
   27.37 +	protected void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
   27.38 +		throws UnsupportedRdbmsOperatorException
   27.39 +	{
   27.40 +		appendGeneralDBDateTimeFunctionBinary(expr, filter, DateTimeFunctionMonetDB.Difference);
   27.41 +	}
   27.42 +	/***/
   27.43 +	
   27.44  	@Override
   27.45  	//Spatial Metric Functions
   27.46  	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
   27.47 @@ -1082,6 +1105,147 @@
   27.48  
   27.49  			}
   27.50  
   27.51 +	/** Addition for datetime metric functions
   27.52 +	 * 
   27.53 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   27.54 +	 * 
   27.55 +	 */
   27.56 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionMonetDB func)
   27.57 +			throws UnsupportedRdbmsOperatorException
   27.58 +	{
   27.59 +		filter.openBracket();
   27.60 +
   27.61 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   27.62 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   27.63 +
   27.64 +		if(check1)
   27.65 +		{
   27.66 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   27.67 +
   27.68 +		}
   27.69 +		else if(check2)
   27.70 +		{
   27.71 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   27.72 +		}
   27.73 +		else
   27.74 +		{
   27.75 +
   27.76 +			GeneralDBSqlExpr tmp = expr;
   27.77 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
   27.78 +			{
   27.79 +				while(true)
   27.80 +				{
   27.81 +					GeneralDBSqlExpr child;
   27.82 +
   27.83 +					if(tmp instanceof BinaryGeneralDBOperator)
   27.84 +					{
   27.85 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
   27.86 +					}
   27.87 +					else //(tmp instanceof UnaryGeneralDBOperator)
   27.88 +					{
   27.89 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
   27.90 +					}
   27.91 +
   27.92 +					tmp = child;
   27.93 +					if(tmp instanceof GeneralDBLabelColumn)
   27.94 +					{
   27.95 +						//Reached the innermost left var -> need to capture its SRID
   27.96 +						String alias;
   27.97 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
   27.98 +							//Predicates used in triple patterns non-existent in db
   27.99 +							alias="NULL";
  27.100 +						}
  27.101 +						else
  27.102 +						{
  27.103 +							//Reached the innermost left var -> need to capture its SRID
  27.104 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  27.105 +						}
  27.106 +						break;
  27.107 +					}
  27.108 +				}
  27.109 +			}
  27.110 +
  27.111 +			filter.openBracket();
  27.112 +
  27.113 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
  27.114 +			{
  27.115 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getLeftArg();
  27.116 +				String raw = arg.getValue();
  27.117 +				filter.append(" "+raw+" ");
  27.118 +			}
  27.119 +			else if(expr.getLeftArg() instanceof GeneralDBDoubleValue) //case met in buffer!
  27.120 +			{
  27.121 +				append(((GeneralDBDoubleValue)expr.getLeftArg()), filter);
  27.122 +			}
  27.123 +			else if(expr.getLeftArg() instanceof GeneralDBNumericColumn) //case met in buffer!
  27.124 +			{
  27.125 +				append(((GeneralDBNumericColumn)expr.getLeftArg()), filter);
  27.126 +			}
  27.127 +			else if(expr.getLeftArg() instanceof GeneralDBURIColumn) //case met in transform!
  27.128 +			{
  27.129 +				filter.keepSRID_part1();
  27.130 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
  27.131 +				filter.keepSRID_part2();
  27.132 +				append(((GeneralDBURIColumn)expr.getLeftArg()), filter);
  27.133 +				filter.keepSRID_part3();
  27.134 +			}
  27.135 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
  27.136 +			else if(expr.getLeftArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getLeftArg()).isSpatial())
  27.137 +			{
  27.138 +				append(((GeneralDBLabelColumn)expr.getLeftArg()),filter);
  27.139 +				appendCastToDouble(filter);
  27.140 +			}
  27.141 +			else
  27.142 +			{
  27.143 +				// Den prepei na ftasei edw
  27.144 +			}
  27.145 +						
  27.146 +			switch(func)
  27.147 +			{
  27.148 +				case Difference: filter.append(" - "); break;			
  27.149 +			}
  27.150 +			
  27.151 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
  27.152 +			{
  27.153 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getRightArg();
  27.154 +				String raw = arg.getValue();
  27.155 +				filter.append(" "+raw+" ");
  27.156 +			}
  27.157 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
  27.158 +			{
  27.159 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
  27.160 +			}
  27.161 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
  27.162 +			{
  27.163 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
  27.164 +			}
  27.165 +			else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform!
  27.166 +			{
  27.167 +				filter.keepSRID_part1();
  27.168 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  27.169 +				filter.keepSRID_part2();
  27.170 +				append(((GeneralDBURIColumn)expr.getRightArg()), filter);
  27.171 +				filter.keepSRID_part3();
  27.172 +			}
  27.173 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
  27.174 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
  27.175 +			{
  27.176 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
  27.177 +				appendCastToDouble(filter);
  27.178 +			}
  27.179 +			else
  27.180 +			{
  27.181 +				// Den prepei na ftasei edw
  27.182 +			}
  27.183 +
  27.184 +
  27.185 +			filter.closeBracket();
  27.186 +		}
  27.187 +		filter.closeBracket();
  27.188 +	}
  27.189 +	
  27.190 +	/***/
  27.191 +
  27.192  
  27.193  	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
  27.194  	//EXCEPT ST_Transform!!!
    28.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Mon Dec 24 14:14:08 2012 +0100
    28.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java	Tue Jan 08 12:30:51 2013 +0200
    28.3 @@ -10,8 +10,10 @@
    28.4  
    28.5  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    28.6  import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar;
    28.7 +import org.openrdf.sail.generaldb.algebra.GeneralDBDateTimeColumn;
    28.8  import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue;
    28.9  import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn;
   28.10 +import org.openrdf.sail.generaldb.algebra.GeneralDBNumberValue;
   28.11  import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn;
   28.12  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbove;
   28.13  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd;
   28.14 @@ -20,6 +22,7 @@
   28.15  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
   28.16  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbContains;
   28.17  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCrosses;
   28.18 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime;
   28.19  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
   28.20  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   28.21  import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
   28.22 @@ -193,6 +196,14 @@
   28.23  		; 
   28.24  	}
   28.25  
   28.26 +	/** Addition for datetime metric functions
   28.27 +	 * 
   28.28 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   28.29 +	 * 
   28.30 +	 */
   28.31 +	public enum DateTimeFunctionPostGIS { Difference; }
   28.32 +	/***/
   28.33 +	
   28.34  	public PostGISQueryBuilder() {
   28.35  		super();
   28.36  	}
   28.37 @@ -232,6 +243,12 @@
   28.38  			}
   28.39  
   28.40  	@Override
   28.41 +	protected void append(GeneralDBDateTimeColumn var, GeneralDBSqlExprBuilder filter) {
   28.42 +		String alias = getDateTimeAlias(var.getRdbmsVar());
   28.43 +		filter.column(alias, "value");
   28.44 +	}
   28.45 +	
   28.46 +	@Override
   28.47  	protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) {
   28.48  		if (var.getRdbmsVar().isResource()) {
   28.49  			filter.appendNull();
   28.50 @@ -718,6 +735,19 @@
   28.51  		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference);
   28.52  			}
   28.53  
   28.54 +	/** Addition for datetime metric functions
   28.55 +	 * 
   28.56 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   28.57 +	 * 
   28.58 +	 */
   28.59 +	@Override
   28.60 +	protected void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter)
   28.61 +		throws UnsupportedRdbmsOperatorException
   28.62 +	{
   28.63 +		appendGeneralDBDateTimeFunctionBinary(expr, filter, DateTimeFunctionPostGIS.Difference);
   28.64 +	}
   28.65 +	/***/
   28.66 +	
   28.67  	//Spatial Metric Functions
   28.68  	@Override
   28.69  	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
   28.70 @@ -1246,7 +1276,117 @@
   28.71  
   28.72  			}
   28.73  
   28.74 +	/** Addition for datetime metric functions
   28.75 +	 * 
   28.76 +	 * @author George Garbis <ggarbis@di.uoa.gr>
   28.77 +	 * 
   28.78 +	 */
   28.79 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionPostGIS func)
   28.80 +			throws UnsupportedRdbmsOperatorException
   28.81 +	{
   28.82 +		filter.openBracket();
   28.83  
   28.84 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   28.85 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
   28.86 +
   28.87 +		if(check1)
   28.88 +		{
   28.89 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
   28.90 +
   28.91 +		}
   28.92 +		else if(check2)
   28.93 +		{
   28.94 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
   28.95 +		}
   28.96 +		else
   28.97 +		{
   28.98 +
   28.99 +			GeneralDBSqlExpr tmp = expr;
  28.100 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
  28.101 +			{
  28.102 +				while(true)
  28.103 +				{
  28.104 +					GeneralDBSqlExpr child;
  28.105 +
  28.106 +					if(tmp instanceof BinaryGeneralDBOperator)
  28.107 +					{
  28.108 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  28.109 +					}
  28.110 +					else //(tmp instanceof UnaryGeneralDBOperator)
  28.111 +					{
  28.112 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
  28.113 +					}
  28.114 +
  28.115 +					tmp = child;
  28.116 +					if(tmp instanceof GeneralDBLabelColumn)
  28.117 +					{
  28.118 +						//Reached the innermost left var -> need to capture its SRID
  28.119 +						String alias;
  28.120 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
  28.121 +							//Predicates used in triple patterns non-existent in db
  28.122 +							alias="NULL";
  28.123 +						}
  28.124 +						else
  28.125 +						{
  28.126 +							//Reached the innermost left var -> need to capture its SRID
  28.127 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  28.128 +						}
  28.129 +						break;
  28.130 +					}
  28.131 +				}
  28.132 +			}
  28.133 +
  28.134 +			filter.openBracket();
  28.135 +
  28.136 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
  28.137 +			{
  28.138 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getLeftArg();
  28.139 +				String raw = arg.getValue();
  28.140 +				filter.append(" "+raw+" ");
  28.141 +			}
  28.142 +			else if(expr.getLeftArg() instanceof GeneralDBNumberValue)
  28.143 +			{
  28.144 +				append(((GeneralDBNumberValue)expr.getLeftArg()), filter);
  28.145 +			}
  28.146 +			else if(expr.getLeftArg() instanceof GeneralDBDateTimeColumn)
  28.147 +			{
  28.148 +				append(((GeneralDBDateTimeColumn)expr.getLeftArg()),filter);
  28.149 +			}
  28.150 +			else
  28.151 +			{
  28.152 +				// Den prepei na ftasei edw
  28.153 +			}
  28.154 +						
  28.155 +			switch(func)
  28.156 +			{
  28.157 +				case Difference: filter.append(" - "); break;			
  28.158 +			}
  28.159 +			
  28.160 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
  28.161 +			{
  28.162 +				GeneralDBStringValue arg = (GeneralDBStringValue) expr.getRightArg();
  28.163 +				String raw = arg.getValue();
  28.164 +				filter.append(" "+raw+" ");
  28.165 +			}
  28.166 +			else if(expr.getRightArg() instanceof GeneralDBNumberValue)
  28.167 +			{
  28.168 +				append(((GeneralDBNumberValue)expr.getRightArg()), filter);
  28.169 +			}
  28.170 +			else if(expr.getRightArg() instanceof GeneralDBDateTimeColumn)
  28.171 +			{
  28.172 +				append(((GeneralDBDateTimeColumn)expr.getRightArg()),filter);	
  28.173 +			}
  28.174 +			else
  28.175 +			{
  28.176 +				// Den prepei na ftasei edw
  28.177 +			}
  28.178 +
  28.179 +
  28.180 +			filter.closeBracket();
  28.181 +		}
  28.182 +		filter.closeBracket();
  28.183 +	}	
  28.184 +	/***/
  28.185  
  28.186  	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
  28.187  	//EXCEPT ST_Transform!!!
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java.orig	Tue Jan 08 12:30:51 2013 +0200
    29.3 @@ -0,0 +1,2150 @@
    29.4 +/*
    29.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    29.6 + *
    29.7 + * Licensed under the Aduna BSD-style license.
    29.8 + */
    29.9 +package org.openrdf.sail.postgis.evaluation;
   29.10 +
   29.11 +import java.util.ArrayList;
   29.12 +import java.util.List;
   29.13 +
   29.14 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   29.15 +import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar;
   29.16 +import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue;
   29.17 +import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn;
   29.18 +import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn;
   29.19 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbove;
   29.20 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd;
   29.21 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnyInteract;
   29.22 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlBelow;
   29.23 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase;
   29.24 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains;
   29.25 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContainsMBB;
   29.26 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCoveredBy;
   29.27 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCovers;
   29.28 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint;
   29.29 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial;
   29.30 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea;
   29.31 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML;
   29.32 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText;
   29.33 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBoundary;
   29.34 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBuffer;
   29.35 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoConvexHull;
   29.36 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDifference;
   29.37 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension;
   29.38 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDistance;
   29.39 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoEnvelope;
   29.40 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoGeometryType;
   29.41 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIntersection;
   29.42 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsEmpty;
   29.43 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsSimple;
   29.44 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSrid;
   29.45 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSymDifference;
   29.46 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoTransform;
   29.47 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoUnion;
   29.48 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlInside;
   29.49 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIntersects;
   29.50 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull;
   29.51 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLeft;
   29.52 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr;
   29.53 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbEquals;
   29.54 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbInside;
   29.55 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbIntersects;
   29.56 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot;
   29.57 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull;
   29.58 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOverlap;
   29.59 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate;
   29.60 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight;
   29.61 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary;
   29.62 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary;
   29.63 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary;
   29.64 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary;
   29.65 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty;
   29.66 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouch;
   29.67 +import org.openrdf.sail.generaldb.algebra.GeneralDBStringValue;
   29.68 +import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn;
   29.69 +import org.openrdf.sail.generaldb.algebra.GeneralDBUnionItem;
   29.70 +import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator;
   29.71 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBFromItem;
   29.72 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
   29.73 +import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator;
   29.74 +import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator;
   29.75 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Contains;
   29.76 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_CoveredBy;
   29.77 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Covers;
   29.78 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Disjoint;
   29.79 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Equals;
   29.80 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Inside;
   29.81 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Meet;
   29.82 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Overlap;
   29.83 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Dc;
   29.84 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ec;
   29.85 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Eq;
   29.86 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntpp;
   29.87 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntppi;
   29.88 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Po;
   29.89 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tpp;
   29.90 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tppi;
   29.91 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Contains;
   29.92 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Crosses;
   29.93 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Disjoint;
   29.94 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Equals;
   29.95 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Intersects;
   29.96 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Overlaps;
   29.97 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Touches;
   29.98 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Within;
   29.99 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilder;
  29.100 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder;
  29.101 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder;
  29.102 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlJoinBuilder;
  29.103 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlQueryBuilder;
  29.104 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
  29.105 +import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
  29.106 +
  29.107 +/**
  29.108 + * Constructs an SQL query from {@link GeneralDBSqlExpr}s and {@link GeneralDBFromItem}s.
  29.109 + * 
  29.110 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
  29.111 + * 
  29.112 + */
  29.113 +public class PostGISQueryBuilder extends GeneralDBQueryBuilder {
  29.114 +
  29.115 +	public static final String STRDFGEO_FIELD = "strdfgeo";
  29.116 +	public static final String SRID_FIELD = "srid";
  29.117 +	public static final String ST_TRANSFORM = "ST_Transform";
  29.118 +	public static final String ST_ASBINARY = "ST_AsBinary";
  29.119 +	/**
  29.120 +	 * If (spatial) label column met is null, I must not try to retrieve its srid. 
  29.121 +	 * Opting to ask for 'null' instead
  29.122 +	 */
  29.123 +	boolean nullLabel = false;
  29.124 +
  29.125 +	public enum SpatialOperandsPostGIS { anyInteract, equals, contains, left, right, above, inside, below; }
  29.126 +	public enum SpatialFunctionsPostGIS 
  29.127 +	{ 	//stSPARQL++
  29.128 +		//Spatial Relationships
  29.129 +		ST_Disjoint, 
  29.130 +		ST_Touches, 
  29.131 +		ST_Covers,
  29.132 +		ST_CoveredBy, 
  29.133 +		ST_Overlaps,
  29.134 +		ST_Intersects,
  29.135 +		ST_Equals,
  29.136 +		ST_Relate, 
  29.137 +		ST_Within,
  29.138 +		ST_Contains,
  29.139 +		
  29.140 +		
  29.141 +		//Spatial Constructs - Binary
  29.142 +		ST_Union, 
  29.143 +		ST_Intersection, 
  29.144 +		ST_Difference,
  29.145 +		ST_Buffer,
  29.146 +		ST_Transform,
  29.147 +		ST_SymDifference,
  29.148 +
  29.149 +
  29.150 +		//Spatial Constructs - Unary
  29.151 +		ST_Envelope,
  29.152 +		ST_ConvexHull,
  29.153 +		ST_Boundary,
  29.154 +
  29.155 +		//Spatial Metrics - Binary
  29.156 +		ST_Distance,
  29.157 +
  29.158 +		//Spatial Metrics - Unary
  29.159 +		ST_Area,
  29.160 +
  29.161 +		//Spatial Properties - All Unary
  29.162 +		ST_Dimension,
  29.163 +		ST_GeometryType,
  29.164 +		ST_AsGML,
  29.165 +		ST_AsText,
  29.166 +		ST_SRID,
  29.167 +		ST_IsEmpty,
  29.168 +		ST_IsSimple,
  29.169 +
  29.170 +		//GeoSPARQL
  29.171 +		//Simple Features
  29.172 +		SF_Equals,
  29.173 +		SF_Disjoint,
  29.174 +		SF_Intersects,
  29.175 +		SF_Touches,
  29.176 +		SF_Within,
  29.177 +		SF_Contains,
  29.178 +		SF_Overlaps,
  29.179 +		SF_Crosses,
  29.180 +
  29.181 +		//RCC8
  29.182 +		RCC8_Eq,
  29.183 +		RCC8_Dc,
  29.184 +		RCC8_Ec,
  29.185 +		RCC8_Po,
  29.186 +		RCC8_Tppi,
  29.187 +		RCC8_Tpp,
  29.188 +		RCC8_Ntppi,
  29.189 +		RCC8_Ntpp,
  29.190 +
  29.191 +		//Egenhofer
  29.192 +		EH_Equals,
  29.193 +		EH_Disjoint,
  29.194 +		EH_Meet,
  29.195 +		EH_Overlap,
  29.196 +		EH_Covers,
  29.197 +		EH_CoveredBy,
  29.198 +		EH_Inside,
  29.199 +		EH_Contains,
  29.200 +		; 
  29.201 +	}
  29.202 +	
  29.203 +	public enum DateTimeFunctionsPostGIS {
  29.204 +		Difference;
  29.205 +	}
  29.206 +
  29.207 +	public PostGISQueryBuilder() {
  29.208 +		super();
  29.209 +	}
  29.210 +
  29.211 +	public PostGISQueryBuilder(GeneralDBSqlQueryBuilder builder) {
  29.212 +		super(builder);
  29.213 +		this.query = builder;
  29.214 +	}
  29.215 +
  29.216 +	@Override
  29.217 +	protected void append(GeneralDBSqlNull expr, GeneralDBSqlExprBuilder filter) {
  29.218 +		filter.appendNull();
  29.219 +	}
  29.220 +
  29.221 +	@Override
  29.222 +	protected void append(GeneralDBSqlIsNull expr, GeneralDBSqlExprBuilder filter)
  29.223 +			throws UnsupportedRdbmsOperatorException
  29.224 +			{
  29.225 +		dispatch(expr.getArg(), filter);
  29.226 +		filter.isNull();
  29.227 +			}
  29.228 +
  29.229 +	@Override
  29.230 +	protected void append(GeneralDBSqlNot expr, GeneralDBSqlExprBuilder filter)
  29.231 +			throws UnsupportedRdbmsOperatorException
  29.232 +			{
  29.233 +		if (expr.getArg() instanceof GeneralDBSqlIsNull) {
  29.234 +			GeneralDBSqlIsNull arg = (GeneralDBSqlIsNull)expr.getArg();
  29.235 +			dispatch(arg.getArg(), filter);
  29.236 +			filter.isNotNull();
  29.237 +		}
  29.238 +		else {
  29.239 +			GeneralDBSqlBracketBuilder open = filter.not();
  29.240 +			dispatch(expr.getArg(), (GeneralDBSqlExprBuilder) open);
  29.241 +			open.close();
  29.242 +		}
  29.243 +			}
  29.244 +
  29.245 +	@Override
  29.246 +	protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) {
  29.247 +		if (var.getRdbmsVar().isResource()) {
  29.248 +			filter.appendNull();
  29.249 +			nullLabel = true;
  29.250 +		}
  29.251 +		else {
  29.252 +			if(var.isSpatial())
  29.253 +			{
  29.254 +				filter.appendFunction(ST_ASBINARY);
  29.255 +				filter.openBracket();
  29.256 +				//XXX SRID
  29.257 +				filter.appendFunction(ST_TRANSFORM);
  29.258 +				filter.openBracket();
  29.259 +				//
  29.260 +				String alias = getLabelAlias(var.getRdbmsVar());
  29.261 +
  29.262 +				filter.column(alias, STRDFGEO_FIELD);
  29.263 +				//XXX SRID
  29.264 +				filter.appendComma();
  29.265 +				filter.column(alias, SRID_FIELD);
  29.266 +				filter.closeBracket();
  29.267 +				//
  29.268 +				filter.closeBracket();
  29.269 +
  29.270 +				//Adding srid field explicitly for my StrabonPolyhedron constructor later on!
  29.271 +				filter.appendComma();
  29.272 +				filter.column(alias, SRID_FIELD);
  29.273 +			}
  29.274 +			else
  29.275 +			{
  29.276 +				//XXX original/default case
  29.277 +				String alias = getLabelAlias(var.getRdbmsVar());
  29.278 +				filter.column(alias, "value");
  29.279 +			}
  29.280 +		}
  29.281 +	}
  29.282 +
  29.283 +	@Override
  29.284 +	protected void append(GeneralDBSqlAnd expr, GeneralDBSqlExprBuilder filter)
  29.285 +			throws UnsupportedRdbmsOperatorException
  29.286 +			{
  29.287 +		dispatch(expr.getLeftArg(), filter);
  29.288 +		filter.and();
  29.289 +		dispatch(expr.getRightArg(), filter);
  29.290 +			}
  29.291 +
  29.292 +	protected GeneralDBSqlJoinBuilder subJoinAndFilter(GeneralDBSqlJoinBuilder query, GeneralDBFromItem from)
  29.293 +			throws RdbmsException, UnsupportedRdbmsOperatorException
  29.294 +			{
  29.295 +		if (from instanceof GeneralDBUnionItem) {
  29.296 +			GeneralDBUnionItem union = (GeneralDBUnionItem)from;
  29.297 +			List<String> names = union.getSelectVarNames();
  29.298 +			List<GeneralDBColumnVar> vars = union.appendVars(new ArrayList<GeneralDBColumnVar>());
  29.299 +			GeneralDBSqlQueryBuilder subquery = query.subquery();
  29.300 +			for (GeneralDBFromItem item : union.getUnion()) {
  29.301 +				for (int i = 0, n = names.size(); i < n; i++) {
  29.302 +					GeneralDBColumnVar var = item.getVar(names.get(i));
  29.303 +					GeneralDBSqlExprBuilder select = subquery.select();
  29.304 +					if (var == null) {
  29.305 +						select.appendNull();
  29.306 +					}
  29.307 +					else if (var.isImplied()) {
  29.308 +						select.appendNumeric(vf.getInternalId(var.getValue()));
  29.309 +					}
  29.310 +					else {
  29.311 +						select.column(var.getAlias(), var.getColumn());
  29.312 +					}
  29.313 +					select.as(vars.get(i).getColumn());
  29.314 +				}
  29.315 +				from(subquery, item);
  29.316 +				subquery = subquery.union();
  29.317 +			}
  29.318 +		}
  29.319 +		for (GeneralDBFromItem join : from.getJoins()) {
  29.320 +			join(query, join);
  29.321 +		}
  29.322 +		for (GeneralDBSqlExpr expr : from.getFilters()) {
  29.323 +			dispatch(expr, query.on().and());
  29.324 +		}
  29.325 +		return query;
  29.326 +			}
  29.327 +
  29.328 +	//FIXME my addition from here on
  29.329 +
  29.330 +	//Issue with this function: crashes when MathExpr is present in Select but does not
  29.331 +	//involve spatial variables! must escape this somehow
  29.332 +	@Override
  29.333 +	public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException
  29.334 +	{
  29.335 +		if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 
  29.336 +				&&!(expr instanceof GeneralDBSqlSpatialMetricUnary)
  29.337 +				&&!(expr instanceof GeneralDBSqlMathExpr)
  29.338 +				&&!(expr instanceof GeneralDBSqlSpatialProperty))
  29.339 +		{
  29.340 +			query.select().appendFunction(ST_ASBINARY);
  29.341 +		}
  29.342 +		else
  29.343 +		{
  29.344 +			query.select();
  29.345 +		}
  29.346 +		if(expr instanceof BinaryGeneralDBOperator)
  29.347 +		{
  29.348 +			dispatchBinarySqlOperator((BinaryGeneralDBOperator) expr, query.select);
  29.349 +		}
  29.350 +		else if(expr instanceof UnaryGeneralDBOperator)
  29.351 +		{
  29.352 +			dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select);
  29.353 +		}
  29.354 +		//SRID support must be explicitly added!
  29.355 +
  29.356 +		return this;
  29.357 +	}
  29.358 +
  29.359 +	//Spatial Relationship Functions
  29.360 +	@Override
  29.361 +	protected void append(GeneralDBSqlAnyInteract expr, GeneralDBSqlExprBuilder filter)
  29.362 +			throws UnsupportedRdbmsOperatorException
  29.363 +			{
  29.364 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects);
  29.365 +			}
  29.366 +
  29.367 +
  29.368 +	@Override
  29.369 +	protected void append(GeneralDBSqlIntersects expr, 	GeneralDBSqlExprBuilder filter)
  29.370 +			throws UnsupportedRdbmsOperatorException {
  29.371 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects);
  29.372 +	}
  29.373 +
  29.374 +	@Override
  29.375 +	protected void append(GeneralDBSqlContains expr, GeneralDBSqlExprBuilder filter)
  29.376 +			throws UnsupportedRdbmsOperatorException {
  29.377 +
  29.378 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Contains);
  29.379 +	}
  29.380 +
  29.381 +
  29.382 +
  29.383 +	
  29.384 +	@Override
  29.385 +	protected void append(GeneralDBSqlEqualsSpatial expr, GeneralDBSqlExprBuilder filter)
  29.386 +			throws UnsupportedRdbmsOperatorException {
  29.387 +
  29.388 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Equals);
  29.389 +	}
  29.390 +
  29.391 +	@Override
  29.392 +	protected void append(GeneralDBSqlInside expr, GeneralDBSqlExprBuilder filter)
  29.393 +			throws UnsupportedRdbmsOperatorException {
  29.394 +
  29.395 +		//appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside);
  29.396 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Within);
  29.397 +
  29.398 +	}
  29.399 +
  29.400 +	@Override
  29.401 +	protected void append(GeneralDBSqlCovers expr, GeneralDBSqlExprBuilder filter)
  29.402 +			throws UnsupportedRdbmsOperatorException {
  29.403 +
  29.404 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Covers);
  29.405 +	}
  29.406 +
  29.407 +	@Override
  29.408 +	protected void append(GeneralDBSqlCoveredBy expr, GeneralDBSqlExprBuilder filter)
  29.409 +			throws UnsupportedRdbmsOperatorException {
  29.410 +
  29.411 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_CoveredBy);
  29.412 +	}
  29.413 +
  29.414 +	@Override
  29.415 +	protected void append(GeneralDBSqlTouch expr, GeneralDBSqlExprBuilder filter)
  29.416 +			throws UnsupportedRdbmsOperatorException {
  29.417 +
  29.418 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Touches);
  29.419 +	}
  29.420 +
  29.421 +	@Override
  29.422 +	protected void append(GeneralDBSqlOverlap expr, GeneralDBSqlExprBuilder filter)
  29.423 +			throws UnsupportedRdbmsOperatorException {
  29.424 +
  29.425 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps);
  29.426 +	}
  29.427 +
  29.428 +	protected void append(GeneralDBSqlDisjoint expr, GeneralDBSqlExprBuilder filter)
  29.429 +			throws UnsupportedRdbmsOperatorException {
  29.430 +
  29.431 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Disjoint);
  29.432 +	}
  29.433 +
  29.434 +	@Override
  29.435 +	protected void append(GeneralDBSqlRelate expr, GeneralDBSqlExprBuilder filter)
  29.436 +			throws UnsupportedRdbmsOperatorException
  29.437 +			{
  29.438 +		appendGeneralDBSpatialFunctionTriple(expr, filter, SpatialFunctionsPostGIS.ST_Relate);
  29.439 +			}
  29.440 +
  29.441 +	@Override	
  29.442 +	protected void append(GeneralDBSqlLeft expr, GeneralDBSqlExprBuilder filter)
  29.443 +			throws UnsupportedRdbmsOperatorException
  29.444 +			{
  29.445 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.left);
  29.446 +			}
  29.447 +
  29.448 +	@Override
  29.449 +	protected void append(GeneralDBSqlRight expr, GeneralDBSqlExprBuilder filter)
  29.450 +			throws UnsupportedRdbmsOperatorException
  29.451 +			{
  29.452 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.right);
  29.453 +			}
  29.454 +
  29.455 +	@Override
  29.456 +	protected void append(GeneralDBSqlAbove expr, GeneralDBSqlExprBuilder filter)
  29.457 +			throws UnsupportedRdbmsOperatorException
  29.458 +			{
  29.459 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.above);
  29.460 +			}
  29.461 +
  29.462 +	@Override
  29.463 +	protected void append(GeneralDBSqlBelow expr, GeneralDBSqlExprBuilder filter)
  29.464 +			throws UnsupportedRdbmsOperatorException
  29.465 +			{
  29.466 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.below);
  29.467 +			}
  29.468 +
  29.469 +	@Override
  29.470 +	protected void append(GeneralDBSqlMbbIntersects expr, GeneralDBSqlExprBuilder filter)
  29.471 +			throws UnsupportedRdbmsOperatorException {
  29.472 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.anyInteract);
  29.473 +	}
  29.474 +
  29.475 +	@Override
  29.476 +	protected void append(GeneralDBSqlMbbInside expr, GeneralDBSqlExprBuilder filter)
  29.477 +			throws UnsupportedRdbmsOperatorException {
  29.478 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside);
  29.479 +	}
  29.480 +
  29.481 +	
  29.482 +	@Override
  29.483 +	protected void append(GeneralDBSqlContainsMBB expr, GeneralDBSqlExprBuilder filter)
  29.484 +			throws UnsupportedRdbmsOperatorException {
  29.485 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.contains);
  29.486 +	}
  29.487 +
  29.488 +	
  29.489 +	@Override
  29.490 +	protected void append(GeneralDBSqlMbbEquals expr, GeneralDBSqlExprBuilder filter)
  29.491 +			throws UnsupportedRdbmsOperatorException {
  29.492 +		appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.equals);
  29.493 +	}
  29.494 +
  29.495 +	//GeoSPARQL - Spatial Relationship Functions 
  29.496 +	//Simple Features
  29.497 +	@Override
  29.498 +	protected void append(GeneralDBSqlSF_Contains expr, GeneralDBSqlExprBuilder filter)
  29.499 +			throws UnsupportedRdbmsOperatorException
  29.500 +			{
  29.501 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Contains);
  29.502 +			}
  29.503 +
  29.504 +	@Override
  29.505 +	protected void append(GeneralDBSqlSF_Crosses expr, GeneralDBSqlExprBuilder filter)
  29.506 +			throws UnsupportedRdbmsOperatorException
  29.507 +			{
  29.508 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Crosses);
  29.509 +			}
  29.510 +
  29.511 +	@Override
  29.512 +	protected void append(GeneralDBSqlSF_Disjoint expr, GeneralDBSqlExprBuilder filter)
  29.513 +			throws UnsupportedRdbmsOperatorException
  29.514 +			{
  29.515 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Disjoint);
  29.516 +			}
  29.517 +
  29.518 +	@Override
  29.519 +	protected void append(GeneralDBSqlSF_Equals expr, GeneralDBSqlExprBuilder filter)
  29.520 +			throws UnsupportedRdbmsOperatorException
  29.521 +			{
  29.522 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Equals);
  29.523 +			}
  29.524 +
  29.525 +	@Override
  29.526 +	protected void append(GeneralDBSqlSF_Intersects expr, GeneralDBSqlExprBuilder filter)
  29.527 +			throws UnsupportedRdbmsOperatorException
  29.528 +			{
  29.529 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Intersects);
  29.530 +			}
  29.531 +
  29.532 +	@Override
  29.533 +	protected void append(GeneralDBSqlSF_Overlaps expr, GeneralDBSqlExprBuilder filter)
  29.534 +			throws UnsupportedRdbmsOperatorException
  29.535 +			{
  29.536 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Overlaps);
  29.537 +			}
  29.538 +
  29.539 +	@Override
  29.540 +	protected void append(GeneralDBSqlSF_Touches expr, GeneralDBSqlExprBuilder filter)
  29.541 +			throws UnsupportedRdbmsOperatorException
  29.542 +			{
  29.543 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Touches);
  29.544 +			}
  29.545 +
  29.546 +	@Override
  29.547 +	protected void append(GeneralDBSqlSF_Within expr, GeneralDBSqlExprBuilder filter)
  29.548 +			throws UnsupportedRdbmsOperatorException
  29.549 +			{
  29.550 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Within);
  29.551 +			}
  29.552 +
  29.553 +	//Egenhofer
  29.554 +	@Override
  29.555 +	protected void append(GeneralDBSqlEgenhofer_CoveredBy expr, GeneralDBSqlExprBuilder filter)
  29.556 +			throws UnsupportedRdbmsOperatorException
  29.557 +			{
  29.558 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_CoveredBy);
  29.559 +			}
  29.560 +
  29.561 +	@Override
  29.562 +	protected void append(GeneralDBSqlEgenhofer_Covers expr, GeneralDBSqlExprBuilder filter)
  29.563 +			throws UnsupportedRdbmsOperatorException
  29.564 +			{
  29.565 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Covers);
  29.566 +			}
  29.567 +
  29.568 +	@Override
  29.569 +	protected void append(GeneralDBSqlEgenhofer_Contains expr, GeneralDBSqlExprBuilder filter)
  29.570 +			throws UnsupportedRdbmsOperatorException
  29.571 +			{
  29.572 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Contains);
  29.573 +			}
  29.574 +
  29.575 +	@Override
  29.576 +	protected void append(GeneralDBSqlEgenhofer_Disjoint expr, GeneralDBSqlExprBuilder filter)
  29.577 +			throws UnsupportedRdbmsOperatorException
  29.578 +			{
  29.579 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Disjoint);
  29.580 +			}
  29.581 +
  29.582 +	@Override
  29.583 +	protected void append(GeneralDBSqlEgenhofer_Equals expr, GeneralDBSqlExprBuilder filter)
  29.584 +			throws UnsupportedRdbmsOperatorException
  29.585 +			{
  29.586 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Equals);
  29.587 +			}
  29.588 +
  29.589 +	@Override
  29.590 +	protected void append(GeneralDBSqlEgenhofer_Inside expr, GeneralDBSqlExprBuilder filter)
  29.591 +			throws UnsupportedRdbmsOperatorException
  29.592 +			{
  29.593 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Inside);
  29.594 +			}
  29.595 +
  29.596 +	@Override
  29.597 +	protected void append(GeneralDBSqlEgenhofer_Meet expr, GeneralDBSqlExprBuilder filter)
  29.598 +			throws UnsupportedRdbmsOperatorException
  29.599 +			{
  29.600 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Meet);
  29.601 +			}
  29.602 +
  29.603 +	@Override
  29.604 +	protected void append(GeneralDBSqlEgenhofer_Overlap expr, GeneralDBSqlExprBuilder filter)
  29.605 +			throws UnsupportedRdbmsOperatorException
  29.606 +			{
  29.607 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Overlap);
  29.608 +			}
  29.609 +
  29.610 +	//RCC8
  29.611 +	@Override
  29.612 +	protected void append(GeneralDBSqlRCC8_Dc expr, GeneralDBSqlExprBuilder filter)
  29.613 +			throws UnsupportedRdbmsOperatorException
  29.614 +			{
  29.615 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Dc);
  29.616 +			}
  29.617 +
  29.618 +	@Override
  29.619 +	protected void append(GeneralDBSqlRCC8_Eq expr, GeneralDBSqlExprBuilder filter)
  29.620 +			throws UnsupportedRdbmsOperatorException
  29.621 +			{
  29.622 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Eq);
  29.623 +			}
  29.624 +
  29.625 +	@Override
  29.626 +	protected void append(GeneralDBSqlRCC8_Ec expr, GeneralDBSqlExprBuilder filter)
  29.627 +			throws UnsupportedRdbmsOperatorException
  29.628 +			{
  29.629 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ec);
  29.630 +			}
  29.631 +
  29.632 +	@Override
  29.633 +	protected void append(GeneralDBSqlRCC8_Po expr, GeneralDBSqlExprBuilder filter)
  29.634 +			throws UnsupportedRdbmsOperatorException
  29.635 +			{
  29.636 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Po);
  29.637 +			}
  29.638 +
  29.639 +	@Override
  29.640 +	protected void append(GeneralDBSqlRCC8_Tppi expr, GeneralDBSqlExprBuilder filter)
  29.641 +			throws UnsupportedRdbmsOperatorException
  29.642 +			{
  29.643 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tppi);
  29.644 +			}
  29.645 +
  29.646 +	@Override
  29.647 +	protected void append(GeneralDBSqlRCC8_Tpp expr, GeneralDBSqlExprBuilder filter)
  29.648 +			throws UnsupportedRdbmsOperatorException
  29.649 +			{
  29.650 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tpp);
  29.651 +			}
  29.652 +
  29.653 +	@Override
  29.654 +	protected void append(GeneralDBSqlRCC8_Ntpp expr, GeneralDBSqlExprBuilder filter)
  29.655 +			throws UnsupportedRdbmsOperatorException
  29.656 +			{
  29.657 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntpp);
  29.658 +			}
  29.659 +
  29.660 +	@Override
  29.661 +	protected void append(GeneralDBSqlRCC8_Ntppi expr, GeneralDBSqlExprBuilder filter)
  29.662 +			throws UnsupportedRdbmsOperatorException
  29.663 +			{
  29.664 +		appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntppi);
  29.665 +			}
  29.666 +
  29.667 +	//Spatial Construct Functions
  29.668 +	@Override
  29.669 +	protected void append(GeneralDBSqlGeoUnion expr, GeneralDBSqlExprBuilder filter)
  29.670 +			throws UnsupportedRdbmsOperatorException
  29.671 +			{
  29.672 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Union);
  29.673 +			}
  29.674 +
  29.675 +	@Override
  29.676 +	protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter)
  29.677 +			throws UnsupportedRdbmsOperatorException
  29.678 +			{
  29.679 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Buffer);
  29.680 +			}
  29.681 +
  29.682 +	//XXX Different Behavior
  29.683 +	@Override
  29.684 +	protected void append(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
  29.685 +			throws UnsupportedRdbmsOperatorException
  29.686 +			{
  29.687 +		appendTransformFunc(expr, filter);
  29.688 +			}
  29.689 +
  29.690 +	@Override
  29.691 +	protected void append(GeneralDBSqlGeoEnvelope expr, GeneralDBSqlExprBuilder filter)
  29.692 +			throws UnsupportedRdbmsOperatorException
  29.693 +			{
  29.694 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Envelope);
  29.695 +			}
  29.696 +
  29.697 +	@Override
  29.698 +	protected void append(GeneralDBSqlGeoConvexHull expr, GeneralDBSqlExprBuilder filter)
  29.699 +			throws UnsupportedRdbmsOperatorException
  29.700 +			{
  29.701 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_ConvexHull);
  29.702 +			}
  29.703 +
  29.704 +	@Override
  29.705 +	protected void append(GeneralDBSqlGeoBoundary expr, GeneralDBSqlExprBuilder filter)
  29.706 +			throws UnsupportedRdbmsOperatorException
  29.707 +			{
  29.708 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Boundary);
  29.709 +			}
  29.710 +
  29.711 +	@Override
  29.712 +	protected void append(GeneralDBSqlGeoIntersection expr, GeneralDBSqlExprBuilder filter)
  29.713 +			throws UnsupportedRdbmsOperatorException
  29.714 +			{
  29.715 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersection);
  29.716 +			}
  29.717 +
  29.718 +	@Override
  29.719 +	protected void append(GeneralDBSqlGeoDifference expr, GeneralDBSqlExprBuilder filter)
  29.720 +			throws UnsupportedRdbmsOperatorException
  29.721 +			{
  29.722 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Difference);
  29.723 +			}
  29.724 +
  29.725 +	@Override
  29.726 +	protected void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter)
  29.727 +			throws UnsupportedRdbmsOperatorException
  29.728 +			{
  29.729 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference);
  29.730 +			}
  29.731 +
  29.732 +	//Spatial Metric Functions
  29.733 +	@Override
  29.734 +	protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter)
  29.735 +			throws UnsupportedRdbmsOperatorException
  29.736 +			{
  29.737 +		appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Distance);
  29.738 +			}
  29.739 +
  29.740 +	@Override
  29.741 +	protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter)
  29.742 +			throws UnsupportedRdbmsOperatorException
  29.743 +			{
  29.744 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Area);
  29.745 +			}
  29.746 +
  29.747 +	//Spatial Property Functions
  29.748 +	@Override
  29.749 +	protected void append(GeneralDBSqlGeoDimension expr, GeneralDBSqlExprBuilder filter)
  29.750 +			throws UnsupportedRdbmsOperatorException
  29.751 +			{
  29.752 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Dimension);
  29.753 +			}
  29.754 +
  29.755 +	@Override
  29.756 +	protected void append(GeneralDBSqlGeoGeometryType expr, GeneralDBSqlExprBuilder filter)
  29.757 +			throws UnsupportedRdbmsOperatorException
  29.758 +			{
  29.759 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_GeometryType);
  29.760 +			}
  29.761 +
  29.762 +	@Override
  29.763 +	protected void append(GeneralDBSqlGeoAsText expr, GeneralDBSqlExprBuilder filter)
  29.764 +			throws UnsupportedRdbmsOperatorException
  29.765 +			{
  29.766 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsText);
  29.767 +			}
  29.768 +
  29.769 +	@Override
  29.770 +	protected void append(GeneralDBSqlGeoAsGML expr, GeneralDBSqlExprBuilder filter)
  29.771 +			throws UnsupportedRdbmsOperatorException
  29.772 +			{
  29.773 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsGML);
  29.774 +			}
  29.775 +
  29.776 +	//	@Override
  29.777 +	//	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
  29.778 +	//	throws UnsupportedRdbmsOperatorException
  29.779 +	//	{
  29.780 +	//		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID);
  29.781 +	//	}
  29.782 +
  29.783 +	/**
  29.784 +	 * Special Case because I need to retrieve a single different column from geo_values when this function occurs
  29.785 +	 * in the select clause
  29.786 +	 */
  29.787 +	@Override
  29.788 +	protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter)
  29.789 +			throws UnsupportedRdbmsOperatorException
  29.790 +			{
  29.791 +		boolean sridNeeded = true;
  29.792 +		filter.openBracket();
  29.793 +
  29.794 +		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  29.795 +		boolean check2 = false;
  29.796 +		if(expr.getArg() instanceof GeneralDBLabelColumn)
  29.797 +		{
  29.798 +			if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource())
  29.799 +			{
  29.800 +				check2 = true;
  29.801 +			}
  29.802 +		}
  29.803 +		if(check1)
  29.804 +		{
  29.805 +			this.append((GeneralDBSqlNull)expr.getArg(), filter);
  29.806 +
  29.807 +		}
  29.808 +		else if (check2)
  29.809 +		{
  29.810 +			appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
  29.811 +		}
  29.812 +		else
  29.813 +		{
  29.814 +			//XXX Incorporating SRID
  29.815 +			GeneralDBSqlExpr tmp = expr;
  29.816 +			if(tmp.getParentNode() == null)
  29.817 +			{
  29.818 +				String sridExpr;
  29.819 +				while(true)
  29.820 +				{
  29.821 +					GeneralDBSqlExpr child = null;
  29.822 +
  29.823 +					if(tmp instanceof BinaryGeneralDBOperator)
  29.824 +					{
  29.825 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
  29.826 +					}
  29.827 +					else if(tmp instanceof UnaryGeneralDBOperator)
  29.828 +					{
  29.829 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
  29.830 +					}
  29.831 +					else if(tmp instanceof GeneralDBStringValue)
  29.832 +					{
  29.833 +						//Constant!!
  29.834 +						sridNeeded  = false;
  29.835 +						break;
  29.836 +					}
  29.837 +
  29.838 +					tmp = child;
  29.839 +					if(tmp instanceof GeneralDBLabelColumn)
  29.840 +					{
  29.841 +						//Reached the innermost left var -> need to capture its SRID
  29.842 +						String alias;
  29.843 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
  29.844 +							//Predicates used in triple patterns non-existent in db
  29.845 +							alias="NULL";
  29.846 +						}
  29.847 +						else
  29.848 +						{
  29.849 +							//Reached the innermost left var -> need to capture its SRID
  29.850 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
  29.851 +							alias=alias+".srid";
  29.852 +						}
  29.853 +						sridExpr = alias;
  29.854 +						filter.append(sridExpr);
  29.855 +						filter.closeBracket();
  29.856 +						return;
  29.857 +						//break;
  29.858 +					}
  29.859 +					else if(tmp instanceof GeneralDBStringValue)
  29.860 +					{
  29.861 +						//Constant!!
  29.862 +						sridNeeded  = false;
  29.863 +						break;
  29.864 +					}
  29.865 +
  29.866 +				}
  29.867 +			}
  29.868 +
  29.869 +			if(sridNeeded)
  29.870 +			{
  29.871 +				filter.appendFunction("ST_SRID");
  29.872 +				filter.openBracket();
  29.873 +				if(expr.getArg() instanceof GeneralDBStringValue)
  29.874 +				{
  29.875 +					appendWKT(expr.getArg(),filter);
  29.876 +				}
  29.877 +				else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary)
  29.878 +				{
  29.879 +					appendConstructFunction(expr.getArg(), filter);
  29.880 +				}
  29.881 +				else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary)
  29.882 +				{
  29.883 +					appendConstructFunction(expr.getArg(), filter);
  29.884 +				}
  29.885 +				else if(expr.getArg() instanceof GeneralDBSqlCase)
  29.886 +				{
  29.887 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
  29.888 +					appendMBB(onlyLabel,filter); 
  29.889 +				}
  29.890 +				else
  29.891 +				{
  29.892 +					appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
  29.893 +				}
  29.894 +
  29.895 +				filter.closeBracket();
  29.896 +			}
  29.897 +			else
  29.898 +			{
  29.899 +				//4326 by default - Software House additions
  29.900 +				filter.append("4326");
  29.901 +			}
  29.902 +		}
  29.903 +
  29.904 +		filter.closeBracket();
  29.905 +			}
  29.906 +
  29.907 +	@Override
  29.908 +	protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter)
  29.909 +			throws UnsupportedRdbmsOperatorException
  29.910 +			{
  29.911 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsSimple);
  29.912 +			}
  29.913 +
  29.914 +	@Override
  29.915 +	protected void append(GeneralDBSqlGeoIsEmpty expr, GeneralDBSqlExprBuilder filter)
  29.916 +			throws UnsupportedRdbmsOperatorException
  29.917 +			{
  29.918 +		appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty);
  29.919 +			}
  29.920 +
  29.921 +
  29.922 +	/**
  29.923 +	 * 'helper' functions
  29.924 +	 */
  29.925 +
  29.926 +	@Override
  29.927 +	protected String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter)
  29.928 +	{
  29.929 +		GeneralDBStringValue arg = (GeneralDBStringValue) expr;
  29.930 +		String raw = arg.getValue();
  29.931 +
  29.932 +		StrabonPolyhedron poly = null;
  29.933 +		try{
  29.934 +			poly = new StrabonPolyhedron(raw);
  29.935 +		} catch (Exception e) {
  29.936 +			e.printStackTrace();
  29.937 +		}
  29.938 +
  29.939 +		filter.append(" ST_GeomFromText('"+poly.toWKT() +"',4326)");
  29.940 +
  29.941 +		return raw;
  29.942 +	}
  29.943 +
  29.944 +	//Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 
  29.945 +	//	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
  29.946 +	//	{
  29.947 +	//		filter.openBracket();
  29.948 +	//
  29.949 +	//		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  29.950 +	//		//boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  29.951 +	//
  29.952 +	//		if(check1a)
  29.953 +	//		{
  29.954 +	//			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
  29.955 +	//
  29.956 +	//		}
  29.957 +	////		else if(check2a)
  29.958 +	////		{
  29.959 +	////			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
  29.960 +	////		}
  29.961 +	//		else
  29.962 +	//		{
  29.963 +	//			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
  29.964 +	//			{
  29.965 +	//				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
  29.966 +	//			}
  29.967 +	//			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
  29.968 +	//			{
  29.969 +	//				appendWKT(expr.getLeftArg(),filter);
  29.970 +	//			}
  29.971 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
  29.972 +	//			{
  29.973 +	//				appendConstructFunction(expr.getLeftArg(), filter);
  29.974 +	//			}
  29.975 +	//			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
  29.976 +	//			{
  29.977 +	//				appendConstructFunction(expr.getLeftArg(), filter);
  29.978 +	//			}
  29.979 +	//			else
  29.980 +	//			{
  29.981 +	//				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
  29.982 +	//			}
  29.983 +	//
  29.984 +	//			switch(operand)
  29.985 +	//			{
  29.986 +	//			case anyInteract: filter.anyInteract(); break;
  29.987 +	//			case equals: filter.equals(); break;
  29.988 +	//			case contains: filter.contains(); break;
  29.989 +	//			case inside: filter.inside(); break;
  29.990 +	//			case left: filter.left(); break;
  29.991 +	//			case right: filter.right(); break;
  29.992 +	//			case above: filter.above(); break;
  29.993 +	//			case below: filter.below(); break;
  29.994 +	//			}
  29.995 +	//
  29.996 +	//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
  29.997 +	//
  29.998 +	//			if(check2a)
  29.999 +	//			{
 29.1000 +	//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1001 +	//			}
 29.1002 +	//			else
 29.1003 +	//			{
 29.1004 +	//
 29.1005 +	//				if(expr.getRightArg() instanceof GeneralDBSqlCase)
 29.1006 +	//				{
 29.1007 +	//					this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
 29.1008 +	//				}
 29.1009 +	//				else if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.1010 +	//				{
 29.1011 +	//					appendWKT(expr.getRightArg(),filter);
 29.1012 +	//				}
 29.1013 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1014 +	//				{
 29.1015 +	//					appendConstructFunction(expr.getRightArg(), filter);
 29.1016 +	//				}
 29.1017 +	//				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1018 +	//				{
 29.1019 +	//					appendConstructFunction(expr.getRightArg(), filter);
 29.1020 +	//				}
 29.1021 +	//				else
 29.1022 +	//				{
 29.1023 +	//					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 29.1024 +	//				}
 29.1025 +	//
 29.1026 +	//			}
 29.1027 +	//		}
 29.1028 +	//		filter.closeBracket();
 29.1029 +	//	}
 29.1030 +
 29.1031 +
 29.1032 +	protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException
 29.1033 +	{
 29.1034 +		filter.openBracket();
 29.1035 +
 29.1036 +		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1037 +		boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1038 +
 29.1039 +		if(check1a)
 29.1040 +		{
 29.1041 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1042 +
 29.1043 +		}
 29.1044 +		else if(check2a)
 29.1045 +		{
 29.1046 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1047 +		}
 29.1048 +		else
 29.1049 +		{
 29.1050 +			if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 29.1051 +			{
 29.1052 +				this.append((GeneralDBSqlCase)expr.getLeftArg(), filter);
 29.1053 +			}
 29.1054 +			else if(expr.getLeftArg() instanceof GeneralDBStringValue)
 29.1055 +			{
 29.1056 +				appendWKT(expr.getLeftArg(),filter);
 29.1057 +			}
 29.1058 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1059 +			{
 29.1060 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1061 +			}
 29.1062 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1063 +			{
 29.1064 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1065 +			}
 29.1066 +			else
 29.1067 +			{
 29.1068 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 29.1069 +			}
 29.1070 +
 29.1071 +			switch(operand)
 29.1072 +			{
 29.1073 +			case anyInteract: filter.intersectsMBB(); break;
 29.1074 +			case equals: filter.equalsMBB(); break;
 29.1075 +			case contains: filter.containsMBB(); break;
 29.1076 +			case inside: filter.insideMBB(); break;
 29.1077 +			case left: filter.leftMBB(); break;
 29.1078 +			case right: filter.rightMBB(); break;
 29.1079 +			case above: filter.aboveMBB(); break;
 29.1080 +			case below: filter.belowMBB(); break;
 29.1081 +			}
 29.1082 +
 29.1083 +			//			boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1084 +			//
 29.1085 +			//			if(check2a)
 29.1086 +			//			{
 29.1087 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1088 +			//			}
 29.1089 +			//			else
 29.1090 +			//			{
 29.1091 +
 29.1092 +			if(expr.getRightArg() instanceof GeneralDBSqlCase)
 29.1093 +			{
 29.1094 +				this.append((GeneralDBSqlCase)expr.getRightArg(), filter);
 29.1095 +			}
 29.1096 +			else if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.1097 +			{
 29.1098 +				appendWKT(expr.getRightArg(),filter);
 29.1099 +			}
 29.1100 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1101 +			{
 29.1102 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1103 +			}
 29.1104 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1105 +			{
 29.1106 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1107 +			}
 29.1108 +			else
 29.1109 +			{
 29.1110 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 29.1111 +			}
 29.1112 +
 29.1113 +			//}
 29.1114 +		}
 29.1115 +		filter.closeBracket();
 29.1116 +	}
 29.1117 +
 29.1118 +	//Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
 29.1119 +	protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter)
 29.1120 +			throws UnsupportedRdbmsOperatorException
 29.1121 +			{
 29.1122 +		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
 29.1123 +		boolean sridNeeded = true;
 29.1124 +		//XXX Incorporating SRID
 29.1125 +		String sridExpr = null;
 29.1126 +
 29.1127 +		filter.openBracket();
 29.1128 +		filter.appendFunction(ST_TRANSFORM);
 29.1129 +		filter.openBracket();
 29.1130 +
 29.1131 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1132 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1133 +
 29.1134 +		if(check1)
 29.1135 +		{
 29.1136 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1137 +
 29.1138 +		}
 29.1139 +		else if(check2)
 29.1140 +		{
 29.1141 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1142 +		}
 29.1143 +		else
 29.1144 +		{
 29.1145 +			GeneralDBSqlExpr tmp = expr;
 29.1146 +			if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null)
 29.1147 +			{
 29.1148 +				while(true)
 29.1149 +				{
 29.1150 +					GeneralDBSqlExpr child;
 29.1151 +
 29.1152 +					if(tmp instanceof BinaryGeneralDBOperator)
 29.1153 +					{
 29.1154 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
 29.1155 +					}
 29.1156 +					else //(tmp instanceof UnaryGeneralDBOperator)
 29.1157 +					{
 29.1158 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
 29.1159 +					}
 29.1160 +
 29.1161 +					tmp = child;
 29.1162 +					if(tmp instanceof GeneralDBLabelColumn)
 29.1163 +					{
 29.1164 +						String alias;
 29.1165 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
 29.1166 +							//Predicates used in triple patterns non-existent in db
 29.1167 +							alias="NULL";
 29.1168 +						}
 29.1169 +						else
 29.1170 +						{
 29.1171 +							//Reached the innermost left var -> need to capture its SRID
 29.1172 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
 29.1173 +							alias=alias+".srid";
 29.1174 +						}
 29.1175 +						sridExpr = alias;
 29.1176 +						break;
 29.1177 +					}
 29.1178 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
 29.1179 +					{
 29.1180 +						sridNeeded  = false;
 29.1181 +						break;
 29.1182 +					}
 29.1183 +
 29.1184 +				}
 29.1185 +				if(sridNeeded)
 29.1186 +				{
 29.1187 +					filter.appendFunction(ST_TRANSFORM);
 29.1188 +					filter.openBracket();
 29.1189 +				}
 29.1190 +			}
 29.1191 +
 29.1192 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 29.1193 +			{
 29.1194 +				appendWKT(expr.getLeftArg(),filter);
 29.1195 +			}
 29.1196 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1197 +			{
 29.1198 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1199 +			}
 29.1200 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1201 +			{
 29.1202 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1203 +			}
 29.1204 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 29.1205 +			{
 29.1206 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 29.1207 +				appendMBB(onlyLabel,filter); 
 29.1208 +			}
 29.1209 +			else
 29.1210 +			{
 29.1211 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 29.1212 +			}
 29.1213 +
 29.1214 +			//SRID Support
 29.1215 +			if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
 29.1216 +			{
 29.1217 +				filter.appendComma();
 29.1218 +				//filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid());
 29.1219 +				filter.append(sridExpr);
 29.1220 +				filter.closeBracket();
 29.1221 +			}
 29.1222 +
 29.1223 +			filter.appendComma();
 29.1224 +
 29.1225 +			if(expr.getRightArg() instanceof GeneralDBSqlCase) //case met in transform!
 29.1226 +			{
 29.1227 +				GeneralDBURIColumn plainURI = (GeneralDBURIColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 29.1228 +
 29.1229 +				//XXX This case would be met if we recovered the SRID URI from the db!!!
 29.1230 +				//Need to set sridExpr to the value of this new URI, otherwise the appended uri
 29.1231 +				//to the spatial object will be the wrong one!!!! (Seee following case)
 29.1232 +				filter.keepSRID_part1();
 29.1233 +				append(plainURI, filter);
 29.1234 +				filter.keepSRID_part2();
 29.1235 +				append(plainURI, filter);
 29.1236 +				filter.keepSRID_part3();
 29.1237 +			}
 29.1238 +			else if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.1239 +			{
 29.1240 +				String unparsedSRID = ((GeneralDBStringValue)expr.getRightArg()).getValue();
 29.1241 +				//				int srid = Integer.parseInt(unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1));
 29.1242 +				sridExpr = unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1);
 29.1243 +				filter.append(sridExpr);
 29.1244 +				filter.closeBracket();
 29.1245 +			}
 29.1246 +
 29.1247 +
 29.1248 +		}
 29.1249 +		filter.closeBracket();
 29.1250 +		//In this case, SRID is the one that has been provided by the user!! 
 29.1251 +		//I am including this extra binding to be used in subsequent (Aggregate) steps
 29.1252 +		if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null)
 29.1253 +		{
 29.1254 +			filter.appendComma();
 29.1255 +			filter.append(sridExpr);
 29.1256 +		}
 29.1257 +
 29.1258 +			}
 29.1259 +
 29.1260 +	/** Addition for datetime metric functions
 29.1261 +	 * 
 29.1262 +	 * @author George Garbis <ggarbis@di.uoa.gr>
 29.1263 +	 * 
 29.1264 +	 */
 29.1265 +	
 29.1266 +	protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionsPostGIS func)
 29.1267 +	throws UnsupportedRdbmsOperatorException
 29.1268 +	{
 29.1269 +
 29.1270 +		filter.openBracket();
 29.1271 +
 29.1272 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1273 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1274 +
 29.1275 +		if(check1)
 29.1276 +		{
 29.1277 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1278 +
 29.1279 +		}
 29.1280 +		else if(check2)
 29.1281 +		{
 29.1282 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1283 +		}
 29.1284 +		else
 29.1285 +		{			
 29.1286 +			switch (func){
 29.1287 +			case Difference:
 29.1288 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 29.1289 +				filter.append(" - ");
 29.1290 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 29.1291 +				break;
 29.1292 +			}
 29.1293 +			
 29.1294 +		}
 29.1295 +	}
 29.1296 +
 29.1297 +	// Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1, ?GEO2)
 29.1298 +	// EXCEPT ST_Transform!!! 
 29.1299 +	protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 29.1300 +			throws UnsupportedRdbmsOperatorException
 29.1301 +			{
 29.1302 +		//In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))")
 29.1303 +		boolean sridNeeded = true;
 29.1304 +		String sridExpr = null;
 29.1305 +
 29.1306 +		filter.openBracket();
 29.1307 +
 29.1308 +		boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1309 +		boolean check2 = false;
 29.1310 +		if(expr.getArg() instanceof GeneralDBLabelColumn)
 29.1311 +		{
 29.1312 +			if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource())
 29.1313 +			{
 29.1314 +				check2 = true;
 29.1315 +			}
 29.1316 +		}
 29.1317 +		if(check1)
 29.1318 +		{
 29.1319 +			this.append((GeneralDBSqlNull)expr.getArg(), filter);
 29.1320 +
 29.1321 +		}
 29.1322 +		else if (check2)
 29.1323 +		{
 29.1324 +			appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
 29.1325 +		}
 29.1326 +		else
 29.1327 +		{
 29.1328 +
 29.1329 +			GeneralDBSqlExpr tmp = expr;
 29.1330 +
 29.1331 +
 29.1332 +			if(tmp instanceof GeneralDBSqlSpatialConstructUnary && tmp.getParentNode() == null)
 29.1333 +			{
 29.1334 +				while(true)
 29.1335 +				{
 29.1336 +					GeneralDBSqlExpr child = null;
 29.1337 +
 29.1338 +					if(tmp instanceof BinaryGeneralDBOperator)
 29.1339 +					{
 29.1340 +						child = ((BinaryGeneralDBOperator) tmp).getLeftArg();
 29.1341 +					}
 29.1342 +					else if(tmp instanceof UnaryGeneralDBOperator)
 29.1343 +					{
 29.1344 +						child = ((UnaryGeneralDBOperator) tmp).getArg();
 29.1345 +					}
 29.1346 +					else if(tmp instanceof GeneralDBStringValue)
 29.1347 +					{
 29.1348 +						sridNeeded  = false;
 29.1349 +						break;
 29.1350 +					}
 29.1351 +
 29.1352 +					tmp = child;
 29.1353 +					if(tmp instanceof GeneralDBLabelColumn)
 29.1354 +					{
 29.1355 +						//Reached the innermost left var -> need to capture its SRID
 29.1356 +						String alias;
 29.1357 +						if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) {
 29.1358 +							//Predicates used in triple patterns non-existent in db
 29.1359 +							alias="NULL";
 29.1360 +						}
 29.1361 +						else
 29.1362 +						{
 29.1363 +							//Reached the innermost left var -> need to capture its SRID
 29.1364 +							alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar());
 29.1365 +							alias=alias+".srid";
 29.1366 +						}
 29.1367 +						sridExpr = alias;
 29.1368 +						break;
 29.1369 +					}
 29.1370 +					else if (tmp instanceof GeneralDBStringValue) //Constant!!
 29.1371 +					{
 29.1372 +						sridNeeded  = false;
 29.1373 +						break;
 29.1374 +					}
 29.1375 +
 29.1376 +				}
 29.1377 +				if(sridNeeded)
 29.1378 +				{
 29.1379 +					filter.appendFunction(ST_TRANSFORM);
 29.1380 +					filter.openBracket();
 29.1381 +				}
 29.1382 +			}
 29.1383 +			/////
 29.1384 +
 29.1385 +			switch(func)
 29.1386 +			{
 29.1387 +			case ST_Envelope: filter.appendFunction("ST_Envelope"); break;
 29.1388 +			case ST_ConvexHull: filter.appendFunction("ST_ConvexHull"); break;
 29.1389 +			case ST_Boundary: filter.appendFunction("ST_Boundary"); break;
 29.1390 +			case ST_Area: filter.appendFunction("ST_Area"); break;
 29.1391 +			case ST_Dimension: filter.appendFunction("ST_Dimension"); break;
 29.1392 +			case ST_GeometryType: filter.appendFunction("ST_GeometryType"); break;
 29.1393 +			case ST_AsText: filter.appendFunction("ST_AsText"); break;
 29.1394 +			case ST_AsGML: filter.appendFunction("ST_AsGML"); break;
 29.1395 +			case ST_SRID: filter.appendFunction("ST_SRID"); break;
 29.1396 +			case ST_IsEmpty: filter.appendFunction("ST_IsEmpty"); break;
 29.1397 +			case ST_IsSimple: filter.appendFunction("ST_IsSimple"); break;
 29.1398 +			}
 29.1399 +			filter.openBracket();
 29.1400 +			if(expr.getArg() instanceof GeneralDBStringValue)
 29.1401 +			{
 29.1402 +				appendWKT(expr.getArg(),filter);
 29.1403 +			}
 29.1404 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1405 +			{
 29.1406 +				appendConstructFunction(expr.getArg(), filter);
 29.1407 +			}
 29.1408 +			else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1409 +			{
 29.1410 +				appendConstructFunction(expr.getArg(), filter);
 29.1411 +			}
 29.1412 +			else if(expr.getArg() instanceof GeneralDBSqlCase)
 29.1413 +			{
 29.1414 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult();
 29.1415 +				appendMBB(onlyLabel,filter); 
 29.1416 +			}
 29.1417 +			else
 29.1418 +			{
 29.1419 +				appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter);
 29.1420 +			}
 29.1421 +
 29.1422 +			filter.closeBracket();
 29.1423 +			//			//SRID Support
 29.1424 +			if(sridNeeded)
 29.1425 +			{
 29.1426 +				if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
 29.1427 +				{
 29.1428 +					filter.appendComma();
 29.1429 +					//				filter.append(((GeneralDBSqlSpatialConstructUnary)expr).getSrid());
 29.1430 +					filter.append(sridExpr);
 29.1431 +					filter.closeBracket();
 29.1432 +				}
 29.1433 +			}
 29.1434 +			///
 29.1435 +		}
 29.1436 +
 29.1437 +		filter.closeBracket();
 29.1438 +		//Used to explicitly include SRID
 29.1439 +		if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null)
 29.1440 +		{
 29.1441 +			filter.appendComma();
 29.1442 +			filter.append(sridExpr);
 29.1443 +		}
 29.1444 +			}
 29.1445 +
 29.1446 +	//Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 
 29.1447 +	protected void appendGeneralDBSpatialFunctionTriple(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 29.1448 +			throws UnsupportedRdbmsOperatorException
 29.1449 +			{
 29.1450 +		filter.openBracket();
 29.1451 +
 29.1452 +		boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1453 +		boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1454 +		boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1455 +
 29.1456 +		if(check1a)
 29.1457 +		{
 29.1458 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1459 +
 29.1460 +		}
 29.1461 +		else if(check2a)
 29.1462 +		{
 29.1463 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1464 +		}
 29.1465 +		else if(check3)
 29.1466 +		{
 29.1467 +			this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
 29.1468 +		}
 29.1469 +		else
 29.1470 +		{
 29.1471 +			switch(func)
 29.1472 +			{
 29.1473 +			case ST_Relate: filter.appendFunction("ST_Relate"); break;
 29.1474 +			}
 29.1475 +			filter.openBracket();
 29.1476 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 29.1477 +			{
 29.1478 +				appendWKT(expr.getLeftArg(),filter);
 29.1479 +			}
 29.1480 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1481 +			{
 29.1482 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1483 +			}
 29.1484 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1485 +			{
 29.1486 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1487 +			}
 29.1488 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 29.1489 +			{
 29.1490 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 29.1491 +				appendMBB(onlyLabel,filter); 
 29.1492 +			}
 29.1493 +			else
 29.1494 +			{
 29.1495 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 29.1496 +			}
 29.1497 +			filter.appendComma();
 29.1498 +			//			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1499 +			//			if(check2)
 29.1500 +			//			{
 29.1501 +			//				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1502 +			//			}
 29.1503 +			//			else
 29.1504 +			//			{
 29.1505 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.1506 +			{
 29.1507 +				appendWKT(expr.getRightArg(),filter);
 29.1508 +			}
 29.1509 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1510 +			{
 29.1511 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1512 +			}
 29.1513 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1514 +			{
 29.1515 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1516 +			}
 29.1517 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 29.1518 +			{
 29.1519 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 29.1520 +				appendMBB(onlyLabel,filter);					 
 29.1521 +			}
 29.1522 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 29.1523 +			{
 29.1524 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 29.1525 +			}
 29.1526 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 29.1527 +			{
 29.1528 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 29.1529 +			}
 29.1530 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 29.1531 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 29.1532 +			{
 29.1533 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 29.1534 +				appendCastToDouble(filter);
 29.1535 +			}
 29.1536 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 29.1537 +			{
 29.1538 +				appendMetricFunction(expr.getRightArg(), filter);
 29.1539 +			}
 29.1540 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 29.1541 +			{
 29.1542 +				appendMetricFunction(expr.getRightArg(), filter);
 29.1543 +			}
 29.1544 +			else
 29.1545 +			{
 29.1546 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 29.1547 +			}
 29.1548 +
 29.1549 +			//			}
 29.1550 +			//3rd arg
 29.1551 +			filter.appendComma();
 29.1552 +			//			boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1553 +			//			if(check3)
 29.1554 +			//			{
 29.1555 +			//				this.append((GeneralDBSqlNull)expr.getThirdArg(), filter);
 29.1556 +			//			}
 29.1557 +			//			else
 29.1558 +			//			{
 29.1559 +
 29.1560 +			if(expr.getThirdArg() instanceof GeneralDBStringValue)
 29.1561 +			{
 29.1562 +				append(((GeneralDBStringValue)expr.getThirdArg()),filter);	
 29.1563 +			}
 29.1564 +			else if(expr.getThirdArg() instanceof GeneralDBSqlCase)
 29.1565 +			{
 29.1566 +				append(((GeneralDBSqlCase)expr.getThirdArg()),filter);				 
 29.1567 +			}
 29.1568 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 29.1569 +			else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial())
 29.1570 +			{
 29.1571 +
 29.1572 +				append(((GeneralDBLabelColumn)expr.getThirdArg()),filter);
 29.1573 +			}
 29.1574 +
 29.1575 +
 29.1576 +			//			}
 29.1577 +			filter.closeBracket();
 29.1578 +		}
 29.1579 +
 29.1580 +		filter.closeBracket();
 29.1581 +			}
 29.1582 +
 29.1583 +
 29.1584 +	//GeoSPARQL
 29.1585 +	//XXX
 29.1586 +	protected void appendRelate(BinaryGeneralDBOperator expr, PostGISSqlExprBuilder filter, char[] intersectionPattern)
 29.1587 +			throws UnsupportedRdbmsOperatorException
 29.1588 +			{
 29.1589 +		filter.openBracket();
 29.1590 +
 29.1591 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1592 +		boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1593 +
 29.1594 +		if(check1)
 29.1595 +		{
 29.1596 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1597 +
 29.1598 +		}
 29.1599 +		else if(check2)
 29.1600 +		{
 29.1601 +			this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.1602 +		}
 29.1603 +		else
 29.1604 +		{	
 29.1605 +			filter.appendFunction("ST_Relate");
 29.1606 +
 29.1607 +
 29.1608 +			filter.openBracket();
 29.1609 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 29.1610 +			{
 29.1611 +				appendWKT(expr.getLeftArg(),filter);
 29.1612 +			}
 29.1613 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1614 +			{
 29.1615 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1616 +			}
 29.1617 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1618 +			{
 29.1619 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.1620 +			}
 29.1621 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 29.1622 +			{
 29.1623 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 29.1624 +				appendMBB(onlyLabel,filter); 
 29.1625 +			}
 29.1626 +			else
 29.1627 +			{
 29.1628 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 29.1629 +			}
 29.1630 +			filter.appendComma();
 29.1631 +
 29.1632 +			if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.1633 +			{
 29.1634 +				appendWKT(expr.getRightArg(),filter);
 29.1635 +			}
 29.1636 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.1637 +			{
 29.1638 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1639 +			}
 29.1640 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.1641 +			{
 29.1642 +				appendConstructFunction(expr.getRightArg(), filter);
 29.1643 +			}
 29.1644 +			else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 29.1645 +			{
 29.1646 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 29.1647 +				appendMBB(onlyLabel,filter);					 
 29.1648 +			}
 29.1649 +			else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 29.1650 +			{
 29.1651 +				append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 29.1652 +			}
 29.1653 +			else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 29.1654 +			{
 29.1655 +				append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 29.1656 +			}
 29.1657 +			//case met in buffer when in select -> buffer(?spatial,?thematic)
 29.1658 +			else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 29.1659 +			{
 29.1660 +				append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 29.1661 +				appendCastToDouble(filter);
 29.1662 +			}
 29.1663 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 29.1664 +			{
 29.1665 +				appendMetricFunction(expr.getRightArg(), filter);
 29.1666 +			}
 29.1667 +			else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 29.1668 +			{
 29.1669 +				appendMetricFunction(expr.getRightArg(), filter);
 29.1670 +			}
 29.1671 +			else
 29.1672 +			{
 29.1673 +				appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 29.1674 +			}
 29.1675 +
 29.1676 +			//3rd arg
 29.1677 +			filter.appendComma();
 29.1678 +
 29.1679 +			//must turn the table of characters I have to a valid sql value!
 29.1680 +			filter.append("'");
 29.1681 +			for(int i = 0; i< intersectionPattern.length; i++)
 29.1682 +			{
 29.1683 +				filter.append(intersectionPattern[i]+"");
 29.1684 +			}
 29.1685 +			filter.append("'");
 29.1686 +
 29.1687 +			filter.closeBracket();
 29.1688 +
 29.1689 +		}
 29.1690 +
 29.1691 +		filter.closeBracket();
 29.1692 +			}
 29.1693 +
 29.1694 +
 29.1695 +	protected void appendgeoSPARQLSpatialRelation(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func)
 29.1696 +			throws UnsupportedRdbmsOperatorException
 29.1697 +			{
 29.1698 +		filter.openBracket();
 29.1699 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.1700 +		if(check1)
 29.1701 +		{
 29.1702 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.1703 +
 29.1704 +		}
 29.1705 +		else
 29.1706 +		{
 29.1707 +			char[][] intersectionPattern = null;
 29.1708 +			switch(func)
 29.1709 +			{
 29.1710 +			case ST_Covers: 
 29.1711 +				intersectionPattern = new char[1][9];
 29.1712 +				intersectionPattern[0][0] = 'T';
 29.1713 +				intersectionPattern[0][1] = '*';
 29.1714 +				intersectionPattern[0][2] = 'T';
 29.1715 +				intersectionPattern[0][3] = 'F';
 29.1716 +				intersectionPattern[0][4] = 'T';
 29.1717 +				intersectionPattern[0][5] = '*';
 29.1718 +				intersectionPattern[0][6] = 'F';
 29.1719 +				intersectionPattern[0][7] = 'F';
 29.1720 +				intersectionPattern[0][8] = '*';
 29.1721 +				break;
 29.1722 +			case ST_CoveredBy: 
 29.1723 +				intersectionPattern = new char[1][9];
 29.1724 +				intersectionPattern[0][0] = 'T';
 29.1725 +				intersectionPattern[0][1] = 'F';
 29.1726 +				intersectionPattern[0][2] = 'F';
 29.1727 +				intersectionPattern[0][3] = '*';
 29.1728 +				intersectionPattern[0][4] = 'T';
 29.1729 +				intersectionPattern[0][5] = 'F';
 29.1730 +				intersectionPattern[0][6] = 'T';
 29.1731 +				intersectionPattern[0][7] = '*';
 29.1732 +				intersectionPattern[0][8] = '*';
 29.1733 +				break;
 29.1734 +			case SF_Contains:  
 29.1735 +				intersectionPattern = new char[1][9];
 29.1736 +				intersectionPattern[0][0] = 'T';
 29.1737 +				intersectionPattern[0][1] = '*';
 29.1738 +				intersectionPattern[0][2] = '*';
 29.1739 +				intersectionPattern[0][3] = '*';
 29.1740 +				intersectionPattern[0][4] = '*';
 29.1741 +				intersectionPattern[0][5] = '*';
 29.1742 +				intersectionPattern[0][6] = 'F';
 29.1743 +				intersectionPattern[0][7] = 'F';
 29.1744 +				intersectionPattern[0][8] = '*';
 29.1745 +				break;
 29.1746 +			case SF_Crosses:  
 29.1747 +				intersectionPattern = new char[1][9];
 29.1748 +				intersectionPattern[0][0] = 'T';
 29.1749 +				intersectionPattern[0][1] = '*';
 29.1750 +				intersectionPattern[0][2] = 'T';
 29.1751 +				intersectionPattern[0][3] = '*';
 29.1752 +				intersectionPattern[0][4] = '*';
 29.1753 +				intersectionPattern[0][5] = '*';
 29.1754 +				intersectionPattern[0][6] = '*';
 29.1755 +				intersectionPattern[0][7] = '*';
 29.1756 +				intersectionPattern[0][8] = '*';
 29.1757 +				break;
 29.1758 +			case SF_Disjoint:
 29.1759 +			case EH_Disjoint:
 29.1760 +				intersectionPattern = new char[1][9];
 29.1761 +				intersectionPattern[0][0] = 'F';
 29.1762 +				intersectionPattern[0][1] = 'F';
 29.1763 +				intersectionPattern[0][2] = '*';
 29.1764 +				intersectionPattern[0][3] = 'F';
 29.1765 +				intersectionPattern[0][4] = 'F';
 29.1766 +				intersectionPattern[0][5] = '*';
 29.1767 +				intersectionPattern[0][6] = '*';
 29.1768 +				intersectionPattern[0][7] = '*';
 29.1769 +				intersectionPattern[0][8] = '*';
 29.1770 +				break;
 29.1771 +			case SF_Equals: 
 29.1772 +			case EH_Equals:
 29.1773 +			case RCC8_Eq:	
 29.1774 +				intersectionPattern = new char[1][9];
 29.1775 +				intersectionPattern[0][0] = 'T';
 29.1776 +				intersectionPattern[0][1] = 'F';
 29.1777 +				intersectionPattern[0][2] = 'F';
 29.1778 +				intersectionPattern[0][3] = 'F';
 29.1779 +				intersectionPattern[0][4] = 'T';
 29.1780 +				intersectionPattern[0][5] = 'F';
 29.1781 +				intersectionPattern[0][6] = 'F';
 29.1782 +				intersectionPattern[0][7] = 'F';
 29.1783 +				intersectionPattern[0][8] = 'T';
 29.1784 +				break;
 29.1785 +			case SF_Overlaps:
 29.1786 +			case EH_Overlap:
 29.1787 +				intersectionPattern = new char[1][9];
 29.1788 +				intersectionPattern[0][0] = 'T';
 29.1789 +				intersectionPattern[0][1] = '*';
 29.1790 +				intersectionPattern[0][2] = 'T';
 29.1791 +				intersectionPattern[0][3] = '*';
 29.1792 +				intersectionPattern[0][4] = '*';
 29.1793 +				intersectionPattern[0][5] = '*';
 29.1794 +				intersectionPattern[0][6] = 'T';
 29.1795 +				intersectionPattern[0][7] = '*';
 29.1796 +				intersectionPattern[0][8] = '*';
 29.1797 +				break;
 29.1798 +			case SF_Within: 
 29.1799 +				intersectionPattern = new char[1][9];
 29.1800 +				intersectionPattern[0][0] = 'T';
 29.1801 +				intersectionPattern[0][1] = '*';
 29.1802 +				intersectionPattern[0][2] = 'F';
 29.1803 +				intersectionPattern[0][3] = '*';
 29.1804 +				intersectionPattern[0][4] = '*';
 29.1805 +				intersectionPattern[0][5] = 'F';
 29.1806 +				intersectionPattern[0][6] = '*';
 29.1807 +				intersectionPattern[0][7] = '*';
 29.1808 +				intersectionPattern[0][8] = '*';
 29.1809 +				break;
 29.1810 +			case EH_Covers: 
 29.1811 +				intersectionPattern = new char[1][9];
 29.1812 +				intersectionPattern[0][0] = 'T';
 29.1813 +				intersectionPattern[0][1] = '*';
 29.1814 +				intersectionPattern[0][2] = 'T';
 29.1815 +				intersectionPattern[0][3] = 'F';
 29.1816 +				intersectionPattern[0][4] = 'T';
 29.1817 +				intersectionPattern[0][5] = '*';
 29.1818 +				intersectionPattern[0][6] = 'F';
 29.1819 +				intersectionPattern[0][7] = 'F';
 29.1820 +				intersectionPattern[0][8] = '*';
 29.1821 +				break;
 29.1822 +			case EH_CoveredBy: 
 29.1823 +				intersectionPattern = new char[1][9];
 29.1824 +				intersectionPattern[0][0] = 'T';
 29.1825 +				intersectionPattern[0][1] = 'F';
 29.1826 +				intersectionPattern[0][2] = 'F';
 29.1827 +				intersectionPattern[0][3] = '*';
 29.1828 +				intersectionPattern[0][4] = 'T';
 29.1829 +				intersectionPattern[0][5] = 'F';
 29.1830 +				intersectionPattern[0][6] = 'T';
 29.1831 +				intersectionPattern[0][7] = '*';
 29.1832 +				intersectionPattern[0][8] = '*';
 29.1833 +				break;
 29.1834 +			case EH_Inside: 
 29.1835 +				intersectionPattern = new char[1][9];
 29.1836 +				intersectionPattern[0][0] = 'T';
 29.1837 +				intersectionPattern[0][1] = 'F';
 29.1838 +				intersectionPattern[0][2] = 'F';
 29.1839 +				intersectionPattern[0][3] = '*';
 29.1840 +				intersectionPattern[0][4] = 'F';
 29.1841 +				intersectionPattern[0][5] = 'F';
 29.1842 +				intersectionPattern[0][6] = 'T';
 29.1843 +				intersectionPattern[0][7] = '*';
 29.1844 +				intersectionPattern[0][8] = '*';
 29.1845 +				break;
 29.1846 +			case EH_Contains: 
 29.1847 +				intersectionPattern = new char[1][9];
 29.1848 +				intersectionPattern[0][0] = 'T';
 29.1849 +				intersectionPattern[0][1] = '*';
 29.1850 +				intersectionPattern[0][2] = 'T';
 29.1851 +				intersectionPattern[0][3] = 'F';
 29.1852 +				intersectionPattern[0][4] = 'F';
 29.1853 +				intersectionPattern[0][5] = '*';
 29.1854 +				intersectionPattern[0][6] = 'F';
 29.1855 +				intersectionPattern[0][7] = 'F';
 29.1856 +				intersectionPattern[0][8] = '*';
 29.1857 +				break;
 29.1858 +			case RCC8_Dc:	
 29.1859 +				intersectionPattern = new char[1][9];
 29.1860 +				intersectionPattern[0][0] = 'F';
 29.1861 +				intersectionPattern[0][1] = 'F';
 29.1862 +				intersectionPattern[0][2] = 'T';
 29.1863 +				intersectionPattern[0][3] = 'F';
 29.1864 +				intersectionPattern[0][4] = 'F';
 29.1865 +				intersectionPattern[0][5] = 'T';
 29.1866 +				intersectionPattern[0][6] = 'T';
 29.1867 +				intersectionPattern[0][7] = 'T';
 29.1868 +				intersectionPattern[0][8] = 'T';
 29.1869 +				break;
 29.1870 +			case RCC8_Ec:	
 29.1871 +				intersectionPattern = new char[1][9];
 29.1872 +				intersectionPattern[0][0] = 'F';
 29.1873 +				intersectionPattern[0][1] = 'F';
 29.1874 +				intersectionPattern[0][2] = 'T';
 29.1875 +				intersectionPattern[0][3] = 'F';
 29.1876 +				intersectionPattern[0][4] = 'T';
 29.1877 +				intersectionPattern[0][5] = 'T';
 29.1878 +				intersectionPattern[0][6] = 'T';
 29.1879 +				intersectionPattern[0][7] = 'T';
 29.1880 +				intersectionPattern[0][8] = 'T';
 29.1881 +				break;
 29.1882 +			case RCC8_Po:	
 29.1883 +				intersectionPattern = new char[1][9];
 29.1884 +				intersectionPattern[0][0] = 'T';
 29.1885 +				intersectionPattern[0][1] = 'T';
 29.1886 +				intersectionPattern[0][2] = 'T';
 29.1887 +				intersectionPattern[0][3] = 'T';
 29.1888 +				intersectionPattern[0][4] = 'T';
 29.1889 +				intersectionPattern[0][5] = 'T';
 29.1890 +				intersectionPattern[0][6] = 'T';
 29.1891 +				intersectionPattern[0][7] = 'T';
 29.1892 +				intersectionPattern[0][8] = 'T';
 29.1893 +				break;
 29.1894 +			case RCC8_Tppi:	
 29.1895 +				intersectionPattern = new char[1][9];
 29.1896 +				intersectionPattern[0][0] = 'T';
 29.1897 +				intersectionPattern[0][1] = 'T';
 29.1898 +				intersectionPattern[0][2] = 'T';
 29.1899 +				intersectionPattern[0][3] = 'F';
 29.1900 +				intersectionPattern[0][4] = 'T';
 29.1901 +				intersectionPattern[0][5] = 'T';
 29.1902 +				intersectionPattern[0][6] = 'F';
 29.1903 +				intersectionPattern[0][7] = 'F';
 29.1904 +				intersectionPattern[0][8] = 'T';
 29.1905 +				break;
 29.1906 +			case RCC8_Tpp:	
 29.1907 +				intersectionPattern = new char[1][9];
 29.1908 +				intersectionPattern[0][0] = 'T';
 29.1909 +				intersectionPattern[0][1] = 'F';
 29.1910 +				intersectionPattern[0][2] = 'F';
 29.1911 +				intersectionPattern[0][3] = 'T';
 29.1912 +				intersectionPattern[0][4] = 'T';
 29.1913 +				intersectionPattern[0][5] = 'F';
 29.1914 +				intersectionPattern[0][6] = 'T';
 29.1915 +				intersectionPattern[0][7] = 'T';
 29.1916 +				intersectionPattern[0][8] = 'T';
 29.1917 +				break;
 29.1918 +			case RCC8_Ntpp:	
 29.1919 +				intersectionPattern = new char[1][9];
 29.1920 +				intersectionPattern[0][0] = 'T';
 29.1921 +				intersectionPattern[0][1] = 'F';
 29.1922 +				intersectionPattern[0][2] = 'F';
 29.1923 +				intersectionPattern[0][3] = 'T';
 29.1924 +				intersectionPattern[0][4] = 'F';
 29.1925 +				intersectionPattern[0][5] = 'F';
 29.1926 +				intersectionPattern[0][6] = 'T';
 29.1927 +				intersectionPattern[0][7] = 'T';
 29.1928 +				intersectionPattern[0][8] = 'T';
 29.1929 +				break;
 29.1930 +			case RCC8_Ntppi:	
 29.1931 +				intersectionPattern = new char[1][9];
 29.1932 +				intersectionPattern[0][0] = 'T';
 29.1933 +				intersectionPattern[0][1] = 'T';
 29.1934 +				intersectionPattern[0][2] = 'T';
 29.1935 +				intersectionPattern[0][3] = 'F';
 29.1936 +				intersectionPattern[0][4] = 'F';
 29.1937 +				intersectionPattern[0][5] = 'T';
 29.1938 +				intersectionPattern[0][6] = 'F';
 29.1939 +				intersectionPattern[0][7] = 'F';
 29.1940 +				intersectionPattern[0][8] = 'T';
 29.1941 +				break;
 29.1942 +			case SF_Intersects:   
 29.1943 +				intersectionPattern = new char[4][9];
 29.1944 +				intersectionPattern[0][0] = 'T';
 29.1945 +				intersectionPattern[0][1] = '*';
 29.1946 +				intersectionPattern[0][2] = '*';
 29.1947 +				intersectionPattern[0][3] = '*';
 29.1948 +				intersectionPattern[0][4] = '*';
 29.1949 +				intersectionPattern[0][5] = '*';
 29.1950 +				intersectionPattern[0][6] = '*';
 29.1951 +				intersectionPattern[0][7] = '*';
 29.1952 +				intersectionPattern[0][8] = '*';
 29.1953 +				//
 29.1954 +				intersectionPattern[1][0] = '*';
 29.1955 +				intersectionPattern[1][1] = 'T';
 29.1956 +				intersectionPattern[1][2] = '*';
 29.1957 +				intersectionPattern[1][3] = '*';
 29.1958 +				intersectionPattern[1][4] = '*';
 29.1959 +				intersectionPattern[1][5] = '*';
 29.1960 +				intersectionPattern[1][6] = '*';
 29.1961 +				intersectionPattern[1][7] = '*';
 29.1962 +				intersectionPattern[1][8] = '*';
 29.1963 +				//
 29.1964 +				intersectionPattern[2][0] = '*';
 29.1965 +				intersectionPattern[2][1] = '*';
 29.1966 +				intersectionPattern[2][2] = '*';
 29.1967 +				intersectionPattern[2][3] = 'T';
 29.1968 +				intersectionPattern[2][4] = '*';
 29.1969 +				intersectionPattern[2][5] = '*';
 29.1970 +				intersectionPattern[2][6] = '*';
 29.1971 +				intersectionPattern[2][7] = '*';
 29.1972 +				intersectionPattern[2][8] = '*';
 29.1973 +				//
 29.1974 +				intersectionPattern[3][0] = '*';
 29.1975 +				intersectionPattern[3][1] = '*';
 29.1976 +				intersectionPattern[3][2] = '*';
 29.1977 +				intersectionPattern[3][3] = '*';
 29.1978 +				intersectionPattern[3][4] = 'T';
 29.1979 +				intersectionPattern[3][5] = '*';
 29.1980 +				intersectionPattern[3][6] = '*';
 29.1981 +				intersectionPattern[3][7] = '*';
 29.1982 +				intersectionPattern[3][8] = '*';
 29.1983 +				break;
 29.1984 +
 29.1985 +			case SF_Touches: 
 29.1986 +			case EH_Meet:
 29.1987 +				intersectionPattern = new char[3][9];
 29.1988 +				intersectionPattern[0][0] = 'F';
 29.1989 +				intersectionPattern[0][1] = 'T';
 29.1990 +				intersectionPattern[0][2] = '*';
 29.1991 +				intersectionPattern[0][3] = '*';
 29.1992 +				intersectionPattern[0][4] = '*';
 29.1993 +				intersectionPattern[0][5] = '*';
 29.1994 +				intersectionPattern[0][6] = '*';
 29.1995 +				intersectionPattern[0][7] = '*';
 29.1996 +				intersectionPattern[0][8] = '*';
 29.1997 +				//
 29.1998 +				intersectionPattern[1][0] = 'F';
 29.1999 +				intersectionPattern[1][1] = '*';
 29.2000 +				intersectionPattern[1][2] = '*';
 29.2001 +				intersectionPattern[1][3] = 'T';
 29.2002 +				intersectionPattern[1][4] = '*';
 29.2003 +				intersectionPattern[1][5] = '*';
 29.2004 +				intersectionPattern[1][6] = '*';
 29.2005 +				intersectionPattern[1][7] = '*';
 29.2006 +				intersectionPattern[1][8] = '*';
 29.2007 +				//
 29.2008 +				intersectionPattern[2][0] = 'F';
 29.2009 +				intersectionPattern[2][1] = '*';
 29.2010 +				intersectionPattern[2][2] = '*';
 29.2011 +				intersectionPattern[2][3] = '*';
 29.2012 +				intersectionPattern[2][4] = 'T';
 29.2013 +				intersectionPattern[2][5] = '*';
 29.2014 +				intersectionPattern[2][6] = '*';
 29.2015 +				intersectionPattern[2][7] = '*';
 29.2016 +				intersectionPattern[2][8] = '*';
 29.2017 +				//
 29.2018 +
 29.2019 +			}
 29.2020 +
 29.2021 +			for(int i = 0; i < intersectionPattern.length ; i++)
 29.2022 +			{
 29.2023 +				appendRelate(expr, filter, intersectionPattern[i]);
 29.2024 +				if(i < intersectionPattern.length - 1)
 29.2025 +				{
 29.2026 +					//append OR and continue
 29.2027 +					filter.or();
 29.2028 +				}
 29.2029 +			}
 29.2030 +
 29.2031 +			//Also need bounding box intersection query to enable the usage of the Gist R-tree index
 29.2032 +			if(func != SpatialFunctionsPostGIS.SF_Disjoint && func != SpatialFunctionsPostGIS.EH_Disjoint && func != SpatialFunctionsPostGIS.RCC8_Dc)
 29.2033 +			{
 29.2034 +				filter.and();
 29.2035 +				appendGeneralDBSpatialFunctionBinary(expr, filter,SpatialFunctionsPostGIS.ST_Intersects);
 29.2036 +			}
 29.2037 +		}
 29.2038 +		filter.closeBracket();
 29.2039 +			}
 29.2040 +
 29.2041 +	@Override
 29.2042 +	//GeoSPARQL
 29.2043 +	//XXX
 29.2044 +
 29.2045 +	protected void appendRelate(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, char[] intersectionPattern)
 29.2046 +			throws UnsupportedRdbmsOperatorException
 29.2047 +			{
 29.2048 +		filter.openBracket();
 29.2049 +		System.out.println(expr.getLeftArg().getClass().getCanonicalName());
 29.2050 +		boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.2051 +		if(check1)
 29.2052 +		{
 29.2053 +			this.append((GeneralDBSqlNull)expr.getLeftArg(), filter);
 29.2054 +
 29.2055 +		}
 29.2056 +		else
 29.2057 +		{	
 29.2058 +			filter.appendFunction("ST_Relate");
 29.2059 +
 29.2060 +
 29.2061 +			filter.openBracket();
 29.2062 +			if(expr.getLeftArg() instanceof GeneralDBStringValue)
 29.2063 +			{
 29.2064 +				appendWKT(expr.getLeftArg(),filter);
 29.2065 +			}
 29.2066 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.2067 +			{
 29.2068 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.2069 +			}
 29.2070 +			else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.2071 +			{
 29.2072 +				appendConstructFunction(expr.getLeftArg(), filter);
 29.2073 +			}
 29.2074 +			else if(expr.getLeftArg() instanceof GeneralDBSqlCase)
 29.2075 +			{
 29.2076 +				GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult();
 29.2077 +				appendMBB(onlyLabel,filter); 
 29.2078 +			}
 29.2079 +			else
 29.2080 +			{
 29.2081 +				appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter);
 29.2082 +			}
 29.2083 +			filter.appendComma();
 29.2084 +			boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull");
 29.2085 +			if(check2)
 29.2086 +			{
 29.2087 +				this.append((GeneralDBSqlNull)expr.getRightArg(), filter);
 29.2088 +			}
 29.2089 +			else
 29.2090 +			{
 29.2091 +				if(expr.getRightArg() instanceof GeneralDBStringValue)
 29.2092 +				{
 29.2093 +					appendWKT(expr.getRightArg(),filter);
 29.2094 +				}
 29.2095 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary)
 29.2096 +				{
 29.2097 +					appendConstructFunction(expr.getRightArg(), filter);
 29.2098 +				}
 29.2099 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary)
 29.2100 +				{
 29.2101 +					appendConstructFunction(expr.getRightArg(), filter);
 29.2102 +				}
 29.2103 +				else if(expr.getRightArg() instanceof GeneralDBSqlCase)
 29.2104 +				{
 29.2105 +					GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult();
 29.2106 +					appendMBB(onlyLabel,filter);					 
 29.2107 +				}
 29.2108 +				else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer!
 29.2109 +				{
 29.2110 +					append(((GeneralDBDoubleValue)expr.getRightArg()), filter);
 29.2111 +				}
 29.2112 +				else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer!
 29.2113 +				{
 29.2114 +					append(((GeneralDBNumericColumn)expr.getRightArg()), filter);
 29.2115 +				}
 29.2116 +				//case met in buffer when in select -> buffer(?spatial,?thematic)
 29.2117 +				else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial())
 29.2118 +				{
 29.2119 +					append(((GeneralDBLabelColumn)expr.getRightArg()),filter);
 29.2120 +					appendCastToDouble(filter);
 29.2121 +				}
 29.2122 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary)
 29.2123 +				{
 29.2124 +					appendMetricFunction(expr.getRightArg(), filter);
 29.2125 +				}
 29.2126 +				else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary)
 29.2127 +				{
 29.2128 +					appendMetricFunction(expr.getRightArg(), filter);
 29.2129 +				}
 29.2130 +				else
 29.2131 +				{
 29.2132 +					appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter);
 29.2133 +				}
 29.2134 +
 29.2135 +			}
 29.2136 +			//3rd arg
 29.2137 +			filter.appendComma();
 29.2138 +
 29.2139 +			//must turn the table of characters I have to a valid sql value!
 29.2140 +			filter.append("'");
 29.2141 +			for(int i = 0; i< intersectionPattern.length; i++)
 29.2142 +			{
 29.2143 +				filter.append(intersectionPattern[i]+"");
 29.2144 +			}
 29.2145 +			filter.append("'");
 29.2146 +
 29.2147 +			filter.closeBracket();
 29.2148 +		}
 29.2149 +
 29.2150 +		filter.closeBracket();
 29.2151 +			}
 29.2152 +
 29.2153 +}
    30.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Mon Dec 24 14:14:08 2012 +0100
    30.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Tue Jan 08 12:30:51 2013 +0200
    30.3 @@ -49,7 +49,7 @@
    30.4  
    30.5  		Strabon strabon = null;
    30.6  		try {
    30.7 -			strabon = new Strabon(db, user, passwd, port, host, false);
    30.8 +			strabon = new Strabon(db, user, passwd, port, host, true);
    30.9  			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
   30.10  			
   30.11  		} catch (Exception e) {
    31.1 --- a/runtime/src/main/resources/log4j.properties	Mon Dec 24 14:14:08 2012 +0100
    31.2 +++ b/runtime/src/main/resources/log4j.properties	Tue Jan 08 12:30:51 2013 +0200
    31.3 @@ -1,6 +1,6 @@
    31.4  # logger level values: OFF, ERROR, WARN, INFO, DEBUG, ALL
    31.5 -log4j.rootLogger=INFO, CA
    31.6 -#log4j.rootLogger=DEBUG, CA
    31.7 +#log4j.rootLogger=INFO, CA
    31.8 +log4j.rootLogger=DEBUG, CA
    31.9  #log4j.rootLogger=INFO, CA, FA
   31.10  
   31.11  # Console Appender
    32.1 --- a/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Mon Dec 24 14:14:08 2012 +0100
    32.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/postgis/TemplateTests.java	Tue Jan 08 12:30:51 2013 +0200
    32.3 @@ -66,8 +66,10 @@
    32.4  		Statement stmt = conn.createStatement();
    32.5  		ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " +
    32.6  						"table_schema='public' AND table_name <> 'spatial_ref_sys' " +
    32.7 -						"AND table_name <> 'geometry_columns' AND " +
    32.8 -						"table_name <> 'geography_columns' AND table_name <> 'locked'");
    32.9 +						"AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " +
   32.10 +						"AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " +
   32.11 +						"AND table_name <> 'locked'"
   32.12 +					);
   32.13  		while (results.next()) {
   32.14  			String table_name = results.getString("table_name");
   32.15  			Statement stmt2 = conn.createStatement();
    33.1 --- a/scripts/endpoint	Mon Dec 24 14:14:08 2012 +0100
    33.2 +++ b/scripts/endpoint	Tue Jan 08 12:30:51 2013 +0200
    33.3 @@ -380,6 +380,6 @@
    33.4  	echo "${CMD}: Printing command for execution"	
    33.5  	echo "	$EXEC"
    33.6  else
    33.7 -	eval ${EXEC}
    33.8 +	eval "${EXEC}"
    33.9  fi
   33.10