Skip to content

Commit 2384006

Browse files
committed
#9885 (#32) - consider all geometry properties if propName is missing
1 parent aca75ad commit 2384006

File tree

13 files changed

+155
-121
lines changed

13 files changed

+155
-121
lines changed

deegree-core/deegree-core-sqldialect/deegree-sqldialect-commons/src/main/java/org/deegree/sqldialect/filter/AbstractWhereBuilder.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,24 @@ protected SQLOperation toProtoSQL(LogicalOperator op) throws UnmappableException
678678
* @throws FilterEvaluationException if the filter contains invalid
679679
* {@link ValueReference}s
680680
*/
681-
protected abstract SQLOperation toProtoSQL(SpatialOperator op)
682-
throws UnmappableException, FilterEvaluationException;
681+
protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException, FilterEvaluationException {
682+
List<SQLExpression> propNameExprs = toProtoSQLSpatial(op.getPropName());
683+
checkIfExpressionsAreSpatial(propNameExprs, op.getPropName());
684+
685+
SQLOperationBuilder builder = new SQLOperationBuilder(BOOLEAN);
686+
boolean isFirst = true;
687+
for (SQLExpression propNameExpr : propNameExprs) {
688+
if (!isFirst) {
689+
builder.add(" OR ");
690+
}
691+
toProtoSql(op, propNameExpr, builder);
692+
isFirst = false;
693+
}
694+
return builder.toOperation();
695+
}
696+
697+
protected abstract void toProtoSql(SpatialOperator op, SQLExpression propNameExpr, SQLOperationBuilder builder)
698+
throws FilterEvaluationException, UnmappableException;
683699

684700
/**
685701
* Translates the given {@link TemporalOperator} into an {@link SQLOperation}.
@@ -916,22 +932,25 @@ protected SQLExpression toProtoSQL(ValueReference propName) throws UnmappableExc
916932
* @throws FilterEvaluationException if the filter contains invalid
917933
* {@link ValueReference}s
918934
*/
919-
protected SQLExpression toProtoSQLSpatial(ValueReference propName)
935+
protected List<SQLExpression> toProtoSQLSpatial(ValueReference propName)
920936
throws FilterEvaluationException, UnmappableException {
921-
SQLExpression sql = null;
922-
PropertyNameMapping propMapping = mapper.getSpatialMapping(propName, aliasManager);
923-
if (propMapping != null) {
924-
propNameMappingList.add(propMapping);
925-
if (propMapping instanceof ConstantPropertyNameMapping) {
926-
// TODO get rid of ConstantPropertyNameMapping
927-
PrimitiveType pt = new PrimitiveType(STRING);
928-
PrimitiveValue value = new PrimitiveValue("" + ((ConstantPropertyNameMapping) propMapping).getValue(),
929-
pt);
930-
PrimitiveParticleConverter converter = new DefaultPrimitiveConverter(pt, null, false);
931-
sql = new SQLArgument(value, converter);
932-
}
933-
else {
934-
sql = new SQLColumn(propMapping.getTableAlias(), propMapping.getColumn(), propMapping.getConverter());
937+
List<SQLExpression> sql = new ArrayList<>();
938+
List<PropertyNameMapping> propMappings = mapper.getSpatialMappings(propName, aliasManager);
939+
if (!propMappings.isEmpty()) {
940+
for (PropertyNameMapping propMapping : propMappings) {
941+
propNameMappingList.add(propMapping);
942+
if (propMapping instanceof ConstantPropertyNameMapping) {
943+
// TODO get rid of ConstantPropertyNameMapping
944+
PrimitiveType pt = new PrimitiveType(STRING);
945+
PrimitiveValue value = new PrimitiveValue(
946+
"" + ((ConstantPropertyNameMapping) propMapping).getValue(), pt);
947+
PrimitiveParticleConverter converter = new DefaultPrimitiveConverter(pt, null, false);
948+
sql.add(new SQLArgument(value, converter));
949+
}
950+
else {
951+
sql.add(new SQLColumn(propMapping.getTableAlias(), propMapping.getColumn(),
952+
propMapping.getConverter()));
953+
}
935954
}
936955
}
937956
else {
@@ -1015,4 +1034,19 @@ protected String getStringValueFromFunction(Expression pattern)
10151034
return ((PrimitiveValue) value).getAsText();
10161035
}
10171036

1037+
private void checkIfExpressionsAreSpatial(List<SQLExpression> sqlExpressions, ValueReference propName)
1038+
throws FilterEvaluationException {
1039+
for (SQLExpression sqlExpression : sqlExpressions)
1040+
checkIfExpressionIsSpatial(sqlExpression, propName);
1041+
}
1042+
1043+
protected void checkIfExpressionIsSpatial(SQLExpression sqlExpression, ValueReference propName)
1044+
throws FilterEvaluationException {
1045+
if (!sqlExpression.isSpatial()) {
1046+
String msg = "Cannot evaluate spatial operator on database. Targeted property name '" + propName
1047+
+ "' does not denote a spatial column.";
1048+
throw new FilterEvaluationException(msg);
1049+
}
1050+
}
1051+
10181052
}

deegree-core/deegree-core-sqldialect/deegree-sqldialect-commons/src/main/java/org/deegree/sqldialect/filter/PropertyNameMapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.deegree.filter.FilterEvaluationException;
3838
import org.deegree.filter.expression.ValueReference;
3939

40+
import java.util.List;
41+
4042
/**
4143
* Implementations provide {@link ValueReference} to table/column mappings for
4244
* {@link AbstractWhereBuilder} implementations.
@@ -56,10 +58,10 @@ public interface PropertyNameMapper {
5658
* invalid
5759
* @throws UnmappableException
5860
*/
59-
public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager)
61+
PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager)
6062
throws FilterEvaluationException, UnmappableException;
6163

62-
public PropertyNameMapping getSpatialMapping(ValueReference propName, TableAliasManager aliasManager)
64+
List<PropertyNameMapping> getSpatialMappings(ValueReference propName, TableAliasManager aliasManager)
6365
throws FilterEvaluationException, UnmappableException;
6466

6567
}

deegree-core/deegree-core-sqldialect/deegree-sqldialect-mssql/src/main/java/org/deegree/sqldialect/mssql/MSSQLWhereBuilder.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
----------------------------------------------------------------------------*/
3535
package org.deegree.sqldialect.mssql;
3636

37-
import static java.sql.Types.BOOLEAN;
38-
import static org.deegree.commons.tom.primitive.BaseType.DECIMAL;
39-
4037
import org.deegree.commons.tom.primitive.PrimitiveType;
4138
import org.deegree.commons.tom.primitive.PrimitiveValue;
4239
import org.deegree.commons.tom.sql.DefaultPrimitiveConverter;
@@ -74,6 +71,9 @@
7471

7572
import java.util.List;
7673

74+
import static java.sql.Types.BOOLEAN;
75+
import static org.deegree.commons.tom.primitive.BaseType.DECIMAL;
76+
7777
/**
7878
* {@link AbstractWhereBuilder} implementation for Microsoft SQL Server databases.
7979
*
@@ -162,17 +162,7 @@ private String replaceAdditionalMsSqlServerSpecialChars(String sqlEncoded) {
162162
}
163163

164164
@Override
165-
protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException, FilterEvaluationException {
166-
167-
SQLOperationBuilder builder = new SQLOperationBuilder(BOOLEAN);
168-
169-
SQLExpression propNameExpr = toProtoSQLSpatial(op.getPropName());
170-
if (!propNameExpr.isSpatial()) {
171-
String msg = "Cannot evaluate spatial operator on database. Targeted property name '" + op.getPropName()
172-
+ "' does not denote a spatial column.";
173-
throw new FilterEvaluationException(msg);
174-
}
175-
165+
protected void toProtoSql(SpatialOperator op, SQLExpression propNameExpr, SQLOperationBuilder builder) {
176166
ICRS storageCRS = propNameExpr.getCRS();
177167
int srid = propNameExpr.getSRID() != null ? Integer.parseInt(propNameExpr.getSRID()) : 0;
178168

@@ -269,7 +259,6 @@ protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException
269259
break;
270260
}
271261
}
272-
return builder.toOperation();
273262
}
274263

275264
private SQLExpression toProtoSQL(Geometry geom, ICRS targetCRS, int srid) {

deegree-core/deegree-core-sqldialect/deegree-sqldialect-mssql/src/test/java/org/deegree/sqldialect/mssql/MSSQLWhereBuilderTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
import org.junit.Before;
5555
import org.junit.Test;
5656

57+
import java.util.Collections;
58+
import java.util.List;
59+
5760
/**
5861
* Tests for {@link MSSQLWhereBuilder}.
5962
*
@@ -70,14 +73,13 @@ public void setup() throws FilterEvaluationException, UnmappableException {
7073
PropertyNameMapper mapper = new PropertyNameMapper() {
7174

7275
@Override
73-
public PropertyNameMapping getSpatialMapping(ValueReference propName, TableAliasManager aliasManager)
74-
throws FilterEvaluationException, UnmappableException {
75-
return new PropertyNameMapping(null, null, propName.getAsText(), "table");
76+
public List<PropertyNameMapping> getSpatialMappings(ValueReference propName,
77+
TableAliasManager aliasManager) {
78+
return Collections.singletonList(new PropertyNameMapping(null, null, propName.getAsText(), "table"));
7679
}
7780

7881
@Override
79-
public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager)
80-
throws FilterEvaluationException, UnmappableException {
82+
public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager) {
8183
return new PropertyNameMapping(null, null, propName.getAsText(), "table");
8284
}
8385
};

deegree-core/deegree-core-sqldialect/deegree-sqldialect-oracle/src/main/java/org/deegree/sqldialect/oracle/OracleWhereBuilder.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,7 @@ class OracleWhereBuilder extends AbstractWhereBuilder {
129129
}
130130

131131
@Override
132-
protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException, FilterEvaluationException {
133-
134-
SQLOperationBuilder builder = new SQLOperationBuilder(BOOLEAN);
135-
SQLExpression propNameExpr = toProtoSQLSpatial(op.getPropName());
136-
132+
protected void toProtoSql(SpatialOperator op, SQLExpression propNameExpr, SQLOperationBuilder builder) {
137133
switch (op.getSubType()) {
138134
case BBOX:
139135
BBOX bbox = (BBOX) op;
@@ -178,8 +174,6 @@ protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException
178174
appendDWithinOperation(builder, propNameExpr, ((Beyond) op).getGeometry(), ((Beyond) op).getDistance());
179175
break;
180176
}
181-
182-
return builder.toOperation();
183177
}
184178

185179
/**

deegree-core/deegree-core-sqldialect/deegree-sqldialect-postgis/src/main/java/org/deegree/sqldialect/postgis/PostGISWhereBuilder.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
import org.deegree.time.position.TimePosition;
8383
import org.deegree.time.primitive.GenericTimeInstant;
8484
import org.deegree.time.primitive.GenericTimePeriod;
85+
import org.slf4j.Logger;
86+
import org.slf4j.LoggerFactory;
8587

8688
/**
8789
* {@link AbstractWhereBuilder} implementation for PostGIS databases.
@@ -90,6 +92,8 @@
9092
*/
9193
public class PostGISWhereBuilder extends AbstractWhereBuilder {
9294

95+
private static final Logger LOG = LoggerFactory.getLogger(PostGISWhereBuilder.class);
96+
9397
private final boolean useLegacyPredicates;
9498

9599
/**
@@ -187,13 +191,8 @@ private SQLOperation getOperationFromBuilder(PropertyIsLike op, SQLExpression pr
187191
}
188192

189193
@Override
190-
protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException, FilterEvaluationException {
191-
192-
SQLOperationBuilder builder = new SQLOperationBuilder(BOOLEAN);
193-
194-
SQLExpression propNameExpr = toProtoSQLSpatial(op.getPropName());
195-
checkIfExpressionIsSpatial(propNameExpr, op.getPropName());
196-
194+
protected void toProtoSql(SpatialOperator op, SQLExpression propNameExpr, SQLOperationBuilder builder)
195+
throws FilterEvaluationException, UnmappableException {
197196
ICRS storageCRS = propNameExpr.getCRS();
198197
int srid = propNameExpr.getSRID() != null ? Integer.parseInt(propNameExpr.getSRID()) : -1;
199198

@@ -376,7 +375,6 @@ protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException
376375
break;
377376
}
378377
}
379-
return builder.toOperation();
380378
}
381379

382380
protected SQLOperation toProtoSQL(TemporalOperator op) throws UnmappableException, FilterEvaluationException {
@@ -495,7 +493,10 @@ private SQLExpression toProtoSQL(Geometry geom, ICRS targetCRS, int srid) throws
495493
private SQLExpression toProtoSqlSecondParameter(SpatialOperator spatialOperator, ICRS storageCRS, int srid)
496494
throws FilterEvaluationException, UnmappableException {
497495
if (spatialOperator.getValueReference() != null) {
498-
SQLExpression sqlExpression = toProtoSQLSpatial(spatialOperator.getValueReference());
496+
List<SQLExpression> sqlExpressions = toProtoSQLSpatial(spatialOperator.getValueReference());
497+
if (sqlExpressions.size() > 1)
498+
LOG.warn("Multiple spatial geometry mappings as second parameter are currently not supported.");
499+
SQLExpression sqlExpression = sqlExpressions.get(0);
499500
checkIfExpressionIsSpatial(sqlExpression, spatialOperator.getValueReference());
500501
return sqlExpression;
501502
}
@@ -575,13 +576,4 @@ private boolean isTimeInstant(Expression parameter2) {
575576
return parameter2 instanceof Literal && ((Literal<?>) parameter2).getValue() instanceof GenericTimeInstant;
576577
}
577578

578-
private void checkIfExpressionIsSpatial(SQLExpression sqlExpression, ValueReference propName)
579-
throws FilterEvaluationException {
580-
if (!sqlExpression.isSpatial()) {
581-
String msg = "Cannot evaluate spatial operator on database. Targeted property name '" + propName
582-
+ "' does not denote a spatial column.";
583-
throw new FilterEvaluationException(msg);
584-
}
585-
}
586-
587579
}

deegree-datastores/deegree-featurestores/deegree-featurestore-shape/src/main/java/org/deegree/feature/persistence/shape/H2WhereBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.deegree.sqldialect.filter.expression.SQLColumn;
5656
import org.deegree.sqldialect.filter.expression.SQLExpression;
5757
import org.deegree.sqldialect.filter.expression.SQLOperation;
58+
import org.deegree.sqldialect.filter.expression.SQLOperationBuilder;
5859

5960
/**
6061
* @author <a href="mailto:[email protected]">Andreas Schmitz</a>
@@ -80,7 +81,8 @@ public H2WhereBuilder(SQLDialect dialect, OperatorFilter filter, SortProperty[]
8081
}
8182

8283
@Override
83-
protected SQLOperation toProtoSQL(SpatialOperator op) throws UnmappableException, FilterEvaluationException {
84+
protected void toProtoSql(SpatialOperator op, SQLExpression propNameExpr, SQLOperationBuilder builder)
85+
throws UnmappableException {
8486
throw new UnmappableException("Spatial operators are currently not mappable in h2.");
8587
}
8688

deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/SQLFeatureStore.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.sql.Statement;
4949
import java.util.ArrayList;
5050
import java.util.Collection;
51+
import java.util.Collections;
5152
import java.util.Date;
5253
import java.util.HashMap;
5354
import java.util.Iterator;
@@ -1680,8 +1681,7 @@ private AbstractWhereBuilder getWhereBuilderBlob(OperatorFilter filter, Connecti
16801681
final String srid = detectConfiguredSrid();
16811682
PropertyNameMapper mapper = new PropertyNameMapper() {
16821683
@Override
1683-
public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager)
1684-
throws FilterEvaluationException, UnmappableException {
1684+
public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager aliasManager) {
16851685
GeometryStorageParams geometryParams = new GeometryStorageParams(blobMapping.getCRS(), srid,
16861686
CoordinateDimension.DIM_2);
16871687
GeometryMapping bboxMapping = new GeometryMapping(null, false, new DBField(blobMapping.getBBoxColumn()),
@@ -1691,9 +1691,9 @@ public PropertyNameMapping getMapping(ValueReference propName, TableAliasManager
16911691
}
16921692

16931693
@Override
1694-
public PropertyNameMapping getSpatialMapping(ValueReference propName, TableAliasManager aliasManager)
1695-
throws FilterEvaluationException, UnmappableException {
1696-
return getMapping(propName, aliasManager);
1694+
public List<PropertyNameMapping> getSpatialMappings(ValueReference propName,
1695+
TableAliasManager aliasManager) {
1696+
return Collections.singletonList(getMapping(propName, aliasManager));
16971697
}
16981698
};
16991699
return dialect.getWhereBuilder(mapper, filter, null, null, allowInMemoryFiltering);

0 commit comments

Comments
 (0)