Strabon

changeset 0:3435769679f3

Strabon goes mercurial
author Kostis Kyzirakos <kkyzir@di.uoa.gr>
date Fri Jan 27 01:08:32 2012 +0200 (2012-01-27)
parents
children b6c4b3cfb296
files .hgignore evaluation/pom.xml evaluation/pom.xml.releaseBackup evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/Polyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/ProjectionsFilter.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialConstructFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialMetricFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialPropertyFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialRelationshipFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlNonTopologicalConstruct.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlNonTopologicalMetric.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlRelateFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlRelation.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferContainsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferCoveredByFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferCoversFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferDisjointFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferEqualsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferInsideFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferMeetFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferOverlapFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlBoundaryFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlBufferFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlConvexHullFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlDifferenceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlDistanceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlEnvelopeFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlIntersectionFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlSymmetricDifferenceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlUnionFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8DisconnectedFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8EqualsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8ExternallyConnectedFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8NonTangentialProperPartFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8NonTangentialProperPartInverseFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8PartiallyOverlappingFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8TangentialProperPartFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8TangentialProperPartInverseFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeatureTouchesFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesContainsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesCrossesFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesDisjointFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesEqualsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesIntersectsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesOverlapsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesWithinFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/aggregate/ExtentFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/BoundaryFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/BufferFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/ConvexHullFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/DifferenceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/EnvelopeFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/IntersectionFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/SymDifferenceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/UnionFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/metric/AreaFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/metric/DistanceFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/AsTextFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/DimensionFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/GeometryTypeFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/IsEmptyFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/IsSimpleFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/SridFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/AboveFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/AnyInteractFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/BelowFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/ContainsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/CoveredByFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/CoversFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/DisjointFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/EqualsFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/InsideFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/LeftFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/OverlapFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/RelateFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/RightFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/TouchFunc.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/FunctionCallsOptimizer.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/SpatialJoinOptimizer.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/stSPARQLConstantOptimizer.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/StSPARQLOrderComparator.java evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function generaldb/pom.xml generaldb/pom.xml.releaseBackup generaldb/src/main/java/org/openrdf/generaldb/managers/base/ManagerBase.java generaldb/src/main/java/org/openrdf/generaldb/managers/base/ValueManagerBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnectionFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBProvider.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSpatialFuncInfo.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlTableFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlValueTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlValueTableFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBStore.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBTripleRepository.java generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBBNodeColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBColumnVar.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDatatypeColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDateTimeColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDoubleValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBFalseValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBHashColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBIdColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBJoinItem.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBLabelColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBLanguageColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBLongLabelColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBLongURIColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBNumberValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBNumericColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBRefIdColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectProjection.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSelectQuery.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlAbove.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlAbs.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlAnd.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlAnyInteract.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlBelow.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlCase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlCast.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlCompare.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlConcat.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlContains.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlCoveredBy.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlCovers.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlDisjoint.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlEq.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlEqualsSpatial.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoArea.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoAsText.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoBoundary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoBuffer.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoConvexHull.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDifference.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDimension.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoDistance.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoEnvelope.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoGeometryType.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoIntersection.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoIsEmpty.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoIsSimple.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoSpatial.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoSrid.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoSymDifference.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlGeoUnion.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlInside.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlIsNull.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlLeft.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlLike.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlLowerCase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlMathExpr.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlNot.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlNull.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlOr.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlOverlap.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlRegex.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlRelate.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlRight.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlShift.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialConstructBinary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialConstructUnary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialMetricBinary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialMetricUnary.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlSpatialProperty.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBSqlTouch.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBStringValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBTrueValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBURIColumn.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBUnionItem.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/BinaryGeneralDBOperator.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBBooleanValue.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBExprSupport.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBFromItem.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelNodeBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBQueryModelVisitorBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBSqlConstant.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBSqlExpr.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/GeneralDBValueColumnBase.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/TripleGeneralDBOperator.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/base/UnaryGeneralDBOperator.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Contains.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_CoveredBy.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Covers.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Disjoint.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Equals.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Inside.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Meet.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/egenhofer/GeneralDBSqlEgenhofer_Overlap.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBNodeExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBBooleanExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBDatatypeExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBHashExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBLabelExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBLanguageExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBNumericExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBSqlExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBTimeExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBURIExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/factories/GeneralDBZonedExprFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Dc.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Ec.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Eq.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Ntpp.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Ntppi.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Po.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Tpp.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/rcc8/GeneralDBSqlRCC8_Tppi.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Contains.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Crosses.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Disjoint.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Equals.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Intersects.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Overlaps.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Touches.java generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/sf/GeneralDBSqlSF_Within.java generaldb/src/main/java/org/openrdf/sail/generaldb/config/GeneralDBStoreConfig.java generaldb/src/main/java/org/openrdf/sail/generaldb/config/GeneralDBStoreFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/config/GeneralDBStoreSchema.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluationFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBQueryBuilderFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlBracketBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlCaseBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlCastBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlExprBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlExprBuilderInterface.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlJoinBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlQueryBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBSqlRegexBuilder.java generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBTripleSource.java generaldb/src/main/java/org/openrdf/sail/generaldb/exceptions/conversionException.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/EmptyGeneralDBResourceIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/EmptyGeneralDBStatementIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBBindingIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBResourceIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/GeneralDBStatementIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/iteration/NamespaceIteration.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/BNodeManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/HashManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/PredicateManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TransTableManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleTableManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/UriManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/managers/helpers/BatchBlockingQueue.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBQueryOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBRegexFlagsInliner.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSelectQueryOptimizerFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSpatialJoinOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBSqlConstantOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBValueIdLookupOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBValueJoinOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/optimizers/GeneralDBVarColumnLookupOptimizer.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/BNodeTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/Batch.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/GeoValueTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/HashBatch.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/HashTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/IdSequence.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/IntegerIdSequence.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LongIdSequence.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/TransactionTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/TripleBatch.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/TripleTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/URITable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/ValueBatch.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/ValueTable.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/ValueTableFactory.java generaldb/src/main/java/org/openrdf/sail/generaldb/util/StSPARQLValueComparator.java generaldb/src/main/resources/META_INF/services/org.openrdf.sail.generaldb.GeneralDBProvider generaldb/src/test/java/org/openrdf/sesame/sail/generaldb/AppTest.java jars/pom.xml jars/pom.xml.releaseBackup monetdb/pom.xml monetdb/pom.xml.releaseBackup monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBConnectionFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBProvider.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBSqlStore.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBSqlTable.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBSqlTableFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBSqlValueTableFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBStore.java monetdb/src/main/java/org/openrdf/sail/monetdb/MonetDBTripleRepository.java monetdb/src/main/java/org/openrdf/sail/monetdb/config/MonetDBStoreFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBEvaluation.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBEvaluationFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBQueryBuilderFactory.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBSqlBracketBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBSqlCastBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBSqlExprBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/evaluation/MonetDBSqlRegexBuilder.java monetdb/src/main/java/org/openrdf/sail/monetdb/iteration/MonetDBBindingIteration.java monetdb/src/main/java/org/openrdf/sail/monetdb/util/MonetDBLockManager.java monetdb/src/main/resources/META_INF/services/org.openrdf.sail.monetdb.MonetDBProvider pom.xml postgis/pom.xml postgis/pom.xml.releaseBackup postgis/src/main/java/org/openrdf/sail/postgis/PostGISConnectionFactory.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISProvider.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlStore.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlTable.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlTableFactory.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlValueTableFactory.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISStore.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISTripleRepository.java postgis/src/main/java/org/openrdf/sail/postgis/config/PostGISStoreFactory.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISEvaluation.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISEvaluationFactory.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISQueryBuilderFactory.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISSqlBracketBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISSqlCastBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISSqlExprBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/evaluation/PostGISSqlRegexBuilder.java postgis/src/main/java/org/openrdf/sail/postgis/iteration/PostGISBindingIteration.java postgis/src/main/resources/META_INF/services/org.openrdf.sail.postgis.PostGISProvider postgis/src/test/java/org/openrdf/sesame/sail/postgis/AppTest.java resultio/pom.xml resultio/pom.xml.releaseBackup resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java runtime/LICENSE.txt runtime/README.txt runtime/pom.xml runtime/pom.xml.releaseBackup runtime/src/main/java/eu/earthobservatory/Runtime.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/Strabon.java runtime/src/main/resources/META-INF/org.openrdf.repository.templates runtime/src/main/resources/META-INF/templates/memory-rdfs-dt.ttl runtime/src/main/resources/META-INF/templates/memory-rdfs.ttl runtime/src/main/resources/META-INF/templates/memory.ttl runtime/src/main/resources/META-INF/templates/mysql.ttl runtime/src/main/resources/META-INF/templates/native-rdfs-dt.ttl runtime/src/main/resources/META-INF/templates/native-rdfs.ttl runtime/src/main/resources/META-INF/templates/native.ttl runtime/src/main/resources/META-INF/templates/pgsql.ttl
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Fri Jan 27 01:08:32 2012 +0200
     1.3 @@ -0,0 +1,1 @@
     1.4 +/target$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/evaluation/pom.xml	Fri Jan 27 01:08:32 2012 +0200
     2.3 @@ -0,0 +1,72 @@
     2.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     2.5 +
     2.6 +	<modelVersion>4.0.0</modelVersion>
     2.7 +
     2.8 +	<parent>
     2.9 +		<groupId>eu.earthobservatory</groupId>
    2.10 +		<artifactId>strabon</artifactId>
    2.11 +		<version>3.1.1-SNAPSHOT</version>
    2.12 +	</parent>
    2.13 +
    2.14 +	<groupId>org.openrdf.sesame</groupId>
    2.15 +	<artifactId>sesame-queryalgebra-evaluation-spatial</artifactId>
    2.16 +	<name>OpenRDF Sesame: Query algebra - evaluation -spatial</name>
    2.17 +	<description>Spatial Extension Functions - stSPARQL </description>
    2.18 +	<packaging>jar</packaging>
    2.19 +	<version>3.1.1-SNAPSHOT</version>
    2.20 +
    2.21 +	<properties>
    2.22 +		<sesame.version>2.6.3</sesame.version>
    2.23 +	</properties>
    2.24 +
    2.25 +	<dependencies>
    2.26 +		<dependency>
    2.27 +			<groupId>org.openrdf.sesame</groupId>
    2.28 +			<artifactId>sesame-queryalgebra-evaluation</artifactId>
    2.29 +			<version>${sesame.version}</version>
    2.30 +		</dependency>
    2.31 +		<dependency>
    2.32 +			<groupId>org.openrdf.sesame</groupId>
    2.33 +			<artifactId>sesame-queryalgebra-model</artifactId>
    2.34 +			<version>${sesame.version}</version>
    2.35 +		</dependency>
    2.36 +		<dependency>
    2.37 +			<groupId>org.openrdf.sesame</groupId>
    2.38 +			<artifactId>sesame-model</artifactId>
    2.39 +			<version>${sesame.version}</version>
    2.40 +		</dependency>
    2.41 +		<!--
    2.42 +		<dependency>
    2.43 +			<groupId>info.aduna.commons</groupId>
    2.44 +			<artifactId>aduna-commons-lang</artifactId>
    2.45 +			<version>2.10.0-SNAPSHOT</version>
    2.46 +		</dependency>
    2.47 +		-->
    2.48 +		<dependency>
    2.49 +			<groupId>org.slf4j</groupId>
    2.50 +			<artifactId>slf4j-api</artifactId>
    2.51 +		</dependency>
    2.52 +		<dependency>
    2.53 +			<groupId>org.slf4j</groupId>
    2.54 +			<artifactId>slf4j-simple</artifactId>
    2.55 +		</dependency>
    2.56 +
    2.57 +		<dependency>
    2.58 +			<groupId>junit</groupId>
    2.59 +			<artifactId>junit</artifactId>
    2.60 +		</dependency>
    2.61 +		<dependency>
    2.62 +			<groupId>org.opengis</groupId>
    2.63 +			<artifactId>geoapi</artifactId>
    2.64 +		</dependency>
    2.65 +		<dependency>
    2.66 +			<groupId>org.geotools</groupId>
    2.67 +			<artifactId>gt-referencing</artifactId>
    2.68 +		</dependency>
    2.69 +		<dependency>
    2.70 +			<groupId>org.geotools</groupId>
    2.71 +			<artifactId>gt-jts-wrapper</artifactId>
    2.72 +		</dependency>
    2.73 +	</dependencies>
    2.74 +</project>
    2.75 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/evaluation/pom.xml.releaseBackup	Fri Jan 27 01:08:32 2012 +0200
     3.3 @@ -0,0 +1,72 @@
     3.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     3.5 +
     3.6 +	<modelVersion>4.0.0</modelVersion>
     3.7 +
     3.8 +	<parent>
     3.9 +		<groupId>eu.earthobservatory</groupId>
    3.10 +		<artifactId>strabon</artifactId>
    3.11 +		<version>3.1.0-SNAPSHOT</version>
    3.12 +	</parent>
    3.13 +
    3.14 +	<groupId>org.openrdf.sesame</groupId>
    3.15 +	<artifactId>sesame-queryalgebra-evaluation-spatial</artifactId>
    3.16 +	<name>OpenRDF Sesame: Query algebra - evaluation -spatial</name>
    3.17 +	<description>Spatial Extension Functions - stSPARQL </description>
    3.18 +	<packaging>jar</packaging>
    3.19 +	<version>3.1.0-SNAPSHOT</version>
    3.20 +
    3.21 +	<properties>
    3.22 +		<sesame.version>2.6.3</sesame.version>
    3.23 +	</properties>
    3.24 +
    3.25 +	<dependencies>
    3.26 +		<dependency>
    3.27 +			<groupId>org.openrdf.sesame</groupId>
    3.28 +			<artifactId>sesame-queryalgebra-evaluation</artifactId>
    3.29 +			<version>${sesame.version}</version>
    3.30 +		</dependency>
    3.31 +		<dependency>
    3.32 +			<groupId>org.openrdf.sesame</groupId>
    3.33 +			<artifactId>sesame-queryalgebra-model</artifactId>
    3.34 +			<version>${sesame.version}</version>
    3.35 +		</dependency>
    3.36 +		<dependency>
    3.37 +			<groupId>org.openrdf.sesame</groupId>
    3.38 +			<artifactId>sesame-model</artifactId>
    3.39 +			<version>${sesame.version}</version>
    3.40 +		</dependency>
    3.41 +		<!--
    3.42 +		<dependency>
    3.43 +			<groupId>info.aduna.commons</groupId>
    3.44 +			<artifactId>aduna-commons-lang</artifactId>
    3.45 +			<version>2.10.0-SNAPSHOT</version>
    3.46 +		</dependency>
    3.47 +		-->
    3.48 +		<dependency>
    3.49 +			<groupId>org.slf4j</groupId>
    3.50 +			<artifactId>slf4j-api</artifactId>
    3.51 +		</dependency>
    3.52 +		<dependency>
    3.53 +			<groupId>org.slf4j</groupId>
    3.54 +			<artifactId>slf4j-simple</artifactId>
    3.55 +		</dependency>
    3.56 +
    3.57 +		<dependency>
    3.58 +			<groupId>junit</groupId>
    3.59 +			<artifactId>junit</artifactId>
    3.60 +		</dependency>
    3.61 +		<dependency>
    3.62 +			<groupId>org.opengis</groupId>
    3.63 +			<artifactId>geoapi</artifactId>
    3.64 +		</dependency>
    3.65 +		<dependency>
    3.66 +			<groupId>org.geotools</groupId>
    3.67 +			<artifactId>gt-referencing</artifactId>
    3.68 +		</dependency>
    3.69 +		<dependency>
    3.70 +			<groupId>org.geotools</groupId>
    3.71 +			<artifactId>gt-jts-wrapper</artifactId>
    3.72 +		</dependency>
    3.73 +	</dependencies>
    3.74 +</project>
    3.75 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/Polyhedron.java	Fri Jan 27 01:08:32 2012 +0200
     4.3 @@ -0,0 +1,26 @@
     4.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     4.5 +
     4.6 +import java.io.ByteArrayInputStream;
     4.7 +import java.io.ByteArrayOutputStream;
     4.8 +import java.io.IOException;
     4.9 +import java.io.ObjectInputStream;
    4.10 +import java.io.ObjectOutputStream;
    4.11 +import java.io.Serializable;
    4.12 +import java.util.ArrayList;
    4.13 +import java.util.HashMap;
    4.14 +
    4.15 +
    4.16 +/**
    4.17 + * @author kkyzir
    4.18 + *
    4.19 + */
    4.20 +public class Polyhedron implements Serializable {
    4.21 +	public static final int OPTIMAL_CONVEX_PARTITION = 0; //Optimal number of pieces, O(n^4) time and O(n^3) space
    4.22 +	public static final int APPROXIMATE_CONVEX_PARTITION = 1; //Approximate optimal number of pieces, uses approximation algorithm of Hertel and Mehlhorn (triangulation), O(n) time and space.
    4.23 +	public static final int GREEN_CONVEX_PARTITION = 2; //Approximate optimal number of pieces, uses sweep-line approximation algorithm of Greene, O(n log(n)) time and O(n) space.
    4.24 +	public static final int Y_MONOTONE_PARTITION = 3; //Same complexity as Hertel and Mehlhorn, but can sometimes produce better results (i.e., convex partitions with fewer pieces).
    4.25 +
    4.26 +	public static final String stRDFSemiLinearPointset="http://strdf.di.uoa.gr/ontology#SemiLinearPointSet";
    4.27 +	public static final String ogcGeometry="http://strdf.di.uoa.gr/ontology#WKT";
    4.28 +
    4.29 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/ProjectionsFilter.java	Fri Jan 27 01:08:32 2012 +0200
     5.3 @@ -0,0 +1,48 @@
     5.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     5.5 +
     5.6 +import com.vividsolutions.jts.geom.Coordinate;
     5.7 +import com.vividsolutions.jts.geom.CoordinateFilter;
     5.8 +
     5.9 +public class ProjectionsFilter implements CoordinateFilter {
    5.10 +
    5.11 +	int[] dims = new int[3];
    5.12 +	
    5.13 +	
    5.14 +	
    5.15 +	public ProjectionsFilter(int[] dims) {
    5.16 +		super();
    5.17 +		this.dims = dims;
    5.18 +	}
    5.19 +
    5.20 +
    5.21 +
    5.22 +	public int[] getDims() {
    5.23 +		return dims;
    5.24 +	}
    5.25 +
    5.26 +
    5.27 +
    5.28 +	public void setDims(int[] dims) {
    5.29 +		this.dims = dims;
    5.30 +	}
    5.31 +
    5.32 +	public void filter(Coordinate coord) {
    5.33 +		
    5.34 +		if(dims[0]==0)
    5.35 +		{
    5.36 +			coord.x=0;
    5.37 +		}
    5.38 +		
    5.39 +		if(dims[1]==0)
    5.40 +		{
    5.41 +			coord.y=0;
    5.42 +		}
    5.43 +		
    5.44 +		if(dims[2]==0)
    5.45 +		{
    5.46 +			coord.z=0;
    5.47 +		}
    5.48 +
    5.49 +	}
    5.50 +
    5.51 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialConstructFunc.java	Fri Jan 27 01:08:32 2012 +0200
     6.3 @@ -0,0 +1,23 @@
     6.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     6.5 +
     6.6 +import org.openrdf.model.Value;
     6.7 +import org.openrdf.model.ValueFactory;
     6.8 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     6.9 +import org.openrdf.query.algebra.evaluation.function.Function;
    6.10 +
    6.11 +public class SpatialConstructFunc implements Function {
    6.12 +
    6.13 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    6.14 +	public Value evaluate(ValueFactory valueFactory, Value... args)
    6.15 +	throws ValueExprEvaluationException {
    6.16 +
    6.17 +		return null;
    6.18 +	}
    6.19 +
    6.20 +	//I'll have everyone override it
    6.21 +	public String getURI() {
    6.22 +
    6.23 +		return null;
    6.24 +	}
    6.25 +
    6.26 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialMetricFunc.java	Fri Jan 27 01:08:32 2012 +0200
     7.3 @@ -0,0 +1,24 @@
     7.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     7.5 +
     7.6 +import org.openrdf.model.Value;
     7.7 +import org.openrdf.model.ValueFactory;
     7.8 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     7.9 +import org.openrdf.query.algebra.evaluation.function.Function;
    7.10 +
    7.11 +public class SpatialMetricFunc implements Function {
    7.12 +
    7.13 +
    7.14 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    7.15 +	public Value evaluate(ValueFactory valueFactory, Value... args)
    7.16 +	throws ValueExprEvaluationException {
    7.17 +
    7.18 +		return null;
    7.19 +	}
    7.20 +
    7.21 +	//I'll have everyone override it
    7.22 +	public String getURI() {
    7.23 +
    7.24 +		return null;
    7.25 +	}
    7.26 +
    7.27 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialPropertyFunc.java	Fri Jan 27 01:08:32 2012 +0200
     8.3 @@ -0,0 +1,24 @@
     8.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     8.5 +
     8.6 +import org.openrdf.model.Value;
     8.7 +import org.openrdf.model.ValueFactory;
     8.8 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     8.9 +import org.openrdf.query.algebra.evaluation.function.Function;
    8.10 +
    8.11 +public class SpatialPropertyFunc implements Function {
    8.12 +
    8.13 +
    8.14 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    8.15 +	public Value evaluate(ValueFactory valueFactory, Value... args)
    8.16 +	throws ValueExprEvaluationException {
    8.17 +
    8.18 +		return null;
    8.19 +	}
    8.20 +
    8.21 +	//I'll have everyone override it
    8.22 +	public String getURI() {
    8.23 +
    8.24 +		return null;
    8.25 +	}
    8.26 +
    8.27 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/SpatialRelationshipFunc.java	Fri Jan 27 01:08:32 2012 +0200
     9.3 @@ -0,0 +1,24 @@
     9.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     9.5 +
     9.6 +import org.openrdf.model.Value;
     9.7 +import org.openrdf.model.ValueFactory;
     9.8 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     9.9 +import org.openrdf.query.algebra.evaluation.function.Function;
    9.10 +
    9.11 +public abstract class SpatialRelationshipFunc implements Function {
    9.12 +
    9.13 +
    9.14 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
    9.15 +	public Value evaluate(ValueFactory valueFactory, Value... args)
    9.16 +	throws ValueExprEvaluationException {
    9.17 +
    9.18 +		return null;
    9.19 +	}
    9.20 +
    9.21 +	//I'll have everyone override it
    9.22 +	public String getURI() {
    9.23 +
    9.24 +		return null;
    9.25 +	}
    9.26 +
    9.27 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Fri Jan 27 01:08:32 2012 +0200
    10.3 @@ -0,0 +1,935 @@
    10.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
    10.5 +import java.util.ArrayList;
    10.6 +
    10.7 +import com.vividsolutions.jts.geom.Coordinate;
    10.8 +import com.vividsolutions.jts.geom.CoordinateSequence;
    10.9 +import com.vividsolutions.jts.geom.Geometry;
   10.10 +import com.vividsolutions.jts.geom.GeometryCollection;
   10.11 +import com.vividsolutions.jts.geom.GeometryFactory;
   10.12 +import com.vividsolutions.jts.geom.LineString;
   10.13 +import com.vividsolutions.jts.geom.LinearRing;
   10.14 +import com.vividsolutions.jts.geom.MultiLineString;
   10.15 +import com.vividsolutions.jts.geom.MultiPoint;
   10.16 +import com.vividsolutions.jts.geom.MultiPolygon;
   10.17 +import com.vividsolutions.jts.geom.Point;
   10.18 +import com.vividsolutions.jts.geom.Polygon;
   10.19 +import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;
   10.20 +import com.vividsolutions.jts.io.ParseException;
   10.21 +import com.vividsolutions.jts.io.WKBReader;
   10.22 +import com.vividsolutions.jts.io.WKBWriter;
   10.23 +import com.vividsolutions.jts.io.WKTReader;
   10.24 +import com.vividsolutions.jts.io.WKTWriter;
   10.25 +
   10.26 +import org.geotools.geometry.jts.JTS;
   10.27 +import org.geotools.referencing.CRS;
   10.28 +import org.opengis.geometry.MismatchedDimensionException;
   10.29 +import org.opengis.referencing.FactoryException;
   10.30 +import org.opengis.referencing.crs.CoordinateReferenceSystem;
   10.31 +import org.opengis.referencing.operation.MathTransform;
   10.32 +import org.opengis.referencing.operation.TransformException;
   10.33 +import org.openrdf.model.Value; 
   10.34 +
   10.35 +public class StrabonPolyhedron implements Value {
   10.36 +
   10.37 +	public static String CACHEPATH = "";
   10.38 +	public static String TABLE_COUNTS = "counts.bin";
   10.39 +	public static String TABLE_SUBJ_OBJ_TYPES = "tableProperties.bin";
   10.40 +	public static String TABLE_SHIFTING = "groupbys.bin";
   10.41 +	
   10.42 +	
   10.43 +	public static final boolean EnableConstraintRepresentation = false;
   10.44 +
   10.45 +	public static final String stRDFSemiLinearPointset="http://strdf.di.uoa.gr/ontology#SemiLinearPointSet";
   10.46 +	public static final String ogcGeometry="http://strdf.di.uoa.gr/ontology#WKT";
   10.47 +	public static final String geof="http://www.opengis.net/def/queryLanguage/OGC-GeoSPARQL/1.0/function/";
   10.48 +	//Extended functions
   10.49 +	//Spatial Relationships
   10.50 +	public static final String anyInteract="http://strdf.di.uoa.gr/ontology#anyInteract";
   10.51 +	public static final String contains="http://strdf.di.uoa.gr/ontology#contains";
   10.52 +	public static final String coveredBy="http://strdf.di.uoa.gr/ontology#coveredBy";
   10.53 +	public static final String covers="http://strdf.di.uoa.gr/ontology#covers";
   10.54 +	public static final String disjoint="http://strdf.di.uoa.gr/ontology#disjoint";
   10.55 +	public static final String equals="http://strdf.di.uoa.gr/ontology#equals";
   10.56 +	public static final String inside="http://strdf.di.uoa.gr/ontology#inside";
   10.57 +	public static final String overlap="http://strdf.di.uoa.gr/ontology#overlap";
   10.58 +	public static final String touch="http://strdf.di.uoa.gr/ontology#touch";
   10.59 +	public static final String relate="http://strdf.di.uoa.gr/ontology#relate";
   10.60 +	public static final String left="http://strdf.di.uoa.gr/ontology#left";
   10.61 +	public static final String right="http://strdf.di.uoa.gr/ontology#right";
   10.62 +	public static final String above="http://strdf.di.uoa.gr/ontology#above";
   10.63 +	public static final String below="http://strdf.di.uoa.gr/ontology#below";
   10.64 +	//Spatial Constructs
   10.65 +	public static final String union="http://strdf.di.uoa.gr/ontology#union";
   10.66 +	public static final String buffer="http://strdf.di.uoa.gr/ontology#buffer";
   10.67 +	public static final String envelope="http://strdf.di.uoa.gr/ontology#envelope";
   10.68 +	public static final String convexHull="http://strdf.di.uoa.gr/ontology#convexHull";
   10.69 +	public static final String boundary="http://strdf.di.uoa.gr/ontology#boundary";
   10.70 +	public static final String intersection="http://strdf.di.uoa.gr/ontology#intersection";
   10.71 +	public static final String difference="http://strdf.di.uoa.gr/ontology#difference";
   10.72 +	public static final String symDifference="http://strdf.di.uoa.gr/ontology#symDifference";
   10.73 +	//Spatial Metric Functions
   10.74 +	public static final String distance="http://strdf.di.uoa.gr/ontology#distance";
   10.75 +	public static final String area="http://strdf.di.uoa.gr/ontology#area";
   10.76 +	//Spatial Properties
   10.77 +	public static final String dimension="http://strdf.di.uoa.gr/ontology#dimension";
   10.78 +	public static final String geometryType="http://strdf.di.uoa.gr/ontology#geometryType";
   10.79 +	public static final String asText="http://strdf.di.uoa.gr/ontology#asText";
   10.80 +	public static final String srid="http://strdf.di.uoa.gr/ontology#srid";
   10.81 +	public static final String isEmpty="http://strdf.di.uoa.gr/ontology#isEmpty";
   10.82 +	public static final String isSimple="http://strdf.di.uoa.gr/ontology#isSimple";
   10.83 +	//Spatial Aggregate Functions
   10.84 +	public static final String extent="http://strdf.di.uoa.gr/ontology#extent";
   10.85 +	////
   10.86 +	
   10.87 +	//GEOSPARQL
   10.88 +	
   10.89 +	//Non-topological
   10.90 +	public static final String geoSparqlDistance = geof+"distance"; //3 arguments
   10.91 +	public static final String geoSparqlBuffer = geof+"buffer"; //3 arguments
   10.92 +	public static final String geoSparqlConvexHull = geof+"convexHull";
   10.93 +	public static final String geoSparqlIntersection = geof+"intersection";
   10.94 +	public static final String geoSparqlUnion = geof+"union";
   10.95 +	public static final String geoSparqlDifference = geof+"difference";
   10.96 +	public static final String geoSparqlSymmetricDifference = geof+"symmetricDifference";
   10.97 +	public static final String geoSparqlEnvelope = geof+"envelope";
   10.98 +	public static final String geoSparqlBoundary = geof+"boundary";
   10.99 +	
  10.100 +	//Simple Features - 8 functions - all with 2 arguments + boolean
  10.101 +	public static final String sfEquals = geof+"sf-equals";  
  10.102 +	public static final String sfDisjoint = geof+"sf-disjoint";  
  10.103 +	public static final String sfIntersects = geof+"sf-intersects";
  10.104 +	public static final String sfTouches = geof+"sf-touches";
  10.105 +	public static final String sfCrosses = geof+"sf-crosses";
  10.106 +	public static final String sfWithin = geof+"sf-within";
  10.107 +	public static final String sfContains = geof+"sf-contains";
  10.108 +	public static final String sfOverlaps = geof+"sf-overlaps";
  10.109 +	
  10.110 +	//Egenhofer - 8 functions - all with 2 arguments + boolean
  10.111 +	public static final String ehEquals = geof+"eh-equals";  
  10.112 +	public static final String ehDisjoint = geof+"eh-disjoint";  
  10.113 +	public static final String ehMeet = geof+"eh-meet";
  10.114 +	public static final String ehOverlap = geof+"eh-overlap";
  10.115 +	public static final String ehCovers = geof+"eh-covers";
  10.116 +	public static final String ehCoveredBy = geof+"eh-coveredBy";
  10.117 +	public static final String ehInside = geof+"eh-inside";
  10.118 +	public static final String ehContains = geof+"eh-contains";
  10.119 +
  10.120 +	//RCC8 - 8 functions - all with 2 arguments + boolean
  10.121 +	public static final String rccEquals = geof+"rcc8-eq";  
  10.122 +	public static final String rccDisconnected = geof+"rcc8-dc";  
  10.123 +	public static final String rccExternallyConnected = geof+"rcc8-ec";
  10.124 +	public static final String rccPartiallyOverlapping = geof+"rcc8-po";
  10.125 +	public static final String rccTangentialProperPartInverse = geof+"rcc8-tppi";
  10.126 +	public static final String rccTangentialProperPart = geof+"rcc8-tpp";
  10.127 +	public static final String rccNonTangentialProperPart = geof+"rcc8-ntpp";
  10.128 +	public static final String rccNonTangentialProperPartInverse = geof+"rcc8-ntppi";
  10.129 +
  10.130 +	public static final String geoSparqlRelate = geof+"relate";
  10.131 +	
  10.132 +	private static int MAX_POINTS = Integer.MAX_VALUE;//40000;//Integer.MAX_VALUE;//10000;
  10.133 +
  10.134 +	private Geometry geometry;
  10.135 +
  10.136 +	public StrabonPolyhedron() {
  10.137 +		this.geometry = null;
  10.138 +	}
  10.139 +	
  10.140 +		
  10.141 +	public void setGeometry(Geometry geometry) {
  10.142 +		this.geometry = geometry;
  10.143 +	}
  10.144 +
  10.145 +
  10.146 +
  10.147 +	public static StrabonPolyhedron ConstructFromWKB(byte[] byteArray) throws Exception {
  10.148 +		return new StrabonPolyhedron(new WKBReader().read(byteArray));
  10.149 +	}
  10.150 +	
  10.151 +	public static Geometry convertSRID(Geometry A, int sourceSRID, int targetSRID)
  10.152 +	{
  10.153 +
  10.154 +		MathTransform transform;
  10.155 +		try {
  10.156 +			//EPSG supported currently - is there a way to be more general??
  10.157 +			CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:"+sourceSRID);
  10.158 +			CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:"+targetSRID);
  10.159 +			transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
  10.160 +			return JTS.transform(A, transform);
  10.161 +		} catch (FactoryException e) {
  10.162 +			// TODO Auto-generated catch block
  10.163 +			e.printStackTrace();
  10.164 +		} catch (MismatchedDimensionException e) {
  10.165 +			// TODO Auto-generated catch block
  10.166 +			e.printStackTrace();
  10.167 +		} catch (TransformException e) {
  10.168 +			System.out.println("Transformation is not possible!!");
  10.169 +			e.printStackTrace();
  10.170 +		}
  10.171 +		return A;
  10.172 +	}
  10.173 +
  10.174 +	//public StrabonPolyhedron(int partitionAlgorithmIgnored, String constraints) throws Exception {
  10.175 +	//	Polyhedron poly = new Polyhedron(constraints);
  10.176 +	//	this.geometry = new WKTReader().read(poly.toWKT());
  10.177 +	//}
  10.178 +	
  10.179 +	public StrabonPolyhedron(Geometry geo) throws Exception {
  10.180 +		this.geometry = new StrabonPolyhedron(geo, 1).geometry;
  10.181 +	}
  10.182 +
  10.183 +	public StrabonPolyhedron(Geometry geo, int algorithm) throws Exception {
  10.184 +		this.geometry = new StrabonPolyhedron(geo, algorithm, MAX_POINTS).geometry;
  10.185 +	}
  10.186 +	
  10.187 +	public StrabonPolyhedron(Geometry geo, int algorithm, int maxPoints) throws Exception {		
  10.188 +		if (geo.isEmpty()) {
  10.189 +			this.geometry = geo;
  10.190 +			return;
  10.191 +		}
  10.192 +		
  10.193 +		if (!EnableConstraintRepresentation) {
  10.194 +			this.geometry = geo;
  10.195 +			return;
  10.196 +		}
  10.197 +		
  10.198 +		//always returns true...
  10.199 +		//if (!geo.isSimple())
  10.200 +		//	throw new Exception("The polygon is not simple. Only simple polygons are supported.");
  10.201 +
  10.202 +		if (Point.class.isInstance(geo)) {
  10.203 +			this.geometry = geo;
  10.204 +		} else if (LineString.class.isInstance(geo)) {
  10.205 +			this.geometry = geo;
  10.206 +		} else if (Polygon.class.isInstance(geo)) {
  10.207 +			//if (!geo.isValid()) {
  10.208 +			//	System.out.println("Non valid " + FindGeoType(geo) + " found. ("+ geo.toString() +")");
  10.209 +			//	geo = geo.buffer(0.0);
  10.210 +			//	System.out.println("Converted to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid. ("+geo.toString()+")");
  10.211 +			//	this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
  10.212 +			//} else {
  10.213 +				this.geometry = new StrabonPolyhedron((Polygon) geo, algorithm, maxPoints).geometry;
  10.214 +			//}
  10.215 +		} else if (MultiPoint.class.isInstance(geo)) {
  10.216 +			this.geometry = geo;
  10.217 +		} else if (MultiLineString.class.isInstance(geo)) {
  10.218 +			//throw new Exception("MultiLineString not implemented yet.");
  10.219 +			MultiLineString mline = (MultiLineString)geo;
  10.220 +			ArrayList<LineString> collection = new ArrayList<LineString>(mline.getNumGeometries());
  10.221 +
  10.222 +			for (int i = 0; i < mline.getNumGeometries(); i++) {
  10.223 +				System.out.println("[1] " + mline.getNumGeometries());
  10.224 +				StrabonPolyhedron line = new StrabonPolyhedron(mline.getGeometryN(i), algorithm, maxPoints);
  10.225 +				System.out.println("[2] " + line.geometry.getNumGeometries());
  10.226 +				for (int j = 0; j < line.geometry.getNumGeometries(); j++) {
  10.227 +					collection.add((LineString)line.geometry.getGeometryN(j));
  10.228 +				}
  10.229 +			}
  10.230 +
  10.231 +			LineString[] linecollection = new LineString[collection.size()];
  10.232 +			int k = 0;
  10.233 +			for (LineString line : collection) {
  10.234 +				linecollection[k] = line;
  10.235 +				k++;
  10.236 +				assert (!line.isEmpty());
  10.237 +			}
  10.238 +			this.geometry = new MultiLineString(linecollection, new GeometryFactory());
  10.239 +		} else if (MultiPolygon.class.isInstance(geo)) {
  10.240 +//			if (!geo.isValid()) {
  10.241 +////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
  10.242 +////				geo = geo.buffer(0.0);
  10.243 +////				
  10.244 +////				Geometry[] geometries = new Geometry[geo.getNumGeometries()];
  10.245 +////				for (int i = 0; i < geo.getNumGeometries(); i++) {
  10.246 +////					boolean before = geo.getGeometryN(i).isValid();
  10.247 +////					geometries[i] = geo.getGeometryN(i).buffer(0.0);
  10.248 +////					boolean after = geometries[i].isValid();
  10.249 +////					//System.out.println("Geometry " + i + " was " + (before ? "" : "not ") + "valid and now it is " + (after ? "still " : "not ") + "valid.");
  10.250 +////				}			
  10.251 +////				
  10.252 +////				Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
  10.253 +////				System.out.println("Converted to a "+FindGeoType(col)+" that is "+(col.isValid() ? "" : "not ")+"valid.");
  10.254 +////				this.geometry = new StrabonPolyhedron(col, algorithm, maxPoints).geometry;
  10.255 +//				
  10.256 +////				System.out.println("Non valid " + FindGeoType(geo) + " found.");
  10.257 +////				
  10.258 +////				System.out.println("Number of geometries: " + geo.getNumGeometries());
  10.259 +////				MultiPolygon multipoly = (MultiPolygon)geo;
  10.260 +////				Geometry newPoly = multipoly.getGeometryN(0);
  10.261 +////				
  10.262 +////				for (int i = 1; i < geo.getNumGeometries(); i++) {
  10.263 +////					newPoly = newPoly.union(geo.getGeometryN(i));
  10.264 +////				}			
  10.265 +////				
  10.266 +////				newPoly.buffer(0.0);
  10.267 +////				
  10.268 +////				//Geometry col = new GeometryCollection(geometries, new GeometryFactory()).buffer(0.0);
  10.269 +////				System.out.println("Converted to a "+FindGeoType(newPoly)+" that is "+(newPoly.isValid() ? "" : "not ")+"valid.");
  10.270 +////				this.geometry = new StrabonPolyhedron(newPoly, algorithm, maxPoints).geometry;
  10.271 +//				
  10.272 +//				//System.out.println("Non valid " + FindGeoType(geo) + " found. (coordinates:"+geo.getCoordinates().length+")");
  10.273 +//				//geo = TopologyPreservingSimplifier.simplify(geo, 0.2);
  10.274 +//				while (true) {
  10.275 +//					if (geo.getCoordinates().length > 300000) {
  10.276 +//						geo = TopologyPreservingSimplifier.simplify(geo, 0.1);
  10.277 +//						System.out.println("Simplified to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
  10.278 +//					}
  10.279 +//					geo = geo.buffer(0.0);
  10.280 +//					System.out.println("Buffered to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid (coordinates:"+geo.getCoordinates().length+").");
  10.281 +//					
  10.282 +//					if (geo.isValid() && (geo.getCoordinates().length < 300000))
  10.283 +//						break;
  10.284 +//				}								
  10.285 +//				
  10.286 +//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
  10.287 +//				
  10.288 +//				//System.out.println("Are the geometries the same? Answer: " + (geo.equals(this.geometry) ? "true" : "false"));
  10.289 +//				
  10.290 +//			} else {
  10.291 +				MultiPolygon mpoly = (MultiPolygon)geo;
  10.292 +				ArrayList<Polygon> collection = new ArrayList<Polygon>(mpoly.getNumGeometries());
  10.293 +	
  10.294 +				for (int i = 0; i < mpoly.getNumGeometries(); i++) {
  10.295 +					System.out.println("[1] " + mpoly.getNumGeometries());
  10.296 +					StrabonPolyhedron poly = new StrabonPolyhedron(mpoly.getGeometryN(i), algorithm, maxPoints);
  10.297 +					System.out.println("[2] " + poly.geometry.getNumGeometries());
  10.298 +					for (int j = 0; j < poly.geometry.getNumGeometries(); j++) {
  10.299 +						collection.add((Polygon)poly.geometry.getGeometryN(j));
  10.300 +					}
  10.301 +				}
  10.302 +	
  10.303 +				Polygon[] polycollection = new Polygon[collection.size()];
  10.304 +				int k = 0;
  10.305 +				for (Polygon polygon : collection) {
  10.306 +					polycollection[k] = polygon;
  10.307 +					k++;
  10.308 +					assert (!polygon.isEmpty());
  10.309 +				}
  10.310 +				this.geometry = new MultiPolygon(polycollection, new GeometryFactory());
  10.311 +//			}
  10.312 +		} else {
  10.313 +//			if (!geo.isValid()) {
  10.314 +//				System.out.println("Non valid " + FindGeoType(geo) + " found.");
  10.315 +//				geo = geo.buffer(0.0);
  10.316 +//				System.out.println("Converted to a "+FindGeoType(geo)+" that is "+(geo.isValid() ? "" : "not ")+"valid+.");
  10.317 +//				this.geometry = new StrabonPolyhedron(geo, algorithm, maxPoints).geometry;
  10.318 +//			} else {
  10.319 +				for (int i = 0; i < geo.getNumGeometries(); i++) {
  10.320 +					StrabonPolyhedron smallGeo = new StrabonPolyhedron(geo.getGeometryN(i), algorithm, maxPoints);
  10.321 +					
  10.322 +					if (this.geometry == null) {
  10.323 +						this.geometry = smallGeo.geometry;
  10.324 +					} else {
  10.325 +						this.geometry.union(smallGeo.geometry);
  10.326 +					}
  10.327 +				}
  10.328 +//			}
  10.329 +		}
  10.330 +	}
  10.331 +
  10.332 +	public static StrabonPolyhedron ParseBigPolyhedron(Geometry polygon, int algorithm, boolean horizontal, int maxPoints) throws Exception {
  10.333 +		assert (Polygon.class.isInstance(polygon) || (MultiPolygon.class.isInstance(polygon)));
  10.334 +		
  10.335 +		if (polygon.getCoordinates().length > maxPoints) {
  10.336 +//			if (polygon.isValid()){
  10.337 +//				System.out.println("Found big polyhedron. Coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
  10.338 +//			} else {
  10.339 +//				System.out.println("Found invalid big polyhedron. Coordinates: " + polygon.getCoordinates().length + ".");
  10.340 +//				//IsValidOp err = new IsValidOp(polygon);
  10.341 +//				//System.out.println("Validation error: " + err.getValidationError());
  10.342 +//				//new Point(new CoordinateArraySequence(new Coordinate[] {polygon.getCoordinates()[0]}), new GeometryFactory());
  10.343 +//				//polygon = polygon.union(onePoint);
  10.344 +//				polygon = polygon.buffer(0.0);
  10.345 +//				System.out.println("After conversion, coordinates: " + polygon.getCoordinates().length + " (valid="+polygon.isValid()+").");
  10.346 +//			}
  10.347 +			double minx = Double.MAX_VALUE, miny = Double.MAX_VALUE, 
  10.348 +			       maxx = Double.MIN_VALUE, maxy = Double.MIN_VALUE;
  10.349 +
  10.350 +			Geometry bbox = polygon.getEnvelope();
  10.351 +			for (int i = 0; i < bbox.getCoordinates().length; i++) {
  10.352 +				Coordinate c = bbox.getCoordinates()[i];
  10.353 +				if (c.x > maxx) maxx = c.x;
  10.354 +				if (c.x < minx)	minx = c.x;
  10.355 +				if (c.y > maxy)	maxy = c.y;
  10.356 +				if (c.y < miny)	miny = c.y;
  10.357 +			}
  10.358 +
  10.359 +			Polygon firsthalf = new Polygon(new LinearRing(new CoordinateArraySequence( 
  10.360 +					new Coordinate[] {
  10.361 +							new Coordinate(minx, 										miny),
  10.362 +							new Coordinate(horizontal ? (minx + (maxx-minx)/2) : maxx, 	miny),
  10.363 +							new Coordinate(horizontal ? (minx + (maxx-minx)/2) : maxx, 	horizontal ? maxy : (miny + (maxy-miny)/2)),
  10.364 +							new Coordinate(minx, 										horizontal ? maxy : (miny + (maxy-miny)/2)),
  10.365 +							new Coordinate(minx, 										miny)}
  10.366 +			), new GeometryFactory()), null, new GeometryFactory());
  10.367 +
  10.368 +			firsthalf.normalize();
  10.369 +			
  10.370 +			Polygon secondhalf = (Polygon) bbox.difference(firsthalf);
  10.371 +			secondhalf.normalize();
  10.372 +			
  10.373 +//			double a = polygon.getArea();
  10.374 +//			double b = polygon.getEnvelope().getArea();
  10.375 +//			double c = firsthalf.getArea();
  10.376 +//			double d = bbox.difference(firsthalf).getArea();
  10.377 +//			
  10.378 +//			double e = b-c-d;
  10.379 +//			double f = c-d;
  10.380 +//			
  10.381 +//			double kk = firsthalf.difference(bbox).difference(firsthalf).getArea();
  10.382 +//			
  10.383 +//			boolean g = firsthalf.equals(bbox.difference(firsthalf));
  10.384 +//			boolean h = firsthalf.disjoint(bbox.difference(firsthalf));
  10.385 +//			boolean i = bbox.equals(firsthalf.union(bbox.difference(firsthalf)));
  10.386 +//			
  10.387 +//			boolean j = firsthalf.intersects(polygon);
  10.388 +//			boolean k = bbox.difference(firsthalf).intersects(polygon);
  10.389 +			
  10.390 +			Geometry A = polygon.intersection(firsthalf);
  10.391 +			System.out.println("First half  : " + A.getCoordinates().length + " coordinates.");
  10.392 +			//Geometry B = polygon.intersection(bbox.difference(firsthalf));
  10.393 +			Geometry B = polygon.intersection(secondhalf);
  10.394 +			System.out.println("Second half : " + B.getCoordinates().length + " coordinates.");
  10.395 +
  10.396 +			StrabonPolyhedron polyA = ParseBigPolyhedron(A, algorithm, !horizontal, maxPoints);			
  10.397 +			StrabonPolyhedron polyB = ParseBigPolyhedron(B, algorithm, !horizontal, maxPoints);
  10.398 +			
  10.399 +			return StrabonPolyhedron.quickUnion(polyA, polyB);
  10.400 +		} else {
  10.401 +System.out.println("Found small polyhedron. Coordinates: " + polygon.getCoordinates().length);
  10.402 +			return new StrabonPolyhedron(polygon, algorithm, maxPoints);
  10.403 +		}
  10.404 +	}
  10.405 +
  10.406 +	public StrabonPolyhedron(Polygon polygon, int algorithm, int maxPoints) throws Exception {
  10.407 +//		if (!polygon.isSimple())
  10.408 +//			throw new Exception(
  10.409 +//			"The polygon is not simple. Only simple polygons are supported");
  10.410 +
  10.411 +		Coordinate[] coordinates = polygon.getCoordinates();
  10.412 +		
  10.413 +		if (coordinates.length > maxPoints) {
  10.414 +			this.geometry = ParseBigPolyhedron(polygon, algorithm, true, maxPoints).geometry;
  10.415 +			return;
  10.416 +		}		
  10.417 +		
  10.418 +		int distinctCoordinates = 0;
  10.419 +boolean fix = false;
  10.420 +		for (int i = 0; i <= coordinates.length - 1; i++) {
  10.421 +			Coordinate c1 = coordinates[i];
  10.422 +			
  10.423 +			if (i == (coordinates.length - 1)) {
  10.424 +				// eimaste sto teleutaio simeio
  10.425 +				if ((c1.x != coordinates[0].x) || (c1.y != coordinates[0].y)) {
  10.426 +					// and den einai to idio me to 1o error
  10.427 +					//throw new Exception("Problem in  geometry. First and last point (i="+i+") do not match (coordinates: "+coordinates.length+", isValid:"+polygon.isValid()+").");
  10.428 +					distinctCoordinates++;
  10.429 +					fix = true;
  10.430 +				} else 
  10.431 +					if ((c1.x == coordinates[i-1].x) && (c1.y == coordinates[i-1].y)) {
  10.432 +					//einai to idio me to proigoumeno opote den kanoume tipota giati
  10.433 +					//exoun hdh auksithei ta dinstinct
  10.434 +				} else {				
  10.435 +					// den einai to idio me to proigoumeno opote auksise ta distinct
  10.436 +					distinctCoordinates++;
  10.437 +				}
  10.438 +				continue;
  10.439 +			} 
  10.440 +			
  10.441 +			Coordinate c2 = coordinates[i+1];
  10.442 +			
  10.443 +			if ((c1.x != c2.x) || (c1.y != c2.y)) {
  10.444 +				distinctCoordinates++;
  10.445 +			}
  10.446 +		}
  10.447 +		
  10.448 +		//System.out.println("---\n---\n---\n---\n---\n");
  10.449 +		//System.out.println("--- Coordinates.length   = " + coordinates.length);
  10.450 +		//System.out.println("--- Distinct coordinates = " + distinctCoordinates);
  10.451 +		//System.out.println("---\n---\n---\n---\n---\n");
  10.452 +		
  10.453 +		// cgal wants counter clockwise order
  10.454 +		//double[][] c = new double[coordinates.length - 1][2];
  10.455 +		int counter = 0;
  10.456 +		double[][] c = new double[(fix ? distinctCoordinates : (distinctCoordinates - 1))][2];
  10.457 +		for (int i = 0; i <= coordinates.length - 2; i++) {
  10.458 +			Coordinate c1 = coordinates[i];
  10.459 +			Coordinate c2 = coordinates[i+1];
  10.460 +			
  10.461 +			if ((c1.x != c2.x) || (c1.y != c2.y)) {
  10.462 +				c[counter][0] = c1.x;
  10.463 +				c[counter][1] = c1.y;
  10.464 +				counter++;
  10.465 +			}			
  10.466 +		}
  10.467 +		
  10.468 +		if (fix) {
  10.469 +			c[distinctCoordinates-1][0] = coordinates[coordinates.length-1].x;
  10.470 +			c[distinctCoordinates-1][1] = coordinates[coordinates.length-1].y;
  10.471 +		}
  10.472 +		
  10.473 +		//System.out.println("--- Counter              = " + counter);
  10.474 +		//System.out.println("---\n---\n---\n---\n---\n");
  10.475 +		
  10.476 +//		BufferedWriter bww = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/cfunction.dat")));
  10.477 +//		BufferedWriter bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/original.dat")));
  10.478 +//		bww.write("void make_polygon(Polygon_2& polygon) {");
  10.479 +//		for (int i = 0; i < coordinates.length - 1; i++) {
  10.480 +//			Coordinate coordinate = coordinates[i];
  10.481 +//			bww.write("\tpolygon.push_back(Point_2(");
  10.482 +//			bww.write(new Double(coordinate.x).toString());
  10.483 +//			bww.write(",");
  10.484 +//			bww.write(new Double(coordinate.y).toString());
  10.485 +//			bww.write("));\n");
  10.486 +//			
  10.487 +//			bw2.write(new Double(coordinate.x).toString());
  10.488 +//			bw2.write(" ");
  10.489 +//			bw2.write(new Double(coordinate.y).toString());
  10.490 +//			bw2.write("\n");
  10.491 +//		}
  10.492 +//		bww.write("}\n");
  10.493 +//		bww.flush();
  10.494 +//		bww.close();
  10.495 +//		
  10.496 +//		bw2.flush();
  10.497 +//		bw2.close();
  10.498 +
  10.499 +		double start = System.nanoTime();
  10.500 +//		double[][][] convexified = Polyhedron.ConvexifyPolygon(c, algorithm);
  10.501 +		double[][][] convexified = new double[1][2][3];		
  10.502 +		
  10.503 +//		if (convexified == null) {
  10.504 +//			throw new ParseGeometryException("Invalid geometry. Only simple geometries are supported.");
  10.505 +//		}
  10.506 +		
  10.507 +		System.out.println("ConvexifyTime " + (System.nanoTime()-start));
  10.508 +
  10.509 +		int[] sizes = new int[255];
  10.510 +		double min = Double.MAX_VALUE;
  10.511 +		double max = Double.MIN_VALUE;
  10.512 +			
  10.513 +		for (int i = 0; i < convexified.length; i++) {
  10.514 +			double[][] convexCoordinates = convexified[i];
  10.515 +			for (int j = 0; j < convexCoordinates.length; j++) {
  10.516 +				if (convexCoordinates[j][0] > max)
  10.517 +					max = convexCoordinates[j][0];
  10.518 +				if (convexCoordinates[j][0] < min)
  10.519 +					min = convexCoordinates[j][0];
  10.520 +			}
  10.521 +		
  10.522 +		}
  10.523 +				
  10.524 +//		String gnuPlotScript = "";
  10.525 +//		
  10.526 +//		for (int i = 0; i < convexified.length; i++) {
  10.527 +//			double[][] convexCoordinates = convexified[i];
  10.528 +//			sizes[convexCoordinates.length]++;
  10.529 +//			
  10.530 +//			BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/data-" + i + ".dat")));
  10.531 +//			bw2 = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-" + i + ".gnuplot")));
  10.532 +//			for (int j = 0; j < convexCoordinates.length; j++) {
  10.533 +//				bw.write(new Double(convexCoordinates[j][0]).toString());
  10.534 +//				bw.write(" ");
  10.535 +//				bw.write(new Double(convexCoordinates[j][1]).toString());
  10.536 +//				bw.write("\n");
  10.537 +//
  10.538 +//			}
  10.539 +//			bw.flush();
  10.540 +//			bw.close();
  10.541 +//			
  10.542 +//			gnuPlotScript += "'data-" + i + ".dat' with lines,";
  10.543 +//			
  10.544 +//			bw2.write("set terminal postscript eps color\n");
  10.545 +//			bw2.write("set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/geo-"+i+".eps'\n");
  10.546 +//			bw2.write("set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n");
  10.547 +//			bw2.write("plot ["+0.95*min+":"+1.05*max+"] 'data-" + i +".dat' with lines, 'original.dat' with lines\n");
  10.548 +//			bw2.flush();
  10.549 +//			bw2.close();
  10.550 +//		}
  10.551 +//			
  10.552 +//		gnuPlotScript = "plot ["+0.95*min+":"+1.05*max+"] " + gnuPlotScript.substring(0, gnuPlotScript.length()-1);
  10.553 +//		gnuPlotScript = "set terminal postscript eps color\n" +
  10.554 +//						"set out '/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/all.eps'\n" +
  10.555 +//						"set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000\n" + 
  10.556 +//						gnuPlotScript;
  10.557 +//		
  10.558 +//		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("/home/kkyzir/Desktop/Spatial data/ssg4env/geometries/gnuplot/script-all.gnuplot")));
  10.559 +//		bw.write(gnuPlotScript);
  10.560 +//		bw.flush();
  10.561 +//		bw.close();
  10.562 +//		
  10.563 +//		for (int i = 0; i < convexified.length; i++) {
  10.564 +//			Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-"+i+".gnuplot");
  10.565 +//		}
  10.566 +//		
  10.567 +//		Runtime.getRuntime().exec("gnuplot /home/kkyzir/Desktop/Spatial\\ data/ssg4env/geometries/gnuplot/script-all.gnuplot");
  10.568 +//		
  10.569 +		
  10.570 +		//Geometry[] collection = new Geometry[convexified.length];
  10.571 +		Polygon[] collection = new Polygon[convexified.length];
  10.572 +		System.out.println("Convex parts: " + convexified.length);		
  10.573 +		for (int i = 0; i < convexified.length; i++) {
  10.574 +			GeometryFactory factory = new GeometryFactory();
  10.575 +			double[][] convexCoordinates = convexified[i];
  10.576 +			Coordinate[] jtsCoordinates = new Coordinate[convexCoordinates.length];
  10.577 +			for (int j = 0; j < convexCoordinates.length; j++) {
  10.578 +				Coordinate co = new Coordinate(convexCoordinates[j][0],
  10.579 +						convexCoordinates[j][1]);
  10.580 +				jtsCoordinates[j] = co;
  10.581 +			}
  10.582 +
  10.583 +			CoordinateSequence points = new CoordinateArraySequence(
  10.584 +					jtsCoordinates);
  10.585 +			//System.out.println("Points: " + points.size());			
  10.586 +			LinearRing ring = new LinearRing(points, factory);
  10.587 +			Polygon poly = new Polygon(ring, null, factory);
  10.588 +
  10.589 +			collection[i] = poly;
  10.590 +			//			if (this.geometry == null) {
  10.591 +			//				this.geometry = poly;
  10.592 +			//			} else {
  10.593 +			//				this.geometry = this.geometry.union(poly);
  10.594 +			//			}
  10.595 +		}
  10.596 +
  10.597 +		//this.geometry = new GeometryCollection(collection, new GeometryFactory());
  10.598 +		//this.geometry.normalize();
  10.599 +		this.geometry = new MultiPolygon(collection, new GeometryFactory());
  10.600 +		this.geometry.normalize();
  10.601 +	}
  10.602 +
  10.603 +	public StrabonPolyhedron(Polygon polygon) throws Exception {
  10.604 +		this.geometry = new StrabonPolyhedron(polygon, 1).geometry;
  10.605 +	}
  10.606 +
  10.607 +	public StrabonPolyhedron(String geometry) throws Exception {
  10.608 +        if (geometry.startsWith("POINT") || 
  10.609 +                        geometry.startsWith("LINESTRING") || 
  10.610 +                        geometry.startsWith("POLYGON") || 
  10.611 +                        geometry.startsWith("MULTIPOINT") || 
  10.612 +                        geometry.startsWith("MULTILINESTRING") || 
  10.613 +                        geometry.startsWith("MULTIPOLYGON") || 
  10.614 +                        geometry.startsWith("GEOMETRYCOLLECTION")) {
  10.615 +                Geometry geo = new WKTReader().read(geometry);
  10.616 +                this.geometry = new StrabonPolyhedron(geo).geometry;
  10.617 +        } else {
  10.618 +                //Polyhedron polyhedron = new Polyhedron(geometry);
  10.619 +                //String polyhedronWKT = polyhedron.toWKT();
  10.620 +                //WKTReader reader = new WKTReader();
  10.621 +                //Geometry geo = reader.read(polyhedronWKT);
  10.622 +                //
  10.623 +                //if (!EnableConstraintRepresentation) {
  10.624 +                //	this.geometry = geo.union(geo);
  10.625 +                //}
  10.626 +        }
  10.627 +}
  10.628 +	
  10.629 +	public StrabonPolyhedron(String WKT, int algorithm) throws Exception {
  10.630 +		Geometry geo = new WKTReader().read(WKT);
  10.631 +		this.geometry = new StrabonPolyhedron(geo, algorithm).geometry;
  10.632 +	}
  10.633 +	
  10.634 +	public StrabonPolyhedron(String WKT, int algorithm, int maxPoints) throws Exception {
  10.635 +		Geometry geo = new WKTReader().read(WKT);
  10.636 +		this.geometry = new StrabonPolyhedron(geo, algorithm).geometry;
  10.637 +	}
  10.638 +
  10.639 +	public StrabonPolyhedron(byte[] byteArray) throws ParseException {
  10.640 +		
  10.641 +		this.geometry = new WKBReader().read(byteArray);
  10.642 +//		System.out.println(geometry.toString()+" "+geometry.getSRID());
  10.643 +	}
  10.644 +
  10.645 +	public String toConstraints() //throws ConversionException 
  10.646 +	{
  10.647 +		if (this.geometry.isEmpty())
  10.648 +			return "";
  10.649 +		
  10.650 +		if (!EnableConstraintRepresentation) {
  10.651 +			return "Constraint representation is disabled.";
  10.652 +		}
  10.653 +		
  10.654 +		//Polyhedron poly = new Polyhedron(this.geometry);
  10.655 +		//return poly.toConstraints();
  10.656 +		return "";
  10.657 +	}
  10.658 +
  10.659 +	public String toString() {
  10.660 +		return this.geometry.toString();
  10.661 +	}
  10.662 +
  10.663 +	public String toText() {
  10.664 +		return this.geometry.toText();
  10.665 +	}
  10.666 +	
  10.667 +	public byte[] toWKB() {
  10.668 +		WKBWriter writer = new WKBWriter();
  10.669 +		return writer.write(this.geometry);		
  10.670 +	}
  10.671 +	
  10.672 +	public String toWKT() {
  10.673 +		WKTWriter writer = new WKTWriter();
  10.674 +		return writer.write(this.geometry);		
  10.675 +	}
  10.676 +
  10.677 +	public byte[] toByteArray() {
  10.678 +		return new WKBWriter().write(this.geometry);
  10.679 +	}
  10.680 +
  10.681 +	public static StrabonPolyhedron union(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.682 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.683 +		poly.geometry = A.geometry.union(B.geometry);
  10.684 +
  10.685 +		return poly;
  10.686 +	}
  10.687 +	
  10.688 +	public static StrabonPolyhedron buffer(StrabonPolyhedron A, double B) throws Exception {
  10.689 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.690 +		poly.geometry = A.geometry.buffer(B);
  10.691 +		
  10.692 +		return poly;
  10.693 +	}
  10.694 +	
  10.695 +	public static StrabonPolyhedron envelope(StrabonPolyhedron A) throws Exception {
  10.696 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.697 +		poly.geometry = A.geometry.getEnvelope();
  10.698 +
  10.699 +		return poly;
  10.700 +	}
  10.701 +	
  10.702 +	public static StrabonPolyhedron convexHull(StrabonPolyhedron A) throws Exception {
  10.703 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.704 +		poly.geometry = A.geometry.convexHull();
  10.705 +
  10.706 +		return poly;
  10.707 +	}
  10.708 +	
  10.709 +	public static StrabonPolyhedron boundary(StrabonPolyhedron A) throws Exception {
  10.710 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.711 +		poly.geometry = A.geometry.getBoundary();
  10.712 +
  10.713 +		return poly;
  10.714 +	}
  10.715 +	
  10.716 +	public static StrabonPolyhedron intersection(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.717 +		Geometry geo = A.geometry.intersection(B.geometry);
  10.718 +		
  10.719 +		return new StrabonPolyhedron(geo);
  10.720 +	}
  10.721 +
  10.722 +	public static StrabonPolyhedron difference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.723 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.724 +		poly.geometry = A.geometry.difference(B.geometry);
  10.725 +
  10.726 +		return poly;
  10.727 +	}
  10.728 +	
  10.729 +	public static StrabonPolyhedron symDifference(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.730 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.731 +		poly.geometry = A.geometry.symDifference(B.geometry);
  10.732 +
  10.733 +		return poly;
  10.734 +	}
  10.735 +	
  10.736 +	public static double area(StrabonPolyhedron A) throws Exception {
  10.737 +		return A.geometry.getArea();
  10.738 +	}
  10.739 +	
  10.740 +	public static double distance(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.741 +		return A.geometry.distance(B.geometry);
  10.742 +	}
  10.743 +	
  10.744 +	public static StrabonPolyhedron project(StrabonPolyhedron A, int[] dims) throws Exception {
  10.745 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.746 +		ProjectionsFilter filter = new ProjectionsFilter(dims);
  10.747 +		A.geometry.apply(filter);
  10.748 +		A.geometry.geometryChanged();
  10.749 +		poly.geometry = A.geometry;
  10.750 +		return poly;
  10.751 +	}
  10.752 +
  10.753 +	/**
  10.754 +	 * Performs quick union between polygons or multipolygons.
  10.755 +	 * 
  10.756 +	 * @param A
  10.757 +	 * @param B
  10.758 +	 * @return
  10.759 +	 * @throws Exception
  10.760 +	 */
  10.761 +	public static StrabonPolyhedron quickUnion(StrabonPolyhedron A, StrabonPolyhedron B) throws Exception {
  10.762 +		System.out.println("Merging polyhedrons: A.coordinates=" + A.getGeometry().getCoordinates().length + 
  10.763 +				", B.coordinates=" + B.getGeometry().getCoordinates().length);
  10.764 +		
  10.765 +		StrabonPolyhedron poly = new StrabonPolyhedron();
  10.766 +		int polygons = 0;
  10.767 +		if (Polygon.class.isInstance(A.geometry)) {			
  10.768 +			polygons++;
  10.769 +		} else if (MultiPolygon.class.isInstance(A.geometry)) {
  10.770 +				polygons += ((MultiPolygon)(A.geometry)).getNumGeometries();
  10.771 +		}
  10.772 +		if (Polygon.class.isInstance(B.geometry)) {
  10.773 +			polygons++;
  10.774 +		} else if (MultiPolygon.class.isInstance(B.geometry)) {
  10.775 +			polygons += ((MultiPolygon)(B.geometry)).getNumGeometries();
  10.776 +		}
  10.777 +
  10.778 +		assert (polygons >= 2);
  10.779 +
  10.780 +		int index = 0;
  10.781 +		Polygon[] polys = new Polygon[polygons];
  10.782 +
  10.783 +		if (Polygon.class.isInstance(A.geometry)) {
  10.784 +			polys[index] = (Polygon)(A.geometry);
  10.785 +			index++;
  10.786 +		}
  10.787 +		if (Polygon.class.isInstance(B.geometry)) {
  10.788 +			polys[index] = (Polygon)(B.geometry);
  10.789 +			index++;
  10.790 +		}
  10.791 +		if (MultiPolygon.class.isInstance(A.geometry)) {
  10.792 +			MultiPolygon multi = (MultiPolygon)(A.geometry);
  10.793 +			for (int i = 0; i < multi.getNumGeometries(); i++) {
  10.794 +				polys[index] = (Polygon)multi.getGeometryN(i);
  10.795 +				index++;
  10.796 +			}
  10.797 +		}
  10.798 +		if (MultiPolygon.class.isInstance(B.geometry)) {
  10.799 +			MultiPolygon multi = (MultiPolygon)(B.geometry);
  10.800 +			for (int i = 0; i < multi.getNumGeometries(); i++) {
  10.801 +				polys[index] = (Polygon)multi.getGeometryN(i);
  10.802 +				index++;
  10.803 +			}
  10.804 +		}
  10.805 +		
  10.806 +		poly.geometry = new MultiPolygon(polys, new GeometryFactory());
  10.807 +
  10.808 +		return poly;
  10.809 +	}
  10.810 +
  10.811 +	
  10.812 +	public StrabonPolyhedron getBuffer(double distance) throws Exception {
  10.813 +		Geometry geo = this.geometry.buffer(distance);
  10.814 +		System.out.println("TEMPORARY ----> BUFFER EXECUTED!!");
  10.815 +		return new StrabonPolyhedron(geo);
  10.816 +	}
  10.817 +
  10.818 +	public StrabonPolyhedron getBoundary() throws Exception {
  10.819 +		Geometry geo = this.geometry.getBoundary();
  10.820 +		System.out.println("TEMPORARY ----> BOUNDARY EXECUTED!!");
  10.821 +		return new StrabonPolyhedron(geo);
  10.822 +	}
  10.823 +
  10.824 +	public StrabonPolyhedron getEnvelope() throws Exception {
  10.825 +		Geometry geo = this.geometry.getEnvelope();
  10.826 +		System.out.println("TEMPORARY ----> BB EXECUTED!!");
  10.827 +		return new StrabonPolyhedron(geo);
  10.828 +	}
  10.829 +
  10.830 +	public double getArea() throws Exception {
  10.831 +		return this.getArea();
  10.832 +	}
  10.833 +
  10.834 +	public Geometry getGeometry() {
  10.835 +		return this.geometry;
  10.836 +	}
  10.837 +	
  10.838 +	public int getNumPoints() {
  10.839 +		return this.geometry.getNumPoints();
  10.840 +	}
  10.841 +	
  10.842 +	private static String FindGeoType(Geometry geo) {
  10.843 +		return 
  10.844 +		Point.class.isInstance(geo) ? "Point" :
  10.845 +			MultiPoint.class.isInstance(geo) ? "MultiPoint" :
  10.846 +				LineString.class.isInstance(geo) ? "LineString" :
  10.847 +					MultiLineString.class.isInstance(geo) ? "MultiLineString" :
  10.848 +						Polygon.class.isInstance(geo) ? "Polygon" :
  10.849 +							MultiPolygon.class.isInstance(geo) ? "MultiPolygon" :
  10.850 +								GeometryCollection.class.isInstance(geo) ? "GeometryCollection" : 
  10.851 +									"Unknown";
  10.852 +	}
  10.853 +
  10.854 +	public static void main(String[] args) {		
  10.855 +		double start, stop;
  10.856 +		double construct = 0;
  10.857 +		double constructWKT = 0;
  10.858 +		double tostring = 0;
  10.859 +		double toconstraints = 0;
  10.860 +
  10.861 +		for (int i = 0; i < 100; i++) {
  10.862 +			try {			
  10.863 +				String WKT = "POLYGON(("
  10.864 +					+ "342164.38954080583 5536425.686612717 , "
  10.865 +					+ "341626.21626698505 5536449.481769281 , "
  10.866 +					+ "341533.2278808594  5536525.216353727 , "
  10.867 +					+ "341233.98619135865 5536475.226529011 , "
  10.868 +					+ "341127.21075357014 5536983.653040268 , "
  10.869 +					+ "341215.02899532224 5537144.780243294 , "
  10.870 +					+ "340955.95747845445 5537799.537709246 , "
  10.871 +					+ "343211.19068847306 5537879.8934287615, "
  10.872 +					+ "343442.00065602345 5537324.533655008 , "
  10.873 +					+ "343314.06638177147 5537172.864526819 , "
  10.874 +					+ "343297.4180221379  5536922.705445975 , "
  10.875 +					+ "342969.57149877446 5536768.366861146 , "
  10.876 +					+ "342464.2661603174  5536951.549574836 , "
  10.877 +					+ "342296.77657097764 5536842.341803761 , "
  10.878 +					+ "342222.48151387094 5536641.402704332 , "
  10.879 +					+ "342286.9145411997  5536458.319970291 , "
  10.880 +					+ "342164.38954080583 5536425.686612717" + "))";
  10.881 +
  10.882 +				start = System.nanoTime();
  10.883 +				Geometry geo = new WKTReader().read(WKT);
  10.884 +				geo.isValid();
  10.885 +				geo.isSimple();
  10.886 +				geo.normalize();
  10.887 +				constructWKT += System.nanoTime() - start;
  10.888 +
  10.889 +				start = System.nanoTime();
  10.890 +				StrabonPolyhedron poly = new StrabonPolyhedron(WKT);
  10.891 +				construct += System.nanoTime() - start;
  10.892 +
  10.893 +				//System.out.println("-------------------S-T-R-I-N-G-----------------start");
  10.894 +				start = System.nanoTime();
  10.895 +				String polyString = poly.toString();
  10.896 +				tostring += System.nanoTime() - start;
  10.897 +				//System.out.println(polyString);
  10.898 +
  10.899 +				//System.out.println("-------------------S-T-R-I-N-G-----------------end");
  10.900 +				//System.out.println("-------------C-O-N-S-T-R-A-I-N-T-S-------------start");
  10.901 +				start = System.nanoTime();
  10.902 +				//String constraintString = poly.toConstraints();
  10.903 +				toconstraints += System.nanoTime() - start;
  10.904 +				//System.out.println(constraintString);
  10.905 +				//System.out.println("-----------------------------------------------end");
  10.906 +			} catch (Exception e) {
  10.907 +				// TODO Auto-generated catch block
  10.908 +				e.printStackTrace();
  10.909 +			}
  10.910 +		}
  10.911 +
  10.912 +		System.out.println("Construct (WKT): " + constructWKT);
  10.913 +		System.out.println("Construct      : " + construct);
  10.914 +		System.out.println("To String      : " + tostring);
  10.915 +		System.out.println("To Constraints : " + toconstraints);
  10.916 +		System.out.println("-------------------------------------------------");
  10.917 +		System.out.println("Costruct/Construct(WKT):" + (100*construct/constructWKT));
  10.918 +		System.out.println("To Constraints/To String:" + (100*toconstraints/tostring));
  10.919 +	}
  10.920 +
  10.921 +	public String stringValue() {
  10.922 +		return this.toWKT();
  10.923 +	}
  10.924 +	
  10.925 +	@Override
  10.926 +	public boolean equals(Object other) {
  10.927 +
  10.928 +		if(other instanceof StrabonPolyhedron)
  10.929 +		{
  10.930 +			if (((StrabonPolyhedron) other).geometry.equals(this.getGeometry()))
  10.931 +			{
  10.932 +				return true;
  10.933 +			}
  10.934 +			
  10.935 +		}
  10.936 +		return false;
  10.937 +	}
  10.938 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlNonTopologicalConstruct.java	Fri Jan 27 01:08:32 2012 +0200
    11.3 @@ -0,0 +1,41 @@
    11.4 +/*
    11.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    11.6 + *
    11.7 + * Licensed under the Aduna BSD-style license.
    11.8 + */
    11.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql;
   11.10 +
   11.11 +import java.math.BigDecimal;
   11.12 +import java.math.BigInteger;
   11.13 +
   11.14 +import org.openrdf.model.Literal;
   11.15 +import org.openrdf.model.URI;
   11.16 +import org.openrdf.model.Value;
   11.17 +import org.openrdf.model.ValueFactory;
   11.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   11.19 +import org.openrdf.model.vocabulary.XMLSchema;
   11.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   11.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   11.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   11.23 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   11.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   11.25 +
   11.26 +//import eu.ist.semsorgrid4env.strabon.structures.StrabonPolyhedron;
   11.27 +
   11.28 +public abstract class GeoSparqlNonTopologicalConstruct extends SpatialConstructFunc {
   11.29 +
   11.30 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
   11.31 +	public Value evaluate(ValueFactory valueFactory, Value... args)
   11.32 +	throws ValueExprEvaluationException {
   11.33 +
   11.34 +		return null;
   11.35 +	}
   11.36 +
   11.37 +	//I'll have everyone override it
   11.38 +	public String getURI() {
   11.39 +
   11.40 +		return null;
   11.41 +	}
   11.42 +
   11.43 +	
   11.44 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlNonTopologicalMetric.java	Fri Jan 27 01:08:32 2012 +0200
    12.3 @@ -0,0 +1,41 @@
    12.4 +/*
    12.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    12.6 + *
    12.7 + * Licensed under the Aduna BSD-style license.
    12.8 + */
    12.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql;
   12.10 +
   12.11 +import java.math.BigDecimal;
   12.12 +import java.math.BigInteger;
   12.13 +
   12.14 +import org.openrdf.model.Literal;
   12.15 +import org.openrdf.model.URI;
   12.16 +import org.openrdf.model.Value;
   12.17 +import org.openrdf.model.ValueFactory;
   12.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   12.19 +import org.openrdf.model.vocabulary.XMLSchema;
   12.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   12.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   12.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   12.23 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   12.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   12.25 +
   12.26 +//import eu.ist.semsorgrid4env.strabon.structures.StrabonPolyhedron;
   12.27 +
   12.28 +public abstract class GeoSparqlNonTopologicalMetric extends SpatialConstructFunc {
   12.29 +
   12.30 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
   12.31 +	public Value evaluate(ValueFactory valueFactory, Value... args)
   12.32 +	throws ValueExprEvaluationException {
   12.33 +
   12.34 +		return null;
   12.35 +	}
   12.36 +
   12.37 +	//I'll have everyone override it
   12.38 +	public String getURI() {
   12.39 +
   12.40 +		return null;
   12.41 +	}
   12.42 +
   12.43 +	
   12.44 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlRelateFunc.java	Fri Jan 27 01:08:32 2012 +0200
    13.3 @@ -0,0 +1,19 @@
    13.4 +/*
    13.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    13.6 + *
    13.7 + * Licensed under the Aduna BSD-style license.
    13.8 + */
    13.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql;
   13.10 +
   13.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   13.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   13.13 +
   13.14 +
   13.15 +public class GeoSparqlRelateFunc extends GeoSparqlRelation {
   13.16 +
   13.17 +	@Override
   13.18 +	public String getURI() {
   13.19 +		return StrabonPolyhedron.geoSparqlRelate;
   13.20 +		}
   13.21 +
   13.22 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/GeoSparqlRelation.java	Fri Jan 27 01:08:32 2012 +0200
    14.3 @@ -0,0 +1,40 @@
    14.4 +/*
    14.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    14.6 + *
    14.7 + * Licensed under the Aduna BSD-style license.
    14.8 + */
    14.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql;
   14.10 +
   14.11 +import java.math.BigDecimal;
   14.12 +import java.math.BigInteger;
   14.13 +
   14.14 +import org.openrdf.model.Literal;
   14.15 +import org.openrdf.model.URI;
   14.16 +import org.openrdf.model.Value;
   14.17 +import org.openrdf.model.ValueFactory;
   14.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   14.19 +import org.openrdf.model.vocabulary.XMLSchema;
   14.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   14.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   14.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   14.23 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   14.24 +
   14.25 +//import eu.ist.semsorgrid4env.strabon.structures.StrabonPolyhedron;
   14.26 +
   14.27 +public abstract class GeoSparqlRelation extends SpatialRelationshipFunc {
   14.28 +
   14.29 +	//No need for any implementation, I will have replaced this class's presence before reaching this place
   14.30 +	public Value evaluate(ValueFactory valueFactory, Value... args)
   14.31 +	throws ValueExprEvaluationException {
   14.32 +
   14.33 +		return null;
   14.34 +	}
   14.35 +
   14.36 +	//I'll have everyone override it
   14.37 +	public String getURI() {
   14.38 +
   14.39 +		return null;
   14.40 +	}
   14.41 +
   14.42 +	
   14.43 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferContainsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    15.3 @@ -0,0 +1,19 @@
    15.4 +/*
    15.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    15.6 + *
    15.7 + * Licensed under the Aduna BSD-style license.
    15.8 + */
    15.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   15.10 +
   15.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   15.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   15.13 +
   15.14 +
   15.15 +public class EgenhoferContainsFunc extends GeoSparqlRelation {
   15.16 +
   15.17 +	@Override
   15.18 +	public String getURI() {
   15.19 +		return StrabonPolyhedron.ehContains;
   15.20 +		}
   15.21 +
   15.22 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferCoveredByFunc.java	Fri Jan 27 01:08:32 2012 +0200
    16.3 @@ -0,0 +1,19 @@
    16.4 +/*
    16.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    16.6 + *
    16.7 + * Licensed under the Aduna BSD-style license.
    16.8 + */
    16.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   16.10 +
   16.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   16.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   16.13 +
   16.14 +
   16.15 +public class EgenhoferCoveredByFunc extends GeoSparqlRelation {
   16.16 +
   16.17 +	@Override
   16.18 +	public String getURI() {
   16.19 +		return StrabonPolyhedron.ehCoveredBy;
   16.20 +		}
   16.21 +
   16.22 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferCoversFunc.java	Fri Jan 27 01:08:32 2012 +0200
    17.3 @@ -0,0 +1,19 @@
    17.4 +/*
    17.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    17.6 + *
    17.7 + * Licensed under the Aduna BSD-style license.
    17.8 + */
    17.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   17.10 +
   17.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   17.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   17.13 +
   17.14 +
   17.15 +public class EgenhoferCoversFunc extends GeoSparqlRelation {
   17.16 +
   17.17 +	@Override
   17.18 +	public String getURI() {
   17.19 +		return StrabonPolyhedron.ehCovers;
   17.20 +		}
   17.21 +
   17.22 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferDisjointFunc.java	Fri Jan 27 01:08:32 2012 +0200
    18.3 @@ -0,0 +1,19 @@
    18.4 +/*
    18.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    18.6 + *
    18.7 + * Licensed under the Aduna BSD-style license.
    18.8 + */
    18.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   18.10 +
   18.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   18.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   18.13 +
   18.14 +
   18.15 +public class EgenhoferDisjointFunc extends GeoSparqlRelation {
   18.16 +
   18.17 +	@Override
   18.18 +	public String getURI() {
   18.19 +		return StrabonPolyhedron.ehDisjoint;
   18.20 +		}
   18.21 +
   18.22 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferEqualsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    19.3 @@ -0,0 +1,19 @@
    19.4 +/*
    19.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    19.6 + *
    19.7 + * Licensed under the Aduna BSD-style license.
    19.8 + */
    19.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   19.10 +
   19.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   19.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   19.13 +
   19.14 +
   19.15 +public class EgenhoferEqualsFunc extends GeoSparqlRelation {
   19.16 +
   19.17 +	@Override
   19.18 +	public String getURI() {
   19.19 +		return StrabonPolyhedron.ehEquals;
   19.20 +		}
   19.21 +
   19.22 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferInsideFunc.java	Fri Jan 27 01:08:32 2012 +0200
    20.3 @@ -0,0 +1,19 @@
    20.4 +/*
    20.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    20.6 + *
    20.7 + * Licensed under the Aduna BSD-style license.
    20.8 + */
    20.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   20.10 +
   20.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   20.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   20.13 +
   20.14 +
   20.15 +public class EgenhoferInsideFunc extends GeoSparqlRelation {
   20.16 +
   20.17 +	@Override
   20.18 +	public String getURI() {
   20.19 +		return StrabonPolyhedron.ehInside;
   20.20 +		}
   20.21 +
   20.22 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferMeetFunc.java	Fri Jan 27 01:08:32 2012 +0200
    21.3 @@ -0,0 +1,19 @@
    21.4 +/*
    21.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    21.6 + *
    21.7 + * Licensed under the Aduna BSD-style license.
    21.8 + */
    21.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   21.10 +
   21.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   21.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   21.13 +
   21.14 +
   21.15 +public class EgenhoferMeetFunc extends GeoSparqlRelation {
   21.16 +
   21.17 +	@Override
   21.18 +	public String getURI() {
   21.19 +		return StrabonPolyhedron.ehMeet;
   21.20 +		}
   21.21 +
   21.22 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/egenhofer/EgenhoferOverlapFunc.java	Fri Jan 27 01:08:32 2012 +0200
    22.3 @@ -0,0 +1,19 @@
    22.4 +/*
    22.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    22.6 + *
    22.7 + * Licensed under the Aduna BSD-style license.
    22.8 + */
    22.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer;
   22.10 +
   22.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   22.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   22.13 +
   22.14 +
   22.15 +public class EgenhoferOverlapFunc extends GeoSparqlRelation {
   22.16 +
   22.17 +	@Override
   22.18 +	public String getURI() {
   22.19 +		return StrabonPolyhedron.ehOverlap;
   22.20 +		}
   22.21 +
   22.22 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlBoundaryFunc.java	Fri Jan 27 01:08:32 2012 +0200
    23.3 @@ -0,0 +1,37 @@
    23.4 +/*
    23.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    23.6 + *
    23.7 + * Licensed under the Aduna BSD-style license.
    23.8 + */
    23.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
   23.10 +
   23.11 +import java.math.BigDecimal;
   23.12 +import java.math.BigInteger;
   23.13 +
   23.14 +import org.openrdf.model.Literal;
   23.15 +import org.openrdf.model.URI;
   23.16 +import org.openrdf.model.Value;
   23.17 +import org.openrdf.model.ValueFactory;
   23.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   23.19 +import org.openrdf.model.vocabulary.XMLSchema;
   23.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   23.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   23.22 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   23.23 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
   23.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   23.25 + 
   23.26 +/**
   23.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   23.28 + * 
   23.29 + * @author Arjohn Kampman
   23.30 + */
   23.31 +public class GeoSparqlBoundaryFunc extends GeoSparqlNonTopologicalConstruct {
   23.32 +
   23.33 +	@Override
   23.34 +	public String getURI() {
   23.35 +		return StrabonPolyhedron.geoSparqlBoundary;
   23.36 +	}
   23.37 +
   23.38 +	 
   23.39 + 
   23.40 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlBufferFunc.java	Fri Jan 27 01:08:32 2012 +0200
    24.3 @@ -0,0 +1,37 @@
    24.4 +/*
    24.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    24.6 + *
    24.7 + * Licensed under the Aduna BSD-style license.
    24.8 + */
    24.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
   24.10 +
   24.11 +import java.math.BigDecimal;
   24.12 +import java.math.BigInteger;
   24.13 +
   24.14 +import org.openrdf.model.Literal;
   24.15 +import org.openrdf.model.URI;
   24.16 +import org.openrdf.model.Value;
   24.17 +import org.openrdf.model.ValueFactory;
   24.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   24.19 +import org.openrdf.model.vocabulary.XMLSchema;
   24.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   24.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   24.22 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   24.23 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
   24.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   24.25 + 
   24.26 +/**
   24.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   24.28 + * 
   24.29 + * @author Arjohn Kampman
   24.30 + */
   24.31 +public class GeoSparqlBufferFunc extends GeoSparqlNonTopologicalConstruct {
   24.32 +
   24.33 +	@Override
   24.34 +	public String getURI() {
   24.35 +		return StrabonPolyhedron.geoSparqlBuffer;
   24.36 +	}
   24.37 +
   24.38 +	 
   24.39 + 
   24.40 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlConvexHullFunc.java	Fri Jan 27 01:08:32 2012 +0200
    25.3 @@ -0,0 +1,37 @@
    25.4 +/*
    25.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    25.6 + *
    25.7 + * Licensed under the Aduna BSD-style license.
    25.8 + */
    25.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
   25.10 +
   25.11 +import java.math.BigDecimal;
   25.12 +import java.math.BigInteger;
   25.13 +
   25.14 +import org.openrdf.model.Literal;
   25.15 +import org.openrdf.model.URI;
   25.16 +import org.openrdf.model.Value;
   25.17 +import org.openrdf.model.ValueFactory;
   25.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   25.19 +import org.openrdf.model.vocabulary.XMLSchema;
   25.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   25.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   25.22 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   25.23 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
   25.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   25.25 + 
   25.26 +/**
   25.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   25.28 + * 
   25.29 + * @author Arjohn Kampman
   25.30 + */
   25.31 +public class GeoSparqlConvexHullFunc extends GeoSparqlNonTopologicalConstruct {
   25.32 +
   25.33 +	@Override
   25.34 +	public String getURI() {
   25.35 +		return StrabonPolyhedron.geoSparqlConvexHull;
   25.36 +	}
   25.37 +
   25.38 +	 
   25.39 + 
   25.40 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlDifferenceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    26.3 @@ -0,0 +1,12 @@
    26.4 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
    26.5 +
    26.6 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    26.7 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
    26.8 +
    26.9 +public class GeoSparqlDifferenceFunc extends GeoSparqlNonTopologicalConstruct {
   26.10 +
   26.11 +	@Override
   26.12 +	public String getURI() {
   26.13 +		return StrabonPolyhedron.geoSparqlDifference;
   26.14 +		}
   26.15 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlDistanceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    27.3 @@ -0,0 +1,31 @@
    27.4 +/*
    27.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    27.6 + *
    27.7 + * Licensed under the Aduna BSD-style license.
    27.8 + */
    27.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
   27.10 +
   27.11 +import java.math.BigDecimal;
   27.12 +import java.math.BigInteger;
   27.13 +
   27.14 +import org.openrdf.model.Literal;
   27.15 +import org.openrdf.model.URI;
   27.16 +import org.openrdf.model.Value;
   27.17 +import org.openrdf.model.ValueFactory;
   27.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   27.19 +import org.openrdf.model.vocabulary.XMLSchema;
   27.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   27.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   27.22 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   27.23 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
   27.24 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalMetric;
   27.25 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   27.26 +
   27.27 +public class GeoSparqlDistanceFunc extends GeoSparqlNonTopologicalMetric {
   27.28 +
   27.29 +	@Override
   27.30 +	public String getURI() {
   27.31 +		return StrabonPolyhedron.geoSparqlDistance;
   27.32 +		}
   27.33 +
   27.34 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlEnvelopeFunc.java	Fri Jan 27 01:08:32 2012 +0200
    28.3 @@ -0,0 +1,32 @@
    28.4 +/*
    28.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    28.6 + *
    28.7 + * Licensed under the Aduna BSD-style license.
    28.8 + */
    28.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
   28.10 +
   28.11 +import java.math.BigDecimal;
   28.12 +import java.math.BigInteger;
   28.13 +
   28.14 +import org.openrdf.model.Literal;
   28.15 +import org.openrdf.model.URI;
   28.16 +import org.openrdf.model.Value;
   28.17 +import org.openrdf.model.ValueFactory;
   28.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   28.19 +import org.openrdf.model.vocabulary.XMLSchema;
   28.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   28.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   28.22 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   28.23 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
   28.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   28.25 + 
   28.26 +public class GeoSparqlEnvelopeFunc extends GeoSparqlNonTopologicalConstruct {
   28.27 +
   28.28 +	@Override
   28.29 +	public String getURI() {
   28.30 +		return StrabonPolyhedron.geoSparqlEnvelope;
   28.31 +	}
   28.32 +
   28.33 +	 
   28.34 + 
   28.35 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlIntersectionFunc.java	Fri Jan 27 01:08:32 2012 +0200
    29.3 @@ -0,0 +1,12 @@
    29.4 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
    29.5 +
    29.6 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    29.7 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
    29.8 +
    29.9 +public class GeoSparqlIntersectionFunc extends GeoSparqlNonTopologicalConstruct {
   29.10 +
   29.11 +	@Override
   29.12 +	public String getURI() {
   29.13 +		return StrabonPolyhedron.geoSparqlIntersection;
   29.14 +		}
   29.15 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlSymmetricDifferenceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    30.3 @@ -0,0 +1,12 @@
    30.4 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
    30.5 +
    30.6 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    30.7 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
    30.8 +
    30.9 +public class GeoSparqlSymmetricDifferenceFunc extends GeoSparqlNonTopologicalConstruct {
   30.10 +
   30.11 +	@Override
   30.12 +	public String getURI() {
   30.13 +		return StrabonPolyhedron.geoSparqlSymmetricDifference;
   30.14 +		}
   30.15 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/nontopological/GeoSparqlUnionFunc.java	Fri Jan 27 01:08:32 2012 +0200
    31.3 @@ -0,0 +1,12 @@
    31.4 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological;
    31.5 +
    31.6 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    31.7 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlNonTopologicalConstruct;
    31.8 +
    31.9 +public class GeoSparqlUnionFunc extends GeoSparqlNonTopologicalConstruct {
   31.10 +
   31.11 +	@Override
   31.12 +	public String getURI() {
   31.13 +		return StrabonPolyhedron.geoSparqlUnion;
   31.14 +		}
   31.15 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8DisconnectedFunc.java	Fri Jan 27 01:08:32 2012 +0200
    32.3 @@ -0,0 +1,20 @@
    32.4 +/*
    32.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    32.6 + *
    32.7 + * Licensed under the Aduna BSD-style license.
    32.8 + */
    32.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   32.10 +
   32.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   32.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   32.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   32.14 +
   32.15 +
   32.16 +public class RCC8DisconnectedFunc extends GeoSparqlRelation {
   32.17 +
   32.18 +	@Override
   32.19 +	public String getURI() {
   32.20 +		return StrabonPolyhedron.rccDisconnected;
   32.21 +		}
   32.22 +
   32.23 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8EqualsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    33.3 @@ -0,0 +1,20 @@
    33.4 +/*
    33.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    33.6 + *
    33.7 + * Licensed under the Aduna BSD-style license.
    33.8 + */
    33.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   33.10 +
   33.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   33.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   33.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   33.14 +
   33.15 +
   33.16 +public class RCC8EqualsFunc extends GeoSparqlRelation {
   33.17 +
   33.18 +	@Override
   33.19 +	public String getURI() {
   33.20 +		return StrabonPolyhedron.rccEquals;
   33.21 +		}
   33.22 +
   33.23 +}
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8ExternallyConnectedFunc.java	Fri Jan 27 01:08:32 2012 +0200
    34.3 @@ -0,0 +1,20 @@
    34.4 +/*
    34.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    34.6 + *
    34.7 + * Licensed under the Aduna BSD-style license.
    34.8 + */
    34.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   34.10 +
   34.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   34.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   34.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   34.14 +
   34.15 +
   34.16 +public class RCC8ExternallyConnectedFunc extends GeoSparqlRelation {
   34.17 +
   34.18 +	@Override
   34.19 +	public String getURI() {
   34.20 +		return StrabonPolyhedron.rccExternallyConnected;
   34.21 +		}
   34.22 +
   34.23 +}
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8NonTangentialProperPartFunc.java	Fri Jan 27 01:08:32 2012 +0200
    35.3 @@ -0,0 +1,20 @@
    35.4 +/*
    35.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    35.6 + *
    35.7 + * Licensed under the Aduna BSD-style license.
    35.8 + */
    35.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   35.10 +
   35.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   35.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   35.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   35.14 +
   35.15 +
   35.16 +public class RCC8NonTangentialProperPartFunc extends GeoSparqlRelation {
   35.17 +
   35.18 +	@Override
   35.19 +	public String getURI() {
   35.20 +		return StrabonPolyhedron.rccNonTangentialProperPart;
   35.21 +		}
   35.22 +
   35.23 +}
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8NonTangentialProperPartInverseFunc.java	Fri Jan 27 01:08:32 2012 +0200
    36.3 @@ -0,0 +1,20 @@
    36.4 +/*
    36.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    36.6 + *
    36.7 + * Licensed under the Aduna BSD-style license.
    36.8 + */
    36.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   36.10 +
   36.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   36.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   36.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   36.14 +
   36.15 +
   36.16 +public class RCC8NonTangentialProperPartInverseFunc extends GeoSparqlRelation {
   36.17 +
   36.18 +	@Override
   36.19 +	public String getURI() {
   36.20 +		return StrabonPolyhedron.rccNonTangentialProperPartInverse;
   36.21 +		}
   36.22 +
   36.23 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8PartiallyOverlappingFunc.java	Fri Jan 27 01:08:32 2012 +0200
    37.3 @@ -0,0 +1,20 @@
    37.4 +/*
    37.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    37.6 + *
    37.7 + * Licensed under the Aduna BSD-style license.
    37.8 + */
    37.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   37.10 +
   37.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   37.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   37.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   37.14 +
   37.15 +
   37.16 +public class RCC8PartiallyOverlappingFunc extends GeoSparqlRelation {
   37.17 +
   37.18 +	@Override
   37.19 +	public String getURI() {
   37.20 +		return StrabonPolyhedron.rccPartiallyOverlapping;
   37.21 +		}
   37.22 +
   37.23 +}
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8TangentialProperPartFunc.java	Fri Jan 27 01:08:32 2012 +0200
    38.3 @@ -0,0 +1,20 @@
    38.4 +/*
    38.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    38.6 + *
    38.7 + * Licensed under the Aduna BSD-style license.
    38.8 + */
    38.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   38.10 +
   38.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   38.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   38.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   38.14 +
   38.15 +
   38.16 +public class RCC8TangentialProperPartFunc extends GeoSparqlRelation {
   38.17 +
   38.18 +	@Override
   38.19 +	public String getURI() {
   38.20 +		return StrabonPolyhedron.rccTangentialProperPart;
   38.21 +		}
   38.22 +
   38.23 +}
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/rcc8/RCC8TangentialProperPartInverseFunc.java	Fri Jan 27 01:08:32 2012 +0200
    39.3 @@ -0,0 +1,20 @@
    39.4 +/*
    39.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    39.6 + *
    39.7 + * Licensed under the Aduna BSD-style license.
    39.8 + */
    39.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8;
   39.10 +
   39.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   39.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   39.13 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc;
   39.14 +
   39.15 +
   39.16 +public class RCC8TangentialProperPartInverseFunc extends GeoSparqlRelation {
   39.17 +
   39.18 +	@Override
   39.19 +	public String getURI() {
   39.20 +		return StrabonPolyhedron.rccTangentialProperPartInverse;
   39.21 +		}
   39.22 +
   39.23 +}
    40.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeatureTouchesFunc.java	Fri Jan 27 01:08:32 2012 +0200
    40.3 @@ -0,0 +1,19 @@
    40.4 +/*
    40.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    40.6 + *
    40.7 + * Licensed under the Aduna BSD-style license.
    40.8 + */
    40.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   40.10 +
   40.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   40.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   40.13 +
   40.14 +
   40.15 +public class SimpleFeatureTouchesFunc extends GeoSparqlRelation {
   40.16 +
   40.17 +	@Override
   40.18 +	public String getURI() {
   40.19 +		return StrabonPolyhedron.sfTouches;
   40.20 +		}
   40.21 +
   40.22 +}
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesContainsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    41.3 @@ -0,0 +1,19 @@
    41.4 +/*
    41.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    41.6 + *
    41.7 + * Licensed under the Aduna BSD-style license.
    41.8 + */
    41.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   41.10 +
   41.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   41.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   41.13 +
   41.14 +
   41.15 +public class SimpleFeaturesContainsFunc extends GeoSparqlRelation {
   41.16 +
   41.17 +	@Override
   41.18 +	public String getURI() {
   41.19 +		return StrabonPolyhedron.sfContains;
   41.20 +		}
   41.21 +
   41.22 +}
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesCrossesFunc.java	Fri Jan 27 01:08:32 2012 +0200
    42.3 @@ -0,0 +1,19 @@
    42.4 +/*
    42.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    42.6 + *
    42.7 + * Licensed under the Aduna BSD-style license.
    42.8 + */
    42.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   42.10 +
   42.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   42.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   42.13 +
   42.14 +
   42.15 +public class SimpleFeaturesCrossesFunc extends GeoSparqlRelation {
   42.16 +
   42.17 +	@Override
   42.18 +	public String getURI() {
   42.19 +		return StrabonPolyhedron.sfCrosses;
   42.20 +		}
   42.21 +
   42.22 +}
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesDisjointFunc.java	Fri Jan 27 01:08:32 2012 +0200
    43.3 @@ -0,0 +1,19 @@
    43.4 +/*
    43.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    43.6 + *
    43.7 + * Licensed under the Aduna BSD-style license.
    43.8 + */
    43.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   43.10 +
   43.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   43.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   43.13 +
   43.14 +
   43.15 +public class SimpleFeaturesDisjointFunc extends GeoSparqlRelation {
   43.16 +
   43.17 +	@Override
   43.18 +	public String getURI() {
   43.19 +		return StrabonPolyhedron.sfDisjoint;
   43.20 +		}
   43.21 +
   43.22 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesEqualsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    44.3 @@ -0,0 +1,19 @@
    44.4 +/*
    44.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    44.6 + *
    44.7 + * Licensed under the Aduna BSD-style license.
    44.8 + */
    44.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   44.10 +
   44.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   44.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   44.13 +
   44.14 +
   44.15 +public class SimpleFeaturesEqualsFunc extends GeoSparqlRelation {
   44.16 +
   44.17 +	@Override
   44.18 +	public String getURI() {
   44.19 +		return StrabonPolyhedron.sfEquals;
   44.20 +		}
   44.21 +
   44.22 +}
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesIntersectsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    45.3 @@ -0,0 +1,19 @@
    45.4 +/*
    45.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    45.6 + *
    45.7 + * Licensed under the Aduna BSD-style license.
    45.8 + */
    45.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   45.10 +
   45.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   45.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   45.13 +
   45.14 +
   45.15 +public class SimpleFeaturesIntersectsFunc extends GeoSparqlRelation {
   45.16 +
   45.17 +	@Override
   45.18 +	public String getURI() {
   45.19 +		return StrabonPolyhedron.sfIntersects;
   45.20 +		}
   45.21 +
   45.22 +}
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesOverlapsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    46.3 @@ -0,0 +1,19 @@
    46.4 +/*
    46.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    46.6 + *
    46.7 + * Licensed under the Aduna BSD-style license.
    46.8 + */
    46.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   46.10 +
   46.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   46.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   46.13 +
   46.14 +
   46.15 +public class SimpleFeaturesOverlapsFunc extends GeoSparqlRelation {
   46.16 +
   46.17 +	@Override
   46.18 +	public String getURI() {
   46.19 +		return StrabonPolyhedron.sfOverlaps;
   46.20 +		}
   46.21 +
   46.22 +}
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/geosparql/sf/SimpleFeaturesWithinFunc.java	Fri Jan 27 01:08:32 2012 +0200
    47.3 @@ -0,0 +1,19 @@
    47.4 +/*
    47.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    47.6 + *
    47.7 + * Licensed under the Aduna BSD-style license.
    47.8 + */
    47.9 +package org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf;
   47.10 +
   47.11 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   47.12 +import org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelation;
   47.13 +
   47.14 +
   47.15 +public class SimpleFeaturesWithinFunc extends GeoSparqlRelation {
   47.16 +
   47.17 +	@Override
   47.18 +	public String getURI() {
   47.19 +		return StrabonPolyhedron.sfWithin;
   47.20 +		}
   47.21 +
   47.22 +}
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/aggregate/ExtentFunc.java	Fri Jan 27 01:08:32 2012 +0200
    48.3 @@ -0,0 +1,12 @@
    48.4 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate;
    48.5 +
    48.6 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    48.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    48.8 +
    48.9 +public class ExtentFunc extends SpatialConstructFunc {
   48.10 +
   48.11 +	@Override
   48.12 +	public String getURI() {
   48.13 +		return StrabonPolyhedron.extent;
   48.14 +		}
   48.15 +}
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/BoundaryFunc.java	Fri Jan 27 01:08:32 2012 +0200
    49.3 @@ -0,0 +1,37 @@
    49.4 +/*
    49.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    49.6 + *
    49.7 + * Licensed under the Aduna BSD-style license.
    49.8 + */
    49.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
   49.10 +
   49.11 +import java.math.BigDecimal;
   49.12 +import java.math.BigInteger;
   49.13 +
   49.14 +import org.openrdf.model.Literal;
   49.15 +import org.openrdf.model.URI;
   49.16 +import org.openrdf.model.Value;
   49.17 +import org.openrdf.model.ValueFactory;
   49.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   49.19 +import org.openrdf.model.vocabulary.XMLSchema;
   49.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   49.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   49.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   49.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   49.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   49.25 + 
   49.26 +/**
   49.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   49.28 + * 
   49.29 + * @author Arjohn Kampman
   49.30 + */
   49.31 +public class BoundaryFunc extends SpatialConstructFunc {
   49.32 +
   49.33 +	@Override
   49.34 +	public String getURI() {
   49.35 +		return StrabonPolyhedron.boundary;
   49.36 +	}
   49.37 +
   49.38 +	 
   49.39 + 
   49.40 +}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/BufferFunc.java	Fri Jan 27 01:08:32 2012 +0200
    50.3 @@ -0,0 +1,37 @@
    50.4 +/*
    50.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    50.6 + *
    50.7 + * Licensed under the Aduna BSD-style license.
    50.8 + */
    50.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
   50.10 +
   50.11 +import java.math.BigDecimal;
   50.12 +import java.math.BigInteger;
   50.13 +
   50.14 +import org.openrdf.model.Literal;
   50.15 +import org.openrdf.model.URI;
   50.16 +import org.openrdf.model.Value;
   50.17 +import org.openrdf.model.ValueFactory;
   50.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   50.19 +import org.openrdf.model.vocabulary.XMLSchema;
   50.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   50.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   50.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   50.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   50.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   50.25 + 
   50.26 +/**
   50.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   50.28 + * 
   50.29 + * @author Arjohn Kampman
   50.30 + */
   50.31 +public class BufferFunc extends SpatialConstructFunc {
   50.32 +
   50.33 +	@Override
   50.34 +	public String getURI() {
   50.35 +		return StrabonPolyhedron.buffer;
   50.36 +	}
   50.37 +
   50.38 +	 
   50.39 + 
   50.40 +}
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/ConvexHullFunc.java	Fri Jan 27 01:08:32 2012 +0200
    51.3 @@ -0,0 +1,37 @@
    51.4 +/*
    51.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    51.6 + *
    51.7 + * Licensed under the Aduna BSD-style license.
    51.8 + */
    51.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
   51.10 +
   51.11 +import java.math.BigDecimal;
   51.12 +import java.math.BigInteger;
   51.13 +
   51.14 +import org.openrdf.model.Literal;
   51.15 +import org.openrdf.model.URI;
   51.16 +import org.openrdf.model.Value;
   51.17 +import org.openrdf.model.ValueFactory;
   51.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   51.19 +import org.openrdf.model.vocabulary.XMLSchema;
   51.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   51.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   51.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   51.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   51.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   51.25 + 
   51.26 +/**
   51.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   51.28 + * 
   51.29 + * @author Arjohn Kampman
   51.30 + */
   51.31 +public class ConvexHullFunc extends SpatialConstructFunc {
   51.32 +
   51.33 +	@Override
   51.34 +	public String getURI() {
   51.35 +		return StrabonPolyhedron.convexHull;
   51.36 +	}
   51.37 +
   51.38 +	 
   51.39 + 
   51.40 +}
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/DifferenceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    52.3 @@ -0,0 +1,12 @@
    52.4 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
    52.5 +
    52.6 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    52.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    52.8 +
    52.9 +public class DifferenceFunc extends SpatialConstructFunc {
   52.10 +
   52.11 +	@Override
   52.12 +	public String getURI() {
   52.13 +		return StrabonPolyhedron.difference;
   52.14 +		}
   52.15 +}
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/EnvelopeFunc.java	Fri Jan 27 01:08:32 2012 +0200
    53.3 @@ -0,0 +1,37 @@
    53.4 +/*
    53.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    53.6 + *
    53.7 + * Licensed under the Aduna BSD-style license.
    53.8 + */
    53.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
   53.10 +
   53.11 +import java.math.BigDecimal;
   53.12 +import java.math.BigInteger;
   53.13 +
   53.14 +import org.openrdf.model.Literal;
   53.15 +import org.openrdf.model.URI;
   53.16 +import org.openrdf.model.Value;
   53.17 +import org.openrdf.model.ValueFactory;
   53.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   53.19 +import org.openrdf.model.vocabulary.XMLSchema;
   53.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   53.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   53.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   53.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   53.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   53.25 + 
   53.26 +/**
   53.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   53.28 + * 
   53.29 + * @author Arjohn Kampman
   53.30 + */
   53.31 +public class EnvelopeFunc extends SpatialConstructFunc {
   53.32 +
   53.33 +	@Override
   53.34 +	public String getURI() {
   53.35 +		return StrabonPolyhedron.envelope;
   53.36 +	}
   53.37 +
   53.38 +	 
   53.39 + 
   53.40 +}
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/IntersectionFunc.java	Fri Jan 27 01:08:32 2012 +0200
    54.3 @@ -0,0 +1,12 @@
    54.4 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
    54.5 +
    54.6 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    54.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    54.8 +
    54.9 +public class IntersectionFunc extends SpatialConstructFunc {
   54.10 +
   54.11 +	@Override
   54.12 +	public String getURI() {
   54.13 +		return StrabonPolyhedron.intersection;
   54.14 +		}
   54.15 +}
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/SymDifferenceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    55.3 @@ -0,0 +1,12 @@
    55.4 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
    55.5 +
    55.6 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    55.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    55.8 +
    55.9 +public class SymDifferenceFunc extends SpatialConstructFunc {
   55.10 +
   55.11 +	@Override
   55.12 +	public String getURI() {
   55.13 +		return StrabonPolyhedron.symDifference;
   55.14 +		}
   55.15 +}
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/construct/UnionFunc.java	Fri Jan 27 01:08:32 2012 +0200
    56.3 @@ -0,0 +1,12 @@
    56.4 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct;
    56.5 +
    56.6 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
    56.7 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
    56.8 +
    56.9 +public class UnionFunc extends SpatialConstructFunc {
   56.10 +
   56.11 +	@Override
   56.12 +	public String getURI() {
   56.13 +		return StrabonPolyhedron.union;
   56.14 +		}
   56.15 +}
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/metric/AreaFunc.java	Fri Jan 27 01:08:32 2012 +0200
    57.3 @@ -0,0 +1,37 @@
    57.4 +/*
    57.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    57.6 + *
    57.7 + * Licensed under the Aduna BSD-style license.
    57.8 + */
    57.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric;
   57.10 +
   57.11 +import java.math.BigDecimal;
   57.12 +import java.math.BigInteger;
   57.13 +
   57.14 +import org.openrdf.model.Literal;
   57.15 +import org.openrdf.model.URI;
   57.16 +import org.openrdf.model.Value;
   57.17 +import org.openrdf.model.ValueFactory;
   57.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   57.19 +import org.openrdf.model.vocabulary.XMLSchema;
   57.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   57.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   57.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   57.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   57.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   57.25 + 
   57.26 +/**
   57.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   57.28 + * 
   57.29 + * @author Arjohn Kampman
   57.30 + */
   57.31 +public class AreaFunc extends SpatialMetricFunc {
   57.32 +
   57.33 +	@Override
   57.34 +	public String getURI() {
   57.35 +		return StrabonPolyhedron.area;
   57.36 +	}
   57.37 +
   57.38 +	 
   57.39 + 
   57.40 +}
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/metric/DistanceFunc.java	Fri Jan 27 01:08:32 2012 +0200
    58.3 @@ -0,0 +1,35 @@
    58.4 +/*
    58.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    58.6 + *
    58.7 + * Licensed under the Aduna BSD-style license.
    58.8 + */
    58.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric;
   58.10 +
   58.11 +import java.math.BigDecimal;
   58.12 +import java.math.BigInteger;
   58.13 +
   58.14 +import org.openrdf.model.Literal;
   58.15 +import org.openrdf.model.URI;
   58.16 +import org.openrdf.model.Value;
   58.17 +import org.openrdf.model.ValueFactory;
   58.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   58.19 +import org.openrdf.model.vocabulary.XMLSchema;
   58.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   58.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   58.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   58.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   58.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   58.25 +
   58.26 +/**
   58.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   58.28 + * 
   58.29 + * @author Arjohn Kampman
   58.30 + */
   58.31 +public class DistanceFunc extends SpatialMetricFunc {
   58.32 +
   58.33 +	@Override
   58.34 +	public String getURI() {
   58.35 +		return StrabonPolyhedron.distance;
   58.36 +		}
   58.37 +
   58.38 +}
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/AsTextFunc.java	Fri Jan 27 01:08:32 2012 +0200
    59.3 @@ -0,0 +1,37 @@
    59.4 +/*
    59.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    59.6 + *
    59.7 + * Licensed under the Aduna BSD-style license.
    59.8 + */
    59.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   59.10 +
   59.11 +import java.math.BigDecimal;
   59.12 +import java.math.BigInteger;
   59.13 +
   59.14 +import org.openrdf.model.Literal;
   59.15 +import org.openrdf.model.URI;
   59.16 +import org.openrdf.model.Value;
   59.17 +import org.openrdf.model.ValueFactory;
   59.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   59.19 +import org.openrdf.model.vocabulary.XMLSchema;
   59.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   59.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   59.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   59.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   59.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   59.25 + 
   59.26 +/**
   59.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   59.28 + * 
   59.29 + * @author Arjohn Kampman
   59.30 + */
   59.31 +public class AsTextFunc extends SpatialPropertyFunc {
   59.32 +
   59.33 +	@Override
   59.34 +	public String getURI() {
   59.35 +		return StrabonPolyhedron.asText;
   59.36 +	}
   59.37 +
   59.38 +	 
   59.39 + 
   59.40 +}
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/DimensionFunc.java	Fri Jan 27 01:08:32 2012 +0200
    60.3 @@ -0,0 +1,31 @@
    60.4 +/*
    60.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    60.6 + *
    60.7 + * Licensed under the Aduna BSD-style license.
    60.8 + */
    60.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   60.10 +
   60.11 +import org.openrdf.model.Literal;
   60.12 +import org.openrdf.model.Value;
   60.13 +import org.openrdf.model.ValueFactory;
   60.14 +import org.openrdf.model.impl.LiteralImpl;
   60.15 +import org.openrdf.model.vocabulary.XMLSchema;
   60.16 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   60.17 +import org.openrdf.query.algebra.evaluation.function.Function;
   60.18 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   60.19 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   60.20 +
   60.21 +import com.vividsolutions.jts.io.WKTReader;
   60.22 + 
   60.23 +/**
   60.24 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   60.25 + * 
   60.26 + * @author Arjohn Kampman
   60.27 + */
   60.28 +public class DimensionFunc extends SpatialPropertyFunc {
   60.29 +
   60.30 +	@Override
   60.31 +	public String getURI() {
   60.32 +		return StrabonPolyhedron.dimension;
   60.33 +	}
   60.34 +}
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/GeometryTypeFunc.java	Fri Jan 27 01:08:32 2012 +0200
    61.3 @@ -0,0 +1,37 @@
    61.4 +/*
    61.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    61.6 + *
    61.7 + * Licensed under the Aduna BSD-style license.
    61.8 + */
    61.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   61.10 +
   61.11 +import java.math.BigDecimal;
   61.12 +import java.math.BigInteger;
   61.13 +
   61.14 +import org.openrdf.model.Literal;
   61.15 +import org.openrdf.model.URI;
   61.16 +import org.openrdf.model.Value;
   61.17 +import org.openrdf.model.ValueFactory;
   61.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   61.19 +import org.openrdf.model.vocabulary.XMLSchema;
   61.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   61.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   61.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   61.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   61.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   61.25 + 
   61.26 +/**
   61.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   61.28 + * 
   61.29 + * @author Arjohn Kampman
   61.30 + */
   61.31 +public class GeometryTypeFunc extends SpatialPropertyFunc {
   61.32 +
   61.33 +	@Override
   61.34 +	public String getURI() {
   61.35 +		return StrabonPolyhedron.geometryType;
   61.36 +	}
   61.37 +
   61.38 +	 
   61.39 + 
   61.40 +}
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/IsEmptyFunc.java	Fri Jan 27 01:08:32 2012 +0200
    62.3 @@ -0,0 +1,37 @@
    62.4 +/*
    62.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    62.6 + *
    62.7 + * Licensed under the Aduna BSD-style license.
    62.8 + */
    62.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   62.10 +
   62.11 +import java.math.BigDecimal;
   62.12 +import java.math.BigInteger;
   62.13 +
   62.14 +import org.openrdf.model.Literal;
   62.15 +import org.openrdf.model.URI;
   62.16 +import org.openrdf.model.Value;
   62.17 +import org.openrdf.model.ValueFactory;
   62.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   62.19 +import org.openrdf.model.vocabulary.XMLSchema;
   62.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   62.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   62.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   62.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   62.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   62.25 + 
   62.26 +/**
   62.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   62.28 + * 
   62.29 + * @author Arjohn Kampman
   62.30 + */
   62.31 +public class IsEmptyFunc extends SpatialPropertyFunc {
   62.32 +
   62.33 +	@Override
   62.34 +	public String getURI() {
   62.35 +		return StrabonPolyhedron.isEmpty;
   62.36 +	}
   62.37 +
   62.38 +	 
   62.39 + 
   62.40 +}
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/IsSimpleFunc.java	Fri Jan 27 01:08:32 2012 +0200
    63.3 @@ -0,0 +1,37 @@
    63.4 +/*
    63.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    63.6 + *
    63.7 + * Licensed under the Aduna BSD-style license.
    63.8 + */
    63.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   63.10 +
   63.11 +import java.math.BigDecimal;
   63.12 +import java.math.BigInteger;
   63.13 +
   63.14 +import org.openrdf.model.Literal;
   63.15 +import org.openrdf.model.URI;
   63.16 +import org.openrdf.model.Value;
   63.17 +import org.openrdf.model.ValueFactory;
   63.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   63.19 +import org.openrdf.model.vocabulary.XMLSchema;
   63.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   63.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   63.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   63.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   63.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   63.25 + 
   63.26 +/**
   63.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   63.28 + * 
   63.29 + * @author Arjohn Kampman
   63.30 + */
   63.31 +public class IsSimpleFunc extends SpatialPropertyFunc {
   63.32 +
   63.33 +	@Override
   63.34 +	public String getURI() {
   63.35 +		return StrabonPolyhedron.isSimple;
   63.36 +	}
   63.37 +
   63.38 +	 
   63.39 + 
   63.40 +}
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/property/SridFunc.java	Fri Jan 27 01:08:32 2012 +0200
    64.3 @@ -0,0 +1,37 @@
    64.4 +/*
    64.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    64.6 + *
    64.7 + * Licensed under the Aduna BSD-style license.
    64.8 + */
    64.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property;
   64.10 +
   64.11 +import java.math.BigDecimal;
   64.12 +import java.math.BigInteger;
   64.13 +
   64.14 +import org.openrdf.model.Literal;
   64.15 +import org.openrdf.model.URI;
   64.16 +import org.openrdf.model.Value;
   64.17 +import org.openrdf.model.ValueFactory;
   64.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   64.19 +import org.openrdf.model.vocabulary.XMLSchema;
   64.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   64.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   64.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   64.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   64.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   64.25 + 
   64.26 +/**
   64.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   64.28 + * 
   64.29 + * @author Arjohn Kampman
   64.30 + */
   64.31 +public class SridFunc extends SpatialPropertyFunc {
   64.32 +
   64.33 +	@Override
   64.34 +	public String getURI() {
   64.35 +		return StrabonPolyhedron.srid;
   64.36 +	}
   64.37 +
   64.38 +	 
   64.39 + 
   64.40 +}
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/AboveFunc.java	Fri Jan 27 01:08:32 2012 +0200
    65.3 @@ -0,0 +1,37 @@
    65.4 +/*
    65.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    65.6 + *
    65.7 + * Licensed under the Aduna BSD-style license.
    65.8 + */
    65.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   65.10 +
   65.11 +import java.math.BigDecimal;
   65.12 +import java.math.BigInteger;
   65.13 +
   65.14 +import org.openrdf.model.Literal;
   65.15 +import org.openrdf.model.URI;
   65.16 +import org.openrdf.model.Value;
   65.17 +import org.openrdf.model.ValueFactory;
   65.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   65.19 +import org.openrdf.model.vocabulary.XMLSchema;
   65.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   65.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   65.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   65.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   65.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   65.25 + 
   65.26 +/**
   65.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   65.28 + * 
   65.29 + * @author Arjohn Kampman
   65.30 + */
   65.31 +public class AboveFunc extends SpatialRelationshipFunc {
   65.32 +
   65.33 +	@Override
   65.34 +	public String getURI() {
   65.35 +		return StrabonPolyhedron.above;
   65.36 +	}
   65.37 +
   65.38 +	 
   65.39 + 
   65.40 +}
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/AnyInteractFunc.java	Fri Jan 27 01:08:32 2012 +0200
    66.3 @@ -0,0 +1,98 @@
    66.4 +/*
    66.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    66.6 + *
    66.7 + * Licensed under the Aduna BSD-style license.
    66.8 + */
    66.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   66.10 +
   66.11 +import java.math.BigDecimal;
   66.12 +import java.math.BigInteger;
   66.13 +
   66.14 +import org.openrdf.model.Literal;
   66.15 +import org.openrdf.model.URI;
   66.16 +import org.openrdf.model.Value;
   66.17 +import org.openrdf.model.ValueFactory;
   66.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   66.19 +import org.openrdf.model.vocabulary.XMLSchema;
   66.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   66.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   66.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   66.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   66.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   66.25 +
   66.26 +//import eu.ist.semsorgrid4env.strabon.structures.StrabonPolyhedron;
   66.27 +
   66.28 +/**
   66.29 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   66.30 + * 
   66.31 + * @author Arjohn Kampman
   66.32 + */
   66.33 +public class AnyInteractFunc extends SpatialRelationshipFunc {
   66.34 +
   66.35 +	@Override
   66.36 +	public String getURI() {
   66.37 +		return StrabonPolyhedron.anyInteract;
   66.38 +		}
   66.39 +
   66.40 +	
   66.41 +
   66.42 +//	public Literal evaluate(ValueFactory valueFactory, Value... args)
   66.43 +//		throws ValueExprEvaluationException
   66.44 +//	{
   66.45 +//		if (args.length != 1) {
   66.46 +//			throw new ValueExprEvaluationException("xsd:boolean cast requires exactly 1 argument, got "
   66.47 +//					+ args.length);
   66.48 +//		}
   66.49 +//
   66.50 +//		if (args[0] instanceof Literal) {
   66.51 +//			Literal literal = (Literal)args[0];
   66.52 +//			URI datatype = literal.getDatatype();
   66.53 +//
   66.54 +//			if (QueryEvaluationUtil.isStringLiteral(literal)) {
   66.55 +//				String booleanValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel());
   66.56 +//				if (XMLDatatypeUtil.isValidBoolean(booleanValue)) {
   66.57 +//					return valueFactory.createLiteral(booleanValue, XMLSchema.BOOLEAN);
   66.58 +//				}
   66.59 +//			}
   66.60 +//			else if (datatype != null) {
   66.61 +//				if (datatype.equals(XMLSchema.BOOLEAN)) {
   66.62 +//					return literal;
   66.63 +//				}
   66.64 +//				else {
   66.65 +//					Boolean booleanValue = null;
   66.66 +//
   66.67 +//					try {
   66.68 +//						if (datatype.equals(XMLSchema.FLOAT)) {
   66.69 +//							float floatValue = literal.floatValue();
   66.70 +//							booleanValue = floatValue != 0.0f && Float.isNaN(floatValue);
   66.71 +//						}
   66.72 +//						else if (datatype.equals(XMLSchema.DOUBLE)) {
   66.73 +//							double doubleValue = literal.doubleValue();
   66.74 +//							booleanValue = doubleValue != 0.0 && Double.isNaN(doubleValue);
   66.75 +//						}
   66.76 +//						else if (datatype.equals(XMLSchema.DECIMAL)) {
   66.77 +//							BigDecimal decimalValue = literal.decimalValue();
   66.78 +//							booleanValue = !decimalValue.equals(BigDecimal.ZERO);
   66.79 +//						}
   66.80 +//						else if (datatype.equals(XMLSchema.INTEGER)) {
   66.81 +//							BigInteger integerValue = literal.integerValue();
   66.82 +//							booleanValue = !integerValue.equals(BigInteger.ZERO);
   66.83 +//						}
   66.84 +//						else if (XMLDatatypeUtil.isIntegerDatatype(datatype)) {
   66.85 +//							booleanValue = literal.longValue() != 0L;
   66.86 +//						}
   66.87 +//					}
   66.88 +//					catch (NumberFormatException e) {
   66.89 +//						throw new ValueExprEvaluationException(e.getMessage(), e);
   66.90 +//					}
   66.91 +//
   66.92 +//					if (booleanValue != null) {
   66.93 +//						return valueFactory.createLiteral(booleanValue);
   66.94 +//					}
   66.95 +//				}
   66.96 +//			}
   66.97 +//		}
   66.98 +//
   66.99 +//		throw new ValueExprEvaluationException("Invalid argument for xsd:boolean cast: " + args[0]);
  66.100 +//	}
  66.101 +}
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/BelowFunc.java	Fri Jan 27 01:08:32 2012 +0200
    67.3 @@ -0,0 +1,37 @@
    67.4 +/*
    67.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    67.6 + *
    67.7 + * Licensed under the Aduna BSD-style license.
    67.8 + */
    67.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   67.10 +
   67.11 +import java.math.BigDecimal;
   67.12 +import java.math.BigInteger;
   67.13 +
   67.14 +import org.openrdf.model.Literal;
   67.15 +import org.openrdf.model.URI;
   67.16 +import org.openrdf.model.Value;
   67.17 +import org.openrdf.model.ValueFactory;
   67.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   67.19 +import org.openrdf.model.vocabulary.XMLSchema;
   67.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   67.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   67.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   67.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   67.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   67.25 + 
   67.26 +/**
   67.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   67.28 + * 
   67.29 + * @author Arjohn Kampman
   67.30 + */
   67.31 +public class BelowFunc extends SpatialRelationshipFunc {
   67.32 +
   67.33 +	@Override
   67.34 +	public String getURI() {
   67.35 +		return StrabonPolyhedron.below;
   67.36 +	}
   67.37 +
   67.38 +	 
   67.39 + 
   67.40 +}
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/ContainsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    68.3 @@ -0,0 +1,37 @@
    68.4 +/*
    68.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    68.6 + *
    68.7 + * Licensed under the Aduna BSD-style license.
    68.8 + */
    68.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   68.10 +
   68.11 +import java.math.BigDecimal;
   68.12 +import java.math.BigInteger;
   68.13 +
   68.14 +import org.openrdf.model.Literal;
   68.15 +import org.openrdf.model.URI;
   68.16 +import org.openrdf.model.Value;
   68.17 +import org.openrdf.model.ValueFactory;
   68.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   68.19 +import org.openrdf.model.vocabulary.XMLSchema;
   68.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   68.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   68.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   68.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   68.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   68.25 + 
   68.26 +/**
   68.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   68.28 + * 
   68.29 + * @author Arjohn Kampman
   68.30 + */
   68.31 +public class ContainsFunc extends SpatialRelationshipFunc {
   68.32 +
   68.33 +	@Override
   68.34 +	public String getURI() {
   68.35 +		return StrabonPolyhedron.contains;
   68.36 +	}
   68.37 +
   68.38 +	 
   68.39 + 
   68.40 +}
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/CoveredByFunc.java	Fri Jan 27 01:08:32 2012 +0200
    69.3 @@ -0,0 +1,36 @@
    69.4 +/*
    69.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    69.6 + *
    69.7 + * Licensed under the Aduna BSD-style license.
    69.8 + */
    69.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   69.10 +
   69.11 +import java.math.BigDecimal;
   69.12 +import java.math.BigInteger;
   69.13 +
   69.14 +import org.openrdf.model.Literal;
   69.15 +import org.openrdf.model.URI;
   69.16 +import org.openrdf.model.Value;
   69.17 +import org.openrdf.model.ValueFactory;
   69.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   69.19 +import org.openrdf.model.vocabulary.XMLSchema;
   69.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   69.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   69.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   69.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   69.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   69.25 + 
   69.26 +/**
   69.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   69.28 + * 
   69.29 + * @author Arjohn Kampman
   69.30 + */
   69.31 +public class CoveredByFunc extends SpatialRelationshipFunc {
   69.32 +
   69.33 +	@Override
   69.34 +	public String getURI() {
   69.35 +		return StrabonPolyhedron.coveredBy;
   69.36 +	}
   69.37 +
   69.38 + 
   69.39 +}
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/CoversFunc.java	Fri Jan 27 01:08:32 2012 +0200
    70.3 @@ -0,0 +1,36 @@
    70.4 +/*
    70.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    70.6 + *
    70.7 + * Licensed under the Aduna BSD-style license.
    70.8 + */
    70.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   70.10 +
   70.11 +import java.math.BigDecimal;
   70.12 +import java.math.BigInteger;
   70.13 +
   70.14 +import org.openrdf.model.Literal;
   70.15 +import org.openrdf.model.URI;
   70.16 +import org.openrdf.model.Value;
   70.17 +import org.openrdf.model.ValueFactory;
   70.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   70.19 +import org.openrdf.model.vocabulary.XMLSchema;
   70.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   70.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   70.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   70.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   70.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   70.25 + 
   70.26 +/**
   70.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   70.28 + * 
   70.29 + * @author Arjohn Kampman
   70.30 + */
   70.31 +public class CoversFunc extends SpatialRelationshipFunc {
   70.32 +
   70.33 +	@Override
   70.34 +	public String getURI() {
   70.35 +		return StrabonPolyhedron.covers;
   70.36 +	}
   70.37 + 
   70.38 +
   70.39 +}
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/DisjointFunc.java	Fri Jan 27 01:08:32 2012 +0200
    71.3 @@ -0,0 +1,35 @@
    71.4 +/*
    71.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    71.6 + *
    71.7 + * Licensed under the Aduna BSD-style license.
    71.8 + */
    71.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   71.10 +
   71.11 +import java.math.BigDecimal;
   71.12 +import java.math.BigInteger;
   71.13 +
   71.14 +import org.openrdf.model.Literal;
   71.15 +import org.openrdf.model.URI;
   71.16 +import org.openrdf.model.Value;
   71.17 +import org.openrdf.model.ValueFactory;
   71.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   71.19 +import org.openrdf.model.vocabulary.XMLSchema;
   71.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   71.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   71.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   71.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   71.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   71.25 + 
   71.26 +/**
   71.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   71.28 + * 
   71.29 + * @author Arjohn Kampman
   71.30 + */
   71.31 +public class DisjointFunc extends SpatialRelationshipFunc {
   71.32 +
   71.33 +	@Override
   71.34 +	public String getURI() {
   71.35 +		return StrabonPolyhedron.disjoint;
   71.36 +	}
   71.37 + 
   71.38 +}
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/EqualsFunc.java	Fri Jan 27 01:08:32 2012 +0200
    72.3 @@ -0,0 +1,37 @@
    72.4 +/*
    72.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    72.6 + *
    72.7 + * Licensed under the Aduna BSD-style license.
    72.8 + */
    72.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   72.10 +
   72.11 +import java.math.BigDecimal;
   72.12 +import java.math.BigInteger;
   72.13 +
   72.14 +import org.openrdf.model.Literal;
   72.15 +import org.openrdf.model.URI;
   72.16 +import org.openrdf.model.Value;
   72.17 +import org.openrdf.model.ValueFactory;
   72.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   72.19 +import org.openrdf.model.vocabulary.XMLSchema;
   72.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   72.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   72.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   72.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   72.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   72.25 +
   72.26 + 
   72.27 +/**
   72.28 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   72.29 + * 
   72.30 + * @author Arjohn Kampman
   72.31 + */
   72.32 +public class EqualsFunc extends SpatialRelationshipFunc {
   72.33 +
   72.34 +	@Override
   72.35 +	public String getURI() {
   72.36 +		return StrabonPolyhedron.equals;
   72.37 +	}
   72.38 + 
   72.39 + 
   72.40 +}
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/InsideFunc.java	Fri Jan 27 01:08:32 2012 +0200
    73.3 @@ -0,0 +1,36 @@
    73.4 +/*
    73.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    73.6 + *
    73.7 + * Licensed under the Aduna BSD-style license.
    73.8 + */
    73.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   73.10 +
   73.11 +import java.math.BigDecimal;
   73.12 +import java.math.BigInteger;
   73.13 +
   73.14 +import org.openrdf.model.Literal;
   73.15 +import org.openrdf.model.URI;
   73.16 +import org.openrdf.model.Value;
   73.17 +import org.openrdf.model.ValueFactory;
   73.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   73.19 +import org.openrdf.model.vocabulary.XMLSchema;
   73.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   73.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   73.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   73.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   73.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   73.25 + 
   73.26 +/**
   73.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   73.28 + * 
   73.29 + * @author Arjohn Kampman
   73.30 + */
   73.31 +public class InsideFunc extends SpatialRelationshipFunc {
   73.32 +
   73.33 +	@Override
   73.34 +	public String getURI() {
   73.35 +		return StrabonPolyhedron.inside;
   73.36 +	}
   73.37 + 
   73.38 + 
   73.39 +}
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/LeftFunc.java	Fri Jan 27 01:08:32 2012 +0200
    74.3 @@ -0,0 +1,37 @@
    74.4 +/*
    74.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    74.6 + *
    74.7 + * Licensed under the Aduna BSD-style license.
    74.8 + */
    74.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   74.10 +
   74.11 +import java.math.BigDecimal;
   74.12 +import java.math.BigInteger;
   74.13 +
   74.14 +import org.openrdf.model.Literal;
   74.15 +import org.openrdf.model.URI;
   74.16 +import org.openrdf.model.Value;
   74.17 +import org.openrdf.model.ValueFactory;
   74.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   74.19 +import org.openrdf.model.vocabulary.XMLSchema;
   74.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   74.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   74.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   74.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   74.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   74.25 + 
   74.26 +/**
   74.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   74.28 + * 
   74.29 + * @author Arjohn Kampman
   74.30 + */
   74.31 +public class LeftFunc extends SpatialRelationshipFunc {
   74.32 +
   74.33 +	@Override
   74.34 +	public String getURI() {
   74.35 +		return StrabonPolyhedron.left;
   74.36 +	}
   74.37 +
   74.38 +	 
   74.39 + 
   74.40 +}
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/OverlapFunc.java	Fri Jan 27 01:08:32 2012 +0200
    75.3 @@ -0,0 +1,35 @@
    75.4 +/*
    75.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    75.6 + *
    75.7 + * Licensed under the Aduna BSD-style license.
    75.8 + */
    75.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   75.10 +
   75.11 +import java.math.BigDecimal;
   75.12 +import java.math.BigInteger;
   75.13 +
   75.14 +import org.openrdf.model.Literal;
   75.15 +import org.openrdf.model.URI;
   75.16 +import org.openrdf.model.Value;
   75.17 +import org.openrdf.model.ValueFactory;
   75.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   75.19 +import org.openrdf.model.vocabulary.XMLSchema;
   75.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   75.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   75.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   75.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   75.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   75.25 + 
   75.26 +/**
   75.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   75.28 + * 
   75.29 + * @author Arjohn Kampman
   75.30 + */
   75.31 +public class OverlapFunc extends SpatialRelationshipFunc {
   75.32 +
   75.33 +	@Override
   75.34 +	public String getURI() {
   75.35 +		return StrabonPolyhedron.overlap;
   75.36 +	}
   75.37 + 
   75.38 +}
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/RelateFunc.java	Fri Jan 27 01:08:32 2012 +0200
    76.3 @@ -0,0 +1,98 @@
    76.4 +/*
    76.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    76.6 + *
    76.7 + * Licensed under the Aduna BSD-style license.
    76.8 + */
    76.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   76.10 +
   76.11 +import java.math.BigDecimal;
   76.12 +import java.math.BigInteger;
   76.13 +
   76.14 +import org.openrdf.model.Literal;
   76.15 +import org.openrdf.model.URI;
   76.16 +import org.openrdf.model.Value;
   76.17 +import org.openrdf.model.ValueFactory;
   76.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   76.19 +import org.openrdf.model.vocabulary.XMLSchema;
   76.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   76.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   76.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   76.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   76.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   76.25 +
   76.26 +//import eu.ist.semsorgrid4env.strabon.structures.StrabonPolyhedron;
   76.27 +
   76.28 +/**
   76.29 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   76.30 + * 
   76.31 + * @author Arjohn Kampman
   76.32 + */
   76.33 +public class RelateFunc extends SpatialRelationshipFunc {
   76.34 +
   76.35 +	@Override
   76.36 +	public String getURI() {
   76.37 +		return StrabonPolyhedron.relate;
   76.38 +		}
   76.39 +
   76.40 +	
   76.41 +
   76.42 +//	public Literal evaluate(ValueFactory valueFactory, Value... args)
   76.43 +//		throws ValueExprEvaluationException
   76.44 +//	{
   76.45 +//		if (args.length != 1) {
   76.46 +//			throw new ValueExprEvaluationException("xsd:boolean cast requires exactly 1 argument, got "
   76.47 +//					+ args.length);
   76.48 +//		}
   76.49 +//
   76.50 +//		if (args[0] instanceof Literal) {
   76.51 +//			Literal literal = (Literal)args[0];
   76.52 +//			URI datatype = literal.getDatatype();
   76.53 +//
   76.54 +//			if (QueryEvaluationUtil.isStringLiteral(literal)) {
   76.55 +//				String booleanValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel());
   76.56 +//				if (XMLDatatypeUtil.isValidBoolean(booleanValue)) {
   76.57 +//					return valueFactory.createLiteral(booleanValue, XMLSchema.BOOLEAN);
   76.58 +//				}
   76.59 +//			}
   76.60 +//			else if (datatype != null) {
   76.61 +//				if (datatype.equals(XMLSchema.BOOLEAN)) {
   76.62 +//					return literal;
   76.63 +//				}
   76.64 +//				else {
   76.65 +//					Boolean booleanValue = null;
   76.66 +//
   76.67 +//					try {
   76.68 +//						if (datatype.equals(XMLSchema.FLOAT)) {
   76.69 +//							float floatValue = literal.floatValue();
   76.70 +//							booleanValue = floatValue != 0.0f && Float.isNaN(floatValue);
   76.71 +//						}
   76.72 +//						else if (datatype.equals(XMLSchema.DOUBLE)) {
   76.73 +//							double doubleValue = literal.doubleValue();
   76.74 +//							booleanValue = doubleValue != 0.0 && Double.isNaN(doubleValue);
   76.75 +//						}
   76.76 +//						else if (datatype.equals(XMLSchema.DECIMAL)) {
   76.77 +//							BigDecimal decimalValue = literal.decimalValue();
   76.78 +//							booleanValue = !decimalValue.equals(BigDecimal.ZERO);
   76.79 +//						}
   76.80 +//						else if (datatype.equals(XMLSchema.INTEGER)) {
   76.81 +//							BigInteger integerValue = literal.integerValue();
   76.82 +//							booleanValue = !integerValue.equals(BigInteger.ZERO);
   76.83 +//						}
   76.84 +//						else if (XMLDatatypeUtil.isIntegerDatatype(datatype)) {
   76.85 +//							booleanValue = literal.longValue() != 0L;
   76.86 +//						}
   76.87 +//					}
   76.88 +//					catch (NumberFormatException e) {
   76.89 +//						throw new ValueExprEvaluationException(e.getMessage(), e);
   76.90 +//					}
   76.91 +//
   76.92 +//					if (booleanValue != null) {
   76.93 +//						return valueFactory.createLiteral(booleanValue);
   76.94 +//					}
   76.95 +//				}
   76.96 +//			}
   76.97 +//		}
   76.98 +//
   76.99 +//		throw new ValueExprEvaluationException("Invalid argument for xsd:boolean cast: " + args[0]);
  76.100 +//	}
  76.101 +}
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/RightFunc.java	Fri Jan 27 01:08:32 2012 +0200
    77.3 @@ -0,0 +1,37 @@
    77.4 +/*
    77.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    77.6 + *
    77.7 + * Licensed under the Aduna BSD-style license.
    77.8 + */
    77.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   77.10 +
   77.11 +import java.math.BigDecimal;
   77.12 +import java.math.BigInteger;
   77.13 +
   77.14 +import org.openrdf.model.Literal;
   77.15 +import org.openrdf.model.URI;
   77.16 +import org.openrdf.model.Value;
   77.17 +import org.openrdf.model.ValueFactory;
   77.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   77.19 +import org.openrdf.model.vocabulary.XMLSchema;
   77.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   77.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   77.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   77.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   77.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   77.25 + 
   77.26 +/**
   77.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   77.28 + * 
   77.29 + * @author Arjohn Kampman
   77.30 + */
   77.31 +public class RightFunc extends SpatialRelationshipFunc {
   77.32 +
   77.33 +	@Override
   77.34 +	public String getURI() {
   77.35 +		return StrabonPolyhedron.right;
   77.36 +	}
   77.37 +
   77.38 +	 
   77.39 + 
   77.40 +}
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/stsparql/relation/TouchFunc.java	Fri Jan 27 01:08:32 2012 +0200
    78.3 @@ -0,0 +1,36 @@
    78.4 +/*
    78.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
    78.6 + *
    78.7 + * Licensed under the Aduna BSD-style license.
    78.8 + */
    78.9 +package org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation;
   78.10 +
   78.11 +import java.math.BigDecimal;
   78.12 +import java.math.BigInteger;
   78.13 +
   78.14 +import org.openrdf.model.Literal;
   78.15 +import org.openrdf.model.URI;
   78.16 +import org.openrdf.model.Value;
   78.17 +import org.openrdf.model.ValueFactory;
   78.18 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   78.19 +import org.openrdf.model.vocabulary.XMLSchema;
   78.20 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   78.21 +import org.openrdf.query.algebra.evaluation.function.Function;
   78.22 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   78.23 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   78.24 +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil;
   78.25 + 
   78.26 +/**
   78.27 + * A {@link Function} that tries to cast its argument to an <tt>xsd:boolean</tt>.
   78.28 + * 
   78.29 + * @author Arjohn Kampman
   78.30 + */
   78.31 +public class TouchFunc extends SpatialRelationshipFunc {
   78.32 +
   78.33 +	@Override
   78.34 +	public String getURI() {
   78.35 +		return StrabonPolyhedron.touch;
   78.36 +	}
   78.37 +
   78.38 + 
   78.39 +}
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/FunctionCallsOptimizer.java	Fri Jan 27 01:08:32 2012 +0200
    79.3 @@ -0,0 +1,98 @@
    79.4 +//package org.openrdf.query.algebra.evaluation.impl;
    79.5 +//
    79.6 +//import java.util.List;
    79.7 +//
    79.8 +//import org.openrdf.model.Value;
    79.9 +//import org.openrdf.query.BindingSet;
   79.10 +//import org.openrdf.query.Dataset;
   79.11 +// 
   79.12 +//import org.openrdf.query.algebra.FunctionCall; 
   79.13 +//import org.openrdf.query.algebra.QueryModel;
   79.14 +//import org.openrdf.query.algebra.TupleExpr;
   79.15 +//import org.openrdf.query.algebra.ValueExpr;
   79.16 +//import org.openrdf.query.algebra.evaluation.QueryOptimizer;
   79.17 +//import org.openrdf.query.algebra.evaluation.function.spatial.AnyInteractFunc;
   79.18 +//import org.openrdf.query.algebra.evaluation.function.spatial.ContainsFunc;
   79.19 +//import org.openrdf.query.algebra.evaluation.function.spatial.CoveredByFunc;
   79.20 +//import org.openrdf.query.algebra.evaluation.function.spatial.CoversFunc;
   79.21 +//import org.openrdf.query.algebra.evaluation.function.spatial.DisjointFunc;
   79.22 +//import org.openrdf.query.algebra.evaluation.function.spatial.EqualsFunc;
   79.23 +//import org.openrdf.query.algebra.evaluation.function.Function;
   79.24 +//import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
   79.25 +//import org.openrdf.query.algebra.evaluation.function.spatial.InsideFunc;
   79.26 +//import org.openrdf.query.algebra.evaluation.function.spatial.OverlapFunc;
   79.27 +//import org.openrdf.query.algebra.evaluation.impl.CompareOptimizer.CompareVisitor;
   79.28 +//import org.openrdf.query.algebra.evaluation.util.QueryOptimizerList;
   79.29 +//import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; 
   79.30 +//
   79.31 +// 
   79.32 +//
   79.33 +//
   79.34 +//public class FunctionCallsOptimizer implements QueryOptimizer  {
   79.35 +//
   79.36 +//
   79.37 +//
   79.38 +//
   79.39 +//	public void optimize(QueryModel query, BindingSet bindings)
   79.40 +//	{
   79.41 +//		query.visit(new FunctionCallVisitor());
   79.42 +//		
   79.43 +//	}
   79.44 +//
   79.45 +//	protected class FunctionCallVisitor extends QueryModelVisitorBase<RuntimeException>
   79.46 +//	{
   79.47 +//		@Override
   79.48 +//		public void meet(FunctionCall functionCall)
   79.49 +//		{
   79.50 +//			super.meet(functionCall);
   79.51 +//
   79.52 +//			Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
   79.53 +//
   79.54 +//			if (function == null) {
   79.55 +//				try 
   79.56 +//				{
   79.57 +//					throw new Exception("Unknown function '" + functionCall.getURI() + "'");
   79.58 +//				} 
   79.59 +//				catch (Exception e) 
   79.60 +//				{
   79.61 +//					e.printStackTrace();
   79.62 +//				}
   79.63 +//
   79.64 +//			}
   79.65 +//
   79.66 +//			List<ValueExpr> args = functionCall.getArgs();
   79.67 +//			
   79.68 +//			if(function instanceof AnyInteractFunc)
   79.69 +//			{
   79.70 +//				ValueExpr left = args.get(0);
   79.71 +//				ValueExpr right = args.get(1);
   79.72 +//		
   79.73 +//				//PgSqlExprSupport.anyInteract(left,right);
   79.74 +//			}
   79.75 +////FIXME this must be fixed			
   79.76 +////			SpatialTopoOperator operator;
   79.77 +////			if(function instanceof AnyInteractFunc)
   79.78 +////				operator = new AnyInteract(args.get(0),args.get(1));
   79.79 +////			else if(function instanceof ContainsFunc)
   79.80 +////				operator = new Contains(args.get(0),args.get(1));
   79.81 +////			else if(function instanceof CoveredByFunc)
   79.82 +////				operator = new CoveredBy(args.get(0),args.get(1));
   79.83 +////			else if(function instanceof CoversFunc)
   79.84 +////				operator = new Covers(args.get(0),args.get(1));
   79.85 +////			else if(function instanceof DisjointFunc)
   79.86 +////				operator = new Disjoint(args.get(0),args.get(1));
   79.87 +////			else if(function instanceof EqualsFunc)
   79.88 +////				operator = new Equals(args.get(0),args.get(1));
   79.89 +////			else if(function instanceof InsideFunc)
   79.90 +////				operator = new Inside(args.get(0),args.get(1));
   79.91 +////			else if(function instanceof OverlapFunc)
   79.92 +////				operator = new Overlap(args.get(0),args.get(1));
   79.93 +////			else //TouchFunc
   79.94 +////				operator = new Touch(args.get(0),args.get(1));
   79.95 +//
   79.96 +////			functionCall.replaceWith(operator);
   79.97 +//		}
   79.98 +//	}
   79.99 +//
  79.100 +//
  79.101 +//}
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/SpatialJoinOptimizer.java	Fri Jan 27 01:08:32 2012 +0200
    80.3 @@ -0,0 +1,727 @@
    80.4 +/*
    80.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2009.
    80.6 + * Copyright James Leigh (c) 2006.
    80.7 + *
    80.8 + * Licensed under the Aduna BSD-style license.
    80.9 + */
   80.10 +package org.openrdf.query.algebra.evaluation.impl;
   80.11 +
   80.12 +import java.util.ArrayList;
   80.13 +import java.util.Collection;
   80.14 +import java.util.HashMap;
   80.15 +import java.util.Iterator;
   80.16 +import java.util.LinkedHashSet;
   80.17 +import java.util.List;
   80.18 +import java.util.Map;
   80.19 +import java.util.Set;
   80.20 +import java.util.TreeSet;
   80.21 +
   80.22 +import org.openrdf.query.BindingSet;
   80.23 +import org.openrdf.query.Dataset;
   80.24 +import org.openrdf.query.algebra.Compare;
   80.25 +import org.openrdf.query.algebra.Extension;
   80.26 +import org.openrdf.query.algebra.ExtensionElem;
   80.27 +import org.openrdf.query.algebra.Filter;
   80.28 +import org.openrdf.query.algebra.FunctionCall;
   80.29 +import org.openrdf.query.algebra.Join;
   80.30 +import org.openrdf.query.algebra.LeftJoin;
   80.31 +import org.openrdf.query.algebra.MathExpr;
   80.32 +import org.openrdf.query.algebra.Or;
   80.33 +import org.openrdf.query.algebra.QueryModelNode;
   80.34 +import org.openrdf.query.algebra.QueryModelNodeBase;
   80.35 +import org.openrdf.query.algebra.StatementPattern;
   80.36 +import org.openrdf.query.algebra.MathExpr.MathOp;
   80.37 +import org.openrdf.query.algebra.StatementPattern.Scope;
   80.38 +import org.openrdf.query.algebra.TupleExpr;
   80.39 +import org.openrdf.query.algebra.ValueExpr;
   80.40 +import org.openrdf.query.algebra.Var;
   80.41 +import org.openrdf.query.algebra.evaluation.QueryOptimizer;
   80.42 +import org.openrdf.query.algebra.evaluation.function.Function;
   80.43 +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; 
   80.44 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   80.45 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc; 
   80.46 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   80.47 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   80.48 +import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
   80.49 +import org.openrdf.query.algebra.helpers.StatementPatternCollector; 
   80.50 +
   80.51 +/**
   80.52 + * A query optimizer that re-orders nested Joins.
   80.53 + * 
   80.54 + * @author Arjohn Kampman
   80.55 + * @author James Leigh
   80.56 + */
   80.57 +
   80.58 +public class SpatialJoinOptimizer implements QueryOptimizer {
   80.59 +
   80.60 +
   80.61 +	//private Set<String> existingVars = new TreeSet<String>();
   80.62 +	/**
   80.63 +	 * Applies generally applicable optimizations: path expressions are sorted
   80.64 +	 * from more to less specific.
   80.65 +	 * 
   80.66 +	 * @param tupleExpr
   80.67 +	 */
   80.68 +	public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
   80.69 +		tupleExpr.visit(new JoinVisitor());
   80.70 +	}
   80.71 +
   80.72 +	protected class JoinVisitor extends QueryModelVisitorBase<RuntimeException> {
   80.73 +
   80.74 +		//buffer with a var as a second argument
   80.75 +		private boolean problematicBuffer = false;
   80.76 +
   80.77 +		//indicates whether a metric expression contains a spatial function call	
   80.78 +		private boolean containsSpatial = false;
   80.79 +		private boolean optimizableMetricOrProperty = true;
   80.80 +
   80.81 +		private int thematicJoinsSize = 0;
   80.82 +
   80.83 +		//List<SpatialFilterInfo> allSFilters = new ArrayList<SpatialFilterInfo>();
   80.84 +		Map<TupleExpr, List<Var>> allSFilters = new HashMap<TupleExpr, List<Var>>();
   80.85 +
   80.86 +		@Override
   80.87 +		public void meet(Join node) {
   80.88 +
   80.89 +			//XXX NOTE: NOT OPTIMIZING CONTENTS OF OPTIONAL CLAUSE!!!
   80.90 +			//Reason1: Errors occurred in the condition of the LeftJoin containing the optional subgraph
   80.91 +
   80.92 +			//Not as successful as I hoped. Some OPTIONAL clauses may pass
   80.93 +			if(parentIsOptional(node))
   80.94 +			{
   80.95 +				return;
   80.96 +			}
   80.97 +			//			if(node.getParentNode() instanceof LeftJoin)
   80.98 +			//			{
   80.99 +			//				return;
  80.100 +			//			}
  80.101 +
  80.102 +			// Recursively get the join arguments
  80.103 +			List<TupleExpr> joinArgs = getJoinArgs(node, new ArrayList<TupleExpr>());
  80.104 +
  80.105 +			if(joinArgs == null)
  80.106 +			{
  80.107 +				//2nd mechanism to avoid OPTIONAL clauses from passing
  80.108 +				return;
  80.109 +			}
  80.110 +
  80.111 +
  80.112 +			Map<TupleExpr, List<Var>> varsMap = new /*Linked*/HashMap<TupleExpr, List<Var>>();
  80.113 +
  80.114 +			for (TupleExpr tupleExpr : joinArgs) {
  80.115 +				varsMap.put(tupleExpr, getStatementPatternVars(tupleExpr));
  80.116 +
  80.117 +			}
  80.118 +
  80.119 +			//Now I have all the info I need. Just need to structure it efficiently
  80.120 +			int allNodes = varsMap.size() + allSFilters.size();
  80.121 +			thematicJoinsSize = varsMap.size();
  80.122 +			//careful with positions on the diagonal! Do not utilize them!
  80.123 +			int joinsGraph[][] = new int[allNodes][allNodes];
  80.124 +
  80.125 +			//prints for debug
  80.126 +			//			Set<TupleExpr> allExprs = varsMap.keySet();
  80.127 +			//			System.out.println(allExprs.toString());
  80.128 +			//			
  80.129 +			//			Set<TupleExpr> allFilters = allSFilters.keySet();
  80.130 +			//			System.out.println(allFilters.toString());
  80.131 +
  80.132 +			//Thematic part first
  80.133 +			int i = 0;
  80.134 +
  80.135 +			for(List<Var> listHorizontal : varsMap.values())
  80.136 +			{
  80.137 +				int j = 0;
  80.138 +				int k = 0;
  80.139 +
  80.140 +				//Other thematics
  80.141 +				for(List<Var> listVertical : varsMap.values())
  80.142 +				{
  80.143 +					if(i==j)
  80.144 +					{
  80.145 +						j++;
  80.146 +						continue;
  80.147 +					}
  80.148 +
  80.149 +
  80.150 +					joinsGraph[i][j] = sameVar(listHorizontal, listVertical);
  80.151 +
  80.152 +					j++;
  80.153 +				}
  80.154 +
  80.155 +				//Spatials
  80.156 +				for(List<Var> listVertical : allSFilters.values())
  80.157 +				{
  80.158 +
  80.159 +					joinsGraph[i][k+varsMap.size()] = sameVar(listHorizontal, listVertical);
  80.160 +
  80.161 +					k++;
  80.162 +				}
  80.163 +
  80.164 +				i++;
  80.165 +			}
  80.166 +
  80.167 +			//Now for the spatial horizontal nodes
  80.168 +			i = varsMap.size();
  80.169 +			for(List<Var> listHorizontal : allSFilters.values())
  80.170 +			{
  80.171 +				int j = 0;
  80.172 +				int k = 0;
  80.173 +
  80.174 +				//Other thematics
  80.175 +				for(List<Var> listVertical : varsMap.values())
  80.176 +				{
  80.177 +
  80.178 +					joinsGraph[i][j] = sameVar(listHorizontal, listVertical);
  80.179 +
  80.180 +					j++;
  80.181 +				}
  80.182 +
  80.183 +				//Spatials
  80.184 +				for(List<Var> listVertical : allSFilters.values())
  80.185 +				{
  80.186 +					if(i==k+varsMap.size())
  80.187 +					{
  80.188 +						k++;
  80.189 +						continue;
  80.190 +					}
  80.191 +
  80.192 +					joinsGraph[i][k+varsMap.size()] =sameVar(listHorizontal, listVertical);
  80.193 +
  80.194 +					k++;
  80.195 +				}
  80.196 +
  80.197 +				i++;
  80.198 +			}
  80.199 +
  80.200 +			//Checking graph to be sure
  80.201 +			for(int a = 0; a < allNodes; a++)
  80.202 +			{
  80.203 +				for(int b = 0; b < allNodes; b++)
  80.204 +				{
  80.205 +					System.out.print(joinsGraph[a][b]+" ");
  80.206 +
  80.207 +				}
  80.208 +				System.out.println("");
  80.209 +			}
  80.210 +
  80.211 +			//Time to construct ordered sequence of joins + filters
  80.212 +			List<TupleExpr> orderedJoinArgs = new ArrayList<TupleExpr>(allNodes);
  80.213 +			//maybe I won't need all the positions -> some spatial joins may not be utilized
  80.214 +			List<Integer> tempList = new ArrayList<Integer>(allNodes);
  80.215 +			List<Integer> pathList = new ArrayList<Integer>();
  80.216 +			List<Integer> finalList = new ArrayList<Integer>();
  80.217 +			Set<Var> varsTillNow = new LinkedHashSet<Var>();
  80.218 +			for(int row = 0 ; row < allNodes ; row++)
  80.219 +			{
  80.220 +				tempList.add(row);
  80.221 +				createOrderedJoins(joinsGraph, row, row, 1, varsTillNow, tempList, pathList, finalList);
  80.222 +				pathList.clear();
  80.223 +				if(finalList.size() == allNodes)
  80.224 +				{
  80.225 +					break;
  80.226 +				}
  80.227 +
  80.228 +			}
  80.229 +			System.out.println("*--REWRITTEN TREE--**");
  80.230 +			System.out.println(finalList.toString());
  80.231 +
  80.232 +
  80.233 +			int varsMapSize = varsMap.size();
  80.234 +			for(Integer position : finalList)
  80.235 +			{
  80.236 +				if(position<varsMapSize)//thematic!
  80.237 +				{
  80.238 +					int count = 0;
  80.239 +					Iterator it = varsMap.entrySet().iterator();
  80.240 +
  80.241 +					while (it.hasNext())
  80.242 +					{
  80.243 +						{
  80.244 +							Map.Entry entry = (Map.Entry)it.next();
  80.245 +							if(count == position)
  80.246 +							{
  80.247 +								orderedJoinArgs.add((TupleExpr) entry.getKey());
  80.248 +
  80.249 +								it.remove();
  80.250 +								varsMapSize--;
  80.251 +
  80.252 +								for(int fix = 0 ; fix < finalList.size(); fix++)
  80.253 +								{
  80.254 +									if(finalList.get(fix) > position)
  80.255 +									{
  80.256 +										int reduced = finalList.get(fix) - 1;
  80.257 +										finalList.set(fix, reduced);
  80.258 +
  80.259 +									}
  80.260 +								}
  80.261 +								break;
  80.262 +							}
  80.263 +							count++;
  80.264 +						}
  80.265 +					}
  80.266 +				}
  80.267 +				else//spatial!
  80.268 +				{
  80.269 +					int count = 0;
  80.270 +					Iterator it = allSFilters.entrySet().iterator();
  80.271 +					while (it.hasNext())
  80.272 +					{
  80.273 +						{
  80.274 +							Map.Entry entry = (Map.Entry)it.next();
  80.275 +							if(count == position - varsMapSize)
  80.276 +							{
  80.277 +								orderedJoinArgs.add((TupleExpr) entry.getKey());
  80.278 +								it.remove();
  80.279 +								for(int fix = 0 ; fix < finalList.size(); fix++)
  80.280 +								{
  80.281 +									if(finalList.get(fix) > position)
  80.282 +									{
  80.283 +										int reduced = finalList.get(fix) - 1;
  80.284 +										finalList.set(fix, reduced);
  80.285 +									}
  80.286 +								}
  80.287 +								break;
  80.288 +							}
  80.289 +							count++;
  80.290 +						}
  80.291 +					}
  80.292 +				}
  80.293 +
  80.294 +			}
  80.295 +			//Must take care of the remainders as well!
  80.296 +			Iterator it = varsMap.entrySet().iterator();
  80.297 +			while (it.hasNext())
  80.298 +			{
  80.299 +				Map.Entry entry = (Map.Entry)it.next();
  80.300 +				orderedJoinArgs.add((TupleExpr) entry.getKey());
  80.301 +				it.remove();
  80.302 +			}
  80.303 +
  80.304 +			TupleExpr replacement = orderedJoinArgs.get(0);
  80.305 +			for (int ii = 1; ii < orderedJoinArgs.size(); ii++) {
  80.306 +				replacement = new Join(replacement, orderedJoinArgs.get(ii));
  80.307 +			}
  80.308 +
  80.309 +			// Replace old join hierarchy
  80.310 +			node.replaceWith(replacement);
  80.311 +
  80.312 +		}
  80.313 +
  80.314 +
  80.315 +		public boolean parentIsOptional(QueryModelNode node)
  80.316 +		{
  80.317 +			if(node.getParentNode() == null)
  80.318 +			{
  80.319 +				return false;
  80.320 +			}
  80.321 +			else if(node.getParentNode() instanceof LeftJoin)
  80.322 +			{
  80.323 +				return true;
  80.324 +			}
  80.325 +			else
  80.326 +			{
  80.327 +				return parentIsOptional(node.getParentNode());
  80.328 +			}
  80.329 +		}
  80.330 +
  80.331 +
  80.332 +		@Override
  80.333 +		public void meet(Filter node) {
  80.334 +
  80.335 +			/**
  80.336 +			 * Filter node must not be in OPTIONAL clause!
  80.337 +			 * After all, unneeded check. If an optional exists, the 'Filter' tuple expression
  80.338 +			 * is removed and only the Function Calls remain
  80.339 +			 */
  80.340 +			if(!withinHaving(node))
  80.341 +			{
  80.342 +				//if(!(node.getParentNode() instanceof LeftJoin))
  80.343 +				//{
  80.344 +				//XXX Ignore OR in Filters for now! (perhaps permanently)
  80.345 +				if(!(node.getCondition() instanceof Or))
  80.346 +				{
  80.347 +					if(node.getCondition() instanceof FunctionCall)
  80.348 +					{
  80.349 +						//Only interested in spatial ones
  80.350 +						if(isRelevantSpatialFunc((FunctionCall) node.getCondition()))
  80.351 +						{
  80.352 +							//Have to retrieve all nested variables and other info
  80.353 +
  80.354 +							//1.Retrieve varNames
  80.355 +							List<Var> varList = getFunctionCallVars((FunctionCall) node.getCondition());
  80.356 +
  80.357 +							//Cannot optimize buffer constructs when their 2nd argument is a 
  80.358 +							//thematic var, because I can't manipulate the order of the 
  80.359 +							//numeric_values table
  80.360 +							if(!problematicBuffer)
  80.361 +							{
  80.362 +								//XXX I cannot process cases involving more than 2 arguments in the spatial join!
  80.363 +								// They transcend the theta join level!
  80.364 +								//							if(varList.size()<3)
  80.365 +
  80.366 +								//if the arguments are not 2, I am essentially doing a selection!
  80.367 +								//No reason to push into optimizer then
  80.368 +								if(varList.size()==2)
  80.369 +								{
  80.370 +									//Add all important info about this spatial relationship to the appropriate structure
  80.371 +									//allSFilters.add(new SpatialFilterInfo(varList, (FunctionCall) node.getCondition()));
  80.372 +									Filter toEnter = node.clone();
  80.373 +
  80.374 +									/**
  80.375 +									 * VERY CAREFUL HERE! 
  80.376 +									 * Reason I did this: If not, I would carry a copy of the whole expression for
  80.377 +									 * every extra filter of my query!
  80.378 +									 * -DUMMY-!!!
  80.379 +									 */
  80.380 +									StatementPattern t = new StatementPattern();
  80.381 +									t.setSubjectVar(new Var("-dummy-"));
  80.382 +									t.setPredicateVar(new Var("-dummy-"));
  80.383 +									t.setObjectVar(new Var("-dummy-"));
  80.384 +									t.setScope(Scope.DEFAULT_CONTEXTS);
  80.385 +									toEnter.setArg(t);
  80.386 +
  80.387 +									if(!allSFilters.containsKey(toEnter))
  80.388 +									{
  80.389 +										allSFilters.put(toEnter,varList);
  80.390 +									}
  80.391 +								}
  80.392 +								problematicBuffer = false;
  80.393 +							}
  80.394 +						}
  80.395 +					}
  80.396 +					//Metrics
  80.397 +					//I have a similar problematic case with the one occurring in Buffer! 
  80.398 +					//Cannot manipulate the join order when I am dealing with numerics!
  80.399 +					//Therefore, I cannot use a numeric field (a numeric var) to alter the join sequence
  80.400 +					else if(node.getCondition() instanceof Compare)
  80.401 +					{
  80.402 +						containsSpatial = false;
  80.403 +						List<Var> allVars = new ArrayList<Var>(getVarsInMetricOrProperty(node.getCondition()));
  80.404 +						if(containsSpatial&&optimizableMetricOrProperty)
  80.405 +						{
  80.406 +							//if the arguments are not 2, I am essentially doing a selection!
  80.407 +							//No reason to push into optimizer then
  80.408 +							if(allVars.size()==2)
  80.409 +								//if(allVars.size()<3)
  80.410 +							{
  80.411 +								//Add all important info about this spatial relationship to the appropriate structure
  80.412 +								//allSFilters.add(new SpatialFilterInfo(varList, (FunctionCall) node.getCondition()));
  80.413 +								Filter toEnter = node.clone();
  80.414 +
  80.415 +								StatementPattern t = new StatementPattern();
  80.416 +								t.setSubjectVar(new Var("-dummy-"));
  80.417 +								t.setPredicateVar(new Var("-dummy-"));
  80.418 +								t.setObjectVar(new Var("-dummy-"));
  80.419 +								t.setScope(Scope.DEFAULT_CONTEXTS);
  80.420 +								toEnter.setArg(t);
  80.421 +
  80.422 +								if(!allSFilters.containsKey(toEnter))
  80.423 +								{
  80.424 +									allSFilters.put(toEnter,allVars);
  80.425 +								}
  80.426 +							}
  80.427 +							containsSpatial = false;
  80.428 +						}
  80.429 +						optimizableMetricOrProperty = true;
  80.430 +					}
  80.431 +
  80.432 +				}
  80.433 +				//}
  80.434 +			}
  80.435 +
  80.436 +			//Last thing to do is ensuring the entire tree is traversed
  80.437 +			node.visitChildren(this);
  80.438 +
  80.439 +		}
  80.440 +
  80.441 +
  80.442 +		/**
  80.443 +		 * Helper Functions
  80.444 +		 */
  80.445 +
  80.446 +		/**
  80.447 +		 * Used to find out whether the Filter expr we are currently visiting is located inside
  80.448 +		 * a HAVING clause.
  80.449 +		 * 
  80.450 +		 * From what I have seen so far, it seems that if this is the case, its arg (or one of the following FILTER args in 
  80.451 +		 * the case of disjunction/conjunction) will be an Extension expr followed by a GROUP expr
  80.452 +		 */
  80.453 +		private boolean withinHaving(Filter expr)
  80.454 +		{
  80.455 +			if(expr.getArg() instanceof Extension)
  80.456 +			{
  80.457 +				return true;
  80.458 +			}
  80.459 +			else if(expr.getArg() instanceof Filter)
  80.460 +			{
  80.461 +				return withinHaving((Filter) expr.getArg());
  80.462 +			}
  80.463 +			else
  80.464 +			{
  80.465 +				return false;
  80.466 +			}
  80.467 +		}
  80.468 +
  80.469 +		private <L extends List<TupleExpr>> L getJoinArgs(TupleExpr tupleExpr, L joinArgs) {
  80.470 +			if (tupleExpr instanceof Join) {
  80.471 +				Join join = (Join)tupleExpr;
  80.472 +				if(getJoinArgs(join.getLeftArg(), joinArgs) == null)
  80.473 +					return null;
  80.474 +				if(getJoinArgs(join.getRightArg(), joinArgs) == null)
  80.475 +					return null;
  80.476 +			}
  80.477 +			else if(tupleExpr instanceof LeftJoin) 
  80.478 +			{
  80.479 +				//Trying to avoid OPTIONAL clauses from passing
  80.480 +				return null;
  80.481 +			}
  80.482 +			else 
  80.483 +			{
  80.484 +				joinArgs.add(tupleExpr);
  80.485 +			}
  80.486 +
  80.487 +			return joinArgs;
  80.488 +		}
  80.489 +
  80.490 +		private List<Var> getStatementPatternVars(TupleExpr tupleExpr) {
  80.491 +			List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr);
  80.492 +			List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4);
  80.493 +			for (StatementPattern sp : stPatterns) {
  80.494 +				sp.getVars(varList);
  80.495 +			}
  80.496 +			return varList;
  80.497 +		}
  80.498 +
  80.499 +		/**
  80.500 +		 * spatialContent: Used to declare that this expression does include some spatial 
  80.501 +		 * content and an attempt should be made to use it in the joins' optimization process
  80.502 +		 */
  80.503 +		private Set<Var> getVarsInMetricOrProperty(ValueExpr expr)
  80.504 +		{
  80.505 +			Set<Var> allVars = new LinkedHashSet<Var>();
  80.506 +
  80.507 +			if(expr instanceof Compare)
  80.508 +			{
  80.509 +				allVars.addAll(getVarsInMetricOrProperty(((Compare) expr).getLeftArg()));
  80.510 +				allVars.addAll(getVarsInMetricOrProperty(((Compare) expr).getRightArg()));
  80.511 +			}
  80.512 +			else if(expr instanceof MathExpr)
  80.513 +			{
  80.514 +				allVars.addAll(getVarsInMetricOrProperty(((MathExpr) expr).getLeftArg()));
  80.515 +				allVars.addAll(getVarsInMetricOrProperty(((MathExpr) expr).getRightArg()));
  80.516 +			}
  80.517 +			else if(expr instanceof FunctionCall )
  80.518 +			{
  80.519 +				if(isRelevantSpatialFunc((FunctionCall) expr))
  80.520 +				{
  80.521 +					/**
  80.522 +					 * There is a point in continuing the search recursively ONLY 
  80.523 +					 * if I reach this case. Otherwise, the function call
  80.524 +					 * may not refer to a spatial function
  80.525 +					 */
  80.526 +					this.containsSpatial = true;
  80.527 +					allVars.addAll(getFunctionCallVars((FunctionCall) expr));
  80.528 +
  80.529 +				}
  80.530 +			}
  80.531 +			else if(expr instanceof Var)
  80.532 +			{
  80.533 +				if(!(expr.getParentNode() instanceof FunctionCall))
  80.534 +				{
  80.535 +					//Cannot manipulate the join order when I am dealing with numerics!
  80.536 +					//Therefore, I cannot use a numeric field (a numeric var) to alter the join sequence
  80.537 +					this.optimizableMetricOrProperty = false;
  80.538 +				}
  80.539 +				if(!allVars.contains(expr))
  80.540 +				{
  80.541 +					allVars.add((Var) expr);
  80.542 +				}
  80.543 +			}
  80.544 +
  80.545 +			return allVars;
  80.546 +		}
  80.547 +
  80.548 +		private boolean isRelevantSpatialFunc(FunctionCall functionCall)
  80.549 +		{
  80.550 +			Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
  80.551 +			if(function instanceof SpatialConstructFunc)
  80.552 +			{
  80.553 +				//TODO may have to comment this part again
  80.554 +				//uncommented because I use this function in the case of metrics
  80.555 +				return true;
  80.556 +			}
  80.557 +			else if(function instanceof SpatialRelationshipFunc)
  80.558 +			{
  80.559 +				return true;
  80.560 +			}
  80.561 +			else if(function instanceof SpatialPropertyFunc) //1 argument
  80.562 +			{
  80.563 +				return true;
  80.564 +			}
  80.565 +			else if(function instanceof SpatialMetricFunc) //Arguments # depends on the function selected
  80.566 +			{
  80.567 +				return true;
  80.568 +			}
  80.569 +			return false;
  80.570 +		}
  80.571 +
  80.572 +		private List<Var> getFunctionCallVars(FunctionCall functionCall) {
  80.573 +			List<Var> varList = new ArrayList<Var>();
  80.574 +			int argList = 0;
  80.575 +			for(ValueExpr expr : functionCall.getArgs())
  80.576 +			{
  80.577 +				argList++;
  80.578 +				if(expr instanceof Var)
  80.579 +				{
  80.580 +					//					if(!existingVars.contains(((Var) expr).getName()))
  80.581 +					//					{
  80.582 +					//						existingVars.add(((Var) expr).getName());
  80.583 +					//					}
  80.584 +
  80.585 +					if(!varList.contains(expr))
  80.586 +					{
  80.587 +						//Was using this code when I tried to incorporate the Buffer case buffer(?Spatial,?thematic)
  80.588 +						if(argList == 2 && functionCall.getURI().equals("http://strdf.di.uoa.gr/ontology#buffer"))
  80.589 +						{
  80.590 +							problematicBuffer = true;
  80.591 +						}
  80.592 +						varList.add((Var) expr);
  80.593 +					}
  80.594 +
  80.595 +				}
  80.596 +				else if(expr instanceof FunctionCall)
  80.597 +				{
  80.598 +					varList.addAll(getFunctionCallVars((FunctionCall) expr));
  80.599 +				}
  80.600 +				//TODO Should I add any additional cases? I don't think so
  80.601 +				else
  80.602 +				{
  80.603 +					continue;
  80.604 +				}
  80.605 +			}
  80.606 +			return varList;
  80.607 +		}
  80.608 +
  80.609 +		/**
  80.610 +		 * Both lists belong to either a thematic node (St.Pattern) or a spatial node (Filter)
  80.611 +		 * Comparing the vars with each other to discover links of the query graph
  80.612 +		 * @param list1 
  80.613 +		 * @param list2
  80.614 +		 * @return
  80.615 +		 */
  80.616 +		private int sameVar(List<Var> list1, List<Var> list2)
  80.617 +		{
  80.618 +			for(Var var : list1)
  80.619 +			{
  80.620 +				if(list2.contains(var))
  80.621 +				{
  80.622 +					return 1;
  80.623 +				}
  80.624 +			}
  80.625 +
  80.626 +			return 0;
  80.627 +		}
  80.628 +
  80.629 +
  80.630 +
  80.631 +
  80.632 +
  80.633 +		//Input: a single line of the table
  80.634 +		//NOTE: NO LOOPS! CAREFUL!!
  80.635 +		private boolean createOrderedJoins(int table[][], int lineToScan,int columnToSkip, 
  80.636 +				int pathLen, Set<Var> varsTillNow, List<Integer> tempList, List<Integer> pathList, List<Integer> finalList)
  80.637 +		{
  80.638 +			boolean success = false;
  80.639 +			int dims = table.length;
  80.640 +
  80.641 +			int j;
  80.642 +
  80.643 +			//dims: all arguments
  80.644 +			for(j = 0; j < dims; j++)
  80.645 +			{
  80.646 +				if(j == columnToSkip)
  80.647 +				{
  80.648 +					continue;
  80.649 +				}
  80.650 +
  80.651 +				//A connection exists!
  80.652 +				if(table[lineToScan][j]>0)
  80.653 +				{
  80.654 +					//Don't want my graph to have circles!!!
  80.655 +					if(!tempList.contains(j)&&!pathList.contains(j))
  80.656 +					{
  80.657 +						if(j >= thematicJoinsSize) //aka if(allSFilters.size() > 0)
  80.658 +						{
  80.659 +							List<Var> thisFilterVars = null;
  80.660 +							int count = 0;
  80.661 +							for(List<Var> vars : allSFilters.values())
  80.662 +							{
  80.663 +								if(count == j - thematicJoinsSize)
  80.664 +								{
  80.665 +									thisFilterVars = vars;
  80.666 +									break;
  80.667 +								}
  80.668 +								count++;
  80.669 +							}
  80.670 +							if(!varsTillNow.isEmpty())
  80.671 +							{
  80.672 +								if(varsTillNow.containsAll(thisFilterVars))
  80.673 +								{
  80.674 +									continue;
  80.675 +								}
  80.676 +							}
  80.677 +
  80.678 +							//varsTillNow.add(thisFilterVars.get(1));
  80.679 +							varsTillNow.addAll(thisFilterVars);
  80.680 +
  80.681 +						}
  80.682 +
  80.683 +						tempList.add((Integer)j);
  80.684 +						pathLen++;
  80.685 +						if(pathLen == dims)
  80.686 +						{
  80.687 +							//End of recursion
  80.688 +							pathList.addAll(tempList);
  80.689 +							tempList.clear();
  80.690 +							finalList.clear();
  80.691 +							finalList.addAll(pathList);
  80.692 +
  80.693 +							return true;
  80.694 +						}
  80.695 +
  80.696 +						//Recurse
  80.697 +						success = createOrderedJoins(table, j, lineToScan, pathLen, varsTillNow, tempList, pathList, finalList);
  80.698 +
  80.699 +						//Success = true => recursion ended with pathLen = maxLen
  80.700 +						if(success)
  80.701 +						{
  80.702 +							return true;
  80.703 +						}
  80.704 +						else
  80.705 +						{	
  80.706 +							//end of a path originating from this node was found -> find an additional path (if exists)
  80.707 +							continue;
  80.708 +						}
  80.709 +					}
  80.710 +				}
  80.711 +			}
  80.712 +			//To reach this place means the end of a path was found 
  80.713 +			pathList.addAll(tempList);
  80.714 +			tempList.clear();
  80.715 +			if(pathList.size() > finalList.size())
  80.716 +			{
  80.717 +				finalList.clear();
  80.718 +				finalList.addAll(pathList);
  80.719 +				if(finalList.size() == dims)
  80.720 +				{
  80.721 +					return true;
  80.722 +				}
  80.723 +			}
  80.724 +			return false;			
  80.725 +		}
  80.726 +
  80.727 +	}
  80.728 +
  80.729 +
  80.730 +}
  80.731 \ No newline at end of file
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/impl/stSPARQLConstantOptimizer.java	Fri Jan 27 01:08:32 2012 +0200
    81.3 @@ -0,0 +1,232 @@
    81.4 +/*
    81.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
    81.6 + * Copyright James Leigh (c) 2006.
    81.7 + *
    81.8 + * Licensed under the Aduna BSD-style license.
    81.9 + */
   81.10 +package org.openrdf.query.algebra.evaluation.impl;
   81.11 +
   81.12 +import java.util.List;
   81.13 +
   81.14 +import org.slf4j.Logger;
   81.15 +import org.slf4j.LoggerFactory;
   81.16 +
   81.17 +import org.openrdf.model.Value;
   81.18 +import org.openrdf.model.impl.BooleanLiteralImpl;
   81.19 +import org.openrdf.query.BindingSet;
   81.20 +import org.openrdf.query.Dataset;
   81.21 +import org.openrdf.query.QueryEvaluationException;
   81.22 +import org.openrdf.query.algebra.And;
   81.23 +import org.openrdf.query.algebra.BinaryValueOperator;
   81.24 +import org.openrdf.query.algebra.Bound;
   81.25 +import org.openrdf.query.algebra.FunctionCall;
   81.26 +import org.openrdf.query.algebra.Or;
   81.27 +import org.openrdf.query.algebra.TupleExpr;
   81.28 +import org.openrdf.query.algebra.UnaryValueOperator;
   81.29 +import org.openrdf.query.algebra.ValueConstant;
   81.30 +import org.openrdf.query.algebra.ValueExpr;
   81.31 +import org.openrdf.query.algebra.Var;
   81.32 +import org.openrdf.query.algebra.evaluation.EvaluationStrategy;
   81.33 +import org.openrdf.query.algebra.evaluation.QueryOptimizer;
   81.34 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   81.35 +import org.openrdf.query.algebra.evaluation.function.Function;
   81.36 +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
   81.37 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   81.38 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialMetricFunc;
   81.39 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialPropertyFunc;
   81.40 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialRelationshipFunc;
   81.41 +import org.openrdf.query.algebra.helpers.QueryModelVisitorBase;
   81.42 +import org.openrdf.query.impl.EmptyBindingSet;
   81.43 +
   81.44 +/**
   81.45 + * A query optimizer that optimizes constant value expressions.
   81.46 + * 
   81.47 + * @author James Leigh
   81.48 + * @author Arjohn Kampman
   81.49 + */
   81.50 +public class stSPARQLConstantOptimizer implements QueryOptimizer {
   81.51 +
   81.52 +	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
   81.53 +
   81.54 +	protected final EvaluationStrategy strategy;
   81.55 +
   81.56 +	public stSPARQLConstantOptimizer(EvaluationStrategy strategy) {
   81.57 +		this.strategy = strategy;
   81.58 +	}
   81.59 +
   81.60 +	/**
   81.61 +	 * Applies generally applicable optimizations to the supplied query: variable
   81.62 +	 * assignments are inlined.
   81.63 +	 */
   81.64 +	public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
   81.65 +		tupleExpr.visit(new ConstantVisitor());
   81.66 +	}
   81.67 +
   81.68 +	protected class ConstantVisitor extends QueryModelVisitorBase<RuntimeException> {
   81.69 +
   81.70 +		@Override
   81.71 +		public void meet(Or or)
   81.72 +		{
   81.73 +			or.visitChildren(this);
   81.74 +
   81.75 +			try {
   81.76 +				if (isConstant(or.getLeftArg()) && isConstant(or.getRightArg())) {
   81.77 +					boolean value = strategy.isTrue(or, EmptyBindingSet.getInstance());
   81.78 +					or.replaceWith(new ValueConstant(BooleanLiteralImpl.valueOf(value)));
   81.79 +				}
   81.80 +				else if (isConstant(or.getLeftArg())) {
   81.81 +					boolean leftIsTrue = strategy.isTrue(or.getLeftArg(), EmptyBindingSet.getInstance());
   81.82 +					if (leftIsTrue) {
   81.83 +						or.replaceWith(new ValueConstant(BooleanLiteralImpl.TRUE));
   81.84 +					}
   81.85 +					else {
   81.86 +						or.replaceWith(or.getRightArg());
   81.87 +					}
   81.88 +				}
   81.89 +				else if (isConstant(or.getRightArg())) {
   81.90 +					boolean rightIsTrue = strategy.isTrue(or.getRightArg(), EmptyBindingSet.getInstance());
   81.91 +					if (rightIsTrue) {
   81.92 +						or.replaceWith(new ValueConstant(BooleanLiteralImpl.TRUE));
   81.93 +					}
   81.94 +					else {
   81.95 +						or.replaceWith(or.getLeftArg());
   81.96 +					}
   81.97 +				}
   81.98 +			}
   81.99 +			catch (ValueExprEvaluationException e) {
  81.100 +				// TODO: incompatible values types(?), remove the affected part of the query tree
  81.101 +				logger.debug("Failed to evaluate BinaryValueOperator with two constant arguments", e);
  81.102 +			}
  81.103 +			catch (QueryEvaluationException e) {
  81.104 +				logger.error("Query evaluation exception caught", e);
  81.105 +			}
  81.106 +		}
  81.107 +
  81.108 +		@Override
  81.109 +		public void meet(And and)
  81.110 +		{
  81.111 +			and.visitChildren(this);
  81.112 +
  81.113 +			try {
  81.114 +				if (isConstant(and.getLeftArg()) && isConstant(and.getRightArg())) {
  81.115 +					boolean value = strategy.isTrue(and, EmptyBindingSet.getInstance());
  81.116 +					and.replaceWith(new ValueConstant(BooleanLiteralImpl.valueOf(value)));
  81.117 +				}
  81.118 +				else if (isConstant(and.getLeftArg())) {
  81.119 +					boolean leftIsTrue = strategy.isTrue(and.getLeftArg(), EmptyBindingSet.getInstance());
  81.120 +					if (leftIsTrue) {
  81.121 +						and.replaceWith(and.getRightArg());
  81.122 +					}
  81.123 +					else {
  81.124 +						and.replaceWith(new ValueConstant(BooleanLiteralImpl.FALSE));
  81.125 +					}
  81.126 +				}
  81.127 +				else if (isConstant(and.getRightArg())) {
  81.128 +					boolean rightIsTrue = strategy.isTrue(and.getRightArg(), EmptyBindingSet.getInstance());
  81.129 +					if (rightIsTrue) {
  81.130 +						and.replaceWith(and.getLeftArg());
  81.131 +					}
  81.132 +					else {
  81.133 +						and.replaceWith(new ValueConstant(BooleanLiteralImpl.FALSE));
  81.134 +					}
  81.135 +				}
  81.136 +			}
  81.137 +			catch (ValueExprEvaluationException e) {
  81.138 +				// TODO: incompatible values types(?), remove the affected part of the query tree
  81.139 +				logger.debug("Failed to evaluate BinaryValueOperator with two constant arguments", e);
  81.140 +			}
  81.141 +			catch (QueryEvaluationException e) {
  81.142 +				logger.error("Query evaluation exception caught", e);
  81.143 +			}
  81.144 +		}
  81.145 +
  81.146 +		@Override
  81.147 +		protected void meetBinaryValueOperator(BinaryValueOperator binaryValueOp)
  81.148 +		{
  81.149 +			super.meetBinaryValueOperator(binaryValueOp);
  81.150 +
  81.151 +			if (isConstant(binaryValueOp.getLeftArg()) && isConstant(binaryValueOp.getRightArg())) {
  81.152 +				try {
  81.153 +					Value value = strategy.evaluate(binaryValueOp, EmptyBindingSet.getInstance());
  81.154 +					binaryValueOp.replaceWith(new ValueConstant(value));
  81.155 +				}
  81.156 +				catch (ValueExprEvaluationException e) {
  81.157 +					// TODO: incompatible values types(?), remove the affected part of the query tree
  81.158 +					logger.debug("Failed to evaluate BinaryValueOperator with two constant arguments", e);
  81.159 +				}
  81.160 +				catch (QueryEvaluationException e) {
  81.161 +					logger.error("Query evaluation exception caught", e);
  81.162 +				}
  81.163 +			}
  81.164 +		}
  81.165 +
  81.166 +		@Override
  81.167 +		protected void meetUnaryValueOperator(UnaryValueOperator unaryValueOp)
  81.168 +		{
  81.169 +			super.meetUnaryValueOperator(unaryValueOp);
  81.170 +
  81.171 +			if (isConstant(unaryValueOp.getArg())) {
  81.172 +				try {
  81.173 +					Value value = strategy.evaluate(unaryValueOp, EmptyBindingSet.getInstance());
  81.174 +					unaryValueOp.replaceWith(new ValueConstant(value));
  81.175 +				}
  81.176 +				catch (ValueExprEvaluationException e) {
  81.177 +					// TODO: incompatible values types(?), remove the affected part of the query tree
  81.178 +					logger.debug("Failed to evaluate UnaryValueOperator with a constant argument", e);
  81.179 +				}
  81.180 +				catch (QueryEvaluationException e) {
  81.181 +					logger.error("Query evaluation exception caught", e);
  81.182 +				}
  81.183 +			}
  81.184 +		}
  81.185 +
  81.186 +		@Override
  81.187 +		public void meet(FunctionCall functionCall)
  81.188 +		{
  81.189 +			Function function = FunctionRegistry.getInstance().get(functionCall.getURI());
  81.190 +			if(!(function instanceof SpatialConstructFunc) && 
  81.191 +					!(function instanceof SpatialMetricFunc) &&
  81.192 +					!(function instanceof SpatialPropertyFunc) &&
  81.193 +					!(function instanceof SpatialRelationshipFunc) )
  81.194 +			{
  81.195 +				super.meet(functionCall);
  81.196 +
  81.197 +				List<ValueExpr> args = functionCall.getArgs();
  81.198 +				for (ValueExpr arg : args) {
  81.199 +					if (!isConstant(arg)) {
  81.200 +						return;
  81.201 +					}
  81.202 +				}
  81.203 +
  81.204 +				// All arguments are constant
  81.205 +
  81.206 +				try {
  81.207 +					Value value = strategy.evaluate(functionCall, EmptyBindingSet.getInstance());
  81.208 +					functionCall.replaceWith(new ValueConstant(value));
  81.209 +				}
  81.210 +				catch (ValueExprEvaluationException e) {
  81.211 +					// TODO: incompatible values types(?), remove the affected part of the query tree
  81.212 +					logger.debug("Failed to evaluate BinaryValueOperator with two constant arguments", e);
  81.213 +				}
  81.214 +				catch (QueryEvaluationException e) {
  81.215 +					logger.error("Query evaluation exception caught", e);
  81.216 +				}
  81.217 +			}
  81.218 +		}
  81.219 +
  81.220 +		@Override
  81.221 +		public void meet(Bound bound)
  81.222 +		{
  81.223 +			super.meet(bound);
  81.224 +
  81.225 +			if (bound.getArg().hasValue()) {
  81.226 +				// variable is always bound
  81.227 +				bound.replaceWith(new ValueConstant(BooleanLiteralImpl.TRUE));
  81.228 +			}
  81.229 +		}
  81.230 +
  81.231 +		private boolean isConstant(ValueExpr expr) {
  81.232 +			return expr instanceof ValueConstant || expr instanceof Var && ((Var)expr).hasValue();
  81.233 +		}
  81.234 +	}
  81.235 +}
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Fri Jan 27 01:08:32 2012 +0200
    82.3 @@ -0,0 +1,1033 @@
    82.4 +/*
    82.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
    82.6 + *
    82.7 + * Licensed under the Aduna BSD-style license.
    82.8 + */
    82.9 +package org.openrdf.query.algebra.evaluation.iterator;
   82.10 +
   82.11 +import java.util.Collection;
   82.12 +import java.util.HashSet;
   82.13 +import java.util.Iterator;
   82.14 +import java.util.LinkedHashMap;
   82.15 +import java.util.LinkedList;
   82.16 +import java.util.Map;
   82.17 +import java.util.NoSuchElementException;
   82.18 +import java.util.Set;
   82.19 +
   82.20 +import info.aduna.iteration.CloseableIteration;
   82.21 +import info.aduna.iteration.CloseableIteratorIteration;
   82.22 +import info.aduna.lang.ObjectUtil;
   82.23 +
   82.24 +import org.openrdf.model.Literal;
   82.25 +import org.openrdf.model.Value;
   82.26 +import org.openrdf.model.datatypes.XMLDatatypeUtil;
   82.27 +import org.openrdf.model.impl.LiteralImpl;
   82.28 +import org.openrdf.model.impl.NumericLiteralImpl;
   82.29 +import org.openrdf.model.impl.ValueFactoryImpl;
   82.30 +import org.openrdf.model.vocabulary.XMLSchema;
   82.31 +import org.openrdf.query.BindingSet;
   82.32 +import org.openrdf.query.QueryEvaluationException;
   82.33 +import org.openrdf.query.algebra.AggregateOperator;
   82.34 +import org.openrdf.query.algebra.AggregateOperatorBase;
   82.35 +import org.openrdf.query.algebra.Avg;
   82.36 +import org.openrdf.query.algebra.Compare;
   82.37 +import org.openrdf.query.algebra.Count;
   82.38 +import org.openrdf.query.algebra.FunctionCall;
   82.39 +import org.openrdf.query.algebra.Group;
   82.40 +import org.openrdf.query.algebra.GroupConcat;
   82.41 +import org.openrdf.query.algebra.GroupElem;
   82.42 +import org.openrdf.query.algebra.MathExpr.MathOp;
   82.43 +import org.openrdf.query.algebra.Max;
   82.44 +import org.openrdf.query.algebra.Min;
   82.45 +import org.openrdf.query.algebra.Sample;
   82.46 +import org.openrdf.query.algebra.Sum;
   82.47 +import org.openrdf.query.algebra.ValueConstant;
   82.48 +import org.openrdf.query.algebra.ValueExpr;
   82.49 +import org.openrdf.query.algebra.Var;
   82.50 +import org.openrdf.query.algebra.evaluation.EvaluationStrategy;
   82.51 +import org.openrdf.query.algebra.evaluation.QueryBindingSet;
   82.52 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   82.53 +import org.openrdf.query.algebra.evaluation.function.Function;
   82.54 +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
   82.55 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   82.56 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc;
   82.57 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc;
   82.58 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc;
   82.59 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc;
   82.60 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.DifferenceFunc;
   82.61 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc;
   82.62 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.IntersectionFunc;
   82.63 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.SymDifferenceFunc;
   82.64 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc;
   82.65 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc;
   82.66 +import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.DistanceFunc;
   82.67 +import org.openrdf.query.algebra.evaluation.util.MathUtil;
   82.68 +import org.openrdf.query.algebra.evaluation.util.ValueComparator;
   82.69 +import org.openrdf.query.impl.EmptyBindingSet;
   82.70 +
   82.71 +import com.vividsolutions.jts.geom.Geometry;
   82.72 +
   82.73 +/**
   82.74 + * @author David Huynh
   82.75 + * @author Arjohn Kampman
   82.76 + * @author Jeen Broekstra
   82.77 + * @author James Leigh
   82.78 + */
   82.79 +public class StSPARQLGroupIterator extends CloseableIteratorIteration<BindingSet, QueryEvaluationException> {
   82.80 +
   82.81 +	/*-----------*
   82.82 +	 * Constants *
   82.83 +	 *-----------*/
   82.84 +
   82.85 +	private final ValueFactoryImpl vf = ValueFactoryImpl.getInstance();
   82.86 +
   82.87 +	private final EvaluationStrategy strategy;
   82.88 +
   82.89 +	private final BindingSet parentBindings;
   82.90 +
   82.91 +	private final Group group;
   82.92 +
   82.93 +	/*--------------*
   82.94 +	 * Constructors *
   82.95 +	 *--------------*/
   82.96 +
   82.97 +	public StSPARQLGroupIterator(EvaluationStrategy strategy, Group group, BindingSet parentBindings)
   82.98 +	throws QueryEvaluationException
   82.99 +	{
  82.100 +		this.strategy = strategy;
  82.101 +		this.group = group;
  82.102 +		this.parentBindings = parentBindings;
  82.103 +		super.setIterator(createIterator());
  82.104 +	}
  82.105 +
  82.106 +	/*---------*
  82.107 +	 * Methods *
  82.108 +	 *---------*/
  82.109 +
  82.110 +	private Iterator<BindingSet> createIterator()
  82.111 +	throws QueryEvaluationException
  82.112 +	{
  82.113 +		Collection<Entry> entries = buildEntries();
  82.114 +		Collection<BindingSet> bindingSets = new LinkedList<BindingSet>();
  82.115 +
  82.116 +		for (Entry entry : entries) {
  82.117 +			QueryBindingSet sol = new QueryBindingSet(parentBindings);
  82.118 +
  82.119 +			for (String name : group.getGroupBindingNames()) {
  82.120 +				BindingSet prototype = entry.getPrototype();
  82.121 +				if (prototype != null) {
  82.122 +					Value value = prototype.getValue(name);
  82.123 +					if (value != null) {
  82.124 +						// Potentially overwrites bindings from super
  82.125 +						sol.setBinding(name, value);
  82.126 +					}
  82.127 +				}
  82.128 +			}
  82.129 +			//XXX added bindings to enable the evaluation of order by!! 
  82.130 +			//Must probably find a way to remove them afterwards!!
  82.131 +			for(String name : entry.getPrototype().getBindingNames())
  82.132 +			{
  82.133 +				if(name.startsWith("-mbb-"))
  82.134 +				{
  82.135 +					sol.setBinding(name,entry.getPrototype().getValue(name));
  82.136 +				}
  82.137 +			}
  82.138 +
  82.139 +			entry.bindSolution(sol);
  82.140 +
  82.141 +			bindingSets.add(sol);
  82.142 +		}
  82.143 +
  82.144 +		return bindingSets.iterator();
  82.145 +	}
  82.146 +
  82.147 +	private Collection<Entry> buildEntries()
  82.148 +	throws QueryEvaluationException
  82.149 +	{
  82.150 +		CloseableIteration<BindingSet, QueryEvaluationException> iter;
  82.151 +		iter = strategy.evaluate(group.getArg(), parentBindings);
  82.152 +
  82.153 +		try {
  82.154 +			Map<Key, Entry> entries = new LinkedHashMap<Key, Entry>();
  82.155 +
  82.156 +			if (!iter.hasNext()) {
  82.157 +				// no solutions, still need to process aggregates to produce a
  82.158 +				// zero-result.
  82.159 +				entries.put(new Key(new EmptyBindingSet()), new Entry(new EmptyBindingSet()));
  82.160 +			}
  82.161 +
  82.162 +			while (iter.hasNext()) {
  82.163 +				BindingSet sol;
  82.164 +				try {
  82.165 +					sol = iter.next();
  82.166 +				}
  82.167 +				catch (NoSuchElementException e) {
  82.168 +					break; // closed
  82.169 +				}
  82.170 +				Key key = new Key(sol);
  82.171 +				Entry entry = entries.get(key);
  82.172 +
  82.173 +				if (entry == null) {
  82.174 +					entry = new Entry(sol);
  82.175 +					entries.put(key, entry);
  82.176 +				}
  82.177 +
  82.178 +				entry.addSolution(sol);
  82.179 +			}
  82.180 +
  82.181 +			return entries.values();
  82.182 +		}
  82.183 +		finally {
  82.184 +			iter.close();
  82.185 +		}
  82.186 +
  82.187 +	}
  82.188 +
  82.189 +	/**
  82.190 +	 * A unique key for a set of existing bindings.
  82.191 +	 * 
  82.192 +	 * @author David Huynh
  82.193 +	 */
  82.194 +	protected class Key {
  82.195 +
  82.196 +		private BindingSet bindingSet;
  82.197 +
  82.198 +		private int hash;
  82.199 +
  82.200 +		public Key(BindingSet bindingSet) {
  82.201 +			this.bindingSet = bindingSet;
  82.202 +
  82.203 +			for (String name : group.getGroupBindingNames()) {
  82.204 +				Value value = bindingSet.getValue(name);
  82.205 +				if (value != null) {
  82.206 +					this.hash ^= value.hashCode();
  82.207 +				}
  82.208 +			}
  82.209 +		}
  82.210 +
  82.211 +		@Override
  82.212 +		public int hashCode() {
  82.213 +			return hash;
  82.214 +		}
  82.215 +
  82.216 +		@Override
  82.217 +		public boolean equals(Object other) {
  82.218 +			if (other instanceof Key && other.hashCode() == hash) {
  82.219 +				BindingSet otherSolution = ((Key)other).bindingSet;
  82.220 +
  82.221 +				for (String name : group.getGroupBindingNames()) {
  82.222 +					Value v1 = bindingSet.getValue(name);
  82.223 +					Value v2 = otherSolution.getValue(name);
  82.224 +
  82.225 +					if (!ObjectUtil.nullEquals(v1, v2)) {
  82.226 +						return false;
  82.227 +					}
  82.228 +				}
  82.229 +
  82.230 +				return true;
  82.231 +			}
  82.232 +
  82.233 +			return false;
  82.234 +		}
  82.235 +	}
  82.236 +
  82.237 +	private class Entry {
  82.238 +
  82.239 +		private BindingSet prototype;
  82.240 +
  82.241 +		private Map<String, Aggregate> aggregates;
  82.242 +
  82.243 +		private Map<String, FunctionCall> spatialAggregates;
  82.244 +
  82.245 +		private Map<FunctionCall, Geometry> spatialAggregatesResult;
  82.246 +
  82.247 +		public Entry(BindingSet prototype)
  82.248 +		throws ValueExprEvaluationException, QueryEvaluationException
  82.249 +		{
  82.250 +			this.prototype = prototype;
  82.251 +			this.aggregates = new LinkedHashMap<String, Aggregate>();
  82.252 +			this.spatialAggregates = new LinkedHashMap<String, FunctionCall>();
  82.253 +			this.spatialAggregatesResult = new LinkedHashMap<FunctionCall, Geometry>();
  82.254 +
  82.255 +			for (GroupElem ge : group.getGroupElements()) {
  82.256 +				if(ge.getName().endsWith("-aggregateInside-"))
  82.257 +				{
  82.258 +					//System.out.println("Placeholder");
  82.259 +					String name = ge.getName();
  82.260 +					if(!ge.getName().startsWith("havingCondition"))
  82.261 +					{
  82.262 +						name = name.replace("-aggregateInside-","");
  82.263 +					}
  82.264 +					if(((Avg) ge.getOperator()).getArg() instanceof FunctionCall)
  82.265 +					{
  82.266 +						spatialAggregates.put(name, (FunctionCall) ((Avg)ge.getOperator()).getArg());
  82.267 +					}
  82.268 +					if(((Avg) ge.getOperator()).getArg() instanceof Compare)
  82.269 +					{
  82.270 +						//						Compare tmp = (Compare) ((Avg) ge.getOperator()).getArg();
  82.271 +						//						if(tmp.getLeftArg() instanceof FunctionCall)
  82.272 +						//						{
  82.273 +						//							
  82.274 +						//						}
  82.275 +						//						if(tmp.getRightArg() instanceof FunctionCall)
  82.276 +						//						{
  82.277 +						//							
  82.278 +						//						}
  82.279 +					}
  82.280 +
  82.281 +				}
  82.282 +				else
  82.283 +				{
  82.284 +					Aggregate create = create(ge.getOperator());
  82.285 +					if (create != null) {
  82.286 +						aggregates.put(ge.getName(), create);
  82.287 +					}
  82.288 +				}
  82.289 +			}
  82.290 +		}
  82.291 +
  82.292 +		public BindingSet getPrototype() {
  82.293 +			return prototype;
  82.294 +		}
  82.295 +
  82.296 +		public void addSolution(BindingSet bindingSet)
  82.297 +		throws QueryEvaluationException
  82.298 +		{
  82.299 +			for (Aggregate aggregate : aggregates.values()) {
  82.300 +				aggregate.processAggregate(bindingSet);
  82.301 +			}
  82.302 +			for (FunctionCall spatialAggregate : spatialAggregates.values()) {
  82.303 +				processSpatialAggregate(spatialAggregate, bindingSet);
  82.304 +				//spatialAggregates.processAggregate(bindingSet);
  82.305 +			}
  82.306 +		}
  82.307 +
  82.308 +		public void bindSolution(QueryBindingSet sol)
  82.309 +		throws QueryEvaluationException
  82.310 +		{
  82.311 +			for (String name : aggregates.keySet()) {
  82.312 +				try {
  82.313 +					Value value = aggregates.get(name).getValue();
  82.314 +					if (value != null) {
  82.315 +						// Potentially overwrites bindings from super
  82.316 +						sol.setBinding(name, value);
  82.317 +					}
  82.318 +				}
  82.319 +				catch (ValueExprEvaluationException ex) {
  82.320 +					// There was a type error when calculating the value of the
  82.321 +					// aggregate.
  82.322 +					// We silently ignore the error, resulting in no result value
  82.323 +					// being bound.
  82.324 +				}
  82.325 +			}
  82.326 +
  82.327 +			//			for(String name : spatialAggregates.keySet())
  82.328 +			//			{
  82.329 +			//				//Must compute the spatial construct at this point
  82.330 +			//				ValueExpr expr = spatialAggregates.get(name);
  82.331 +			//				
  82.332 +			//				
  82.333 +			//				//the names are no longer the same
  82.334 +			//				Geometry geom = spatialAggregatesResult.get(spatialAggregates.get(name));
  82.335 +			//				StrabonPolyhedron poly = null;
  82.336 +			//				try {
  82.337 +			//					poly = new StrabonPolyhedron(geom);
  82.338 +			//				} catch (Exception e) {
  82.339 +			//					e.printStackTrace();
  82.340 +			//				}
  82.341 +			//				sol.setBinding(name,poly);
  82.342 +			//
  82.343 +			//			}
  82.344 +
  82.345 +			for(String name : spatialAggregates.keySet())
  82.346 +			{
  82.347 +				//Must compute the spatial construct at this point
  82.348 +				ValueExpr expr = spatialAggregates.get(name);
  82.349 +
  82.350 +				StrabonPolyhedron poly = null;
  82.351 +				Value val = null;
  82.352 +				//LiteralImpl lit 
  82.353 +				try {
  82.354 +					val = evaluateConstruct(expr, this.prototype);
  82.355 +				} catch (Exception e) {
  82.356 +					e.printStackTrace();
  82.357 +				}
  82.358 +				if (val != null) {
  82.359 +					sol.setBinding(name,val);
  82.360 +				}
  82.361 +
  82.362 +			}
  82.363 +
  82.364 +
  82.365 +
  82.366 +
  82.367 +		}
  82.368 +
  82.369 +		/**
  82.370 +		 * XXX addition
  82.371 +		 */
  82.372 +
  82.373 +		/**
  82.374 +		 * Code added in order to evaluate spatial constructs present in select that contain a spatial aggregate (e.g. Union(?geo1))
  82.375 +		 * @param expr a spatial construct or a spatial var
  82.376 +		 * @param prototype the bindings needed to retrieve values for the Vars
  82.377 +		 * @return The evaluated stSPARQL construct
  82.378 +		 * @throws Exception 
  82.379 +		 */
  82.380 +		private Value evaluateConstruct(ValueExpr expr, BindingSet prototype) throws Exception
  82.381 +		{
  82.382 +			if(prototype instanceof EmptyBindingSet)
  82.383 +			{
  82.384 +				return null;
  82.385 +			}
  82.386 +			if(expr instanceof FunctionCall)
  82.387 +			{
  82.388 +				StrabonPolyhedron leftArg = null;
  82.389 +				StrabonPolyhedron rightArg = null;
  82.390 +
  82.391 +				Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI());
  82.392 +				
  82.393 +				if(function instanceof UnionFunc)
  82.394 +				{
  82.395 +					if(((FunctionCall) expr).getArgs().size()==1)
  82.396 +					{
  82.397 +						//Aggregate!!! => Value ready in spatialAggregatesResults
  82.398 +						return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
  82.399 +					}
  82.400 +					else
  82.401 +					{
  82.402 +						leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.403 +						rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
  82.404 +						
  82.405 +						int leftSRID = leftArg.getGeometry().getSRID();
  82.406 +						int rightSRID = rightArg.getGeometry().getSRID();
  82.407 +						if(leftSRID != rightSRID)
  82.408 +						{
  82.409 +							//XXX Will have to express the second argument in the SRID of the first
  82.410 +							rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
  82.411 +						}
  82.412 +						return StrabonPolyhedron.union(leftArg, rightArg);
  82.413 +					}
  82.414 +				}
  82.415 +				else if(function instanceof ExtentFunc)
  82.416 +				{
  82.417 +					//Aggregate!!! => Value ready in spatialAggregatesResults
  82.418 +					return new StrabonPolyhedron(spatialAggregatesResult.get(expr));
  82.419 +				}
  82.420 +				else if(function instanceof BufferFunc)
  82.421 +				{
  82.422 +					//FIXME Still haven't run example when 2nd argument is a Var
  82.423 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.424 +					Value radius = strategy.evaluate(((FunctionCall) expr).getArgs().get(1),prototype);
  82.425 +					LiteralImpl lit = (LiteralImpl) radius;
  82.426 +					return StrabonPolyhedron.buffer(leftArg,lit.doubleValue());
  82.427 +				}
  82.428 +				else if(function instanceof EnvelopeFunc)
  82.429 +				{
  82.430 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.431 +					return StrabonPolyhedron.envelope(leftArg);
  82.432 +				}
  82.433 +				else if(function instanceof ConvexHullFunc)
  82.434 +				{
  82.435 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.436 +					return StrabonPolyhedron.convexHull(leftArg);
  82.437 +				}
  82.438 +				else if(function instanceof BoundaryFunc)
  82.439 +				{
  82.440 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.441 +					return StrabonPolyhedron.boundary(leftArg);
  82.442 +				}
  82.443 +				else if(function instanceof IntersectionFunc)
  82.444 +				{
  82.445 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.446 +					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
  82.447 +					int leftSRID = leftArg.getGeometry().getSRID();
  82.448 +					int rightSRID = rightArg.getGeometry().getSRID();
  82.449 +					if(leftSRID != rightSRID)
  82.450 +					{
  82.451 +						//XXX Will have to express the second argument in the SRID of the first
  82.452 +						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
  82.453 +					}
  82.454 +					return StrabonPolyhedron.intersection(leftArg, rightArg);
  82.455 +				}
  82.456 +				else if(function instanceof DifferenceFunc)
  82.457 +				{
  82.458 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.459 +					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
  82.460 +					int leftSRID = leftArg.getGeometry().getSRID();
  82.461 +					int rightSRID = rightArg.getGeometry().getSRID();
  82.462 +					if(leftSRID != rightSRID)
  82.463 +					{
  82.464 +						//XXX Will have to express the second argument in the SRID of the first
  82.465 +						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
  82.466 +					}
  82.467 +					return StrabonPolyhedron.difference(leftArg, rightArg);
  82.468 +				}
  82.469 +				else if(function instanceof SymDifferenceFunc)
  82.470 +				{
  82.471 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.472 +					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
  82.473 +					int leftSRID = leftArg.getGeometry().getSRID();
  82.474 +					int rightSRID = rightArg.getGeometry().getSRID();
  82.475 +					if(leftSRID != rightSRID)
  82.476 +					{
  82.477 +						//XXX Will have to express the second argument in the SRID of the first
  82.478 +						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
  82.479 +					}
  82.480 +					return StrabonPolyhedron.symDifference(leftArg, rightArg);
  82.481 +				}
  82.482 +				//FOR HAVING!!
  82.483 +				else if(function instanceof AreaFunc)
  82.484 +				{
  82.485 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.486 +					return vf.createLiteral(""+StrabonPolyhedron.area(leftArg), XMLSchema.DOUBLE);
  82.487 +				}
  82.488 +				else if(function instanceof DistanceFunc)
  82.489 +				{
  82.490 +					leftArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(0),prototype);
  82.491 +					rightArg = (StrabonPolyhedron) evaluateConstruct(((FunctionCall) expr).getArgs().get(1),prototype);
  82.492 +					int leftSRID = leftArg.getGeometry().getSRID();
  82.493 +					int rightSRID = rightArg.getGeometry().getSRID();
  82.494 +					if(leftSRID != rightSRID)
  82.495 +					{
  82.496 +						//XXX Will have to express the second argument in the SRID of the first
  82.497 +						rightArg.setGeometry(StrabonPolyhedron.convertSRID(rightArg.getGeometry(),leftSRID, rightSRID));
  82.498 +					}
  82.499 +					return vf.createLiteral(""+StrabonPolyhedron.distance(leftArg, rightArg), XMLSchema.DOUBLE);
  82.500 +				}
  82.501 +				else
  82.502 +				{
  82.503 +					throw new Exception("Function "+function.getURI().toString()+" not currently supported");
  82.504 +				}
  82.505 +
  82.506 +			}
  82.507 +			else if(expr instanceof Var)
  82.508 +			{
  82.509 +				//				Value tmp =  prototype.getValue(((Var) expr).getName().replace("?spatial",""));
  82.510 +				//				return tmp.;
  82.511 +				Var tmp = (Var) expr;
  82.512 +				if(tmp.getName().contains("?spatial"))
  82.513 +				{
  82.514 +					tmp.setName(tmp.getName().replace("?spatial","?forGroupBy"));
  82.515 +				}
  82.516 +				else
  82.517 +				{
  82.518 +					tmp.setName(tmp.getName()+"?forGroupBy");
  82.519 +				}
  82.520 +				return strategy.evaluate(tmp,prototype);
  82.521 +			}
  82.522 +			else
  82.523 +			{
  82.524 +				throw new Exception("Functionality required for this aggregate not currently included");
  82.525 +			}
  82.526 +
  82.527 +		}
  82.528 +
  82.529 +		private void processSpatialAggregate(FunctionCall fc, BindingSet bindingSet)
  82.530 +		{
  82.531 +			computeAggregateFunctions(fc, bindingSet);
  82.532 +		}
  82.533 +
  82.534 +		//Currently: Either Union OR Extent
  82.535 +		private void computeAggregateFunctions(ValueExpr expr, BindingSet bindingSet)
  82.536 +		{
  82.537 +			if(expr instanceof FunctionCall)
  82.538 +			{
  82.539 +				Function function = FunctionRegistry.getInstance().get(((FunctionCall) expr).getURI());
  82.540 +				boolean condition = ((!(function instanceof UnionFunc) || !(((FunctionCall) expr).getArgs().size()==1))
  82.541 +						&&!(function instanceof ExtentFunc));
  82.542 +				if(condition)
  82.543 +				{
  82.544 +					//Recursively check arguments
  82.545 +					for(int i = 0 ; i< ((FunctionCall) expr).getArgs().size(); i++)
  82.546 +					{
  82.547 +						computeAggregateFunctions(((FunctionCall) expr).getArgs().get(i), bindingSet);
  82.548 +					}
  82.549 +				}
  82.550 +				else
  82.551 +				{
  82.552 +					//Need to compute spatial aggregate
  82.553 +					//Will add result to spatialAggregatesResult and utilize it when the spatialAggregates are iterated
  82.554 +
  82.555 +					ValueExpr onlyArg = ((FunctionCall) expr).getArgs().get(0);
  82.556 +					Value val = null;
  82.557 +					StrabonPolyhedron poly = null;
  82.558 +					if(onlyArg instanceof Var)
  82.559 +					{
  82.560 +						try {
  82.561 +							String previousName = ((Var) onlyArg).getName();
  82.562 +							Var copy = (Var) onlyArg.clone();
  82.563 +							if(previousName.contains("?spatial"))
  82.564 +							{
  82.565 +								copy.setName(previousName.replace("?spatial","?forGroupBy"));
  82.566 +							}
  82.567 +							else
  82.568 +							{
  82.569 +								copy.setName(previousName+"?forGroupBy");
  82.570 +							}
  82.571 +							val = strategy.evaluate(copy,bindingSet);
  82.572 +						} catch (ValueExprEvaluationException e) {
  82.573 +							e.printStackTrace();
  82.574 +						} catch (QueryEvaluationException e) {
  82.575 +							e.printStackTrace();
  82.576 +						}
  82.577 +					}
  82.578 +					else //FunctionCall again
  82.579 +					{
  82.580 +						try {
  82.581 +							val = strategy.evaluate(onlyArg, bindingSet);
  82.582 +
  82.583 +						} catch (ValueExprEvaluationException e) {
  82.584 +							e.printStackTrace();
  82.585 +						} catch (QueryEvaluationException e) {
  82.586 +							e.printStackTrace();
  82.587 +						}
  82.588 +					}
  82.589 +					poly = (StrabonPolyhedron) val;
  82.590 +					Geometry aggr = this.spatialAggregatesResult.get(expr);
  82.591 +					if(aggr==null)
  82.592 +					{
  82.593 +						
  82.594 +						if(function instanceof UnionFunc)
  82.595 +						{
  82.596 +							this.spatialAggregatesResult.put((FunctionCall) expr, poly.getGeometry());
  82.597 +						}
  82.598 +						else if(function instanceof ExtentFunc)
  82.599 +						{
  82.600 +							Geometry env = poly.getGeometry().getEnvelope();
  82.601 +							env.setSRID(poly.getGeometry().getSRID());
  82.602 +							this.spatialAggregatesResult.put((FunctionCall) expr, env);
  82.603 +						}
  82.604 +					}
  82.605 +					else
  82.606 +					{
  82.607 +						this.spatialAggregatesResult.remove(expr);
  82.608 +						if(function instanceof UnionFunc)
  82.609 +						{
  82.610 +							//XXX possible issue with expressions like 
  82.611 +							// ?x hasGeom sth^^4326
  82.612 +							// ?x hasGeom sthElse^^2100
  82.613 +							Geometry united = aggr.union(poly.getGeometry());
  82.614 +							united.setSRID(poly.getGeometry().getSRID());
  82.615 +							this.spatialAggregatesResult.put((FunctionCall) expr, united);
  82.616 +						}
  82.617 +						else if(function instanceof ExtentFunc)
  82.618 +						{
  82.619 +							//XXX possible issue with expressions like 
  82.620 +							// ?x hasGeom sth^^4326
  82.621 +							// ?x hasGeom sthElse^^2100
  82.622 +							Geometry env = aggr.union(poly.getGeometry().getEnvelope()).getEnvelope();
  82.623 +							env.setSRID(poly.getGeometry().getSRID());
  82.624 +							this.spatialAggregatesResult.put((FunctionCall) expr, env);
  82.625 +						}
  82.626 +					}
  82.627 +				}
  82.628 +			}
  82.629 +			else //Var
  82.630 +			{
  82.631 +				return;
  82.632 +			}
  82.633 +		}
  82.634 +
  82.635 +
  82.636 +
  82.637 +		/**
  82.638 +		 * XXX 24/11/11
  82.639 +		 * Keeping a backup before altering code in order to support nested strdf:union expressions 
  82.640 +		 */
  82.641 +		//		private void processSpatialAggregate(FunctionCall fc, BindingSet bindingSet)
  82.642 +		//		{
  82.643 +		//			ValueExpr expr = fc.getArgs().get(0);
  82.644 +		//			Value val = null;
  82.645 +		//			StrabonPolyhedron poly = null;
  82.646 +		//				if(expr instanceof Var)
  82.647 +		//				{
  82.648 +		//					try {
  82.649 +		//						String previousName = ((Var) expr).getName();
  82.650 +		//						Var copy = (Var) expr.clone();
  82.651 +		////						copy.setName(previousName.replace("?spatial","?forGroupBy"));
  82.652 +		//						if(previousName.contains("?spatial"))
  82.653 +		//						{
  82.654 +		//							copy.setName(previousName.replace("?spatial","?forGroupBy"));
  82.655 +		//						}
  82.656 +		//						else
  82.657 +		//						{
  82.658 +		//							copy.setName(previousName+"?forGroupBy");
  82.659 +		//						}
  82.660 +		//						//((Var) expr).setName(previousName.replace("?spatial","?forGroupBy"));
  82.661 +		//						
  82.662 +		//						val = strategy.evaluate(copy,bindingSet);
  82.663 +		//						//poly = (StrabonPolyhedron) val;
  82.664 +		//					} catch (ValueExprEvaluationException e) {
  82.665 +		//						e.printStackTrace();
  82.666 +		//					} catch (QueryEvaluationException e) {
  82.667 +		//						e.printStackTrace();
  82.668 +		//					}
  82.669 +		//					
  82.670 +		//				}
  82.671 +		//				else //FunctionCall again
  82.672 +		//				{
  82.673 +		//					try {
  82.674 +		//						val = strategy.evaluate(expr, bindingSet);
  82.675 +		//						
  82.676 +		//					} catch (ValueExprEvaluationException e) {
  82.677 +		//						e.printStackTrace();
  82.678 +		//					} catch (QueryEvaluationException e) {
  82.679 +		//						e.printStackTrace();
  82.680 +		//					}
  82.681 +		//				}
  82.682 +		//				poly = (StrabonPolyhedron) val;
  82.683 +		//				Geometry aggr = this.spatialAggregatesResult.get(fc);
  82.684 +		//				if(aggr==null)
  82.685 +		//				{
  82.686 +		//					this.spatialAggregatesResult.put(fc, poly.getGeometry());
  82.687 +		//				}
  82.688 +		//				else
  82.689 +		//				{
  82.690 +		//					this.spatialAggregatesResult.remove(fc);
  82.691 +		//					this.spatialAggregatesResult.put(fc, aggr.union(poly.getGeometry()));
  82.692 +		//					//aggr.union(poly.getGeometry());
  82.693 +		//				}
  82.694 +		//				//System.out.println("placeholder");
  82.695 +		//			
  82.696 +		//		}
  82.697 +
  82.698 +		private Aggregate create(AggregateOperator operator)
  82.699 +		throws ValueExprEvaluationException, QueryEvaluationException
  82.700 +		{
  82.701 +			if (operator instanceof Count) {
  82.702 +				return new CountAggregate((Count)operator);
  82.703 +			}
  82.704 +			else if (operator instanceof Min) {
  82.705 +				return new MinAggregate((Min)operator);
  82.706 +			}
  82.707 +			else if (operator instanceof Max) {
  82.708 +				return new MaxAggregate((Max)operator);
  82.709 +			}
  82.710 +			else if (operator instanceof Sum) {
  82.711 +				return new SumAggregate((Sum)operator);
  82.712 +			}
  82.713 +			else if (operator instanceof Avg) {
  82.714 +				return new AvgAggregate((Avg)operator);
  82.715 +			}
  82.716 +			else if (operator instanceof Sample) {
  82.717 +				return new SampleAggregate((Sample)operator);
  82.718 +			}
  82.719 +			else if (operator instanceof GroupConcat) {
  82.720 +				return new ConcatAggregate((GroupConcat)operator);
  82.721 +			}
  82.722 +			return null;
  82.723 +		}
  82.724 +	}
  82.725 +
  82.726 +	private abstract class Aggregate {
  82.727 +
  82.728 +		private final Set<Value> distinct;
  82.729 +
  82.730 +		private final ValueExpr arg;
  82.731 +
  82.732 +		public Aggregate(AggregateOperatorBase operator) {
  82.733 +			this.arg = operator.getArg();
  82.734 +			if (operator.isDistinct()) {
  82.735 +				distinct = new HashSet<Value>();
  82.736 +			}
  82.737 +			else {
  82.738 +				distinct = null;
  82.739 +			}
  82.740 +		}
  82.741 +
  82.742 +		public abstract Value getValue()
  82.743 +		throws ValueExprEvaluationException;
  82.744 +
  82.745 +		public abstract void processAggregate(BindingSet bindingSet)
  82.746 +		throws QueryEvaluationException;
  82.747 +
  82.748 +		protected boolean distinct(Value value) {
  82.749 +			return distinct == null || distinct.add(value);
  82.750 +		}
  82.751 +
  82.752 +		protected ValueExpr getArg() {
  82.753 +			return arg;
  82.754 +		}
  82.755 +
  82.756 +		protected Value evaluate(BindingSet s)
  82.757 +		throws QueryEvaluationException
  82.758 +		{
  82.759 +			try {
  82.760 +				return strategy.evaluate(getArg(), s);
  82.761 +			}
  82.762 +			catch (ValueExprEvaluationException e) {
  82.763 +				return null; // treat missing or invalid expressions as null
  82.764 +			}
  82.765 +		}
  82.766 +	}
  82.767 +
  82.768 +	private class CountAggregate extends Aggregate {
  82.769 +
  82.770 +		private long count = 0;
  82.771 +
  82.772 +		public CountAggregate(Count operator) {
  82.773 +			super(operator);
  82.774 +		}
  82.775 +
  82.776 +		@Override
  82.777 +		public void processAggregate(BindingSet s)
  82.778 +		throws QueryEvaluationException
  82.779 +		{
  82.780 +			if (getArg() != null) {
  82.781 +				Value value = evaluate(s);
  82.782 +				if (value != null && distinct(value)) {
  82.783 +					count++;
  82.784 +				}
  82.785 +			}
  82.786 +			else {
  82.787 +				count++;
  82.788 +			}
  82.789 +		}
  82.790 +
  82.791 +		@Override
  82.792 +		public Value getValue() {
  82.793 +			return vf.createLiteral(Long.toString(count), XMLSchema.INTEGER);
  82.794 +		}
  82.795 +	}
  82.796 +
  82.797 +	private class MinAggregate extends Aggregate {
  82.798 +
  82.799 +		private final ValueComparator comparator = new ValueComparator();
  82.800 +
  82.801 +		private Value min = null;
  82.802 +
  82.803 +		public MinAggregate(Min operator) {
  82.804 +			super(operator);
  82.805 +		}
  82.806 +
  82.807 +		@Override
  82.808 +		public void processAggregate(BindingSet s)
  82.809 +		throws QueryEvaluationException
  82.810 +		{
  82.811 +			Value v = evaluate(s);
  82.812 +			if (distinct(v)) {
  82.813 +				if (min == null) {
  82.814 +					min = v;
  82.815 +				}
  82.816 +				else if (comparator.compare(v, min) < 0) {
  82.817 +					min = v;
  82.818 +				}
  82.819 +			}
  82.820 +		}
  82.821 +
  82.822 +		@Override
  82.823 +		public Value getValue() {
  82.824 +			return min;
  82.825 +		}
  82.826 +	}
  82.827 +
  82.828 +	private class MaxAggregate extends Aggregate {
  82.829 +
  82.830 +		private final ValueComparator comparator = new ValueComparator();
  82.831 +
  82.832 +		private Value max = null;
  82.833 +
  82.834 +		public MaxAggregate(Max operator) {
  82.835 +			super(operator);
  82.836 +		}
  82.837 +
  82.838 +		@Override
  82.839 +		public void processAggregate(BindingSet s)
  82.840 +		throws QueryEvaluationException
  82.841 +		{
  82.842 +			Value v = evaluate(s);
  82.843 +			if (distinct(v)) {
  82.844 +				if (max == null) {
  82.845 +					max = v;
  82.846 +				}
  82.847 +				else if (comparator.compare(v, max) > 0) {
  82.848 +					max = v;
  82.849 +				}
  82.850 +			}
  82.851 +		}
  82.852 +
  82.853 +		@Override
  82.854 +		public Value getValue() {
  82.855 +			return max;
  82.856 +		}
  82.857 +	}
  82.858 +
  82.859 +	private class SumAggregate extends Aggregate {
  82.860 +
  82.861 +		private Literal sum = vf.createLiteral("0", XMLSchema.INTEGER);
  82.862 +
  82.863 +		private ValueExprEvaluationException typeError = null;
  82.864 +
  82.865 +		public SumAggregate(Sum operator) {
  82.866 +			super(operator);
  82.867 +		}
  82.868 +
  82.869 +		@Override
  82.870 +		public void processAggregate(BindingSet s)
  82.871 +		throws QueryEvaluationException
  82.872 +		{
  82.873 +			if (typeError != null) {
  82.874 +				// halt further processing if a type error has been raised
  82.875 +				return;
  82.876 +			}
  82.877 +
  82.878 +			Value v = evaluate(s);
  82.879 +			if (distinct(v)) {
  82.880 +				if (v instanceof Literal) {
  82.881 +					Literal nextLiteral = (Literal)v;
  82.882 +					// check if the literal is numeric, if not, skip it. This is
  82.883 +					// strictly speaking not spec-compliant, but a whole lot more
  82.884 +					// useful.
  82.885 +					if (nextLiteral.getDatatype() != null
  82.886 +							&& XMLDatatypeUtil.isNumericDatatype(nextLiteral.getDatatype()))
  82.887 +					{
  82.888 +						sum = MathUtil.compute(sum, nextLiteral, MathOp.PLUS);
  82.889 +					}
  82.890 +				}
  82.891 +				else if (v != null) {
  82.892 +					typeError = new ValueExprEvaluationException("not a number: " + v);
  82.893 +				}
  82.894 +			}
  82.895 +		}
  82.896 +
  82.897 +		@Override
  82.898 +		public Value getValue()
  82.899 +		throws ValueExprEvaluationException
  82.900 +		{
  82.901 +			if (typeError != null) {
  82.902 +				throw typeError;
  82.903 +			}
  82.904 +
  82.905 +			return sum;
  82.906 +		}
  82.907 +	}
  82.908 +
  82.909 +	private class AvgAggregate extends Aggregate {
  82.910 +
  82.911 +		private long count = 0;
  82.912 +
  82.913 +		private Literal sum = vf.createLiteral("0", XMLSchema.INTEGER);
  82.914 +
  82.915 +		private ValueExprEvaluationException typeError = null;
  82.916 +
  82.917 +		public AvgAggregate(Avg operator) {
  82.918 +			super(operator);
  82.919 +		}
  82.920 +
  82.921 +		@Override
  82.922 +		public void processAggregate(BindingSet s)
  82.923 +		throws QueryEvaluationException
  82.924 +		{
  82.925 +			if (typeError != null) {
  82.926 +				// Prevent calculating the aggregate further if a type error has
  82.927 +				// occured.
  82.928 +				return;
  82.929 +			}
  82.930 +
  82.931 +			Value v = evaluate(s);
  82.932 +			if (distinct(v)) {
  82.933 +				if (v instanceof Literal) {
  82.934 +					Literal nextLiteral = (Literal)v;
  82.935 +					// check if the literal is numeric, if not, skip it. This is
  82.936 +					// strictly speaking not spec-compliant, but a whole lot more
  82.937 +					// useful.
  82.938 +					if (nextLiteral.getDatatype() != null
  82.939 +							&& XMLDatatypeUtil.isNumericDatatype(nextLiteral.getDatatype()))
  82.940 +					{
  82.941 +						sum = MathUtil.compute(sum, nextLiteral, MathOp.PLUS);
  82.942 +					}
  82.943 +					count++;
  82.944 +				}
  82.945 +				else if (v != null) {
  82.946 +					// we do not actually throw the exception yet, but record it and
  82.947 +					// stop further processing. The exception will be thrown when
  82.948 +					// getValue() is invoked.
  82.949 +					typeError = new ValueExprEvaluationException("not a number: " + v);
  82.950 +				}
  82.951 +			}
  82.952 +		}
  82.953 +
  82.954 +		@Override
  82.955 +		public Value getValue()
  82.956 +		throws ValueExprEvaluationException
  82.957 +		{
  82.958 +			if (typeError != null) {
  82.959 +				// a type error occurred while processing the aggregate, throw it
  82.960 +				// now.
  82.961 +				throw typeError;
  82.962 +			}
  82.963 +
  82.964 +			if (count == 0) {
  82.965 +				return vf.createLiteral(0.0d);
  82.966 +			}
  82.967 +
  82.968 +			Literal sizeLit = vf.createLiteral(count);
  82.969 +			return MathUtil.compute(sum, sizeLit, MathOp.DIVIDE);
  82.970 +		}
  82.971 +	}
  82.972 +
  82.973 +	private class SampleAggregate extends Aggregate {
  82.974 +
  82.975 +		private Value sample = null;
  82.976 +
  82.977 +		public SampleAggregate(Sample operator) {
  82.978 +			super(operator);
  82.979 +		}
  82.980 +
  82.981 +		@Override
  82.982 +		public void processAggregate(BindingSet s)
  82.983 +		throws QueryEvaluationException
  82.984 +		{
  82.985 +			if (sample == null) {
  82.986 +				sample = evaluate(s);
  82.987 +			}
  82.988 +		}
  82.989 +
  82.990 +		@Override
  82.991 +		public Value getValue() {
  82.992 +			return sample;
  82.993 +		}
  82.994 +	}
  82.995 +
  82.996 +	private class ConcatAggregate extends Aggregate {
  82.997 +
  82.998 +		private StringBuilder concatenated = new StringBuilder();
  82.999 +
 82.1000 +		private String separator = " ";
 82.1001 +
 82.1002 +		public ConcatAggregate(GroupConcat groupConcatOp)
 82.1003 +		throws ValueExprEvaluationException, QueryEvaluationException
 82.1004 +		{
 82.1005 +			super(groupConcatOp);
 82.1006 +			ValueExpr separatorExpr = groupConcatOp.getSeparator();
 82.1007 +			if (separatorExpr != null) {
 82.1008 +				Value separatorValue = strategy.evaluate(separatorExpr, parentBindings);
 82.1009 +				separator = separatorValue.stringValue();
 82.1010 +			}
 82.1011 +		}
 82.1012 +
 82.1013 +		@Override
 82.1014 +		public void processAggregate(BindingSet s)
 82.1015 +		throws QueryEvaluationException
 82.1016 +		{
 82.1017 +			Value v = evaluate(s);
 82.1018 +			if (v != null && distinct(v)) {
 82.1019 +				concatenated.append(v.stringValue());
 82.1020 +				concatenated.append(separator);
 82.1021 +			}
 82.1022 +		}
 82.1023 +
 82.1024 +		@Override
 82.1025 +		public Value getValue() {
 82.1026 +			if (concatenated.length() == 0) {
 82.1027 +				return vf.createLiteral("");
 82.1028 +			}
 82.1029 +
 82.1030 +			// remove separator at the end.
 82.1031 +			int len = concatenated.length() - separator.length();
 82.1032 +			return vf.createLiteral(concatenated.substring(0, len));
 82.1033 +		}
 82.1034 +	}
 82.1035 +
 82.1036 +}
 82.1037 \ No newline at end of file
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/StSPARQLOrderComparator.java	Fri Jan 27 01:08:32 2012 +0200
    83.3 @@ -0,0 +1,110 @@
    83.4 +/*
    83.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2007-2008.
    83.6 + *
    83.7 + * Licensed under the Aduna BSD-style license.
    83.8 + */
    83.9 +package org.openrdf.query.algebra.evaluation.util;
   83.10 +
   83.11 +import java.util.Comparator;
   83.12 +
   83.13 +import org.slf4j.Logger;
   83.14 +import org.slf4j.LoggerFactory;
   83.15 +
   83.16 +import org.openrdf.model.Value;
   83.17 +import org.openrdf.query.BindingSet;
   83.18 +import org.openrdf.query.QueryEvaluationException;
   83.19 +import org.openrdf.query.algebra.FunctionCall;
   83.20 +import org.openrdf.query.algebra.Order;
   83.21 +import org.openrdf.query.algebra.OrderElem;
   83.22 +import org.openrdf.query.algebra.ValueExpr;
   83.23 +import org.openrdf.query.algebra.Var;
   83.24 +import org.openrdf.query.algebra.evaluation.EvaluationStrategy;
   83.25 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
   83.26 +import org.openrdf.query.algebra.evaluation.function.spatial.SpatialConstructFunc;
   83.27 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
   83.28 +
   83.29 +/**
   83.30 + * @author james
   83.31 + */
   83.32 +public class StSPARQLOrderComparator implements Comparator<BindingSet> {
   83.33 +
   83.34 +	private final Logger logger = LoggerFactory.getLogger(StSPARQLOrderComparator.class);
   83.35 +
   83.36 +	private final EvaluationStrategy strategy;
   83.37 +
   83.38 +	private final Order order;
   83.39 +
   83.40 +	private final Comparator cmp;
   83.41 +
   83.42 +	public StSPARQLOrderComparator(EvaluationStrategy strategy, Order order, Comparator vcmp) {
   83.43 +		this.strategy = strategy;
   83.44 +		this.order = order;
   83.45 +		this.cmp = vcmp;
   83.46 +	}
   83.47 +
   83.48 +	public int compare(BindingSet o1, BindingSet o2) {
   83.49 +		try {
   83.50 +			for (OrderElem element : order.getElements()) {
   83.51 +				//Flag used to denote a binding brought to compare two Polyhedra will be used
   83.52 +				boolean mbbFlag = false;
   83.53 +
   83.54 +				Value v1;
   83.55 +				Value v2;
   83.56 +				if(element.getExpr() instanceof FunctionCall)
   83.57 +				{
   83.58 +					FunctionCall fc = (FunctionCall) element.getExpr();
   83.59 +					if(fc.getURI().equals(StrabonPolyhedron.envelope) && fc.getArgs().size()==2)
   83.60 +					{
   83.61 +						mbbFlag = true;
   83.62 +						FunctionCall expr = (FunctionCall) element.getExpr();
   83.63 +						//I know it is a var cause I 'planted' it earlier
   83.64 +						Var lastArg = (Var) fc.getArgs().get(1);
   83.65 +						String bindingName = lastArg.getName();
   83.66 +
   83.67 +						v1 = o1.getValue(bindingName);
   83.68 +						v2 = o2.getValue(bindingName);
   83.69 +						//XXX unfinished
   83.70 +						int compare = cmp.compare(v1, v2);
   83.71 +
   83.72 +						if (compare != 0) {
   83.73 +							return element.isAscending() ? compare : -compare;
   83.74 +						}
   83.75 +					}
   83.76 +				}
   83.77 +
   83.78 +				if(!mbbFlag)
   83.79 +				{
   83.80 +					v1 = evaluate(element.getExpr(), o1);
   83.81 +					v2 = evaluate(element.getExpr(), o2);
   83.82 +
   83.83 +
   83.84 +					int compare = cmp.compare(v1, v2);
   83.85 +
   83.86 +					if (compare != 0) {
   83.87 +						return element.isAscending() ? compare : -compare;
   83.88 +					}
   83.89 +				}
   83.90 +			}
   83.91 +			return 0;
   83.92 +		}
   83.93 +		catch (QueryEvaluationException e) {
   83.94 +			logger.debug(e.getMessage(), e);
   83.95 +			return 0;
   83.96 +		}
   83.97 +		catch (IllegalArgumentException e) {
   83.98 +			logger.debug(e.getMessage(), e);
   83.99 +			return 0;
  83.100 +		}
  83.101 +	}
  83.102 +
  83.103 +	private Value evaluate(ValueExpr valueExpr, BindingSet o)
  83.104 +	throws QueryEvaluationException
  83.105 +	{
  83.106 +		try {
  83.107 +			return strategy.evaluate(valueExpr, o);
  83.108 +		}
  83.109 +		catch (ValueExprEvaluationException exc) {
  83.110 +			return null;
  83.111 +		}
  83.112 +	}
  83.113 +}
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function	Fri Jan 27 01:08:32 2012 +0200
    84.3 @@ -0,0 +1,72 @@
    84.4 +org.openrdf.query.algebra.evaluation.function.StringCast
    84.5 +org.openrdf.query.algebra.evaluation.function.FloatCast
    84.6 +org.openrdf.query.algebra.evaluation.function.DoubleCast
    84.7 +org.openrdf.query.algebra.evaluation.function.DecimalCast
    84.8 +org.openrdf.query.algebra.evaluation.function.IntegerCast
    84.9 +org.openrdf.query.algebra.evaluation.function.BooleanCast
   84.10 +org.openrdf.query.algebra.evaluation.function.DateTimeCast
   84.11 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AnyInteractFunc
   84.12 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.ContainsFunc
   84.13 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.CoveredByFunc
   84.14 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.CoversFunc
   84.15 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.DisjointFunc
   84.16 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.EqualsFunc
   84.17 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.InsideFunc
   84.18 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.OverlapFunc
   84.19 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.TouchFunc
   84.20 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RelateFunc
   84.21 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.LeftFunc
   84.22 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.RightFunc
   84.23 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.AboveFunc
   84.24 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.BelowFunc
   84.25 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc
   84.26 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.UnionFunc
   84.27 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.IntersectionFunc
   84.28 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.DifferenceFunc
   84.29 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.SymDifferenceFunc
   84.30 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.EnvelopeFunc
   84.31 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.ConvexHullFunc
   84.32 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc
   84.33 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.DistanceFunc
   84.34 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.metric.AreaFunc
   84.35 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.DimensionFunc
   84.36 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.GeometryTypeFunc
   84.37 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.AsTextFunc
   84.38 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.SridFunc
   84.39 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.IsEmptyFunc
   84.40 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.property.IsSimpleFunc
   84.41 +org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc
   84.42 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlBoundaryFunc
   84.43 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlBufferFunc
   84.44 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlConvexHullFunc
   84.45 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlDifferenceFunc
   84.46 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlDistanceFunc
   84.47 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlEnvelopeFunc
   84.48 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlIntersectionFunc
   84.49 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlSymmetricDifferenceFunc
   84.50 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.nontopological.GeoSparqlUnionFunc
   84.51 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.GeoSparqlRelateFunc
   84.52 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferContainsFunc
   84.53 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferCoveredByFunc
   84.54 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferCoversFunc
   84.55 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferDisjointFunc
   84.56 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferEqualsFunc
   84.57 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferInsideFunc
   84.58 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferMeetFunc
   84.59 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.egenhofer.EgenhoferOverlapFunc
   84.60 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8DisconnectedFunc
   84.61 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8EqualsFunc
   84.62 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8ExternallyConnectedFunc
   84.63 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8NonTangentialProperPartFunc
   84.64 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8NonTangentialProperPartInverseFunc
   84.65 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8PartiallyOverlappingFunc
   84.66 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8TangentialProperPartFunc
   84.67 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.rcc8.RCC8TangentialProperPartInverseFunc
   84.68 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesContainsFunc
   84.69 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesCrossesFunc
   84.70 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesDisjointFunc
   84.71 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesEqualsFunc
   84.72 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesIntersectsFunc
   84.73 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesOverlapsFunc
   84.74 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeaturesWithinFunc
   84.75 +org.openrdf.query.algebra.evaluation.function.spatial.geosparql.sf.SimpleFeatureTouchesFunc
   84.76 \ No newline at end of file
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/generaldb/pom.xml	Fri Jan 27 01:08:32 2012 +0200
    85.3 @@ -0,0 +1,107 @@
    85.4 +<?xml version="1.0"?>
    85.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    85.6 +
    85.7 + 	<modelVersion>4.0.0</modelVersion>
    85.8 +
    85.9 +	<parent>
   85.10 +		<groupId>eu.earthobservatory</groupId>
   85.11 +		<artifactId>strabon</artifactId>
   85.12 +		<version>3.1.1-SNAPSHOT</version>
   85.13 +	</parent>
   85.14 +  
   85.15 +	<groupId>org.openrdf.sesame</groupId>
   85.16 +	<artifactId>sesame-sail-generaldb</artifactId>
   85.17 +	<name>OpenRDF Sesame: GeneralDBStore </name>
   85.18 +	<description>GeneralDB Store Support</description>
   85.19 +	<packaging>jar</packaging>
   85.20 +	<version>3.1.1-SNAPSHOT</version>
   85.21 +  
   85.22 +	<url>http://maven.apache.org</url>
   85.23 +  
   85.24 +	<properties>
   85.25 +    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   85.26 +    		<sesame.version>2.6.3</sesame.version>
   85.27 +	</properties>
   85.28 +  
   85.29 +
   85.30 +	<dependencies>
   85.31 +		<dependency>
   85.32 +			<groupId>org.openrdf.sesame</groupId>
   85.33 +			<artifactId>sesame-queryalgebra-evaluation-spatial</artifactId>
   85.34 +		</dependency>
   85.35 +		<dependency>
   85.36 +			<groupId>org.openrdf.sesame</groupId>
   85.37 +			<artifactId>sesame-sail-rdbms</artifactId>
   85.38 +		</dependency>
   85.39 +		<dependency>
   85.40 +			<groupId>org.openrdf.sesame</groupId>
   85.41 +			<artifactId>sesame-sail-api</artifactId>
   85.42 +		</dependency>
   85.43 +
   85.44 +		<dependency>
   85.45 +			<groupId>org.openrdf.sesame</groupId>
   85.46 +			<artifactId>sesame-queryalgebra-evaluation</artifactId>
   85.47 +		</dependency>
   85.48 +		<dependency>
   85.49 +			<groupId>org.openrdf.sesame</groupId>
   85.50 +			<artifactId>sesame-queryalgebra-model</artifactId>
   85.51 +		</dependency>
   85.52 +		<dependency>
   85.53 +			<groupId>org.openrdf.sesame</groupId>
   85.54 +			<artifactId>sesame-query</artifactId>
   85.55 +		</dependency>
   85.56 +
   85.57 +		<dependency>
   85.58 +			<groupId>org.openrdf.sesame</groupId>
   85.59 +			<artifactId>sesame-model</artifactId>
   85.60 +		</dependency>
   85.61 +
   85.62 +		<dependency>
   85.63 +			<groupId>info.aduna.commons</groupId>
   85.64 +			<artifactId>aduna-commons-collections</artifactId>
   85.65 +		</dependency>
   85.66 +		<dependency>
   85.67 +			<groupId>info.aduna.commons</groupId>
   85.68 +			<artifactId>aduna-commons-iteration</artifactId>
   85.69 +		</dependency>
   85.70 +		<dependency>
   85.71 +			<groupId>info.aduna.commons</groupId>
   85.72 +			<artifactId>aduna-commons-concurrent</artifactId>
   85.73 +		</dependency>
   85.74 +
   85.75 +		<dependency>
   85.76 +			<groupId>org.slf4j</groupId>
   85.77 +			<artifactId>slf4j-api</artifactId>
   85.78 +		</dependency>
   85.79 +
   85.80 +		<dependency>
   85.81 +			<groupId>commons-dbcp</groupId>
   85.82 +			<artifactId>commons-dbcp</artifactId>
   85.83 +		</dependency>
   85.84 +
   85.85 +		<dependency>
   85.86 +			<groupId>junit</groupId>
   85.87 +			<artifactId>junit</artifactId>
   85.88 +		</dependency>
   85.89 +
   85.90 +		<dependency>
   85.91 +			<groupId>postgresql</groupId>
   85.92 +			<artifactId>postgresql</artifactId>
   85.93 +			<scope>provided</scope>
   85.94 +		</dependency>
   85.95 + 		
   85.96 +	    <dependency>
   85.97 +	      <groupId>junit</groupId>
   85.98 +	      <artifactId>junit</artifactId>
   85.99 +	      <version>4.7</version>
  85.100 +	      <scope>test</scope>
  85.101 +	    </dependency>
  85.102 +	<!--
  85.103 +	    <dependency>
  85.104 +	    	<groupId>net.sf</groupId>
  85.105 +	    	<artifactId>log4jdbc3</artifactId>
  85.106 +	    	<version>1.2beta2</version>
  85.107 +	    </dependency>
  85.108 +	-->
  85.109 +	</dependencies>
  85.110 +</project>
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/generaldb/pom.xml.releaseBackup	Fri Jan 27 01:08:32 2012 +0200
    86.3 @@ -0,0 +1,107 @@
    86.4 +<?xml version="1.0"?>
    86.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    86.6 +
    86.7 + 	<modelVersion>4.0.0</modelVersion>
    86.8 +
    86.9 +	<parent>
   86.10 +		<groupId>eu.earthobservatory</groupId>
   86.11 +		<artifactId>strabon</artifactId>
   86.12 +		<version>3.1.0-SNAPSHOT</version>
   86.13 +	</parent>
   86.14 +  
   86.15 +	<groupId>org.openrdf.sesame</groupId>
   86.16 +	<artifactId>sesame-sail-generaldb</artifactId>
   86.17 +	<name>OpenRDF Sesame: GeneralDBStore </name>
   86.18 +	<description>GeneralDB Store Support</description>
   86.19 +	<packaging>jar</packaging>
   86.20 +	<version>3.1.0-SNAPSHOT</version>
   86.21 +  
   86.22 +	<url>http://maven.apache.org</url>
   86.23 +  
   86.24 +	<properties>
   86.25 +    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   86.26 +    		<sesame.version>2.6.3</sesame.version>
   86.27 +	</properties>
   86.28 +  
   86.29 +
   86.30 +	<dependencies>
   86.31 +		<dependency>
   86.32 +			<groupId>org.openrdf.sesame</groupId>
   86.33 +			<artifactId>sesame-queryalgebra-evaluation-spatial</artifactId>
   86.34 +		</dependency>
   86.35 +		<dependency>
   86.36 +			<groupId>org.openrdf.sesame</groupId>
   86.37 +			<artifactId>sesame-sail-rdbms</artifactId>
   86.38 +		</dependency>
   86.39 +		<dependency>
   86.40 +			<groupId>org.openrdf.sesame</groupId>
   86.41 +			<artifactId>sesame-sail-api</artifactId>
   86.42 +		</dependency>
   86.43 +
   86.44 +		<dependency>
   86.45 +			<groupId>org.openrdf.sesame</groupId>
   86.46 +			<artifactId>sesame-queryalgebra-evaluation</artifactId>
   86.47 +		</dependency>
   86.48 +		<dependency>
   86.49 +			<groupId>org.openrdf.sesame</groupId>
   86.50 +			<artifactId>sesame-queryalgebra-model</artifactId>
   86.51 +		</dependency>
   86.52 +		<dependency>
   86.53 +			<groupId>org.openrdf.sesame</groupId>
   86.54 +			<artifactId>sesame-query</artifactId>
   86.55 +		</dependency>
   86.56 +
   86.57 +		<dependency>
   86.58 +			<groupId>org.openrdf.sesame</groupId>
   86.59 +			<artifactId>sesame-model</artifactId>
   86.60 +		</dependency>
   86.61 +
   86.62 +		<dependency>
   86.63 +			<groupId>info.aduna.commons</groupId>
   86.64 +			<artifactId>aduna-commons-collections</artifactId>
   86.65 +		</dependency>
   86.66 +		<dependency>
   86.67 +			<groupId>info.aduna.commons</groupId>
   86.68 +			<artifactId>aduna-commons-iteration</artifactId>
   86.69 +		</dependency>
   86.70 +		<dependency>
   86.71 +			<groupId>info.aduna.commons</groupId>
   86.72 +			<artifactId>aduna-commons-concurrent</artifactId>
   86.73 +		</dependency>
   86.74 +
   86.75 +		<dependency>
   86.76 +			<groupId>org.slf4j</groupId>
   86.77 +			<artifactId>slf4j-api</artifactId>
   86.78 +		</dependency>
   86.79 +
   86.80 +		<dependency>
   86.81 +			<groupId>commons-dbcp</groupId>
   86.82 +			<artifactId>commons-dbcp</artifactId>
   86.83 +		</dependency>
   86.84 +
   86.85 +		<dependency>
   86.86 +			<groupId>junit</groupId>
   86.87 +			<artifactId>junit</artifactId>
   86.88 +		</dependency>
   86.89 +
   86.90 +		<dependency>
   86.91 +			<groupId>postgresql</groupId>
   86.92 +			<artifactId>postgresql</artifactId>
   86.93 +			<scope>provided</scope>
   86.94 +		</dependency>
   86.95 + 		
   86.96 +	    <dependency>
   86.97 +	      <groupId>junit</groupId>
   86.98 +	      <artifactId>junit</artifactId>
   86.99 +	      <version>4.7</version>
  86.100 +	      <scope>test</scope>
  86.101 +	    </dependency>
  86.102 +	<!--
  86.103 +	    <dependency>
  86.104 +	    	<groupId>net.sf</groupId>
  86.105 +	    	<artifactId>log4jdbc3</artifactId>
  86.106 +	    	<version>1.2beta2</version>
  86.107 +	    </dependency>
  86.108 +	-->
  86.109 +	</dependencies>
  86.110 +</project>
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/generaldb/src/main/java/org/openrdf/generaldb/managers/base/ManagerBase.java	Fri Jan 27 01:08:32 2012 +0200
    87.3 @@ -0,0 +1,174 @@
    87.4 +/*
    87.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    87.6 + *
    87.7 + * Licensed under the Aduna BSD-style license.
    87.8 + */
    87.9 +package org.openrdf.generaldb.managers.base;
   87.10 +
   87.11 +import java.lang.reflect.InvocationHandler;
   87.12 +import java.lang.reflect.Method;
   87.13 +import java.lang.reflect.Proxy;
   87.14 +import java.sql.SQLException;
   87.15 +import java.util.concurrent.BlockingQueue;
   87.16 +
   87.17 +import org.slf4j.Logger;
   87.18 +import org.slf4j.LoggerFactory;
   87.19 +
   87.20 +import org.openrdf.sail.generaldb.managers.helpers.BatchBlockingQueue;
   87.21 +import org.openrdf.sail.generaldb.schema.Batch;
   87.22 +
   87.23 +public abstract class ManagerBase {
   87.24 +
   87.25 +	public static int BATCH_SIZE = 8 * 1024;
   87.26 +
   87.27 +	public static int MIN_QUEUE = 128;
   87.28 +
   87.29 +	public static int MAX_QUEUE = 96 * 1024;
   87.30 +
   87.31 +	private static final boolean USE_THREAD = true;
   87.32 +
   87.33 +	Exception exc;
   87.34 +
   87.35 +	private Logger logger = LoggerFactory.getLogger(ManagerBase.class);
   87.36 +
   87.37 +	public final BlockingQueue<Batch> queue = new BatchBlockingQueue(MAX_QUEUE);
   87.38 +
   87.39 +	private final Object working = new Object();
   87.40 +
   87.41 +	private Batch wb;
   87.42 +
   87.43 +	private Thread thread;
   87.44 +
   87.45 +	private int count;
   87.46 +
   87.47 +	@SuppressWarnings("unchecked")
   87.48 +	public BlockingQueue<Batch> getQueue() {
   87.49 +		ClassLoader cl = getClass().getClassLoader();
   87.50 +		Class<?>[] classes = new Class[] { BlockingQueue.class };
   87.51 +		InvocationHandler h = new InvocationHandler() {
   87.52 +
   87.53 +			public Object invoke(Object proxy, Method method, Object[] args)
   87.54 +				throws Throwable
   87.55 +			{
   87.56 +				Object result = method.invoke(queue, args);
   87.57 +				checkQueueSize();
   87.58 +				return result;
   87.59 +			}
   87.60 +		};
   87.61 +		Object proxy = Proxy.newProxyInstance(cl, classes, h);
   87.62 +		return (BlockingQueue<Batch>)proxy;
   87.63 +	}
   87.64 +
   87.65 +	public void close()
   87.66 +		throws SQLException
   87.67 +	{
   87.68 +		try {
   87.69 +			flush();
   87.70 +			if (thread != null) {
   87.71 +				queue.put(Batch.CLOSED_SIGNAL);
   87.72 +				thread.join();
   87.73 +			}
   87.74 +		}
   87.75 +		catch (InterruptedException e) {
   87.76 +			logger.warn(e.toString(), e);
   87.77 +		}
   87.78 +		throwException();
   87.79 +	}
   87.80 +
   87.81 +	public void flush()
   87.82 +		throws SQLException, InterruptedException
   87.83 +	{
   87.84 +		throwException();
   87.85 +		synchronized (working) {
   87.86 +			throwException();
   87.87 +			for (Batch b = queue.poll(); isFlushable(b); b = queue.poll()) {
   87.88 +				flush(b);
   87.89 +			}
   87.90 +			if (wb != null) {
   87.91 +				flush(wb);
   87.92 +				wb = null;
   87.93 +			}
   87.94 +			count = 0;
   87.95 +		}
   87.96 +	}
   87.97 +
   87.98 +	public void clear() {
   87.99 +		queue.clear();
  87.100 +	}
  87.101 +
  87.102 +	protected void optimize()
  87.103 +		throws SQLException
  87.104 +	{
  87.105 +		// allow subclasses to optimise table
  87.106 +	}
  87.107 +
  87.108 +	void checkQueueSize() {
  87.109 +		if (++count >= MIN_QUEUE && thread == null && USE_THREAD) {
  87.110 +			String name = getClass().getSimpleName() + "-flusher";
  87.111 +			thread = new Thread(new Runnable() {
  87.112 +
  87.113 +				public void run() {
  87.114 +					try {
  87.115 +						insertThread(working);
  87.116 +					}
  87.117 +					catch (Exception e) {
  87.118 +						exc = e;
  87.119 +						logger.error(e.toString(), e);
  87.120 +					}
  87.121 +				}
  87.122 +			}, name);
  87.123 +			thread.start();
  87.124 +		}
  87.125 +	}
  87.126 +
  87.127 +	protected void flush(Batch batch)
  87.128 +		throws SQLException
  87.129 +	{
  87.130 +		batch.flush();
  87.131 +	}
  87.132 +
  87.133 +	void insertThread(Object working)
  87.134 +		throws SQLException, InterruptedException
  87.135 +	{
  87.136 +		String name = Thread.currentThread().getName();
  87.137 +		logger.debug("Starting helper thread {}", name);
  87.138 +		int notReadyCount = 0;
  87.139 +		for (wb = queue.take(); isFlushable(wb); wb = queue.take()) {
  87.140 +			if (wb.isReady() || queue.size() <= notReadyCount) {
  87.141 +				synchronized (working) {
  87.142 +					if (wb != null) {
  87.143 +						flush(wb);
  87.144 +						wb = null;
  87.145 +					}
  87.146 +				}
  87.147 +				optimize();
  87.148 +				notReadyCount = 0;
  87.149 +			}
  87.150 +			else {
  87.151 +				queue.add(wb);
  87.152 +				notReadyCount++;
  87.153 +			}
  87.154 +		}
  87.155 +		logger.debug("Closing helper thread {}", name);
  87.156 +	}
  87.157 +
  87.158 +	private boolean isFlushable(Batch batch) {
  87.159 +		return batch != null && batch != Batch.CLOSED_SIGNAL;
  87.160 +	}
  87.161 +
  87.162 +	private void throwException()
  87.163 +		throws SQLException
  87.164 +	{
  87.165 +		if (exc instanceof SQLException) {
  87.166 +			SQLException e = (SQLException)exc;
  87.167 +			exc = null;
  87.168 +			throw e;
  87.169 +		}
  87.170 +		else if (exc instanceof RuntimeException) {
  87.171 +			RuntimeException e = (RuntimeException)exc;
  87.172 +			exc = null;
  87.173 +			throw e;
  87.174 +		}
  87.175 +	}
  87.176 +
  87.177 +}
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/generaldb/src/main/java/org/openrdf/generaldb/managers/base/ValueManagerBase.java	Fri Jan 27 01:08:32 2012 +0200
    88.3 @@ -0,0 +1,124 @@
    88.4 +/*
    88.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    88.6 + *
    88.7 + * Licensed under the Aduna BSD-style license.
    88.8 + */
    88.9 +package org.openrdf.generaldb.managers.base;
   88.10 +
   88.11 +import java.sql.SQLException;
   88.12 +import java.util.concurrent.atomic.AtomicInteger;
   88.13 +
   88.14 +import info.aduna.collections.LRUMap;
   88.15 +
   88.16 +import org.openrdf.sail.generaldb.managers.HashManager;
   88.17 +import org.openrdf.sail.rdbms.model.RdbmsValue;
   88.18 +import org.openrdf.sail.generaldb.schema.IdSequence;
   88.19 +
   88.20 +public abstract class ValueManagerBase<V extends RdbmsValue> extends ManagerBase {
   88.21 +
   88.22 +	private LRUMap<Object, V> cache;
   88.23 +
   88.24 +	private HashManager hashes;
   88.25 +
   88.26 +	private AtomicInteger version = new AtomicInteger();
   88.27 +
   88.28 +	private IdSequence ids;
   88.29 +
   88.30 +	public void setHashManager(HashManager hashes) {
   88.31 +		this.hashes = hashes;
   88.32 +	}
   88.33 +
   88.34 +	public IdSequence getIdSequence() {
   88.35 +		return ids;
   88.36 +	}
   88.37 +
   88.38 +	public void setIdSequence(IdSequence ids) {
   88.39 +		this.ids = ids;
   88.40 +	}
   88.41 +
   88.42 +	public void init() {
   88.43 +		cache = new LRUMap<Object, V>(getBatchSize());
   88.44 +	}
   88.45 +
   88.46 +	@Override
   88.47 +	public void flush()
   88.48 +	throws SQLException, InterruptedException
   88.49 +	{
   88.50 +		if (hashes != null) {
   88.51 +			hashes.flush();
   88.52 +		}
   88.53 +		super.flush();
   88.54 +	}
   88.55 +
   88.56 +	public V findInCache(Object key) {
   88.57 +		synchronized (cache) {
   88.58 +			if (cache.containsKey(key))
   88.59 +				return cache.get(key);
   88.60 +		}
   88.61 +		return null;
   88.62 +	}
   88.63 +
   88.64 +	public void cache(V value)
   88.65 +	throws InterruptedException
   88.66 +	{
   88.67 +		if (value.isExpired(getIdVersion())) {
   88.68 +			synchronized (cache) {
   88.69 +				cache.put(key(value), value);
   88.70 +			}
   88.71 +			if (hashes != null) {
   88.72 +				hashes.lookupId(value);
   88.73 +			}
   88.74 +		}
   88.75 +	}
   88.76 +
   88.77 +	public Number getInternalId(V value)
   88.78 +	throws SQLException, InterruptedException
   88.79 +	{
   88.80 +		if (value.isExpired(getIdVersion())) {
   88.81 +			if (hashes == null) {
   88.82 +				Number id = ids.idOf(value);
   88.83 +				value.setInternalId(id);
   88.84 +				value.setVersion(getIdVersion());
   88.85 +				insert(id, value);
   88.86 +			}
   88.87 +			else if (value.isExpired(getIdVersion())) {
   88.88 +				hashes.assignId(value, getIdVersion());
   88.89 +			}
   88.90 +		}
   88.91 +		return value.getInternalId();
   88.92 +	}
   88.93 +
   88.94 +	
   88.95 +
   88.96 +	public int getIdVersion() {
   88.97 +		return version.intValue() + (hashes == null ? 0 : hashes.getIdVersion());
   88.98 +	}
   88.99 +
  88.100 +	public void removedStatements(String condition)
  88.101 +	throws SQLException
  88.102 +	{
  88.103 +		if (expunge(condition)) {
  88.104 +			version.addAndGet(1);
  88.105 +		}
  88.106 +	}
  88.107 +
  88.108 +	protected abstract int getBatchSize();
  88.109 +
  88.110 +	protected abstract void insert(Number id, V value)
  88.111 +	throws SQLException, InterruptedException;
  88.112 +
  88.113 +	protected abstract Object key(V value);
  88.114 +
  88.115 +	protected abstract boolean expunge(String condition)
  88.116 +	throws SQLException;
  88.117 +
  88.118 +	@Override
  88.119 +	protected void optimize()
  88.120 +	throws SQLException
  88.121 +	{
  88.122 +		if (hashes != null) {
  88.123 +			hashes.optimize();
  88.124 +		}
  88.125 +	}
  88.126 +
  88.127 +}
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnection.java	Fri Jan 27 01:08:32 2012 +0200
    89.3 @@ -0,0 +1,311 @@
    89.4 +/*
    89.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    89.6 + *
    89.7 + * Licensed under the Aduna BSD-style license.
    89.8 + */
    89.9 +package org.openrdf.sail.generaldb;
   89.10 +
   89.11 +import java.sql.SQLException;
   89.12 +import java.util.Collection;
   89.13 +
   89.14 +import info.aduna.concurrent.locks.ExclusiveLockManager;
   89.15 +import info.aduna.concurrent.locks.Lock;
   89.16 +import info.aduna.iteration.CloseableIteration;
   89.17 +
   89.18 +import org.openrdf.model.Namespace;
   89.19 +import org.openrdf.model.Resource;
   89.20 +import org.openrdf.model.Statement;
   89.21 +import org.openrdf.model.URI;
   89.22 +import org.openrdf.model.Value;
   89.23 +import org.openrdf.query.BindingSet;
   89.24 +import org.openrdf.query.Dataset;
   89.25 +import org.openrdf.query.QueryEvaluationException;
   89.26 +import org.openrdf.query.algebra.TupleExpr;
   89.27 +import org.openrdf.query.algebra.evaluation.EvaluationStrategy;
   89.28 +import org.openrdf.query.impl.EmptyBindingSet;
   89.29 +import org.openrdf.sail.SailConnection;
   89.30 +import org.openrdf.sail.SailException;
   89.31 +import org.openrdf.sail.helpers.DefaultSailChangedEvent;
   89.32 +import org.openrdf.sail.helpers.SailConnectionBase;
   89.33 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluationFactory;
   89.34 +import org.openrdf.sail.generaldb.iteration.NamespaceIteration;
   89.35 +import org.openrdf.sail.generaldb.iteration.GeneralDBResourceIteration;
   89.36 +import org.openrdf.sail.generaldb.optimizers.GeneralDBQueryOptimizer;
   89.37 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   89.38 +import org.openrdf.sail.rdbms.managers.NamespaceManager;
   89.39 +import org.openrdf.sail.rdbms.model.RdbmsResource;
   89.40 +import org.openrdf.sail.rdbms.model.RdbmsURI;
   89.41 +import org.openrdf.sail.rdbms.model.RdbmsValue;
   89.42 +
   89.43 +/**
   89.44 + * Coordinates the triple store, namespace manager, optimizer, and evaluation
   89.45 + * strategy into the {@link SailConnection} interface.
   89.46 + * 
   89.47 + * @author James Leigh
   89.48 + * 
   89.49 + */
   89.50 +public class GeneralDBConnection extends SailConnectionBase {
   89.51 +
   89.52 +	private GeneralDBStore sail;
   89.53 +
   89.54 +	private GeneralDBValueFactory vf;
   89.55 +
   89.56 +	private GeneralDBTripleRepository triples;
   89.57 +
   89.58 +	private NamespaceManager namespaces;
   89.59 +
   89.60 +	private GeneralDBQueryOptimizer optimizer;
   89.61 +
   89.62 +	private GeneralDBEvaluationFactory factory;
   89.63 +
   89.64 +	private ExclusiveLockManager lockManager;
   89.65 +
   89.66 +	private Lock lock;
   89.67 +
   89.68 +	public GeneralDBConnection(GeneralDBStore sail, GeneralDBTripleRepository triples) {
   89.69 +		super(sail);
   89.70 +		this.sail = sail;
   89.71 +		this.vf = sail.getValueFactory();
   89.72 +		this.triples = triples;
   89.73 +	}
   89.74 +
   89.75 +	public void setNamespaces(NamespaceManager namespaces) {
   89.76 +		this.namespaces = namespaces;
   89.77 +	}
   89.78 +
   89.79 +	public void setRdbmsQueryOptimizer(GeneralDBQueryOptimizer optimizer) {
   89.80 +		this.optimizer = optimizer;
   89.81 +	}
   89.82 +
   89.83 +	public void setRdbmsEvaluationFactory(GeneralDBEvaluationFactory factory) {
   89.84 +		this.factory = factory;
   89.85 +	}
   89.86 +
   89.87 +	public void setLockManager(ExclusiveLockManager lock) {
   89.88 +		this.lockManager = lock;
   89.89 +	}
   89.90 +
   89.91 +	@Override
   89.92 +	protected void addStatementInternal(Resource subj, URI pred, Value obj, Resource... contexts)
   89.93 +		throws SailException
   89.94 +	{
   89.95 +		try {
   89.96 +			if (contexts.length == 0) {
   89.97 +				triples.add(vf.createStatement(subj, pred, obj));
   89.98 +			}
   89.99 +			else {
  89.100 +				for (Resource ctx : contexts) {
  89.101 +					triples.add(vf.createStatement(subj, pred, obj, ctx));
  89.102 +				}
  89.103 +			}
  89.104 +		}
  89.105 +		catch (SQLException e) {
  89.106 +			throw new RdbmsException(e);
  89.107 +		}
  89.108 +		catch (InterruptedException e) {
  89.109 +			throw new RdbmsException(e);
  89.110 +		}
  89.111 +	}
  89.112 +
  89.113 +	@Override
  89.114 +	protected void clearInternal(Resource... contexts)
  89.115 +		throws SailException
  89.116 +	{
  89.117 +		removeStatementsInternal(null, null, null, contexts);
  89.118 +		//XXX our code
  89.119 +		triples.clearGeoValues();
  89.120 +	}
  89.121 +
  89.122 +	@Override
  89.123 +	protected void closeInternal()
  89.124 +		throws SailException
  89.125 +	{
  89.126 +		try {
  89.127 +			triples.close();
  89.128 +		}
  89.129 +		catch (SQLException e) {
  89.130 +			throw new RdbmsException(e);
  89.131 +		}
  89.132 +		finally {
  89.133 +			unlock();
  89.134 +		}
  89.135 +	}
  89.136 +
  89.137 +	@Override
  89.138 +	protected void commitInternal()
  89.139 +		throws SailException
  89.140 +	{
  89.141 +		try {
  89.142 +			triples.commit();
  89.143 +			unlock();
  89.144 +		}
  89.145 +		catch (SQLException e) {
  89.146 +			throw new RdbmsException(e);
  89.147 +		}
  89.148 +		catch (InterruptedException e) {
  89.149 +			throw new RdbmsException(e);
  89.150 +		}
  89.151 +
  89.152 +		// create a fresh event object.
  89.153 +		triples.setSailChangedEvent(new DefaultSailChangedEvent(sail));
  89.154 +	}
  89.155 +
  89.156 +	@Override
  89.157 +	protected GeneralDBResourceIteration getContextIDsInternal()
  89.158 +		throws SailException
  89.159 +	{
  89.160 +		try {
  89.161 +			return triples.findContexts();
  89.162 +		}
  89.163 +		catch (SQLException e) {
  89.164 +			throw new RdbmsException(e);
  89.165 +		}
  89.166 +	}
  89.167 +
  89.168 +	@Override
  89.169 +	protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(Resource subj,
  89.170 +			URI pred, Value obj, boolean includeInferred, Resource... contexts)
  89.171 +		throws SailException
  89.172 +	{
  89.173 +		RdbmsResource s = vf.asRdbmsResource(subj);
  89.174 +		RdbmsURI p = vf.asRdbmsURI(pred);
  89.175 +		RdbmsValue o = vf.asRdbmsValue(obj);
  89.176 +		RdbmsResource[] c = vf.asRdbmsResource(contexts);
  89.177 +		return triples.find(s, p, o, c);
  89.178 +	}
  89.179 +
  89.180 +	@Override
  89.181 +	protected void removeStatementsInternal(Resource subj, URI pred, Value obj, Resource... contexts)
  89.182 +		throws SailException
  89.183 +	{
  89.184 +		RdbmsResource s = vf.asRdbmsResource(subj);
  89.185 +		RdbmsURI p = vf.asRdbmsURI(pred);
  89.186 +		RdbmsValue o = vf.asRdbmsValue(obj);
  89.187 +		RdbmsResource[] c = vf.asRdbmsResource(contexts);
  89.188 +		triples.remove(s, p, o, c);
  89.189 +	}
  89.190 +
  89.191 +	@Override
  89.192 +	protected void rollbackInternal()
  89.193 +		throws SailException
  89.194 +	{
  89.195 +		try {
  89.196 +			triples.rollback();
  89.197 +		}
  89.198 +		catch (SQLException e) {
  89.199 +			throw new RdbmsException(e);
  89.200 +		}
  89.201 +		finally {
  89.202 +			unlock();
  89.203 +		}
  89.204 +	}
  89.205 +
  89.206 +	@Override
  89.207 +	protected CloseableIteration<BindingSet, QueryEvaluationException> evaluateInternal(TupleExpr expr,
  89.208 +			Dataset dataset, BindingSet bindings, boolean includeInferred)
  89.209 +		throws SailException
  89.210 +	{
  89.211 +		triples.flush();
  89.212 +		try {
  89.213 +			TupleExpr tupleExpr;
  89.214 +			EvaluationStrategy strategy;
  89.215 +			strategy = factory.createRdbmsEvaluation(dataset);
  89.216 +			tupleExpr = optimizer.optimize(expr, dataset, bindings, strategy);
  89.217 +			return strategy.evaluate(tupleExpr, EmptyBindingSet.getInstance());
  89.218 +		}
  89.219 +		catch (QueryEvaluationException e) {
  89.220 +			throw new SailException(e);
  89.221 +		}
  89.222 +	}
  89.223 +
  89.224 +	@Override
  89.225 +	protected void clearNamespacesInternal()
  89.226 +		throws SailException
  89.227 +	{
  89.228 +		namespaces.clearPrefixes();
  89.229 +	}
  89.230 +
  89.231 +	@Override
  89.232 +	protected String getNamespaceInternal(String prefix)
  89.233 +		throws SailException
  89.234 +	{
  89.235 +		Namespace ns = namespaces.findByPrefix(prefix);
  89.236 +		if (ns == null)
  89.237 +			return null;
  89.238 +		return ns.getName();
  89.239 +	}
  89.240 +
  89.241 +	@Override
  89.242 +	protected CloseableIteration<? extends Namespace, SailException> getNamespacesInternal()
  89.243 +		throws SailException
  89.244 +	{
  89.245 +		Collection<? extends Namespace> ns = namespaces.getNamespacesWithPrefix();
  89.246 +		return new NamespaceIteration(ns.iterator());
  89.247 +	}
  89.248 +
  89.249 +	@Override
  89.250 +	protected void removeNamespaceInternal(String prefix)
  89.251 +		throws SailException
  89.252 +	{
  89.253 +		namespaces.removePrefix(prefix);
  89.254 +	}
  89.255 +
  89.256 +	@Override
  89.257 +	protected void setNamespaceInternal(String prefix, String name)
  89.258 +		throws SailException
  89.259 +	{
  89.260 +		namespaces.setPrefix(prefix, name);
  89.261 +	}
  89.262 +
  89.263 +	@Override
  89.264 +	protected long sizeInternal(Resource... contexts)
  89.265 +		throws SailException
  89.266 +	{
  89.267 +		try {
  89.268 +			return triples.size(vf.asRdbmsResource(contexts));
  89.269 +		}
  89.270 +		catch (SQLException e) {
  89.271 +			throw new RdbmsException(e);
  89.272 +		}
  89.273 +	}
  89.274 +
  89.275 +	@Override
  89.276 +	protected void startTransactionInternal()
  89.277 +		throws SailException
  89.278 +	{
  89.279 +		try {
  89.280 +			lock();
  89.281 +			triples.begin();
  89.282 +		}
  89.283 +		catch (SQLException e) {
  89.284 +			unlock();
  89.285 +			throw new RdbmsException(e);
  89.286 +		}
  89.287 +		catch (InterruptedException e) {
  89.288 +			unlock();
  89.289 +			throw new RdbmsException(e);
  89.290 +		}
  89.291 +	}
  89.292 +
  89.293 +	@Override
  89.294 +	protected void finalize()
  89.295 +		throws Throwable
  89.296 +	{
  89.297 +		unlock();
  89.298 +		super.finalize();
  89.299 +	}
  89.300 +
  89.301 +	private void lock() throws InterruptedException {
  89.302 +		if (lockManager != null) {
  89.303 +			lock = lockManager.getExclusiveLock();
  89.304 +		}
  89.305 +	}
  89.306 +
  89.307 +	private void unlock() {
  89.308 +		if (lockManager != null && lock != null) {
  89.309 +			lock.release();
  89.310 +			lock = null;
  89.311 +		}
  89.312 +	}
  89.313 +
  89.314 +}
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBConnectionFactory.java	Fri Jan 27 01:08:32 2012 +0200
    90.3 @@ -0,0 +1,371 @@
    90.4 +/*
    90.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    90.6 + *
    90.7 + * Licensed under the Aduna BSD-style license.
    90.8 + */
    90.9 +package org.openrdf.sail.generaldb;
   90.10 +
   90.11 +import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
   90.12 +
   90.13 +import java.sql.Connection;
   90.14 +import java.sql.SQLException;
   90.15 +
   90.16 +import javax.sql.DataSource;
   90.17 +
   90.18 +import info.aduna.concurrent.locks.ExclusiveLockManager;
   90.19 +import info.aduna.concurrent.locks.Lock;
   90.20 +
   90.21 +import org.openrdf.model.impl.ValueFactoryImpl;
   90.22 +import org.openrdf.sail.SailConnection;
   90.23 +import org.openrdf.sail.SailException;
   90.24 +import org.openrdf.sail.helpers.DefaultSailChangedEvent;
   90.25 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluationFactory;
   90.26 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory;
   90.27 +import org.openrdf.sail.generaldb.optimizers.GeneralDBQueryOptimizer;
   90.28 +import org.openrdf.sail.generaldb.optimizers.GeneralDBSelectQueryOptimizerFactory;
   90.29 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   90.30 +import org.openrdf.sail.generaldb.managers.BNodeManager;
   90.31 +import org.openrdf.sail.generaldb.managers.HashManager;
   90.32 +import org.openrdf.sail.generaldb.managers.LiteralManager;
   90.33 +import org.openrdf.sail.rdbms.managers.NamespaceManager;
   90.34 +import org.openrdf.sail.generaldb.managers.PredicateManager;
   90.35 +import org.openrdf.sail.generaldb.managers.TransTableManager;
   90.36 +import org.openrdf.sail.generaldb.managers.TripleManager;
   90.37 +import org.openrdf.sail.generaldb.managers.TripleTableManager;
   90.38 +import org.openrdf.sail.generaldb.managers.UriManager;
   90.39 +import org.openrdf.sail.generaldb.schema.BNodeTable;
   90.40 +import org.openrdf.sail.generaldb.schema.HashTable;
   90.41 +import org.openrdf.sail.generaldb.schema.IdSequence;
   90.42 +import org.openrdf.sail.generaldb.schema.IntegerIdSequence;
   90.43 +import org.openrdf.sail.generaldb.schema.LiteralTable;
   90.44 +import org.openrdf.sail.generaldb.schema.LongIdSequence;
   90.45 +import org.openrdf.sail.rdbms.schema.NamespacesTable;
   90.46 +import org.openrdf.sail.rdbms.schema.TableFactory;
   90.47 +import org.openrdf.sail.generaldb.schema.URITable;
   90.48 +import org.openrdf.sail.generaldb.schema.ValueTableFactory;
   90.49 +import org.openrdf.sail.rdbms.util.DatabaseLockManager;
   90.50 +import org.openrdf.sail.rdbms.util.Tracer;
   90.51 +
   90.52 +/**
   90.53 + * Responsible to initialise and wire all components together that will be
   90.54 + * needed to satisfy any sail connection request.
   90.55 + * 
   90.56 + * @author James Leigh
   90.57 + */
   90.58 +public abstract class GeneralDBConnectionFactory {
   90.59 +
   90.60 +	protected GeneralDBStore sail;
   90.61 +
   90.62 +	protected DataSource ds;
   90.63 +
   90.64 +	protected String user;
   90.65 +
   90.66 +	protected String password;
   90.67 +
   90.68 +	protected Connection resourceInserts;
   90.69 +
   90.70 +	protected Connection literalInserts;
   90.71 +
   90.72 +	protected Connection hashLookups;
   90.73 +
   90.74 +	protected Connection nsAndTableIndexes;
   90.75 +
   90.76 +	protected NamespaceManager namespaces;
   90.77 +
   90.78 +	protected TripleTableManager tripleTableManager;
   90.79 +
   90.80 +	protected HashManager hashManager;
   90.81 +
   90.82 +	protected GeneralDBValueFactory vf;
   90.83 +
   90.84 +	protected UriManager uriManager;
   90.85 +
   90.86 +	protected BNodeManager bnodeManager;
   90.87 +
   90.88 +	protected LiteralManager literalManager;
   90.89 +
   90.90 +	protected PredicateManager predicateManager;
   90.91 +
   90.92 +	protected int maxTripleTables;
   90.93 +
   90.94 +	protected boolean triplesIndexed = true;
   90.95 +
   90.96 +	protected boolean sequenced;
   90.97 +
   90.98 +	protected HashTable hashTable;
   90.99 +
  90.100 +	protected URITable uriTable;
  90.101 +
  90.102 +	protected BNodeTable bnodeTable;
  90.103 +
  90.104 +	protected LiteralTable literalTable;
  90.105 +
  90.106 +	protected IdSequence ids;
  90.107 +
  90.108 +	protected final ExclusiveLockManager lock = new ExclusiveLockManager();
  90.109 +
  90.110 +	protected Lock databaseLock;
  90.111 +
  90.112 +	public void setSail(GeneralDBStore sail) {
  90.113 +		this.sail = sail;
  90.114 +	}
  90.115 +
  90.116 +	public DataSource getDataSource() {
  90.117 +		return ds;
  90.118 +	}
  90.119 +
  90.120 +	public void setDataSource(DataSource ds) {
  90.121 +		if (Tracer.isTraceEnabled()) {
  90.122 +			this.ds = Tracer.traceDataSource(ds);
  90.123 +		}
  90.124 +		else {
  90.125 +			this.ds = ds;
  90.126 +		}
  90.127 +	}
  90.128 +
  90.129 +	public void setDataSource(DataSource ds, String user, String password) {
  90.130 +		setDataSource(ds);
  90.131 +		this.user = user;
  90.132 +		this.password = password;
  90.133 +	}
  90.134 +
  90.135 +	public int getMaxNumberOfTripleTables() {
  90.136 +		return maxTripleTables;
  90.137 +	}
  90.138 +
  90.139 +	public void setMaxNumberOfTripleTables(int max) {
  90.140 +		maxTripleTables = max;
  90.141 +	}
  90.142 +
  90.143 +	public boolean isSequenced() {
  90.144 +		return sequenced || hashManager != null;
  90.145 +	}
  90.146 +
  90.147 +	public void setSequenced(boolean useSequence) {
  90.148 +		this.sequenced = useSequence;
  90.149 +	}
  90.150 +
  90.151 +	public boolean isTriplesIndexed() {
  90.152 +		return triplesIndexed;
  90.153 +	}
  90.154 +
  90.155 +	public void setTriplesIndexed(boolean triplesIndexed)
  90.156 +		throws SailException
  90.157 +	{
  90.158 +		this.triplesIndexed = triplesIndexed;
  90.159 +		if (tripleTableManager != null) {
  90.160 +			try {
  90.161 +				if (triplesIndexed) {
  90.162 +					tripleTableManager.createTripleIndexes();
  90.163 +				}
  90.164 +				else {
  90.165 +					tripleTableManager.dropTripleIndexes();
  90.166 +				}
  90.167 +			}
  90.168 +			catch (SQLException e) {
  90.169 +				throw new RdbmsException(e);
  90.170 +			}
  90.171 +		}
  90.172 +	}
  90.173 +
  90.174 +	public GeneralDBValueFactory getValueFactory() {
  90.175 +		return vf;
  90.176 +	}
  90.177 +
  90.178 +	public void init()
  90.179 +		throws Exception
  90.180 +	{
  90.181 +		databaseLock = createDatabaseLock();
  90.182 +		try {
  90.183 +			nsAndTableIndexes = getConnection();
  90.184 +			resourceInserts = getConnection();
  90.185 +			literalInserts = getConnection();
  90.186 +			nsAndTableIndexes.setAutoCommit(true);
  90.187 +			resourceInserts.setAutoCommit(true);
  90.188 +			literalInserts.setAutoCommit(true);
  90.189 +			bnodeManager = new BNodeManager();
  90.190 +			uriManager = new UriManager();
  90.191 +			literalManager = new LiteralManager();
  90.192 +			ValueTableFactory tables = createValueTableFactory();
  90.193 +			tables.setSequenced(sequenced);
  90.194 +			if (sequenced) {
  90.195 +				ids = new IntegerIdSequence();
  90.196 +				tables.setIdSequence(ids);
  90.197 +				hashLookups = getConnection();
  90.198 +				hashLookups.setAutoCommit(true);
  90.199 +				hashManager = new HashManager();
  90.200 +				hashTable = tables.createHashTable(hashLookups, hashManager.getQueue());
  90.201 +				ids.setHashTable(hashTable);
  90.202 +				ids.init();
  90.203 +				hashManager.setHashTable(hashTable);
  90.204 +				hashManager.setBNodeManager(bnodeManager);
  90.205 +				hashManager.setLiteralManager(literalManager);
  90.206 +				hashManager.setUriManager(uriManager);
  90.207 +				hashManager.setIdSequence(ids);
  90.208 +				hashManager.init();
  90.209 +			}
  90.210 +			else {
  90.211 +				ids = new LongIdSequence();
  90.212 +				ids.init();
  90.213 +				tables.setIdSequence(ids);
  90.214 +			}
  90.215 +			namespaces = new NamespaceManager();
  90.216 +			namespaces.setConnection(resourceInserts);
  90.217 +			NamespacesTable nsTable = tables.createNamespacesTable(nsAndTableIndexes);
  90.218 +			nsTable.initialize();
  90.219 +			namespaces.setNamespacesTable(nsTable);
  90.220 +			namespaces.initialize();
  90.221 +			bnodeManager.setHashManager(hashManager);
  90.222 +			bnodeManager.setIdSequence(ids);
  90.223 +			uriManager.setHashManager(hashManager);
  90.224 +			uriManager.setIdSequence(ids);
  90.225 +			bnodeTable = tables.createBNodeTable(resourceInserts, bnodeManager.getQueue());
  90.226 +			uriTable = tables.createURITable(resourceInserts, uriManager.getQueue());
  90.227 +			literalManager.setHashManager(hashManager);
  90.228 +			literalManager.setIdSequence(ids);
  90.229 +			literalTable = tables.createLiteralTable(literalInserts, literalManager.getQueue());
  90.230 +			literalTable.setIdSequence(ids);
  90.231 +			vf = new GeneralDBValueFactory();
  90.232 +			vf.setDelegate(ValueFactoryImpl.getInstance());
  90.233 +			vf.setIdSequence(ids);
  90.234 +			uriManager.setUriTable(uriTable);
  90.235 +			uriManager.init();
  90.236 +			predicateManager = new PredicateManager();
  90.237 +			predicateManager.setUriManager(uriManager);
  90.238 +			tripleTableManager = new TripleTableManager(tables);
  90.239 +			tripleTableManager.setConnection(nsAndTableIndexes);
  90.240 +			tripleTableManager.setIdSequence(ids);
  90.241 +			tripleTableManager.setBNodeManager(bnodeManager);
  90.242 +			tripleTableManager.setUriManager(uriManager);
  90.243 +			tripleTableManager.setLiteralManager(literalManager);
  90.244 +			tripleTableManager.setHashManager(hashManager);
  90.245 +			tripleTableManager.setPredicateManager(predicateManager);
  90.246 +			tripleTableManager.setMaxNumberOfTripleTables(maxTripleTables);
  90.247 +			tripleTableManager.setIndexingTriples(triplesIndexed);
  90.248 +			tripleTableManager.initialize();
  90.249 +			if (triplesIndexed) {
  90.250 +				tripleTableManager.createTripleIndexes();
  90.251 +			}
  90.252 +			else {
  90.253 +				tripleTableManager.dropTripleIndexes();
  90.254 +			}
  90.255 +			bnodeManager.setTable(bnodeTable);
  90.256 +			bnodeManager.init();
  90.257 +			vf.setBNodeManager(bnodeManager);
  90.258 +			vf.setURIManager(uriManager);
  90.259 +			literalManager.setTable(literalTable);
  90.260 +			literalManager.init();
  90.261 +			vf.setLiteralManager(literalManager);
  90.262 +			vf.setPredicateManager(predicateManager);
  90.263 +		}
  90.264 +		catch (SQLException e) {
  90.265 +			throw new RdbmsException(e);
  90.266 +		}
  90.267 +	}
  90.268 +
  90.269 +	public boolean isWritable()
  90.270 +		throws SailException
  90.271 +	{
  90.272 +		try {
  90.273 +			return !nsAndTableIndexes.isReadOnly();
  90.274 +		}
  90.275 +		catch (SQLException e) {
  90.276 +			throw new RdbmsException(e);
  90.277 +		}
  90.278 +	}
  90.279 +
  90.280 +	public abstract SailConnection createConnection()
  90.281 +		throws SailException;
  90.282 +
  90.283 +	public void shutDown()
  90.284 +		throws SailException
  90.285 +	{
  90.286 +		try {
  90.287 +			if (tripleTableManager != null) {
  90.288 +				tripleTableManager.close();
  90.289 +			}
  90.290 +			if (uriManager != null) {
  90.291 +				uriManager.close();
  90.292 +			}
  90.293 +			if (bnodeManager != null) {
  90.294 +				bnodeManager.close();
  90.295 +			}
  90.296 +			if (literalManager != null) {
  90.297 +				literalManager.close();
  90.298 +			}
  90.299 +			if (hashManager != null) {
  90.300 +				hashManager.close();
  90.301 +			}
  90.302 +			if (resourceInserts != null) {
  90.303 +				resourceInserts.close();
  90.304 +				resourceInserts = null;
  90.305 +			}
  90.306 +			if (literalInserts != null) {
  90.307 +				literalInserts.close();
  90.308 +				literalInserts = null;
  90.309 +			}
  90.310 +			if (hashLookups != null) {
  90.311 +				hashLookups.close();
  90.312 +				hashLookups = null;
  90.313 +			}
  90.314 +			if (nsAndTableIndexes != null) {
  90.315 +				nsAndTableIndexes.close();
  90.316 +				nsAndTableIndexes = null;
  90.317 +			}
  90.318 +		}
  90.319 +		catch (SQLException e) {
  90.320 +			throw new RdbmsException(e);
  90.321 +		}
  90.322 +		finally {
  90.323 +			if (databaseLock != null) {
  90.324 +				databaseLock.release();
  90.325 +			}
  90.326 +		}
  90.327 +	}
  90.328 +
  90.329 +	protected abstract Lock createDatabaseLock()
  90.330 +		throws SailException;
  90.331 +
  90.332 +	protected abstract GeneralDBQueryBuilderFactory createQueryBuilderFactory();
  90.333 +
  90.334 +	protected abstract ValueTableFactory createValueTableFactory();
  90.335 +
  90.336 +	protected abstract TableFactory createTableFactory();
  90.337 +
  90.338 +	protected TransTableManager createTransTableManager() {
  90.339 +		return new TransTableManager();
  90.340 +	}
  90.341 +
  90.342 +	protected GeneralDBQueryOptimizer createOptimizer() {
  90.343 +		return new GeneralDBQueryOptimizer();
  90.344 +	}
  90.345 +
  90.346 +	protected GeneralDBSelectQueryOptimizerFactory createSelectQueryOptimizerFactory() {
  90.347 +		return new GeneralDBSelectQueryOptimizerFactory();
  90.348 +	}
  90.349 +
  90.350 +	/**
  90.351 +	 * FROM DUAL
  90.352 +	 * 
  90.353 +	 * @return from clause or empty string
  90.354 +	 */
  90.355 +	protected String getFromDummyTable() {
  90.356 +		return "";
  90.357 +	}
  90.358 +
  90.359 +	protected Connection getConnection()
  90.360 +		throws SQLException
  90.361 +	{
  90.362 +		Connection conn;
  90.363 +		if (user == null)
  90.364 +			// return ds.getConnection();
  90.365 +			conn = ds.getConnection();
  90.366 +		else
  90.367 +			// return ds.getConnection(user, password);
  90.368 +			conn = ds.getConnection(user, password);
  90.369 +
  90.370 +		return conn;
  90.371 +		//return new net.sf.log4jdbc.ConnectionSpy(conn);
  90.372 +	}
  90.373 +
  90.374 +}
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBProvider.java	Fri Jan 27 01:08:32 2012 +0200
    91.3 @@ -0,0 +1,22 @@
    91.4 +/*
    91.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    91.6 + *
    91.7 + * Licensed under the Aduna BSD-style license.
    91.8 + */
    91.9 +package org.openrdf.sail.generaldb;
   91.10 +
   91.11 +import org.openrdf.sail.rdbms.RdbmsProvider;
   91.12 +
   91.13 + 
   91.14 +/**
   91.15 + * Checks the database product name and version to be compatible with this
   91.16 + * Sesame store.
   91.17 + * 
   91.18 + * @author James Leigh
   91.19 + * 
   91.20 + */
   91.21 +public abstract class GeneralDBProvider  {
   91.22 +
   91.23 +	public abstract GeneralDBConnectionFactory createRdbmsConnectionFactory(String dbName, String dbVersion);
   91.24 +
   91.25 +}
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSpatialFuncInfo.java	Fri Jan 27 01:08:32 2012 +0200
    92.3 @@ -0,0 +1,47 @@
    92.4 +package org.openrdf.sail.generaldb;
    92.5 +
    92.6 +/**
    92.7 + * 
    92.8 + * @author manolee
    92.9 + * Class used to store all info needed about a spatial construct / metric / property located in select clause
   92.10 + * Currently storing info about the name of the field that has to be retrieved from the Result Set, 
   92.11 + * as well as the type of the spatial function 
   92.12 + */
   92.13 +public class GeneralDBSpatialFuncInfo {
   92.14 +	
   92.15 +	public enum typeOfField 
   92.16 +	{
   92.17 +			Integer,
   92.18 +			Double,
   92.19 +			Boolean,
   92.20 +			String,
   92.21 +			WKB
   92.22 +			;
   92.23 +	}
   92.24 +	
   92.25 +	
   92.26 +
   92.27 +	public GeneralDBSpatialFuncInfo(String fieldName, typeOfField type) {
   92.28 +		super();
   92.29 +		this.fieldName = fieldName;
   92.30 +		this.type = type;
   92.31 +	}
   92.32 +	private String fieldName;
   92.33 +	private typeOfField type;
   92.34 +	public String getFieldName() {
   92.35 +		return fieldName;
   92.36 +	}
   92.37 +	public void setFieldName(String fieldName) {
   92.38 +		this.fieldName = fieldName;
   92.39 +	}
   92.40 +	public typeOfField getType() {
   92.41 +		return type;
   92.42 +	}
   92.43 +	public void setType(typeOfField type) {
   92.44 +		this.type = type;
   92.45 +	}
   92.46 +	
   92.47 +	
   92.48 +}
   92.49 +
   92.50 +
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlTable.java	Fri Jan 27 01:08:32 2012 +0200
    93.3 @@ -0,0 +1,37 @@
    93.4 +/*
    93.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    93.6 + *
    93.7 + * Licensed under the Aduna BSD-style license.
    93.8 + */
    93.9 +package org.openrdf.sail.generaldb;
   93.10 +
   93.11 +import java.sql.SQLException;
   93.12 +
   93.13 +import org.openrdf.sail.rdbms.schema.RdbmsTable;
   93.14 +
   93.15 +/**
   93.16 + * Converts table names to lower-case and include the analyse optimisation.
   93.17 + * 
   93.18 + * @author James Leigh
   93.19 + * 
   93.20 + */
   93.21 +public abstract class GeneralDBSqlTable extends RdbmsTable {
   93.22 +
   93.23 +	public GeneralDBSqlTable(String name) {
   93.24 +		super(name.toLowerCase());
   93.25 +	}
   93.26 +
   93.27 +	@Override
   93.28 +	protected String buildLongIndex(String... columns) {
   93.29 +		// TODO How can we index text columns?
   93.30 +		return null;
   93.31 +	}
   93.32 +
   93.33 +	@Override
   93.34 +	protected abstract String buildOptimize()
   93.35 +		throws SQLException;
   93.36 +
   93.37 +	@Override
   93.38 +	protected abstract String buildClear();
   93.39 +
   93.40 +}
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlTableFactory.java	Fri Jan 27 01:08:32 2012 +0200
    94.3 @@ -0,0 +1,21 @@
    94.4 +/*
    94.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    94.6 + *
    94.7 + * Licensed under the Aduna BSD-style license.
    94.8 + */
    94.9 +package org.openrdf.sail.generaldb;
   94.10 +
   94.11 +import org.openrdf.sail.rdbms.schema.RdbmsTable;
   94.12 +import org.openrdf.sail.rdbms.schema.TableFactory;
   94.13 +
   94.14 +/**
   94.15 + * Overrides PostgreSQL specific table commands.
   94.16 + * 
   94.17 + * @author James Leigh
   94.18 + * 
   94.19 + */
   94.20 +public abstract class GeneralDBSqlTableFactory extends TableFactory {
   94.21 +
   94.22 +	@Override
   94.23 +	protected abstract RdbmsTable newTable(String name);
   94.24 +}
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlValueTable.java	Fri Jan 27 01:08:32 2012 +0200
    95.3 @@ -0,0 +1,31 @@
    95.4 +/*
    95.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    95.6 + *
    95.7 + * Licensed under the Aduna BSD-style license.
    95.8 + */
    95.9 +package org.openrdf.sail.generaldb;
   95.10 +
   95.11 +import java.sql.Types;
   95.12 +
   95.13 +import org.openrdf.sail.generaldb.schema.ValueTable;
   95.14 +
   95.15 +/**
   95.16 + * Optimises prepared insert statements for PostgreSQL and overrides the DOUBLE
   95.17 + * column type.
   95.18 + * 
   95.19 + * @author James Leigh
   95.20 + * 
   95.21 + */
   95.22 +public class GeneralDBSqlValueTable extends ValueTable {
   95.23 +
   95.24 +	@Override
   95.25 +	public String sql(int type, int length) {
   95.26 +		switch (type) {
   95.27 +			case Types.DOUBLE:
   95.28 +				return "double precision";
   95.29 +			default:
   95.30 +				return super.sql(type, length);
   95.31 +		}
   95.32 +	}
   95.33 +
   95.34 +}
    96.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    96.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBSqlValueTableFactory.java	Fri Jan 27 01:08:32 2012 +0200
    96.3 @@ -0,0 +1,34 @@
    96.4 +/*
    96.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    96.6 + *
    96.7 + * Licensed under the Aduna BSD-style license.
    96.8 + */
    96.9 +package org.openrdf.sail.generaldb;
   96.10 +
   96.11 +import java.sql.Connection;
   96.12 +
   96.13 +import org.openrdf.sail.generaldb.schema.TripleTable;
   96.14 +import org.openrdf.sail.generaldb.schema.ValueTableFactory;
   96.15 +
   96.16 +/**
   96.17 + * Overrides PostgreSQL specific table commands.
   96.18 + * 
   96.19 + * @author James Leigh
   96.20 + * 
   96.21 + */
   96.22 +public abstract class GeneralDBSqlValueTableFactory extends ValueTableFactory {
   96.23 +
   96.24 +	public GeneralDBSqlValueTableFactory(GeneralDBSqlTableFactory sqlTableFactory) {
   96.25 +		super(sqlTableFactory);
   96.26 +	}
   96.27 +
   96.28 +	@Override
   96.29 +	public GeneralDBSqlValueTable newValueTable() {
   96.30 +		return new GeneralDBSqlValueTable();
   96.31 +	}
   96.32 +
   96.33 +	@Override
   96.34 +	public TripleTable createTripleTable(Connection conn, String tableName) {
   96.35 +		return super.createTripleTable(conn, tableName.toLowerCase());
   96.36 +	}
   96.37 +}
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBStore.java	Fri Jan 27 01:08:32 2012 +0200
    97.3 @@ -0,0 +1,250 @@
    97.4 +/*
    97.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    97.6 + *
    97.7 + * Licensed under the Aduna BSD-style license.
    97.8 + */
    97.9 +package org.openrdf.sail.generaldb;
   97.10 +
   97.11 +import java.sql.Connection;
   97.12 +import java.sql.DatabaseMetaData;
   97.13 +import java.sql.SQLException;
   97.14 +import java.util.Iterator;
   97.15 +
   97.16 +import javax.imageio.spi.ServiceRegistry;
   97.17 +import javax.naming.InitialContext;
   97.18 +import javax.naming.NamingException;
   97.19 +import javax.sql.DataSource;
   97.20 +
   97.21 +import org.apache.commons.dbcp.BasicDataSource;
   97.22 +
   97.23 +import org.openrdf.sail.SailConnection;
   97.24 +import org.openrdf.sail.SailException;
   97.25 +import org.openrdf.sail.helpers.SailBase;
   97.26 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   97.27 +
   97.28 +/**
   97.29 + * The RDBMS SAIL for relational database storage in Sesame. This class acts
   97.30 + * both as a base class for database specific stores as well as a generic store
   97.31 + * that can infer the type of database through the JDBC connection.
   97.32 + * 
   97.33 + * @author James Leigh
   97.34 + */
   97.35 +public abstract class GeneralDBStore extends SailBase {
   97.36 +
   97.37 +	protected GeneralDBConnectionFactory factory;
   97.38 +
   97.39 +	protected String jdbcDriver;
   97.40 +
   97.41 +	protected String url;
   97.42 +
   97.43 +	protected String user;
   97.44 +
   97.45 +	protected String password;
   97.46 +
   97.47 +	protected int maxTripleTables;
   97.48 +
   97.49 +	protected boolean triplesIndexed = true;
   97.50 +
   97.51 +	protected boolean sequenced = true;
   97.52 +
   97.53 +	protected BasicDataSource ds;
   97.54 +
   97.55 +	public GeneralDBStore() {
   97.56 +		super();
   97.57 +	}
   97.58 +
   97.59 +	/**
   97.60 +	 * Creates a new RDBMS RDF Store using the provided database connection.
   97.61 +	 * 
   97.62 +	 * @param url
   97.63 +	 *        JDNI url of a DataSource
   97.64 +	 */
   97.65 +	public GeneralDBStore(String url) {
   97.66 +		this.url = url;
   97.67 +	}
   97.68 +
   97.69 +	/**
   97.70 +	 * Creates a new RDBMS RDF Store using the provided database connection.
   97.71 +	 * 
   97.72 +	 * @param url
   97.73 +	 *        JDNI url of a DataSource
   97.74 +	 * @param user
   97.75 +	 * @param password
   97.76 +	 */
   97.77 +	public GeneralDBStore(String url, String user, String password) {
   97.78 +		this.url = url;
   97.79 +		this.user = user;
   97.80 +		this.password = password;
   97.81 +	}
   97.82 +
   97.83 +	/**
   97.84 +	 * Creates a new RDBMS RDF Store using the provided database connection.
   97.85 +	 * 
   97.86 +	 * @param jdbcDriver
   97.87 +	 * @param jdbcUrl
   97.88 +	 */
   97.89 +	public GeneralDBStore(String jdbcDriver, String jdbcUrl) {
   97.90 +		this.jdbcDriver = jdbcDriver;
   97.91 +		this.url = jdbcUrl;
   97.92 +	}
   97.93 +
   97.94 +	/**
   97.95 +	 * Creates a new RDBMS RDF Store using the provided database connection.
   97.96 +	 * 
   97.97 +	 * @param jdbcDriver
   97.98 +	 * @param jdbcUrl
   97.99 +	 * @param user
  97.100 +	 * @param password
  97.101 +	 */
  97.102 +	public GeneralDBStore(String jdbcDriver, String jdbcUrl, String user, String password) {
  97.103 +		this.jdbcDriver = jdbcDriver;
  97.104 +		this.url = jdbcUrl;
  97.105 +		this.user = user;
  97.106 +		this.password = password;
  97.107 +	}
  97.108 +
  97.109 +	public int getMaxNumberOfTripleTables() {
  97.110 +		return maxTripleTables;
  97.111 +	}
  97.112 +
  97.113 +	public void setMaxNumberOfTripleTables(int max) {
  97.114 +		maxTripleTables = max;
  97.115 +	}
  97.116 +
  97.117 +	public boolean isIndexed() {
  97.118 +		return triplesIndexed;
  97.119 +	}
  97.120 +
  97.121 +	public void setIndexed(boolean indexed)
  97.122 +		throws SailException
  97.123 +	{
  97.124 +		triplesIndexed = indexed;
  97.125 +		if (factory != null) {
  97.126 +			factory.setTriplesIndexed(triplesIndexed);
  97.127 +		}
  97.128 +	}
  97.129 +
  97.130 +	public boolean isSequenced() {
  97.131 +		return sequenced;
  97.132 +	}
  97.133 +
  97.134 +	public void setSequenced(boolean useSequence) {
  97.135 +		this.sequenced = useSequence;
  97.136 +	}
  97.137 +
  97.138 +	@Override
  97.139 +	protected void initializeInternal()
  97.140 +		throws SailException
  97.141 +	{
  97.142 +		if (factory == null) {
  97.143 +			try {
  97.144 +				factory = createFactory(jdbcDriver, url, user, password);
  97.145 +			}
  97.146 +			catch (SailException e) {
  97.147 +				throw e;
  97.148 +			}
  97.149 +			catch (Exception e) {
  97.150 +				throw new RdbmsException(e);
  97.151 +			}
  97.152 +		}
  97.153 +		factory.setMaxNumberOfTripleTables(maxTripleTables);
  97.154 +		factory.setTriplesIndexed(triplesIndexed);
  97.155 +		factory.setSequenced(sequenced);
  97.156 +		try {
  97.157 +			factory.init();
  97.158 +		} catch (Exception ex) {
  97.159 +			// TODO Auto-generated catch block
  97.160 +			throw new RdbmsException(ex);
  97.161 +
  97.162 +		}
  97.163 +	}
  97.164 +
  97.165 +	public boolean isWritable()
  97.166 +		throws SailException
  97.167 +	{
  97.168 +		return factory.isWritable();
  97.169 +	}
  97.170 +
  97.171 +	public GeneralDBValueFactory getValueFactory() {
  97.172 +		return factory.getValueFactory();
  97.173 +	}
  97.174 +
  97.175 +	@Override
  97.176 +	protected SailConnection getConnectionInternal()
  97.177 +		throws SailException
  97.178 +	{
  97.179 +		return factory.createConnection();
  97.180 +	}
  97.181 +
  97.182 +	@Override
  97.183 +	protected void shutDownInternal()
  97.184 +		throws SailException
  97.185 +	{
  97.186 +		factory.shutDown();
  97.187 +		try {
  97.188 +			if (ds != null) {
  97.189 +				ds.close();
  97.190 +			}
  97.191 +		}
  97.192 +		catch (SQLException e) {
  97.193 +			throw new RdbmsException(e);
  97.194 +		}
  97.195 +	}
  97.196 +
  97.197 +	protected void setConnectionFactory(GeneralDBConnectionFactory factory) {
  97.198 +		this.factory = factory;
  97.199 +	}
  97.200 +
  97.201 +	protected void setBasicDataSource(BasicDataSource ds) {
  97.202 +		this.ds = ds;
  97.203 +	}
  97.204 +
  97.205 +	protected GeneralDBConnectionFactory createFactory(String jdbcDriver, String url, String user, String password)
  97.206 +		throws Exception
  97.207 +	{
  97.208 +		if (jdbcDriver != null) {
  97.209 +			Class.forName(jdbcDriver);
  97.210 +		}
  97.211 +		DataSource ds = lookupDataSource(url, user, password);
  97.212 +		Connection con;
  97.213 +		if (user == null || url.startsWith("jdbc:")) {
  97.214 +			con = ds.getConnection();
  97.215 +		}
  97.216 +		else {
  97.217 +			con = ds.getConnection(user, password);
  97.218 +		}
  97.219 +		try {
  97.220 +			DatabaseMetaData metaData = con.getMetaData();
  97.221 +			GeneralDBConnectionFactory factory = newFactory(metaData);
  97.222 +			factory.setSail(this);
  97.223 +			if (user == null || url.startsWith("jdbc:")) {
  97.224 +				factory.setDataSource(ds);
  97.225 +			}
  97.226 +			else {
  97.227 +				factory.setDataSource(ds, user, password);
  97.228 +			}
  97.229 +			return factory;
  97.230 +		}
  97.231 +		finally {
  97.232 +			con.close();
  97.233 +		}
  97.234 +	}
  97.235 +
  97.236 +	protected DataSource lookupDataSource(String url, String user, String password)
  97.237 +		throws NamingException
  97.238 +	{
  97.239 +		if (url.startsWith("jdbc:")) {
  97.240 +			BasicDataSource ds = new BasicDataSource();
  97.241 +			ds.setUrl(url);
  97.242 +			ds.setUsername(user);
  97.243 +			ds.setPassword(password);
  97.244 +			setBasicDataSource(ds);
  97.245 +			return ds;
  97.246 +		}
  97.247 +		return (DataSource)new InitialContext().lookup(url);
  97.248 +	}
  97.249 +
  97.250 +	protected abstract GeneralDBConnectionFactory newFactory(DatabaseMetaData metaData)
  97.251 +		throws SQLException;
  97.252 +
  97.253 +}
    98.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    98.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBTripleRepository.java	Fri Jan 27 01:08:32 2012 +0200
    98.3 @@ -0,0 +1,561 @@
    98.4 +/*
    98.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    98.6 + *
    98.7 + * Licensed under the Aduna BSD-style license.
    98.8 + */
    98.9 +package org.openrdf.sail.generaldb;
   98.10 +
   98.11 +import java.sql.Connection;
   98.12 +import java.sql.PreparedStatement;
   98.13 +import java.sql.ResultSet;
   98.14 +import java.sql.SQLException;
   98.15 +import java.util.ArrayList;
   98.16 +import java.util.Collection;
   98.17 +import java.util.Collections;
   98.18 +import java.util.LinkedList;
   98.19 +import java.util.List;
   98.20 +
   98.21 +import info.aduna.concurrent.locks.Lock;
   98.22 +
   98.23 +import org.openrdf.model.Resource;
   98.24 +import org.openrdf.model.URI;
   98.25 +import org.openrdf.model.Value;
   98.26 +import org.openrdf.sail.SailException;
   98.27 +import org.openrdf.sail.helpers.DefaultSailChangedEvent;
   98.28 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory;
   98.29 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder;
   98.30 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlJoinBuilder;
   98.31 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlQueryBuilder;
   98.32 +import org.openrdf.sail.generaldb.iteration.EmptyGeneralDBResourceIteration;
   98.33 +import org.openrdf.sail.generaldb.iteration.EmptyGeneralDBStatementIteration;
   98.34 +import org.openrdf.sail.generaldb.iteration.GeneralDBResourceIteration;
   98.35 +import org.openrdf.sail.generaldb.iteration.GeneralDBStatementIteration;
   98.36 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   98.37 +import org.openrdf.sail.generaldb.managers.TransTableManager;
   98.38 +import org.openrdf.sail.generaldb.managers.TripleManager;
   98.39 +import org.openrdf.sail.rdbms.model.RdbmsResource;
   98.40 +import org.openrdf.sail.rdbms.model.RdbmsStatement;
   98.41 +import org.openrdf.sail.rdbms.model.RdbmsURI;
   98.42 +import org.openrdf.sail.rdbms.model.RdbmsValue;
   98.43 +import org.openrdf.sail.generaldb.schema.BNodeTable;
   98.44 +import org.openrdf.sail.generaldb.schema.IdSequence;
   98.45 +import org.openrdf.sail.generaldb.schema.LiteralTable;
   98.46 +import org.openrdf.sail.generaldb.schema.URITable;
   98.47 +import org.openrdf.sail.generaldb.schema.ValueTable;
   98.48 +
   98.49 +/**
   98.50 + * Facade to {@link GeneralDBTransTableManager}, {@link URITable}, {@link BNodeTable} and
   98.51 + * {@link LiteralTable} for adding, removing, and retrieving statements from the
   98.52 + * database.
   98.53 + * 
   98.54 + * @author James Leigh
   98.55 + */
   98.56 +public abstract class GeneralDBTripleRepository {
   98.57 +
   98.58 +	public static int STMT_BUFFER = 32;
   98.59 +
   98.60 +	protected Connection conn;
   98.61 +
   98.62 +	protected GeneralDBValueFactory vf;
   98.63 +
   98.64 +	protected TransTableManager statements;
   98.65 +
   98.66 +	protected GeneralDBQueryBuilderFactory factory;
   98.67 +
   98.68 +	protected BNodeTable bnodes;
   98.69 +
   98.70 +	protected URITable uris;
   98.71 +
   98.72 +	protected LiteralTable literals;
   98.73 +
   98.74 +	protected Lock readLock;
   98.75 +
   98.76 +	protected DefaultSailChangedEvent sailChangedEvent;
   98.77 +
   98.78 +	protected TripleManager manager;
   98.79 +
   98.80 +	protected LinkedList<RdbmsStatement> queue = new LinkedList<RdbmsStatement>();
   98.81 +
   98.82 +	protected IdSequence ids;
   98.83 +
   98.84 +	public Connection getConnection() {
   98.85 +		return conn;
   98.86 +	}
   98.87 +
   98.88 +	public void setConnection(Connection conn) {
   98.89 +		this.conn = conn;
   98.90 +	}
   98.91 +
   98.92 +	public void setIdSequence(IdSequence ids) {
   98.93 +		this.ids = ids;
   98.94 +	}
   98.95 +
   98.96 +	public GeneralDBValueFactory getValueFactory() {
   98.97 +		return vf;
   98.98 +	}
   98.99 +
  98.100 +	public void setValueFactory(GeneralDBValueFactory vf) {
  98.101 +		this.vf = vf;
  98.102 +	}
  98.103 +
  98.104 +	public DefaultSailChangedEvent getSailChangedEvent() {
  98.105 +		return sailChangedEvent;
  98.106 +	}
  98.107 +
  98.108 +	public void setSailChangedEvent(DefaultSailChangedEvent sailChangedEvent) {
  98.109 +		this.sailChangedEvent = sailChangedEvent;
  98.110 +	}
  98.111 +
  98.112 +	public void setQueryBuilderFactory(GeneralDBQueryBuilderFactory factory) {
  98.113 +		this.factory = factory;
  98.114 +	}
  98.115 +
  98.116 +	public void setBNodeTable(BNodeTable bnodes) {
  98.117 +		this.bnodes = bnodes;
  98.118 +	}
  98.119 +
  98.120 +	public void setURITable(URITable uris) {
  98.121 +		this.uris = uris;
  98.122 +	}
  98.123 +
  98.124 +	public void setLiteralTable(LiteralTable literals) {
  98.125 +		this.literals = literals;
  98.126 +	}
  98.127 +
  98.128 +	public void setTransaction(TransTableManager temporary) {
  98.129 +		this.statements = temporary;
  98.130 +	}
  98.131 +
  98.132 +	public void setTripleManager(TripleManager tripleManager) {
  98.133 +		this.manager = tripleManager;
  98.134 +	}
  98.135 +
  98.136 +	public void flush()
  98.137 +		throws RdbmsException
  98.138 +	{
  98.139 +		try {
  98.140 +			synchronized (queue) {
  98.141 +				while (!queue.isEmpty()) {
  98.142 +					insert(queue.removeFirst());
  98.143 +				}
  98.144 +			}
  98.145 +			vf.flush();
  98.146 +			manager.flush();
  98.147 +		}
  98.148 +		catch (SQLException e) {
  98.149 +			throw new RdbmsException(e);
  98.150 +		}
  98.151 +		catch (InterruptedException e) {
  98.152 +			throw new RdbmsException(e);
  98.153 +		}
  98.154 +	}
  98.155 +
  98.156 +	public synchronized void begin()
  98.157 +		throws SQLException
  98.158 +	{
  98.159 +		conn.setAutoCommit(false);
  98.160 +	}
  98.161 +
  98.162 +	public synchronized void close()
  98.163 +		throws SQLException
  98.164 +	{
  98.165 +		manager.close();
  98.166 +		if (!conn.getAutoCommit()) {
  98.167 +			conn.rollback();
  98.168 +		}
  98.169 +		conn.setAutoCommit(true);
  98.170 +		conn.close();
  98.171 +		releaseLock();
  98.172 +	}
  98.173 +
  98.174 +	public synchronized void commit()
  98.175 +		throws SQLException, RdbmsException, InterruptedException
  98.176 +	{
  98.177 +		synchronized (queue) {
  98.178 +			while (!queue.isEmpty()) {
  98.179 +				insert(queue.removeFirst());
  98.180 +			}
  98.181 +		}
  98.182 +		manager.flush();
  98.183 +		conn.commit();
  98.184 +		conn.setAutoCommit(true);
  98.185 +		releaseLock();
  98.186 +		Lock writeLock = vf.tryIdWriteLock();
  98.187 +		try {
  98.188 +			vf.flush();
  98.189 +			statements.committed(writeLock != null);
  98.190 +		}
  98.191 +		finally {
  98.192 +			if (writeLock != null) {
  98.193 +				writeLock.release();
  98.194 +			}
  98.195 +		}
  98.196 +	}
  98.197 +
  98.198 +	public void rollback()
  98.199 +		throws SQLException, SailException
  98.200 +	{
  98.201 +		synchronized (queue) {
  98.202 +			queue.clear();
  98.203 +		}
  98.204 +		manager.clear();
  98.205 +		if (!conn.getAutoCommit()) {
  98.206 +			conn.rollback();
  98.207 +			conn.setAutoCommit(true);
  98.208 +		}
  98.209 +		releaseLock();
  98.210 +	}
  98.211 +
  98.212 +	@Override
  98.213 +	protected void finalize()
  98.214 +		throws Throwable
  98.215 +	{
  98.216 +		releaseLock();
  98.217 +		super.finalize();
  98.218 +	}
  98.219 +
  98.220 +	public void add(RdbmsStatement st)
  98.221 +		throws SailException, SQLException, InterruptedException
  98.222 +	{
  98.223 +		acquireLock();
  98.224 +		synchronized (queue) {
  98.225 +			queue.add(st);
  98.226 +			if (queue.size() > getMaxQueueSize()) {
  98.227 +				insert(queue.removeFirst());
  98.228 +			}
  98.229 +		}
  98.230 +	}
  98.231 +
  98.232 +	public GeneralDBStatementIteration find(Resource subj, URI pred, Value obj, Resource... ctxs)
  98.233 +		throws RdbmsException
  98.234 +	{
  98.235 +		try {
  98.236 +			RdbmsResource s = vf.asRdbmsResource(subj);
  98.237 +			RdbmsURI p = vf.asRdbmsURI(pred);
  98.238 +			RdbmsValue o = vf.asRdbmsValue(obj);
  98.239 +			RdbmsResource[] c = vf.asRdbmsResource(ctxs);
  98.240 +			flush();
  98.241 +			GeneralDBSqlQueryBuilder query = buildSelectQuery(s, p, o, c);
  98.242 +			if (query == null)
  98.243 +				return new EmptyGeneralDBStatementIteration();
  98.244 +			List<?> parameters = query.findParameters(new ArrayList<Object>());
  98.245 +			PreparedStatement stmt = conn.prepareStatement(query.toString());
  98.246 +			try {
  98.247 +				for (int i = 0, n = parameters.size(); i < n; i++) {
  98.248 +					stmt.setObject(i + 1, parameters.get(i));
  98.249 +				}
  98.250 +				return new GeneralDBStatementIteration(vf, stmt, ids);
  98.251 +			}
  98.252 +			catch (SQLException e) {
  98.253 +				stmt.close();
  98.254 +				throw e;
  98.255 +			}
  98.256 +		}
  98.257 +		catch (SQLException e) {
  98.258 +			throw new RdbmsException(e);
  98.259 +		}
  98.260 +
  98.261 +	}
  98.262 +
  98.263 +	public GeneralDBResourceIteration findContexts()
  98.264 +		throws SQLException, RdbmsException
  98.265 +	{
  98.266 +		flush();
  98.267 +		String qry = buildContextQuery();
  98.268 +		if (qry == null)
  98.269 +			return new EmptyGeneralDBResourceIteration();
  98.270 +		PreparedStatement stmt = conn.prepareStatement(qry);
  98.271 +		try {
  98.272 +			return new GeneralDBResourceIteration(vf, stmt);
  98.273 +		}
  98.274 +		catch (SQLException e) {
  98.275 +			stmt.close();
  98.276 +			throw e;
  98.277 +		}
  98.278 +	}
  98.279 +
  98.280 +	public boolean isClosed()
  98.281 +		throws SQLException
  98.282 +	{
  98.283 +		return conn.isClosed();
  98.284 +	}
  98.285 +
  98.286 +	public int remove(Resource subj, URI pred, Value obj, Resource... ctxs)
  98.287 +		throws RdbmsException
  98.288 +	{
  98.289 +		RdbmsResource s = vf.asRdbmsResource(subj);
  98.290 +		RdbmsURI p = vf.asRdbmsURI(pred);
  98.291 +		RdbmsValue o = vf.asRdbmsValue(obj);
  98.292 +		RdbmsResource[] c = vf.asRdbmsResource(ctxs);
  98.293 +		flush();
  98.294 +		try {
  98.295 +			Collection<Number> predicates;
  98.296 +			if (p == null) {
  98.297 +				predicates = statements.getPredicateIds();
  98.298 +			}
  98.299 +			else {
  98.300 +				predicates = Collections.singleton(vf.getInternalId(p));
  98.301 +			}
  98.302 +			int total = 0;
  98.303 +			for (Number id : predicates) {
  98.304 +				String tableName = statements.findTableName(id);
  98.305 +				if (!statements.isPredColumnPresent(id)) {
  98.306 +					p = null;
  98.307 +				}
  98.308 +				String query = buildDeleteQuery(tableName, s, p, o, c);
  98.309 +				PreparedStatement stmt = conn.prepareStatement(query);
  98.310 +				try {
  98.311 +					setSelectQuery(stmt, s, p, o, c);
  98.312 +					int count = stmt.executeUpdate();
  98.313 +					statements.removed(id, count);
  98.314 +					total += count;
  98.315 +				}
  98.316 +				finally {
  98.317 +					stmt.close();
  98.318 +				}
  98.319 +			}
  98.320 +			if (total > 0) {
  98.321 +				sailChangedEvent.setStatementsRemoved(true);
  98.322 +			}
  98.323 +			return total;
  98.324 +		}
  98.325 +		catch (SQLException e) {
  98.326 +			throw new RdbmsException(e);
  98.327 +		}
  98.328 +	}
  98.329 +
  98.330 +	public long size(RdbmsResource... ctxs)
  98.331 +		throws SQLException, SailException
  98.332 +	{
  98.333 +		flush();
  98.334 +		String qry = buildCountQuery(ctxs);
  98.335 +		if (qry == null)
  98.336 +			return 0;
  98.337 +		PreparedStatement stmt = conn.prepareStatement(qry);
  98.338 +		try {
  98.339 +			setCountQuery(stmt, ctxs);
  98.340 +			ResultSet rs = stmt.executeQuery();
  98.341 +			try {
  98.342 +				if (rs.next())
  98.343 +					return rs.getLong(1);
  98.344 +				throw new RdbmsException("Could not determine size");
  98.345 +			}
  98.346 +			finally {
  98.347 +				rs.close();
  98.348 +			}
  98.349 +		}
  98.350 +		finally {
  98.351 +			stmt.close();
  98.352 +		}
  98.353 +	}
  98.354 +
  98.355 +	protected int getMaxQueueSize() {
  98.356 +		return STMT_BUFFER;
  98.357 +	}
  98.358 +
  98.359 +	protected synchronized void acquireLock()
  98.360 +		throws InterruptedException
  98.361 +	{
  98.362 +		if (readLock == null) {
  98.363 +			readLock = vf.getIdReadLock();
  98.364 +		}
  98.365 +	}
  98.366 +
  98.367 +	protected synchronized void releaseLock() {
  98.368 +		if (readLock != null) {
  98.369 +			readLock.release();
  98.370 +			readLock = null;
  98.371 +		}
  98.372 +	}
  98.373 +
  98.374 +	protected String buildContextQuery()
  98.375 +		throws SQLException
  98.376 +	{
  98.377 +		if (statements.isEmpty())
  98.378 +			return null;
  98.379 +		String tableName = statements.getCombinedTableName();
  98.380 +		GeneralDBSqlQueryBuilder query = factory.createSqlQueryBuilder();
  98.381 +		query.select().column("t", "ctx");
  98.382 +		query.select().append("CASE WHEN MIN(u.value) IS NOT NULL THEN MIN(u.value) ELSE MIN(b.value) END");
  98.383 +		GeneralDBSqlJoinBuilder join = query.from(tableName, "t");
  98.384 +		join.leftjoin(bnodes.getName(), "b").on("id", "t.ctx");
  98.385 +		join.leftjoin(uris.getShortTableName(), "u").on("id", "t.ctx");
  98.386 +		GeneralDBSqlBracketBuilder open = query.filter().and().open();
  98.387 +		open.column("u", "value").isNotNull();
  98.388 +		open.or();
  98.389 +		open.column("b", "value").isNotNull();
  98.390 +		open.close();
  98.391 +		query.groupBy("t.ctx");
  98.392 +		return query.toString();
  98.393 +	}
  98.394 +
  98.395 +	protected String buildCountQuery(RdbmsResource... ctxs)
  98.396 +		throws SQLException
  98.397 +	{
  98.398 +		String tableName = statements.getCombinedTableName();
  98.399 +		StringBuilder sb = new StringBuilder();
  98.400 +		sb.append("SELECT COUNT(*) FROM ");
  98.401 +		sb.append(tableName).append(" t");
  98.402 +		if (ctxs != null && ctxs.length > 0) {
  98.403 +			sb.append("\nWHERE ");
  98.404 +			for (int i = 0; i < ctxs.length; i++) {
  98.405 +				sb.append("t.ctx = ?");
  98.406 +				if (i < ctxs.length - 1) {
  98.407 +					sb.append(" OR ");
  98.408 +				}
  98.409 +			}
  98.410 +		}
  98.411 +		return sb.toString();
  98.412 +	}
  98.413 +
  98.414 +	protected abstract String buildDeleteQuery(String tableName, RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
  98.415 +			RdbmsResource... ctxs)
  98.416 +		throws RdbmsException, SQLException;
  98.417 +
  98.418 +	protected GeneralDBSqlQueryBuilder buildSelectQuery(RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
  98.419 +			RdbmsResource... ctxs)
  98.420 +		throws RdbmsException, SQLException
  98.421 +	{
  98.422 +		String tableName = statements.getTableName(vf.getInternalId(pred));
  98.423 +		GeneralDBSqlQueryBuilder query = factory.createSqlQueryBuilder();
  98.424 +		query.select().column("t", "ctx");
  98.425 +		query.select().append(
  98.426 +				"CASE WHEN cu.value IS NOT NULL THEN cu.value WHEN clu.value IS NOT NULL THEN clu.value ELSE cb.value END");
  98.427 +		query.select().column("t", "subj");
  98.428 +		query.select().append(
  98.429 +				"CASE WHEN su.value IS NOT NULL THEN su.value WHEN slu.value IS NOT NULL THEN slu.value ELSE sb.value END");
  98.430 +		query.select().column("pu", "id");
  98.431 +		query.select().column("pu", "value");
  98.432 +		query.select().column("t", "obj");
  98.433 +		query.select().append(
  98.434 +				"CASE WHEN ou.value IS NOT NULL THEN ou.value" + " WHEN olu.value IS NOT NULL THEN olu.value"
  98.435 +						+ " WHEN ob.value IS NOT NULL THEN ob.value"
  98.436 +						+ " WHEN ol.value IS NOT NULL THEN ol.value ELSE oll.value END");
  98.437 +		query.select().column("od", "value");
  98.438 +		query.select().column("og", "value");
  98.439 +		GeneralDBSqlJoinBuilder join;
  98.440 +		if (pred != null) {
  98.441 +			join = query.from(uris.getShortTableName(), "pu");
  98.442 +			// TODO what about long predicate URIs?
  98.443 +			join = join.join(tableName, "t");
  98.444 +		}
  98.445 +		else {
  98.446 +			join = query.from(tableName, "t");
  98.447 +		}
  98.448 +		if (pred == null) {
  98.449 +			join.join(uris.getShortTableName(), "pu").on("id", "t.pred");
  98.450 +		}
  98.451 +		join.leftjoin(uris.getShortTableName(), "cu").on("id", "t.ctx");
  98.452 +		join.leftjoin(uris.getLongTableName(), "clu").on("id", "t.ctx");
  98.453 +		join.leftjoin(bnodes.getName(), "cb").on("id", "t.ctx");
  98.454 +		join.leftjoin(uris.getShortTableName(), "su").on("id", "t.subj");
  98.455 +		join.leftjoin(uris.getLongTableName(), "slu").on("id", "t.subj");
  98.456 +		join.leftjoin(bnodes.getName(), "sb").on("id", "t.subj");
  98.457 +		join.leftjoin(uris.getShortTableName(), "ou").on("id", "t.obj");
  98.458 +		join.leftjoin(uris.getLongTableName(), "olu").on("id", "t.obj");
  98.459 +		join.leftjoin(bnodes.getName(), "ob").on("id", "t.obj");
  98.460 +		join.leftjoin(literals.getLabelTable().getName(), "ol").on("id", "t.obj");
  98.461 +		join.leftjoin(literals.getLongLabelTable().getName(), "oll").on("id", "t.obj");
  98.462 +		join.leftjoin(literals.getLanguageTable().getName(), "og").on("id", "t.obj");
  98.463 +		join.leftjoin(literals.getDatatypeTable().getName(), "od").on("id", "t.obj");
  98.464 +		if (ctxs != null && ctxs.length > 0) {
  98.465 +			Number[] ids = new Number[ctxs.length];
  98.466 +			for (int i = 0; i < ids.length; i++) {
  98.467 +				ids[i] = vf.getInternalId(ctxs[i]);
  98.468 +			}
  98.469 +			query.filter().and().columnIn("t", "ctx", ids);
  98.470 +		}
  98.471 +		if (subj != null) {
  98.472 +			Number id = vf.getInternalId(subj);
  98.473 +			query.filter().and().columnEquals("t", "subj", id);
  98.474 +		}
  98.475 +		if (pred != null) {
  98.476 +			Number id = vf.getInternalId(pred);
  98.477 +			query.filter().and().columnEquals("pu", "id", id);
  98.478 +			if (statements.isPredColumnPresent(id)) {
  98.479 +				query.filter().and().columnEquals("t", "pred", id);
  98.480 +			}
  98.481 +		}
  98.482 +		if (obj != null) {
  98.483 +			Number id = vf.getInternalId(obj);
  98.484 +			query.filter().and().columnEquals("t", "obj", id);
  98.485 +		}
  98.486 +		return query;
  98.487 +	}
  98.488 +
  98.489 +	protected abstract String buildWhere(StringBuilder sb, RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
  98.490 +			RdbmsResource... ctxs);
  98.491 +
  98.492 +	protected void insert(RdbmsStatement st)
  98.493 +		throws RdbmsException, SQLException, InterruptedException
  98.494 +	{
  98.495 +		Number ctx = vf.getInternalId(st.getContext());
  98.496 +		Number subj = vf.getInternalId(st.getSubject());
  98.497 +		Number pred = vf.getPredicateId(st.getPredicate());
  98.498 +		Number obj = vf.getInternalId(st.getObject());
  98.499 +		manager.insert(ctx, subj, pred, obj);
  98.500 +	}
  98.501 +
  98.502 +	protected void setCountQuery(PreparedStatement stmt, RdbmsResource... ctxs)
  98.503 +		throws SQLException, RdbmsException
  98.504 +	{
  98.505 +		if (ctxs != null && ctxs.length > 0) {
  98.506 +			for (int i = 0; i < ctxs.length; i++) {
  98.507 +				stmt.setObject(i + 1, vf.getInternalId(ctxs[i]));
  98.508 +			}
  98.509 +		}
  98.510 +	}
  98.511 +
  98.512 +	protected void setSelectQuery(PreparedStatement stmt, RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
  98.513 +			RdbmsResource... ctxs)
  98.514 +		throws SQLException, RdbmsException
  98.515 +	{
  98.516 +		int p = 0;
  98.517 +		if (ctxs != null && ctxs.length > 0) {
  98.518 +			for (int i = 0; i < ctxs.length; i++) {
  98.519 +				if (ctxs[i] == null) {
  98.520 +					stmt.setLong(++p, ValueTable.NIL_ID);
  98.521 +				}
  98.522 +				else {
  98.523 +					stmt.setObject(++p, vf.getInternalId(ctxs[i]));
  98.524 +				}
  98.525 +			}
  98.526 +		}
  98.527 +		if (subj != null) {
  98.528 +			stmt.setObject(++p, vf.getInternalId(subj));
  98.529 +		}
  98.530 +		if (pred != null) {
  98.531 +			stmt.setObject(++p, vf.getInternalId(pred));
  98.532 +		}
  98.533 +		if (obj != null) {
  98.534 +			stmt.setObject(++p, vf.getInternalId(obj));
  98.535 +		}
  98.536 +	}
  98.537 +	
  98.538 +	/****XXX MY ADDITION 21/4/10 ***/
  98.539 +	public void clearGeoValues()
  98.540 +	throws RdbmsException
  98.541 +	{
  98.542 +
  98.543 +		try
  98.544 +		{
  98.545 +
  98.546 +			String query = buildDeleteQuery("geo_values", null,null,null,null);
  98.547 +			PreparedStatement stmt = conn.prepareStatement(query);
  98.548 +			try {
  98.549 +				setSelectQuery(stmt, null,null,null,null);
  98.550 +				int count = stmt.executeUpdate();
  98.551 +
  98.552 +			}
  98.553 +			finally {
  98.554 +				stmt.close();
  98.555 +			}
  98.556 +
  98.557 +		}
  98.558 +		catch (SQLException e) {
  98.559 +			throw new RdbmsException(e);
  98.560 +		}
  98.561 +
  98.562 +	}
  98.563 +
  98.564 +}
    99.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    99.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/GeneralDBValueFactory.java	Fri Jan 27 01:08:32 2012 +0200
    99.3 @@ -0,0 +1,346 @@
    99.4 +/*
    99.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
    99.6 + *
    99.7 + * Licensed under the Aduna BSD-style license.
    99.8 + */
    99.9 +package org.openrdf.sail.generaldb;
   99.10 +
   99.11 +import java.io.IOException;
   99.12 +import java.sql.SQLException;
   99.13 +
   99.14 +import info.aduna.concurrent.locks.Lock;
   99.15 +import info.aduna.concurrent.locks.WritePrefReadWriteLockManager;
   99.16 +
   99.17 +import org.openrdf.model.BNode;
   99.18 +import org.openrdf.model.Literal;
   99.19 +import org.openrdf.model.Resource;
   99.20 +import org.openrdf.model.Statement;
   99.21 +import org.openrdf.model.URI;
   99.22 +import org.openrdf.model.Value;
   99.23 +import org.openrdf.model.ValueFactory;
   99.24 +import org.openrdf.model.impl.ValueFactoryBase;
   99.25 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
   99.26 +import org.openrdf.sail.rdbms.exceptions.RdbmsException;
   99.27 +import org.openrdf.sail.rdbms.exceptions.RdbmsRuntimeException;
   99.28 +import org.openrdf.sail.generaldb.managers.BNodeManager;
   99.29 +import org.openrdf.sail.generaldb.managers.LiteralManager;
   99.30 +import org.openrdf.sail.generaldb.managers.PredicateManager;
   99.31 +import org.openrdf.sail.generaldb.managers.UriManager;
   99.32 +import org.openrdf.sail.rdbms.model.RdbmsBNode;
   99.33 +import org.openrdf.sail.rdbms.model.RdbmsLiteral;
   99.34 +import org.openrdf.sail.rdbms.model.RdbmsResource;
   99.35 +import org.openrdf.sail.rdbms.model.RdbmsStatement;
   99.36 +import org.openrdf.sail.rdbms.model.RdbmsURI;
   99.37 +import org.openrdf.sail.rdbms.model.RdbmsValue;
   99.38 +import org.openrdf.sail.generaldb.schema.IdSequence;
   99.39 +import org.openrdf.sail.generaldb.schema.LiteralTable;
   99.40 +import org.openrdf.sail.generaldb.schema.ValueTable;
   99.41 +
   99.42 +import com.vividsolutions.jts.io.ParseException;
   99.43 +
   99.44 +/**
   99.45 + * Provides basic value creation both for traditional values as well as values
   99.46 + * with an internal id. {@link RdbmsValue}s behaviour similar to the default
   99.47 + * {@link Value} implementation with the addition that they also include an
   99.48 + * internal id and a version associated with that id. The internal ids should
   99.49 + * not be accessed directly, but rather either through this class or the
   99.50 + * corresponding manager class.
   99.51 + * 
   99.52 + * @author James Leigh
   99.53 + * 
   99.54 + */
   99.55 +public class GeneralDBValueFactory extends ValueFactoryBase {
   99.56 +
   99.57 +	@Deprecated
   99.58 +	public static final String NIL_LABEL = "nil";
   99.59 +
   99.60 +	private ValueFactory vf;
   99.61 +
   99.62 +	private BNodeManager bnodes;
   99.63 +
   99.64 +	private UriManager uris;
   99.65 +
   99.66 +	private LiteralManager literals;
   99.67 +
   99.68 +	private PredicateManager predicates;
   99.69 +
   99.70 +	private WritePrefReadWriteLockManager lock = new WritePrefReadWriteLockManager();
   99.71 +
   99.72 +	private IdSequence ids;
   99.73 +
   99.74 +	public void setIdSequence(IdSequence ids) {
   99.75 +		this.ids = ids;
   99.76 +	}
   99.77 +
   99.78 +	public void setBNodeManager(BNodeManager bnodes) {
   99.79 +		this.bnodes = bnodes;
   99.80 +	}
   99.81 +
   99.82 +	public void setURIManager(UriManager uris) {
   99.83 +		this.uris = uris;
   99.84 +	}
   99.85 +
   99.86 +	public void setLiteralManager(LiteralManager literals) {
   99.87 +		this.literals = literals;
   99.88 +	}
   99.89 +
   99.90 +	public void setPredicateManager(PredicateManager predicates) {
   99.91 +		this.predicates = predicates;
   99.92 +	}
   99.93 +
   99.94 +	public void setDelegate(ValueFactory vf) {
   99.95 +		this.vf = vf;
   99.96 +	}
   99.97 +
   99.98 +	public void flush()
   99.99 +	throws RdbmsException
  99.100 +	{
  99.101 +		try {
  99.102 +			bnodes.flush();
  99.103 +			uris.flush();
  99.104 +			literals.flush();
  99.105 +		}
  99.106 +		catch (SQLException e) {
  99.107 +			throw new RdbmsException(e);
  99.108 +		}
  99.109 +		catch (InterruptedException e) {
  99.110 +			throw new RdbmsException(e);
  99.111 +		}
  99.112 +	}
  99.113 +
  99.114 +	public RdbmsBNode createBNode(String nodeID) {
  99.115 +		RdbmsBNode resource = bnodes.findInCache(nodeID);
  99.116 +		if (resource == null) {
  99.117 +			try {
  99.118 +				BNode impl = vf.createBNode(nodeID);
  99.119 +				resource = new RdbmsBNode(impl);
  99.120 +				bnodes.cache(resource);
  99.121 +			}
  99.122 +			catch (InterruptedException e) {
  99.123 +				throw new RdbmsRuntimeException(e);
  99.124 +			}
  99.125 +		}
  99.126 +		return resource;
  99.127 +	}
  99.128 +
  99.129 +	public RdbmsLiteral createLiteral(String label) {
  99.130 +		return asRdbmsLiteral(vf.createLiteral(label));
  99.131 +	}
  99.132 +
  99.133 +	public RdbmsLiteral createLiteral(String label, String language) {
  99.134 +		if (LiteralTable.ONLY_INSERT_LABEL)
  99.135 +			return createLiteral(label);
  99.136 +		return asRdbmsLiteral(vf.createLiteral(label, language));
  99.137 +	}
  99.138 +
  99.139 +	public RdbmsLiteral createLiteral(String label, URI datatype) {
  99.140 +		if (LiteralTable.ONLY_INSERT_LABEL)
  99.141 +			return createLiteral(label);
  99.142 +		return asRdbmsLiteral(vf.createLiteral(label, datatype));
  99.143 +	}
  99.144 +
  99.145 +	public RdbmsStatement createStatement(Resource subject, URI predicate, Value object) {
  99.146 +		return createStatement(subject, predicate, object, null);
  99.147 +	}
  99.148 +
  99.149 +	public RdbmsStatement createStatement(Resource subject, URI predicate, Value object, Resource context) {
  99.150 +		RdbmsResource subj = asRdbmsResource(subject);
  99.151 +		RdbmsURI pred = asRdbmsURI(predicate);
  99.152 +		RdbmsValue obj = asRdbmsValue(object);
  99.153 +		RdbmsResource ctx = asRdbmsResource(context);
  99.154 +		return new RdbmsStatement(subj, pred, obj, ctx);
  99.155 +	}
  99.156 +
  99.157 +	public RdbmsURI createURI(String uri) {
  99.158 +		RdbmsURI resource = uris.findInCache(uri);
  99.159 +		if (resource == null) {
  99.160 +			try {
  99.161 +				URI impl = vf.createURI(uri);
  99.162 +				resource = new RdbmsURI(impl);
  99.163 +				uris.cache(resource);
  99.164 +			}
  99.165 +			catch (InterruptedException e) {
  99.166 +				throw new RdbmsRuntimeException(e);
  99.167 +			}
  99.168 +		}
  99.169 +		return resource;
  99.170 +	}
  99.171 +
  99.172 +	public RdbmsURI createURI(String namespace, String localName) {
  99.173 +		return createURI(namespace + localName);
  99.174 +	}
  99.175 +
  99.176 +	public RdbmsResource getRdbmsResource(Number num, String stringValue) {
  99.177 +		assert stringValue != null : "Null stringValue for ID: " + num;
  99.178 +		Number id = ids.idOf(num);
  99.179 +		if (ids.isURI(id))
  99.180 +			return new RdbmsURI(id, uris.getIdVersion(), vf.createURI(stringValue));
  99.181 +		return new RdbmsBNode(id, bnodes.getIdVersion(), vf.createBNode(stringValue));
  99.182 +	}
  99.183 +
  99.184 +	public RdbmsLiteral getRdbmsLiteral(Number num, String label, String language, String datatype) {
  99.185 +		Number id = ids.idOf(num);
  99.186 +		if (datatype == null && language == null)
  99.187 +			return new RdbmsLiteral(id, literals.getIdVersion(), vf.createLiteral(label));
  99.188 +		if (datatype == null)
  99.189 +			return new RdbmsLiteral(id, literals.getIdVersion(), vf.createLiteral(label, language));
  99.190 +		return new RdbmsLiteral(id, literals.getIdVersion(), vf.createLiteral(label, vf.createURI(datatype)));
  99.191 +	}
  99.192 +
  99.193 +	public RdbmsResource asRdbmsResource(Resource node) {
  99.194 +		if (node == null)
  99.195 +			return null;
  99.196 +		if (node instanceof URI)
  99.197 +			return asRdbmsURI((URI)node);
  99.198 +		if (node instanceof RdbmsBNode) {
  99.199 +			try {
  99.200 +				bnodes.cache((RdbmsBNode)node);
  99.201 +				return (RdbmsBNode)node;
  99.202 +			}
  99.203 +			catch (InterruptedException e) {
  99.204 +				throw new RdbmsRuntimeException(e);
  99.205 +			}
  99.206 +		}
  99.207 +		return createBNode(((BNode)node).getID());
  99.208 +	}
  99.209 +
  99.210 +	public RdbmsURI asRdbmsURI(URI uri) {
  99.211 +		if (uri == null)
  99.212 +			return null;
  99.213 +		if (uri instanceof RdbmsURI) {
  99.214 +			try {
  99.215 +				uris.cache((RdbmsURI)uri);
  99.216 +				return (RdbmsURI)uri;
  99.217 +			}
  99.218 +			catch (InterruptedException e) {
  99.219 +				throw new RdbmsRuntimeException(e);
  99.220 +			}
  99.221 +		}
  99.222 +		return createURI(uri.stringValue());
  99.223 +	}
  99.224 +
  99.225 +	public RdbmsValue asRdbmsValue(Value value) {
  99.226 +		if (value == null)
  99.227 +			return null;
  99.228 +		if (value instanceof Literal)
  99.229 +			return asRdbmsLiteral((Literal)value);
  99.230 +		return asRdbmsResource((Resource)value);
  99.231 +	}
  99.232 +
  99.233 +	public RdbmsLiteral asRdbmsLiteral(Literal literal) {
  99.234 +		try {
  99.235 +			if (literal instanceof RdbmsLiteral) {
  99.236 +				literals.cache((RdbmsLiteral)literal);
  99.237 +				return (RdbmsLiteral)literal;
  99.238 +			}
  99.239 +			RdbmsLiteral lit = literals.findInCache(literal);
  99.240 +			if (lit == null) {
  99.241 +				lit = new RdbmsLiteral(literal);
  99.242 +				literals.cache(lit);
  99.243 +			}
  99.244 +			return lit;
  99.245 +		}
  99.246 +		catch (InterruptedException e) {
  99.247 +			throw new RdbmsRuntimeException(e);
  99.248 +		}
  99.249 +	}
  99.250 +
  99.251 +	public RdbmsResource[] asRdbmsResource(Resource... contexts) {
  99.252 +		RdbmsResource[] ctxs = new RdbmsResource[contexts.length];
  99.253 +		for (int i = 0; i < ctxs.length; i++) {
  99.254 +			ctxs[i] = asRdbmsResource(contexts[i]);
  99.255 +		}
  99.256 +		return ctxs;
  99.257 +	}
  99.258 +
  99.259 +	public RdbmsStatement asRdbmsStatement(Statement stmt) {
  99.260 +		if (stmt instanceof RdbmsStatement)
  99.261 +			return (RdbmsStatement)stmt;
  99.262 +		Resource s = stmt.getSubject();
  99.263 +		URI p = stmt.getPredicate();
  99.264 +		Value o = stmt.getObject();
  99.265 +		Resource c = stmt.getContext();
  99.266 +		return createStatement(s, p, o, c);
  99.267 +	}
  99.268 +
  99.269 +	public Number getInternalId(Value r)
  99.270 +	throws RdbmsException
  99.271 +	{
  99.272 +		try {
  99.273 +			if (r == null)
  99.274 +				return ValueTable.NIL_ID;
  99.275 +			RdbmsValue value = asRdbmsValue(r);
  99.276 +			if (value instanceof RdbmsURI)
  99.277 +				return uris.getInternalId((RdbmsURI)value);
  99.278 +			if (value instanceof RdbmsBNode)
  99.279 +				return bnodes.getInternalId((RdbmsBNode)value);
  99.280 +			return literals.getInternalId((RdbmsLiteral)value);
  99.281 +		}
  99.282 +		catch (SQLException e) {
  99.283 +			throw new RdbmsException(e);
  99.284 +		}
  99.285 +		catch (InterruptedException e) {
  99.286 +			throw new RdbmsRuntimeException(e);
  99.287 +		}
  99.288 +	}
  99.289 +
  99.290 +	public Number getPredicateId(RdbmsURI predicate)
  99.291 +	throws RdbmsException
  99.292 +	{
  99.293 +		try {
  99.294 +			return predicates.getIdOfPredicate(predicate);
  99.295 +		}
  99.296 +		catch (SQLException e) {
  99.297 +			throw new RdbmsException(e);
  99.298 +		}
  99.299 +		catch (InterruptedException e) {
  99.300 +			throw new RdbmsRuntimeException(e);
  99.301 +		}
  99.302 +	}
  99.303 +
  99.304 +	public Lock getIdReadLock() throws InterruptedException {
  99.305 +		return lock.getReadLock();
  99.306 +	}
  99.307 +
  99.308 +	public Lock tryIdWriteLock() {
  99.309 +		return lock.tryWriteLock();
  99.310 +	}
  99.311 +
  99.312 +	public Lock getIdWriteLock() throws InterruptedException {
  99.313 +		return lock.getWriteLock();
  99.314 +	}
  99.315 +
  99.316 +	/**
  99.317 +	 * FIXME my addition
  99.318 +	 * @throws ParseException 
  99.319 +	 */
  99.320 +
  99.321 +	public GeneralDBPolyhedron getRdbmsPolyhedron(Number num, String datatype, byte[] pointSet)  {
  99.322 +
  99.323 +		Number id = ids.idOf(num);
  99.324 +		try {
  99.325 +			return new GeneralDBPolyhedron(id, literals.getIdVersion(), vf.createURI(datatype), pointSet);
  99.326 +		} catch (IOException e) {
  99.327 +			e.printStackTrace();
  99.328 +		} catch (ClassNotFoundException e) {
  99.329 +			e.printStackTrace();
  99.330 +		}
  99.331 +		return null;
  99.332 +	}
  99.333 +	
  99.334 +//	public GeneralDBPolyhedron getRdbmsPolyhedron(Number num, String datatype, String pointSet) {
  99.335 +//
  99.336 +//		Number id = ids.idOf(num);
  99.337 +//		try {
  99.338 +//			return new GeneralDBPolyhedron(id, literals.getIdVersion(), vf.createURI(datatype), pointSet);
  99.339 +//		} catch (IOException e) {
  99.340 +//			e.printStackTrace();
  99.341 +//		} catch (ClassNotFoundException e) {
  99.342 +//			e.printStackTrace();
  99.343 +//		}
  99.344 +//		return null;
  99.345 +//	}
  99.346 +	/**
  99.347 +	 * 
  99.348 +	 */
  99.349 +}
   100.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   100.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBBNodeColumn.java	Fri Jan 27 01:08:32 2012 +0200
   100.3 @@ -0,0 +1,34 @@
   100.4 +/*
   100.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   100.6 + *
   100.7 + * Licensed under the Aduna BSD-style license.
   100.8 + */
   100.9 +package org.openrdf.sail.generaldb.algebra;
  100.10 +
  100.11 +import org.openrdf.query.algebra.Var;
  100.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  100.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBValueColumnBase;
  100.14 +
  100.15 +/**
  100.16 + * Represents the BNode value of a variable.
  100.17 + * 
  100.18 + * @author James Leigh
  100.19 + * 
  100.20 + */
  100.21 +public class GeneralDBBNodeColumn extends GeneralDBValueColumnBase {
  100.22 +
  100.23 +	public GeneralDBBNodeColumn(GeneralDBColumnVar var) {
  100.24 +		super(var);
  100.25 +	}
  100.26 +
  100.27 +	public GeneralDBBNodeColumn(Var var) {
  100.28 +		super(var);
  100.29 +	}
  100.30 +
  100.31 +	@Override
  100.32 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  100.33 +		throws X
  100.34 +	{
  100.35 +		visitor.meet(this);
  100.36 +	}
  100.37 +}
   101.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   101.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBColumnVar.java	Fri Jan 27 01:08:32 2012 +0200
   101.3 @@ -0,0 +1,305 @@
   101.4 +/*
   101.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   101.6 + *
   101.7 + * Licensed under the Aduna BSD-style license.
   101.8 + */
   101.9 +package org.openrdf.sail.generaldb.algebra;
  101.10 +
  101.11 +import org.openrdf.model.Resource;
  101.12 +import org.openrdf.model.URI;
  101.13 +import org.openrdf.model.Value;
  101.14 +import org.openrdf.query.algebra.Var;
  101.15 +import org.openrdf.sail.rdbms.model.RdbmsResource;
  101.16 +import org.openrdf.sail.rdbms.model.RdbmsURI;
  101.17 +import org.openrdf.sail.rdbms.schema.ValueTypes;
  101.18 +
  101.19 +/**
  101.20 + * Represents a variable in an SQL expression.
  101.21 + * 
  101.22 + * @author James Leigh
  101.23 + * 
  101.24 + */
  101.25 +public class GeneralDBColumnVar implements Cloneable {
  101.26 +
  101.27 +	private int index;
  101.28 +
  101.29 +	private boolean anonymous;
  101.30 +
  101.31 +	private boolean hidden;
  101.32 +
  101.33 +	private boolean implied;
  101.34 +
  101.35 +	private String name;
  101.36 +
  101.37 +	private Value value;
  101.38 +
  101.39 +	private String alias;
  101.40 +
  101.41 +	
  101.42 +
  101.43 +	private String column;
  101.44 +
  101.45 +	private boolean nullable;
  101.46 +
  101.47 +	private ValueTypes types;
  101.48 +	
  101.49 +	//indicates whether the object is of spatial nature
  101.50 +	private boolean spatial = false;
  101.51 +	
  101.52 +	//used to change numeric in case of buffer in select
  101.53 +	public void setAlias(String alias) {
  101.54 +		this.alias = alias;
  101.55 +	}
  101.56 +
  101.57 +	private GeneralDBColumnVar() {
  101.58 +	}
  101.59 +
  101.60 +	public static GeneralDBColumnVar createSubj(String alias, Var v, Resource resource) {
  101.61 +		GeneralDBColumnVar var = new GeneralDBColumnVar();
  101.62 +		var.alias = alias;
  101.63 +		var.column = "subj";
  101.64 +		var.name = v.getName();
  101.65 +		var.anonymous = v.isAnonymous();
  101.66 +		var.value = resource;
  101.67 +		var.types = ValueTypes.RESOURCE;
  101.68 +		if (resource instanceof RdbmsURI) {
  101.69 +			var.types = ValueTypes.URI;
  101.70 +		}
  101.71 +		return var;
  101.72 +	}
  101.73 +
  101.74 +	public static GeneralDBColumnVar createPred(String alias, Var v, URI uri, boolean implied) {
  101.75 +		GeneralDBColumnVar var = createSubj(alias, v, uri);
  101.76 +		var.column = "pred";
  101.77 +		var.implied = uri != null && implied;
  101.78 +		var.types = ValueTypes.URI;
  101.79 +		return var;
  101.80 +	}
  101.81 +
  101.82 +	public static GeneralDBColumnVar createObj(String alias, Var v, Value value) {
  101.83 +		GeneralDBColumnVar var = new GeneralDBColumnVar();
  101.84 +		var.alias = alias;
  101.85 +		var.column = "obj";
  101.86 +		var.name = v.getName();
  101.87 +		var.anonymous = v.isAnonymous();
  101.88 +		var.value = value;
  101.89 +		var.types = ValueTypes.UNKNOWN;
  101.90 +		if (value instanceof RdbmsURI) {
  101.91 +			var.types = ValueTypes.URI;
  101.92 +		}
  101.93 +		else if (value instanceof RdbmsResource) {
  101.94 +			var.types = ValueTypes.RESOURCE;
  101.95 +		}
  101.96 +		return var;
  101.97 +	}
  101.98 +	
  101.99 +	/**
 101.100 +	 * 13/09/2011
 101.101 +	 * Extra constructor to use in spatial cases
 101.102 +	 * 
 101.103 +	 */
 101.104 +	public static GeneralDBColumnVar createSpatialColumn(String alias, Var v, Value value) {
 101.105 +		GeneralDBColumnVar var = new GeneralDBColumnVar();
 101.106 +		var.alias = alias;
 101.107 +		var.column = "id";
 101.108 +		var.name = v.getName();
 101.109 +		var.anonymous = v.isAnonymous();
 101.110 +		var.value = value;
 101.111 +		var.types = ValueTypes.UNKNOWN;
 101.112 +		if (value instanceof RdbmsResource) {
 101.113 +			var.types = ValueTypes.RESOURCE;
 101.114 +		}
 101.115 +		
 101.116 +		var.setSpatial(true);
 101.117 +		
 101.118 +		return var;
 101.119 +	}
 101.120 +	
 101.121 +	/**
 101.122 +	 * Extra constructor to use in spatial cases
 101.123 +	 * @param isSpatial
 101.124 +	 * @return
 101.125 +	 */
 101.126 +	public static GeneralDBColumnVar createObj(String alias, Var v, Value value, boolean isSpatial) {
 101.127 +		GeneralDBColumnVar var = new GeneralDBColumnVar();
 101.128 +		var.alias = alias;
 101.129 +		var.column = "obj";
 101.130 +		var.name = v.getName();
 101.131 +		var.anonymous = v.isAnonymous();
 101.132 +		var.value = value;
 101.133 +		var.types = ValueTypes.UNKNOWN;
 101.134 +		if (value instanceof RdbmsURI) {
 101.135 +			var.types = ValueTypes.URI;
 101.136 +		}
 101.137 +		else if (value instanceof RdbmsResource) {
 101.138 +			var.types = ValueTypes.RESOURCE;
 101.139 +		}
 101.140 +		
 101.141 +		var.setSpatial(isSpatial);
 101.142 +		
 101.143 +		return var;
 101.144 +	}
 101.145 +
 101.146 +	public static GeneralDBColumnVar createCtx(String alias, Var v, Resource resource) {
 101.147 +		GeneralDBColumnVar var = new GeneralDBColumnVar();
 101.148 +		var.alias = alias;
 101.149 +		var.column = "ctx";
 101.150 +		if (v == null) {
 101.151 +			var.name = "__ctx" + Integer.toHexString(System.identityHashCode(var));
 101.152 +			var.anonymous = true;
 101.153 +			var.hidden = true;
 101.154 +		}
 101.155 +		else {
 101.156 +			var.name = v.getName();
 101.157 +			var.anonymous = v.isAnonymous();
 101.158 +		}
 101.159 +		var.value = resource;
 101.160 +		var.types = ValueTypes.RESOURCE;
 101.161 +		if (resource instanceof RdbmsURI) {
 101.162 +			var.types = ValueTypes.URI;
 101.163 +		}
 101.164 +		return var;
 101.165 +	}
 101.166 +
 101.167 +	
 101.168 +	
 101.169 +	public boolean isSpatial() {
 101.170 +		return spatial;
 101.171 +	}
 101.172 +
 101.173 +	public void setSpatial(boolean spatial) {
 101.174 +		this.spatial = spatial;
 101.175 +	}
 101.176 +
 101.177 +	public ValueTypes getTypes() {
 101.178 +		return types;
 101.179 +	}
 101.180 +
 101.181 +	public void setTypes(ValueTypes types) {
 101.182 +		this.types = types;
 101.183 +	}
 101.184 +
 101.185 +	public boolean isAnonymous() {
 101.186 +		return anonymous;
 101.187 +	}
 101.188 +
 101.189 +	public boolean isHidden() {
 101.190 +		return hidden;
 101.191 +	}
 101.192 +
 101.193 +	public boolean isHiddenOrConstant() {
 101.194 +		return hidden || value != null;
 101.195 +	}
 101.196 +
 101.197 +	public boolean isImplied() {
 101.198 +		return implied;
 101.199 +	}
 101.200 +
 101.201 +	public boolean isResource() {
 101.202 +		return !types.isLiterals();
 101.203 +	}
 101.204 +
 101.205 +	public boolean isURI() {
 101.206 +		return !types.isLiterals() && !types.isBNodes();
 101.207 +	}
 101.208 +
 101.209 +	public boolean isNullable() {
 101.210 +		return nullable;
 101.211 +	}
 101.212 +
 101.213 +	public int getIndex() {
 101.214 +		return index;
 101.215 +	}
 101.216 +
 101.217 +	public void setIndex(int index) {
 101.218 +		this.index = index;
 101.219 +	}
 101.220 +
 101.221 +	public String getName() {
 101.222 +		return name;
 101.223 +	}
 101.224 +
 101.225 +	public Value getValue() {
 101.226 +		return value;
 101.227 +	}
 101.228 +
 101.229 +	public void setValue(Value value) {
 101.230 +		this.value = value;
 101.231 +		if (value == null) {
 101.232 +			implied = false;
 101.233 +		}
 101.234 +	}
 101.235 +
 101.236 +	public String getColumn() {
 101.237 +		return column;
 101.238 +	}
 101.239 +
 101.240 +	public boolean isPredicate() {
 101.241 +		return "pred".equals(column);
 101.242 +	}
 101.243 +
 101.244 +	public String getAlias() {
 101.245 +		return alias;
 101.246 +	}
 101.247 +
 101.248 +	public GeneralDBColumnVar as(String name) {
 101.249 +		try {
 101.250 +			GeneralDBColumnVar clone = (GeneralDBColumnVar)super.clone();
 101.251 +			clone.name = name;
 101.252 +			return clone;
 101.253 +		}
 101.254 +		catch (CloneNotSupportedException e) {
 101.255 +			throw new AssertionError(e);
 101.256 +		}
 101.257 +	}
 101.258 +
 101.259 +	public GeneralDBColumnVar as(String alias, String column) {
 101.260 +		try {
 101.261 +			GeneralDBColumnVar clone = (GeneralDBColumnVar)super.clone();
 101.262 +			clone.alias = alias;
 101.263 +			clone.column = column;
 101.264 +			clone.nullable = true;
 101.265 +			//XXX
 101.266 +			clone.spatial = spatial;
 101.267 +			return clone;
 101.268 +		}
 101.269 +		catch (CloneNotSupportedException e) {
 101.270 +			throw new AssertionError(e);
 101.271 +		}
 101.272 +	}
 101.273 +
 101.274 +	@Override
 101.275 +	public boolean equals(Object other) {
 101.276 +		if (other instanceof GeneralDBColumnVar) {
 101.277 +			return name.equals(((GeneralDBColumnVar)other).name);
 101.278 +		}
 101.279 +
 101.280 +		return false;
 101.281 +	}
 101.282 +
 101.283 +	@Override
 101.284 +	public int hashCode() {
 101.285 +		return name.hashCode();
 101.286 +	}
 101.287 +
 101.288 +	@Override
 101.289 +	public String toString() {
 101.290 +		StringBuilder sb = new StringBuilder(128);
 101.291 +
 101.292 +		sb.append(alias).append(".").append(column);
 101.293 +
 101.294 +		sb.append(" (name=").append(name);
 101.295 +
 101.296 +		if (value != null) {
 101.297 +			sb.append(", value=").append(value.toString());
 101.298 +		}
 101.299 +
 101.300 +		sb.append(")");
 101.301 +		if (index > 0) {
 101.302 +			sb.append("#").append(index);
 101.303 +		}
 101.304 +
 101.305 +		return sb.toString();
 101.306 +	}
 101.307 +
 101.308 +}
   102.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   102.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDatatypeColumn.java	Fri Jan 27 01:08:32 2012 +0200
   102.3 @@ -0,0 +1,35 @@
   102.4 +/*
   102.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   102.6 + *
   102.7 + * Licensed under the Aduna BSD-style license.
   102.8 + */
   102.9 +package org.openrdf.sail.generaldb.algebra;
  102.10 +
  102.11 +import org.openrdf.query.algebra.Var;
  102.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  102.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBValueColumnBase;
  102.14 +
  102.15 +/**
  102.16 + * Represents a variable's datatype value in an SQL expression.
  102.17 + * 
  102.18 + * @author James Leigh
  102.19 + * 
  102.20 + */
  102.21 +public class GeneralDBDatatypeColumn extends GeneralDBValueColumnBase {
  102.22 +
  102.23 +	public GeneralDBDatatypeColumn(Var var) {
  102.24 +		super(var);
  102.25 +	}
  102.26 +
  102.27 +	public GeneralDBDatatypeColumn(GeneralDBColumnVar var) {
  102.28 +		super(var);
  102.29 +	}
  102.30 +
  102.31 +	@Override
  102.32 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  102.33 +		throws X
  102.34 +	{
  102.35 +		visitor.meet(this);
  102.36 +	}
  102.37 +
  102.38 +}
   103.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   103.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDateTimeColumn.java	Fri Jan 27 01:08:32 2012 +0200
   103.3 @@ -0,0 +1,31 @@
   103.4 +/*
   103.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   103.6 + *
   103.7 + * Licensed under the Aduna BSD-style license.
   103.8 + */
   103.9 +package org.openrdf.sail.generaldb.algebra;
  103.10 +
  103.11 +import org.openrdf.query.algebra.Var;
  103.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  103.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBValueColumnBase;
  103.14 +
  103.15 +/**
  103.16 + * Represents a variable's time value in an SQL expression.
  103.17 + * 
  103.18 + * @author James Leigh
  103.19 + * 
  103.20 + */
  103.21 +public class GeneralDBDateTimeColumn extends GeneralDBValueColumnBase {
  103.22 +
  103.23 +	public GeneralDBDateTimeColumn(Var var) {
  103.24 +		super(var);
  103.25 +	}
  103.26 +
  103.27 +	@Override
  103.28 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  103.29 +		throws X
  103.30 +	{
  103.31 +		visitor.meet(this);
  103.32 +	}
  103.33 +
  103.34 +}
   104.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   104.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBDoubleValue.java	Fri Jan 27 01:08:32 2012 +0200
   104.3 @@ -0,0 +1,29 @@
   104.4 +/*
   104.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   104.6 + *
   104.7 + * Licensed under the Aduna BSD-style license.
   104.8 + */
   104.9 +package org.openrdf.sail.generaldb.algebra;
  104.10 +
  104.11 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  104.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlConstant;
  104.13 +
  104.14 +/**
  104.15 + * A static number in an SQL expression.
  104.16 + * 
  104.17 + * @author James Leigh
  104.18 + * 
  104.19 + */
  104.20 +public class GeneralDBDoubleValue extends GeneralDBSqlConstant<Double> {
  104.21 +
  104.22 +	public GeneralDBDoubleValue(Double value) {
  104.23 +		super(value);
  104.24 +	}
  104.25 +
  104.26 +	@Override
  104.27 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  104.28 +		throws X
  104.29 +	{
  104.30 +		visitor.meet(this);
  104.31 +	}
  104.32 +}
   105.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   105.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBFalseValue.java	Fri Jan 27 01:08:32 2012 +0200
   105.3 @@ -0,0 +1,29 @@
   105.4 +/*
   105.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   105.6 + *
   105.7 + * Licensed under the Aduna BSD-style license.
   105.8 + */
   105.9 +package org.openrdf.sail.generaldb.algebra;
  105.10 +
  105.11 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBBooleanValue;
  105.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  105.13 +
  105.14 +/**
  105.15 + * Represents the value false in an SQL expression.
  105.16 + * 
  105.17 + * @author James Leigh
  105.18 + * 
  105.19 + */
  105.20 +public class GeneralDBFalseValue extends GeneralDBBooleanValue {
  105.21 +
  105.22 +	public GeneralDBFalseValue() {
  105.23 +		super(false);
  105.24 +	}
  105.25 +
  105.26 +	@Override
  105.27 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  105.28 +		throws X
  105.29 +	{
  105.30 +		visitor.meet(this);
  105.31 +	}
  105.32 +}
   106.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBHashColumn.java	Fri Jan 27 01:08:32 2012 +0200
   106.3 @@ -0,0 +1,34 @@
   106.4 +/*
   106.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   106.6 + *
   106.7 + * Licensed under the Aduna BSD-style license.
   106.8 + */
   106.9 +package org.openrdf.sail.generaldb.algebra;
  106.10 +
  106.11 +import org.openrdf.query.algebra.Var;
  106.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  106.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBValueColumnBase;
  106.14 +
  106.15 +/**
  106.16 + * Represents the Hash value of a variable.
  106.17 + * 
  106.18 + * @author James Leigh
  106.19 + * 
  106.20 + */
  106.21 +public class GeneralDBHashColumn extends GeneralDBValueColumnBase {
  106.22 +
  106.23 +	public GeneralDBHashColumn(GeneralDBColumnVar var) {
  106.24 +		super(var);
  106.25 +	}
  106.26 +
  106.27 +	public GeneralDBHashColumn(Var var) {
  106.28 +		super(var);
  106.29 +	}
  106.30 +
  106.31 +	@Override
  106.32 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  106.33 +		throws X
  106.34 +	{
  106.35 +		visitor.meet(this);
  106.36 +	}
  106.37 +}
   107.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   107.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBIdColumn.java	Fri Jan 27 01:08:32 2012 +0200
   107.3 @@ -0,0 +1,99 @@
   107.4 +/*
   107.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   107.6 + *
   107.7 + * Licensed under the Aduna BSD-style license.
   107.8 + */
   107.9 +package org.openrdf.sail.generaldb.algebra;
  107.10 +
  107.11 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelNodeBase;
  107.12 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  107.13 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr;
  107.14 +
  107.15 +/**
  107.16 + * A particular column in an SQL expression.
  107.17 + * 
  107.18 + * @author James Leigh
  107.19 + * 
  107.20 + */
  107.21 +public class GeneralDBIdColumn extends GeneralDBQueryModelNodeBase implements GeneralDBSqlExpr {
  107.22 +
  107.23 +	private String alias;
  107.24 +
  107.25 +	private String column;
  107.26 +
  107.27 +	public GeneralDBIdColumn(String alias) {
  107.28 +		super();
  107.29 +		this.alias = alias;
  107.30 +		this.column = "id";
  107.31 +	}
  107.32 +
  107.33 +	public GeneralDBIdColumn(GeneralDBColumnVar var) {
  107.34 +		super();
  107.35 +		this.alias = var.getAlias();
  107.36 +		this.column = var.getColumn();
  107.37 +	}
  107.38 +
  107.39 +	public GeneralDBIdColumn(String alias, String column) {
  107.40 +		super();
  107.41 +		this.alias = alias;
  107.42 +		this.column = column;
  107.43 +	}
  107.44 +
  107.45 +	public String getAlias() {
  107.46 +		return alias;
  107.47 +	}
  107.48 +
  107.49 +	public String getColumn() {
  107.50 +		return column;
  107.51 +	}
  107.52 +
  107.53 +	@Override
  107.54 +	public String getSignature() {
  107.55 +		return super.getSignature() + " " + alias + "." + column;
  107.56 +	}
  107.57 +
  107.58 +	@Override
  107.59 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  107.60 +		throws X
  107.61 +	{
  107.62 +		visitor.meet(this);
  107.63 +	}
  107.64 +
  107.65 +	@Override
  107.66 +	public GeneralDBIdColumn clone() {
  107.67 +		return (GeneralDBIdColumn)super.clone();
  107.68 +	}
  107.69 +
  107.70 +	@Override
  107.71 +	public int hashCode() {
  107.72 +		final int prime = 31;
  107.73 +		int result = 1;
  107.74 +		result = prime * result + ((alias == null) ? 0 : alias.hashCode());
  107.75 +		result = prime * result + ((column == null) ? 0 : column.hashCode());
  107.76 +		return result;
  107.77 +	}
  107.78 +
  107.79 +	@Override
  107.80 +	public boolean equals(Object obj) {
  107.81 +		if (this == obj)
  107.82 +			return true;
  107.83 +		if (obj == null)
  107.84 +			return false;
  107.85 +		if (getClass() != obj.getClass())
  107.86 +			return false;
  107.87 +		final GeneralDBIdColumn other = (GeneralDBIdColumn)obj;
  107.88 +		if (alias == null) {
  107.89 +			if (other.alias != null)
  107.90 +				return false;
  107.91 +		}
  107.92 +		else if (!alias.equals(other.alias))
  107.93 +			return false;
  107.94 +		if (column == null) {
  107.95 +			if (other.column != null)
  107.96 +				return false;
  107.97 +		}
  107.98 +		else if (!column.equals(other.column))
  107.99 +			return false;
 107.100 +		return true;
 107.101 +	}
 107.102 +}
   108.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   108.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/algebra/GeneralDBJoinItem.java	Fri Jan 27 01:08:32 2012 +0200
   108.3 @@ -0,0 +1,93 @@
   108.4 +/*
   108.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   108.6 + *
   108.7 + * Licensed under the Aduna BSD-style license.
   108.8 + */
   108.9 +package org.openrdf.sail.generaldb.algebra;
  108.10 +
  108.11 +import java.util.ArrayList;
  108.12 +import java.util.List;
  108.13 +
  108.14 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBFromItem;
  108.15 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBQueryModelVisitorBase;
  108.16 +
  108.17 +/**
  108.18 + * An SQL join.
  108.19 + * 
  108.20 + * @author James Leigh
  108.21 + * 
  108.22 + */
  108.23 +public class GeneralDBJoinItem extends GeneralDBFromItem {
  108.24 +
  108.25 +	private String tableName;
  108.26 +
  108.27 +	private Number predId;
  108.28 +
  108.29 +	private List<GeneralDBColumnVar> vars = new ArrayList<GeneralDBColumnVar>();
  108.30 +
  108.31 +	public GeneralDBJoinItem(String alias, String tableName, Number predId) {
  108.32 +		super(alias);
  108.33 +		this.tableName = tableName;
  108.34 +		this.predId = predId;
  108.35 +	}
  108.36 +
  108.37 +	public GeneralDBJoinItem(String alias, String tableName) {
  108.38 +		super(alias);
  108.39 +		this.tableName = tableName;
  108.40 +		this.predId = 0;
  108.41 +	}
  108.42 +
  108.43 +	public String getTableName() {
  108.44 +		return tableName;
  108.45 +	}
  108.46 +
  108.47 +	public Number getPredId() {
  108.48 +		return predId;
  108.49 +	}
  108.50 +
  108.51 +	public void addVar(GeneralDBColumnVar var) {
  108.52 +		this.vars.add(var);
  108.53 +	}
  108.54 +
  108.55 +	@Override
  108.56 +	public GeneralDBColumnVar getVarForChildren(String name) {
  108.57 +		for (GeneralDBColumnVar var : vars) {
  108.58 +			if (var.getName().equals(name))
  108.59 +				return var;
  108.60 +		}
  108.61 +		return super.getVarForChildren(name);
  108.62 +	}
  108.63 +
  108.64 +	@Override
  108.65 +	public List<GeneralDBColumnVar> appendVars(List<GeneralDBColumnVar> vars) {
  108.66 +		vars.addAll(this.vars);
  108.67 +		return super.appendVars(vars);
  108.68 +	}
  108.69 +
  108.70 +	@Override
  108.71 +	public String getSignature() {
  108.72 +		StringBuilder sb = new StringBuilder();
  108.73 +		if (isLeft()) {
  108.74 +			sb.append("LEFT ");
  108.75 +		}
  108.76 +		sb.append(super.getSignature());
  108.77 +		sb.append(" ").append(tableName);
  108.78 +		sb.append(" ").append(getAlias());
  108.79 +		return sb.toString();
  108.80 +	}
  108.81 +
  108.82 +	@Override
  108.83 +	public GeneralDBJoinItem clone() {
  108.84 +		GeneralDBJoinItem clone = (GeneralDBJoinItem)super.clone();
  108.85 +		clone.vars = new ArrayList<GeneralDBColumnVar>(vars);
  108.86 +		return clone;
  108.87 +	}
  108.88 +
  108.89 +	@Override
  108.90 +	public <X extends Exception> void visit(GeneralDBQueryModelVisitorBase<X> visitor)
  108.91 +		throws X
  108.92 +	{
  108.93 +		visitor.meet(this);
  10