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,
T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FeatureAdapter
The converter from aResultSet
row to aFeature
instance.(package private) static final int
Characteristics of the iterator.private final FeatureIterator[]
The feature sets referenced through foreigner keys, or an empty array if none.private final long
Estimated number of remaining rows, or ≤ 0 if unknown.private ResultSet
The result of executing the SQL query for aTable
.private final InfoStatements
A cache of statements for fetching spatial information such as geometry columns or SRID.private final PreparedStatement
If 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
ConstructorsModifierConstructorDescriptionprivate
FeatureIterator
(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 TypeMethodDescriptionint
Declares that this iterator never returnsnull
elements.void
close()
Closes the (pooled) connection, including the statements of all dependencies.private FeatureIterator
dependency
(int i) Returns the dependency at the given index, creating it when first needed.long
Returns the estimated number of remaining features, orLong.MAX_VALUE
if unknown.private boolean
fetch
(Consumer<? super AbstractFeature> action, boolean all) Gives at least the next feature to the given consumer.private Object
fetchReferenced
(AbstractFeature owner) Executes the currentstatement
and stores all features in a list.void
forEachRemaining
(Consumer<? super AbstractFeature> action) Gives all remaining features to the given consumer.boolean
tryAdvance
(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, wait
Methods 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 toDeferredStream
constructor.- See Also:
-
adapter
The converter from aResultSet
row to aFeature
instance. -
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.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 theWHERE
keyword.sort
- theORDER BY
clauses, ornull
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 aResultSet
row to aFeature
instance.connection
- connection to the database, used for creating statement.table
- the source table, ornull
if we are creating an iterator for a dependency.filter
- condition to append, not including theWHERE
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
Returns the dependency at the given index, creating it when first needed.- Throws:
SQLException
-
characteristics
public int characteristics()Declares that this iterator never returnsnull
elements.- Specified by:
characteristics
in interfaceSpliterator<AbstractFeature>
-
estimateSize
public long estimateSize()Returns the estimated number of remaining features, orLong.MAX_VALUE
if unknown.- Specified by:
estimateSize
in interfaceSpliterator<AbstractFeature>
-
trySplit
Current version does not support split.- Specified by:
trySplit
in interfaceSpliterator<AbstractFeature>
- Returns:
- always
null
.
-
tryAdvance
Gives the next feature to the given consumer.- Specified by:
tryAdvance
in interfaceSpliterator<AbstractFeature>
-
forEachRemaining
Gives all remaining features to the given consumer.- Specified by:
forEachRemaining
in interfaceSpliterator<AbstractFeature>
-
fetch
Gives at least the next feature to the given consumer. Gives all remaining features ifall
istrue
.- Parameters:
action
- the action to execute for eachFeature
instances fetched by this method.all
-true
for reading all remaining feature instances, orfalse
for only the next one.- Returns:
true
if we have read an instance andall
isfalse
(so there is maybe other instances).- Throws:
Exception
-
fetchReferenced
Executes the currentstatement
and stores all features in a list. Returnsnull
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 aCollection<Feature>
. - Throws:
Exception
-
close
Closes the (pooled) connection, including the statements of all dependencies.- Specified by:
close
in interfaceAutoCloseable
- Throws:
SQLException
-