Class FeatureIterator
java.lang.Object
org.apache.sis.internal.sql.feature.FeatureIterator
- All Implemented Interfaces:
AutoCloseable,Spliterator<AbstractFeature>
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 ofFeatureIterator does not support parallelism.
This iterator is not thread-safe and the trySplit() method always returns null.- Since:
- 1.0
- Version:
- 1.2
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,T_CONS extends Object, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FeatureAdapterThe converter from aResultSetrow to aFeatureinstance.(package private) static final intCharacteristics of the iterator.private final FeatureIterator[]The feature sets referenced through foreigner keys, or an empty array if none.private final longEstimated number of remaining rows, or ≤ 0 if unknown.private ResultSetThe result of executing the SQL query for aTable.private final InfoStatementsA cache of statements for fetching spatial information such as geometry columns or SRID.private final PreparedStatementIf this iterator returns only the features matching some condition (typically a primary key value), the statement for performing that filtering.Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFeatureIterator(FeatureAdapter adapter, Connection connection, InfoStatements spatialInformation) Creates a new iterator over the dependencies of a feature.(package private)FeatureIterator(Table table, Connection connection, boolean distinct, String filter, SortBy<? super AbstractFeature> sort, long offset, long count) Creates a new iterator over features. -
Method Summary
Modifier and TypeMethodDescriptionintDeclares that this iterator never returnsnullelements.voidclose()Closes the (pooled) connection, including the statements of all dependencies.private FeatureIteratordependency(int i) Returns the dependency at the given index, creating it when first needed.longReturns the estimated number of remaining features, orLong.MAX_VALUEif unknown.private booleanfetch(Consumer<? super AbstractFeature> action, boolean all) Gives at least the next feature to the given consumer.private ObjectfetchReferenced(AbstractFeature owner) Executes the currentstatementand stores all features in a list.voidforEachRemaining(Consumer<? super AbstractFeature> action) Gives all remaining features to the given consumer.booleantryAdvance(Consumer<? super AbstractFeature> action) Gives the next feature to the given consumer.trySplit()Current version does not support split.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
CHARACTERISTICS
static final int CHARACTERISTICSCharacteristics of the iterator. The value returned bycharacteristics()must be consistent with the value given toDeferredStreamconstructor.- See Also:
-
adapter
The converter from aResultSetrow to aFeatureinstance. -
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 isnull. -
result
-
estimatedSize
private final long estimatedSizeEstimated number of remaining rows, or ≤ 0 if unknown. -
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 thisFeatureIterator. -
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 firstFeatureAdapter.importCountiterators 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 theWHEREkeyword.sort- theORDER BYclauses, ornullif 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:
SQLExceptionInternalDataStoreException
-
FeatureIterator
private FeatureIterator(FeatureAdapter adapter, Connection connection, InfoStatements spatialInformation) throws SQLException Creates a new iterator over the dependencies of a feature.- Parameters:
table- the source table, ornullif we are creating an iterator for a dependency.adapter- converter from aResultSetrow to aFeatureinstance.connection- connection to the database, used for creating statement.filter- condition to append, not including theWHEREkeyword.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
Returns the dependency at the given index, creating it when first needed.- Throws:
SQLException
-
characteristics
public int characteristics()Declares that this iterator never returnsnullelements.- Specified by:
characteristicsin interfaceSpliterator<AbstractFeature>
-
estimateSize
public long estimateSize()Returns the estimated number of remaining features, orLong.MAX_VALUEif unknown.- Specified by:
estimateSizein interfaceSpliterator<AbstractFeature>
-
trySplit
Current version does not support split.- Specified by:
trySplitin interfaceSpliterator<AbstractFeature>- Returns:
- always
null.
-
tryAdvance
Gives the next feature to the given consumer.- Specified by:
tryAdvancein interfaceSpliterator<AbstractFeature>
-
forEachRemaining
Gives all remaining features to the given consumer.- Specified by:
forEachRemainingin interfaceSpliterator<AbstractFeature>
-
fetch
Gives at least the next feature to the given consumer. Gives all remaining features ifallistrue.- Parameters:
action- the action to execute for eachFeatureinstances fetched by this method.all-truefor reading all remaining feature instances, orfalsefor only the next one.- Returns:
trueif we have read an instance andallisfalse(so there is maybe other instances).- Throws:
Exception
-
fetchReferenced
Executes the currentstatementand stores all features in a list. Returnsnullif 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
Featureor as aCollection<Feature>. - Throws:
Exception
-
close
Closes the (pooled) connection, including the statements of all dependencies.- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-