From a551c748021d92b45d41e3d839f48722c40ba836 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Wed, 1 Feb 2023 16:54:15 +0100 Subject: [PATCH] #1458 - apply count and startindex to queries without SORTBY/FILTER in blob mode --- .../persistence/sql/SQLFeatureStore.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/SQLFeatureStore.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/SQLFeatureStore.java index 4d48a4d72c..c40f027927 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/SQLFeatureStore.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/SQLFeatureStore.java @@ -77,7 +77,6 @@ import org.deegree.commons.utils.kvp.InvalidParameterValueException; import org.deegree.cs.coordinatesystems.ICRS; import org.deegree.cs.persistence.CRSManager; -import org.deegree.cs.refs.coordinatesystem.CRSRef; import org.deegree.db.ConnectionProvider; import org.deegree.db.ConnectionProviderProvider; import org.deegree.feature.Feature; @@ -1011,10 +1010,10 @@ public FeatureInputStream query( final Query[] queries ) } } + boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries ); if ( wmsStyleQuery ) { - return queryMultipleFts( queries, env ); + return queryMultipleFtsFromBlob( queries, env, isMaxFeaturesAndStartIndexApplicable ); } - boolean isMaxFeaturesAndStartIndexApplicable = isMaxFeaturesAndStartIndexApplicable( queries ); Iterator rsIter = new Iterator() { int i = 0; @@ -1534,7 +1533,8 @@ private FeatureInputStream queryByOperatorFilter( Query query, List ftNam return result; } - private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox ) + private FeatureInputStream queryMultipleFtsFromBlob( Query[] queries, Envelope looseBBox, + boolean isMaxFeaturesAndStartIndexApplicable ) throws FeatureStoreException { FeatureInputStream result = null; Connection conn = null; @@ -1547,14 +1547,20 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox blobWb = getWhereBuilderBlob( bboxFilter, conn ); } conn = getConnection(); - final short[] ftId = getQueriedFeatureTypeIds( queries ); + final List ftIds = new ArrayList<>(); final StringBuilder sql = new StringBuilder(); - for ( int i = 0; i < ftId.length; i++ ) { + for ( int i = 0; i < queries.length; i++ ) { + Query query = queries[i]; + if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) { + String msg = "Join queries between multiple feature types are currently not supported."; + throw new UnsupportedOperationException( msg ); + } + short ftId = getFtId( query.getTypeNames()[0].getFeatureTypeName() ); if ( i > 0 ) { sql.append( " UNION " ); } sql.append( "SELECT gml_id,binary_object" ); - if ( ftId.length > 1 ) { + if ( queries.length > 1 ) { sql.append( "," ); sql.append( i ); sql.append( " AS QUERY_POS" ); @@ -1565,14 +1571,18 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox if ( looseBBox != null ) { sql.append( " AND gml_bounded_by && ?" ); } + if (isMaxFeaturesAndStartIndexApplicable) { + appendOffsetAndFetch(sql, query.getMaxFeatures(), query.getStartIndex()); + } + ftIds.add( ftId ); } - if ( ftId.length > 1 ) { + if ( queries.length > 1 ) { sql.append( " ORDER BY QUERY_POS" ); } stmt = conn.prepareStatement( sql.toString() ); stmt.setFetchSize( fetchSize ); int argIdx = 1; - for ( final short ftId2 : ftId ) { + for ( final short ftId2 : ftIds ) { stmt.setShort( argIdx++, ftId2 ); if ( blobWb != null && blobWb.getWhere() != null ) { for ( SQLArgument o : blobWb.getWhere().getArguments() ) { @@ -1595,19 +1605,6 @@ private FeatureInputStream queryMultipleFts( Query[] queries, Envelope looseBBox return result; } - private short[] getQueriedFeatureTypeIds( Query[] queries ) { - short[] ftId = new short[queries.length]; - for ( int i = 0; i < ftId.length; i++ ) { - Query query = queries[i]; - if ( query.getTypeNames() == null || query.getTypeNames().length > 1 ) { - String msg = "Join queries between multiple feature types are currently not supported."; - throw new UnsupportedOperationException( msg ); - } - ftId[i] = getFtId( query.getTypeNames()[0].getFeatureTypeName() ); - } - return ftId; - } - private AbstractWhereBuilder getWhereBuilder( Collection ftMappings, OperatorFilter filter, SortProperty[] sortCrit, boolean handleStrict ) throws FilterEvaluationException, UnmappableException {