sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Remove (for now) SQLQuery and QueriedFeatureSet. We will need to revisit later how to handle SQL queries, and if possible to extend to other languages (e.g. CQL). https://issues.apache.org/jira/browse/SIS-423
Date Wed, 11 Jul 2018 10:18:31 GMT
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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 892d108  Remove (for now) SQLQuery and QueriedFeatureSet. We will need to revisit
later how to handle SQL queries, and if possible to extend to other languages (e.g. CQL).
https://issues.apache.org/jira/browse/SIS-423
892d108 is described below

commit 892d108b024147709888bed655f2a7bc5beb8d86
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 11 11:39:43 2018 +0200

    Remove (for now) SQLQuery and QueriedFeatureSet. We will need to revisit later how to
handle SQL queries, and if possible to extend to other languages (e.g. CQL).
    https://issues.apache.org/jira/browse/SIS-423
---
 .../apache/sis/internal/sql/feature/Database.java  |   6 +-
 .../internal/sql/feature/QueriedFeatureSet.java    | 111 ---------------------
 .../apache/sis/internal/sql/feature/Schema.java    |  89 -----------------
 .../java/org/apache/sis/storage/sql/SQLQuery.java  |  72 -------------
 .../java/org/apache/sis/storage/sql/SQLStore.java  |  18 +---
 .../apache/sis/storage/sql/SQLStoreProvider.java   |   3 -
 .../org/apache/sis/storage/sql/package-info.java   |   3 -
 .../java/org/apache/sis/storage/Aggregate.java     |   2 +-
 8 files changed, 8 insertions(+), 296 deletions(-)

diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
index 46dacb8..5599554 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
@@ -77,12 +77,16 @@ public final class Database {
         for (final String tablePattern : tablePatterns) {
             try (ResultSet reflect = analyzer.metadata.getTables(catalog, schemaPattern,
tablePattern, tableTypes)) {
                 while (reflect.next()) {
+                    final String table = reflect.getString(Reflection.TABLE_NAME);
+                    if (analyzer.isIgnoredTable(table)) {
+                        continue;
+                    }
                     String remarks = reflect.getString(Reflection.REMARKS);
                     remarks = (remarks != null) ? remarks.trim() : "";      // Empty string
means that we verified that there is no remarks.
                     analyzer.addDependency(new TableName(remarks,           // Opportunistically
use the 'name' field for storing remarks.
                             reflect.getString(Reflection.TABLE_CAT),
                             reflect.getString(Reflection.TABLE_SCHEM),
-                            reflect.getString(Reflection.TABLE_NAME)));
+                            table));
                 }
             }
         }
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueriedFeatureSet.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueriedFeatureSet.java
deleted file mode 100644
index bcb4172..0000000
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueriedFeatureSet.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.internal.sql.feature;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.stream.Stream;
-import org.apache.sis.storage.sql.SQLQuery;
-import org.apache.sis.storage.sql.SQLStore;
-import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.internal.storage.AbstractFeatureSet;
-import org.apache.sis.feature.builder.AttributeTypeBuilder;
-import org.apache.sis.feature.builder.FeatureTypeBuilder;
-
-// Branch-dependent imports
-import org.opengis.feature.Feature;
-import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyType;
-
-
-/**
- * A FeatureSet above a custom SQL query.
- *
- * @author  Johann Sorel (Geomatys)
- * @version 1.0
- * @since   1.0
- * @module
- */
-public final class QueriedFeatureSet extends AbstractFeatureSet {
-
-    private final Database model;
-    private final SQLStore store;
-    private final SQLQuery query;
-    private FeatureType type;
-
-    public QueriedFeatureSet(final SQLStore store, final Database model, final SQLQuery query)
{
-        super((AbstractFeatureSet) null);
-        this.store = store;
-        this.model = model;
-        this.query = query;
-    }
-
-    @Override
-    public FeatureType getType() throws DataStoreException {
-        if (type == null) {
-            final String sql = query.getStatement();
-            try (Connection cnx = store.getDataSource().getConnection();
-                Statement stmt = cnx.createStatement();
-                ResultSet rs = stmt.executeQuery(sql)) {
-                type = analyzeResult(rs, query.getName());
-            } catch (SQLException ex) {
-                throw new DataStoreException(ex);
-            }
-        }
-        return type;
-    }
-
-    /**
-     * Analyze the metadata of the ResultSet to rebuild a feature type.
-     */
-    final FeatureType analyzeResult(final ResultSet result, final String name) throws SQLException
{
-        final FeatureTypeBuilder ftb = new FeatureTypeBuilder().setName(name);
-        final ResultSetMetaData metadata = result.getMetaData();
-        final int nbcol = metadata.getColumnCount();
-        for (int i=1; i <= nbcol; i++) {
-            /*
-             * Search if we already have this property.
-             */
-            PropertyType desc = null; // TODO
-//                model.getProperty(metadata.getCatalogName(i),
-//                                  metadata.getSchemaName(i),
-//                                  metadata.getTableName(i),
-//                                  metadata.getColumnName(i));
-            if (desc != null) {
-                ftb.addProperty(desc);
-            } else {
-                /*
-                 * Could not find the type. This column may be a calculation result.
-                 */
-                final Class<?> type = model.functions.toJavaType(metadata.getColumnType(i),
metadata.getColumnTypeName(i));
-                final AttributeTypeBuilder<?> atb = ftb.addAttribute(type).setName(metadata.getColumnLabel(i));
-                if (metadata.isNullable(i) == ResultSetMetaData.columnNullable) {
-                    atb.setMinimumOccurs(0);
-                }
-            }
-        }
-        return ftb.build();
-    }
-
-    @Override
-    public Stream<Feature> features(boolean parallel) throws DataStoreException {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
-}
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Schema.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Schema.java
deleted file mode 100644
index cc6001b..0000000
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Schema.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.internal.sql.feature;
-
-import java.util.Map;
-import java.util.LinkedHashMap;
-import java.util.Collection;
-import org.apache.sis.util.Debug;
-import org.apache.sis.util.collection.TreeTable;
-import org.apache.sis.storage.DataStoreContentException;
-
-
-/**
- * Description of a database schema.
- * Each schema contains a collection of {@link Table}s.
- *
- * @author  Johann Sorel (Geomatys)
- * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
- * @since   1.0
- * @module
- */
-final class Schema extends MetaModel {
-    /**
-     * The tables in this schema.
-     */
-    private final Map<String,Table> tables;
-
-    /**
-     * Creates a new, initially empty, schema of the given name.
-     *
-     * @param  schemaName  name of this schema.
-     */
-    Schema(final String schemaName) {
-        super(schemaName);
-        tables = new LinkedHashMap<>();
-    }
-
-    /**
-     * Adds a table in this schema.
-     *
-     * @param  table  the table to add.
-     * @throws DataStoreContentException if a table of the same name has already been added.
-     */
-    void addTable(final Table table) throws DataStoreContentException {
-        if (tables.putIfAbsent(table.name, table) != null) {
-            throw new DataStoreContentException(Resources.format(Resources.Keys.DuplicatedEntity_2,
"Table", table.name));
-        }
-    }
-
-    /**
-     * Returns the table of the given name, or {@code null} if none.
-     */
-    Table getTable(final String name) {
-        return tables.get(name);
-    }
-
-    /**
-     * Returns all tables in this schema.
-     */
-    Collection<Table> getTables() {
-        return tables.values();
-    }
-
-    /**
-     * Creates a tree representation of this schema with the list of all tables.
-     */
-    @Debug
-    @Override
-    TreeTable.Node appendTo(final TreeTable.Node parent) {
-        final TreeTable.Node node = super.appendTo(parent);
-        appendAll(parent, null, getTables());
-        return node;
-    }
-}
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLQuery.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLQuery.java
deleted file mode 100644
index 0a4fec1..0000000
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLQuery.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.storage.sql;
-
-import org.apache.sis.storage.Query;
-import org.apache.sis.util.ArgumentChecks;
-
-
-/**
- * An SQL query executed directly on the database.
- * Such query should be transfered to the JDBC without or with minimum modifications.
- *
- * <div class="warning">This is an experimental class,
- * not yet target for any Apache SIS release at this time.</div>
- *
- * @author Johann Sorel (Geomatys)
- * @version 1.0
- * @since   1.0
- * @module
- */
-public class SQLQuery extends Query {
-
-    private final String statement;
-    private final String name;
-
-    /**
-     * Create a new SQL query object.
-     *
-     * @param statement SQL query text, not null
-     * @param name common name, used for returned feature types, not null
-     */
-    public SQLQuery(String statement, String name) {
-        ArgumentChecks.ensureNonNull("statement", statement);
-        ArgumentChecks.ensureNonNull("name", name);
-        this.statement = statement;
-        this.name = name;
-    }
-
-    /**
-     * Returns the query text.
-     * Example : SELECT * FROM Road
-     *
-     * @return SQL query text, not null
-     */
-    public String getStatement() {
-        return statement;
-    }
-
-    /**
-     * Returns the query name.
-     * This name is used to build the returned feature type.
-     *
-     * @return common query name
-     */
-    public String getName() {
-        return name;
-    }
-}
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStore.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStore.java
index 540728f..ba7fbd9 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStore.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStore.java
@@ -18,10 +18,9 @@ package org.apache.sis.storage.sql;
 
 import javax.sql.DataSource;
 import org.apache.sis.internal.sql.feature.Database;
-import org.apache.sis.internal.sql.feature.QueriedFeatureSet;
+import org.apache.sis.storage.Aggregate;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.DataStoreException;
-import org.apache.sis.storage.FeatureSet;
 import org.apache.sis.storage.StorageConnector;
 
 
@@ -29,15 +28,12 @@ import org.apache.sis.storage.StorageConnector;
  * A data store capable to read and create features from a spatial database.
  * An example of spatial database is PostGIS.
  *
- * <div class="warning">This is an experimental class,
- * not yet target for any Apache SIS release at this time.</div>
- *
  * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-public abstract class SQLStore extends DataStore {
+public abstract class SQLStore extends DataStore implements Aggregate {
     /**
      * The data source to use for obtaining connections to the database.
      */
@@ -70,14 +66,4 @@ public abstract class SQLStore extends DataStore {
     public DataSource getDataSource() {
         return source;
     }
-
-    /**
-     * Executes a query directly on the database.
-     *
-     * @param  query the query to execute (can not be null).
-     * @return the features obtained by the given given query.
-     */
-    public FeatureSet query(final SQLQuery query) {
-        return new QueriedFeatureSet(this, model, query);
-    }
 }
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
index db55910..3fb4467 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/SQLStoreProvider.java
@@ -22,9 +22,6 @@ import org.apache.sis.storage.DataStoreProvider;
 /**
  * Provider of {@code SQLStore} instances.
  *
- * <div class="warning">This is an experimental class,
- * not yet target for any Apache SIS release at this time.</div>
- *
  * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/package-info.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/package-info.java
index 4c3499b..795bc0c 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/package-info.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/storage/sql/package-info.java
@@ -19,9 +19,6 @@
 /**
  * Data store capable to read and create features from a JDBC connection to a database.
  *
- * <div class="warning">This is an experimental package,
- * not yet target for any Apache SIS release at this time.</div>
- *
  * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
index 9503eb5..b977658 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
@@ -19,7 +19,7 @@ package org.apache.sis.storage;
 import java.util.Collection;
 
 /**
- * A collection of resources. An aggregate can have two or more components.
+ * A collection of resources. An aggregate can have any number of components.
  * Each component can be another aggregate, thus forming a tree of resources.
  * Different kinds of aggregate may exist for various reasons, for example (adapted from
ISO 19115):
  *


Mime
View raw message