sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Move `SubsetAdapter` to "SQL storage" module, where it is used.
Date Sat, 10 Oct 2020 14:39:15 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

commit a9cd8bf39080e57ad0390746ce2450548eae62d3
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Oct 10 15:11:27 2020 +0200

    Move `SubsetAdapter` to "SQL storage" module, where it is used.
---
 .../sis/internal/sql/feature/QueryFeatureSet.java  |  2 +-
 .../sis/internal/sql/feature/SQLQueryAdapter.java  |  1 -
 .../sis/internal/sql/feature}/SubsetAdapter.java   | 42 ++++++++++++----------
 .../org/apache/sis/internal/sql/feature/Table.java |  1 -
 4 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryFeatureSet.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryFeatureSet.java
index 883e4b1..fc6c293 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryFeatureSet.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/QueryFeatureSet.java
@@ -209,7 +209,7 @@ public class QueryFeatureSet extends AbstractFeatureSet {
     @Override
     public FeatureSet subset(Query query) throws UnsupportedQueryException, DataStoreException
{
         if (query instanceof SimpleQuery) {
-            final org.apache.sis.internal.storage.SubsetAdapter subsetAdapter = new org.apache.sis.internal.storage.SubsetAdapter(fs
-> new SubsetAdapter());
+            final org.apache.sis.internal.sql.feature.SubsetAdapter subsetAdapter = new org.apache.sis.internal.sql.feature.SubsetAdapter(fs
-> new SubsetAdapter());
             return subsetAdapter.subset(this, (SimpleQuery) query);
         }
 
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
index 19c5339..d73742b 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
@@ -25,7 +25,6 @@ import org.opengis.filter.Filter;
 import org.opengis.filter.sort.SortBy;
 
 import org.apache.sis.internal.metadata.sql.Dialect;
-import org.apache.sis.internal.storage.SubsetAdapter;
 import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.storage.FeatureSet;
 
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SubsetAdapter.java
similarity index 91%
rename from storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
rename to storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SubsetAdapter.java
index 3c3e244..55aa807 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SubsetAdapter.java
@@ -14,25 +14,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.storage;
+package org.apache.sis.internal.sql.feature;
 
 import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Function;
-
 import org.opengis.filter.Filter;
 import org.opengis.filter.sort.SortBy;
-
 import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.storage.FeatureSet;
+import org.apache.sis.storage.Query;
 
-import static org.apache.sis.internal.storage.query.SimpleQuery.UNLIMITED;
 
-public final class SubsetAdapter {
+/**
+ * Helper class for {@link FeatureSet#subset(Query)} implementations.
+ *
+ * @author  Alexis Manin (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+final class SubsetAdapter {
 
-    final Function<FeatureSet, AdapterBuilder> driverSupplier;
+    private final Function<FeatureSet, AdapterBuilder> driverSupplier;
 
     public SubsetAdapter(Function<FeatureSet, AdapterBuilder> driverSupplier) {
         this.driverSupplier = driverSupplier;
@@ -40,15 +46,15 @@ public final class SubsetAdapter {
 
     public final FeatureSet subset(final FeatureSet source, SimpleQuery query) {
         final AdapterBuilder driver = driverSupplier.apply(source);
-
         final SimpleQuery remaining = new SimpleQuery();
-
         final long offset = query.getOffset();
-        if (offset > 0) remaining.setOffset(driver.offset(offset));
-
+        if (offset > 0) {
+            remaining.setOffset(driver.offset(offset));
+        }
         final long limit = query.getLimit();
-        if (limit != UNLIMITED) remaining.setLimit(driver.limit(limit));
-
+        if (limit != SimpleQuery.UNLIMITED) {
+            remaining.setLimit(driver.limit(limit));
+        }
         if (filteringRequired(query)) {
             final Filter baseFilter = query.getFilter();
             try {
@@ -58,22 +64,20 @@ public final class SubsetAdapter {
                 remaining.setFilter(baseFilter);
             }
         }
-
-        if (sortRequired(query) && !driver.sort(query.getSortBy())) remaining.setSortBy(query.getSortBy());
-
+        if (sortRequired(query) && !driver.sort(query.getSortBy())) {
+            remaining.setSortBy(query.getSortBy());
+        }
         if (!allColumnsIncluded(query) && !driver.select(query.getColumns())) {
             List<SimpleQuery.Column> columns = query.getColumns();
             remaining.setColumns(columns != null ? columns.toArray(new SimpleQuery.Column[columns.size()])
: null);
         }
-
         final FeatureSet driverSubset = driver.build().orElse(source);
-
         return isNoOp(remaining) ? driverSubset : remaining.execute(driverSubset);
     }
 
     protected static final boolean isNoOp(final SimpleQuery in) {
         return in.getOffset() <= 0
-                && in.getLimit() == UNLIMITED
+                && in.getLimit() == SimpleQuery.UNLIMITED
                 && allColumnsIncluded(in)
                 && !filteringRequired(in)
                 && !sortRequired(in);
@@ -95,7 +99,6 @@ public final class SubsetAdapter {
     }
 
     public interface AdapterBuilder {
-
         /**
          * Specify an offset to use in custom query.
          *
@@ -150,6 +153,7 @@ public final class SubsetAdapter {
 
         /**
          * Specify a subset of columns to return to the driver.
+         *
          * @param columns The columns to fetch in result set. Neither null nor empty list
accepted.
          * @return True if underlying driver can entirely manage column selection. False
otherwise, meaning that column
          * selection won't be done, or only partially, and a fallback filter must be applied
over driver feature set to
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
index 9669c29..c336ee3 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
@@ -40,7 +40,6 @@ import org.opengis.util.GenericName;
 import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.internal.metadata.sql.SQLBuilder;
 import org.apache.sis.internal.storage.AbstractFeatureSet;
-import org.apache.sis.internal.storage.SubsetAdapter;
 import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;


Mime
View raw message