Class FeatureIterator

java.lang.Object
org.apache.sis.internal.sql.feature.FeatureIterator
All Implemented Interfaces:
AutoCloseable, Spliterator<AbstractFeature>

final class FeatureIterator extends Object implements Spliterator<AbstractFeature>, AutoCloseable
Iterator over feature instances. This iterator converters ResultSet rows to Feature instances. Each FeatureIterator iterator is created for one specific SQL query and can be used for only one iteration.

Parallelism

Current implementation of FeatureIterator does not support parallelism. This iterator is not thread-safe and the trySplit() method always returns null.
Since:
1.0
Version:
1.2
  • Field Details

    • CHARACTERISTICS

      static final int CHARACTERISTICS
      Characteristics of the iterator. The value returned by characteristics() must be consistent with the value given to DeferredStream constructor.
      See Also:
    • adapter

      private final FeatureAdapter adapter
      The converter from a ResultSet row to a Feature instance.
    • statement

      private final PreparedStatement statement
      If this iterator returns only the features matching some condition (typically a primary key value), the statement for performing that filtering. Otherwise if this iterator returns all features, then this field is null.
    • result

      private ResultSet result
      The result of executing the SQL query for a Table. If statement is null, then a single ResultSet is used for all the lifetime of this FeatureIterator instance. Otherwise an arbitrary number of ResultSets may be created from the statement.
    • estimatedSize

      private final long estimatedSize
      Estimated number of remaining rows, or ≤ 0 if unknown.
    • spatialInformation

      private final InfoStatements spatialInformation
      A cache of statements for fetching spatial information such as geometry columns or SRID. This is non-null only if the database is spatial. The same instance is shared by all dependencies of this FeatureIterator.
    • dependencies

      private final FeatureIterator[] dependencies
      The feature sets referenced through foreigner keys, or an empty array if none. This includes the associations inferred from both the imported and exported keys. The first FeatureAdapter.importCount iterators are for imported keys, and the remaining iterators are for the exported keys.

      All elements in this array are initially null. Iterators are created when first needed. They may be never created because those features may be in the cache.

  • Constructor Details

    • FeatureIterator

      FeatureIterator(Table table, Connection connection, boolean distinct, String filter, SortBy<? super AbstractFeature> sort, long offset, long count) throws SQLException, InternalDataStoreException
      Creates a new iterator over features.
      Parameters:
      table - the source table.
      connection - connection to the database, used for creating the statement.
      distinct - whether the set should contain distinct feature instances.
      filter - condition to append, not including the WHERE keyword.
      sort - the ORDER BY clauses, or null if none.
      offset - number of rows to skip in underlying SQL query, or ≤ 0 for none.
      count - maximum number of rows to return, or ≤ 0 for no limit.
      Throws:
      SQLException
      InternalDataStoreException
    • FeatureIterator

      private FeatureIterator(FeatureAdapter adapter, Connection connection, InfoStatements spatialInformation) throws SQLException
      Creates a new iterator over the dependencies of a feature.
      Parameters:
      adapter - converter from a ResultSet row to a Feature instance.
      connection - connection to the database, used for creating statement.
      table - the source table, or null if we are creating an iterator for a dependency.
      filter - condition to append, not including the WHERE keyword.
      distinct - whether the set should contain distinct feature instances.
      offset - number of rows to skip in underlying SQL query, or ≤ 0 for none.
      count - maximum number of rows to return, or ≤ 0 for no limit.
      Throws:
      SQLException
  • Method Details

    • dependency

      private FeatureIterator dependency(int i) throws SQLException
      Returns the dependency at the given index, creating it when first needed.
      Throws:
      SQLException
    • characteristics

      public int characteristics()
      Declares that this iterator never returns null elements.
      Specified by:
      characteristics in interface Spliterator<AbstractFeature>
    • estimateSize

      public long estimateSize()
      Returns the estimated number of remaining features, or Long.MAX_VALUE if unknown.
      Specified by:
      estimateSize in interface Spliterator<AbstractFeature>
    • trySplit

      public Spliterator<AbstractFeature> trySplit()
      Current version does not support split.
      Specified by:
      trySplit in interface Spliterator<AbstractFeature>
      Returns:
      always null.
    • tryAdvance

      public boolean tryAdvance(Consumer<? super AbstractFeature> action)
      Gives the next feature to the given consumer.
      Specified by:
      tryAdvance in interface Spliterator<AbstractFeature>
    • forEachRemaining

      public void forEachRemaining(Consumer<? super AbstractFeature> action)
      Gives all remaining features to the given consumer.
      Specified by:
      forEachRemaining in interface Spliterator<AbstractFeature>
    • fetch

      private boolean fetch(Consumer<? super AbstractFeature> action, boolean all) throws Exception
      Gives at least the next feature to the given consumer. Gives all remaining features if all is true.
      Parameters:
      action - the action to execute for each Feature instances fetched by this method.
      all - true for reading all remaining feature instances, or false for only the next one.
      Returns:
      true if we have read an instance and all is false (so there is maybe other instances).
      Throws:
      Exception
    • fetchReferenced

      private Object fetchReferenced(AbstractFeature owner) throws Exception
      Executes the current statement and stores all features in a list. Returns null if there are no features, or returns the feature instance if there is only one such instance, or returns a list of features otherwise.
      Parameters:
      owner - if the features to fetch are components of another feature, that container feature instance.
      Returns:
      the feature as a singleton Feature or as a Collection<Feature>.
      Throws:
      Exception
    • close

      public void close() throws SQLException
      Closes the (pooled) connection, including the statements of all dependencies.
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException