This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit ab515ea614849d462989b659c90b7fa8a1a7233c Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Feb 23 11:43:13 2025 +0100 Accept materialized views in SQL queries. --- .../main/org/apache/sis/storage/sql/feature/Analyzer.java | 8 +++++++- .../org/apache/sis/storage/sql/feature/QueryAnalyzer.java | 13 +++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/Analyzer.java b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/Analyzer.java index d83976afba..44a06d9368 100644 --- a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/Analyzer.java +++ b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/Analyzer.java @@ -45,6 +45,7 @@ import org.apache.sis.storage.sql.ResourceDefinition; import org.apache.sis.storage.sql.postgis.Postgres; import org.apache.sis.metadata.sql.privy.Dialect; import org.apache.sis.metadata.sql.privy.Reflection; +import org.apache.sis.util.ArraysExt; import org.apache.sis.util.iso.DefaultNameFactory; import org.apache.sis.util.resources.ResourceInternationalString; @@ -59,6 +60,11 @@ import org.apache.sis.util.resources.ResourceInternationalString; * @author Alexis Manin (Geomatys) */ public final class Analyzer { + /** + * Types of table accepted by this class. + */ + private static final String[] ACCEPTED_TABLE_TYPES = {"TABLE", "VIEW", "BASE TABLE", "MATERIALIZED VIEW"}; + /** * Information about the spatial database to analyze. */ @@ -169,7 +175,7 @@ public final class Analyzer { try (ResultSet reflect = metadata.getTableTypes()) { while (reflect.next()) { final String type = reflect.getString(Reflection.TABLE_TYPE); - if ("TABLE".equalsIgnoreCase(type) || "VIEW".equalsIgnoreCase(type) || "BASE TABLE".equalsIgnoreCase(type)) { + if (ArraysExt.containsIgnoreCase(ACCEPTED_TABLE_TYPES, type)) { types.add(type); } } diff --git a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java index d2083beeee..50448a641c 100644 --- a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java +++ b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/QueryAnalyzer.java @@ -18,7 +18,6 @@ package org.apache.sis.storage.sql.feature; import java.util.Map; import java.util.Set; -import java.util.List; import java.util.HashMap; import java.util.ArrayList; import java.sql.ResultSet; @@ -40,11 +39,6 @@ import org.apache.sis.metadata.sql.privy.Reflection; * @author Martin Desruisseaux (Geomatys) */ final class QueryAnalyzer extends FeatureAnalyzer { - /** - * The query submitted by user. - */ - private final String query; - /** * All columns, without filtering for separating attributes from associations. */ @@ -67,7 +61,6 @@ final class QueryAnalyzer extends FeatureAnalyzer { throws Exception { super(analyzer, new TableReference(name, definition)); - this.query = query; /* * Get the list of all columns in the query. We do that now because we will need this list * for finding primary keys (below) and also before `getForeignerKeys(…)` can be executed. @@ -78,7 +71,7 @@ final class QueryAnalyzer extends FeatureAnalyzer { columns = new Column[meta.getColumnCount()]; columnsPerTable = new HashMap<>(); for (int i=1; i <= columns.length; i++) { - final Column column = new Column(meta, i, quote); + final var column = new Column(meta, i, quote); columns[i-1] = column; /* * In order to identify geometry columns, we need to know the table where the column come from. @@ -86,7 +79,7 @@ final class QueryAnalyzer extends FeatureAnalyzer { */ final String table = Strings.trimOrNull(meta.getTableName(i)); if (table != null) { - final TableReference source = new TableReference( + final var source = new TableReference( Strings.trimOrNull(meta.getCatalogName(i)), Strings.trimOrNull(meta.getSchemaName(i)), table, null); @@ -172,7 +165,7 @@ final class QueryAnalyzer extends FeatureAnalyzer { /* * Creates attributes only after we updated all columns with geometry informations. */ - final List<Column> attributes = new ArrayList<>(); + final var attributes = new ArrayList<Column>(); for (final Column column : columns) { if (createAttribute(column)) { attributes.add(column);