Class TupleQueryResultConverter
- java.lang.Object
-
- org.eclipse.rdf4j.spring.dao.support.operation.TupleQueryResultConverter
-
public class TupleQueryResultConverter extends Object
- Since:
- 4.0.0
- Author:
- Florian Kleedorfer
-
-
Constructor Summary
Constructors Constructor Description TupleQueryResultConverter(TupleQueryResult result)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
applyToResult(Function<TupleQueryResult,T> function)
Applies the function to theTupleQueryResult
and closes the result afterwards.void
consumeResult(Consumer<TupleQueryResult> consumer)
Passes theTupleQueryResult
to the consumer and closes the result afterwards.Stream<BindingSet>
getBindingStream(TupleQueryResult result)
If the result has only one empty binding set, this method returns an empty stream, otherwise the stream of BindingSets<T,A,R>
RmapAndCollect(Function<BindingSet,T> mapper, Collector<T,A,R> collector)
<T> List<T>
toList(BindingSetMapper<T> mapper)
Maps the query result to aList
.<T,O>
List<O>toList(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the query result to aList
.<K,V>
Map<K,V>toMap(Function<BindingSet,Map.Entry<K,V>> entryMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.<K,V>
Map<K,V>toMap(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.<T,K,V>
Map<K,V>toMap(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.<K,V>
Map<K,List<V>>toMapOfList(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
<T,K,V>
Map<K,List<V>>toMapOfList(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
<K,V>
Map<K,Set<V>>toMapOfSet(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
<T,K,V>
Map<K,Set<V>>toMapOfSet(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
<T> Set<T>
toSet(BindingSetMapper<T> mapper)
Maps the query result to aSet
.<T,O>
Set<O>toSet(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the query result to aSet
.<T> T
toSingleton(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result, throwing an exception if there are no results or more than one.<T,O>
OtoSingleton(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the firstBindingSet
in the result, throwing an exception if there are no results or more than one.<T> T
toSingletonMaybe(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result if one exists, throwing an exception if there are more.<T,O>
OtoSingletonMaybe(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the firstBindingSet
in the result if one exists, throwing an exception if there are more.<T> T
toSingletonMaybeOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to one object, which may be null.<T> T
toSingletonOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to an object, throwing an exception if the mapper returnsnull
.<T> Optional<T>
toSingletonOptional(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result, throwing an exception if there are more than one.<T,O>
Optional<O>toSingletonOptional(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
<T> Optional<T>
toSingletonOptionalOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to oneOptional
.Stream<BindingSet>
toStream()
Obtains a stream ofBindingSet
s.<T> Stream<T>
toStream(BindingSetMapper<T> mapper)
Obtains aStream
of mapped query results.<T,O>
Stream<O>toStream(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Obtains aStream
of mapped query results, using the postprocessor to map it again.
-
-
-
Constructor Detail
-
TupleQueryResultConverter
public TupleQueryResultConverter(TupleQueryResult result)
-
-
Method Detail
-
consumeResult
public void consumeResult(Consumer<TupleQueryResult> consumer)
Passes theTupleQueryResult
to the consumer and closes the result afterwards.
-
applyToResult
public <T> T applyToResult(Function<TupleQueryResult,T> function)
Applies the function to theTupleQueryResult
and closes the result afterwards.
-
toStream
public Stream<BindingSet> toStream()
Obtains a stream ofBindingSet
s. The result is completely consumed and closed when the stream is returned.
-
toStream
public <T> Stream<T> toStream(BindingSetMapper<T> mapper)
Obtains aStream
of mapped query results. The result is completely consumed and closed when the stream is returned. Any null values are filterd from the resulting stream.
-
toStream
public <T,O> Stream<O> toStream(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Obtains aStream
of mapped query results, using the postprocessor to map it again. Any null values are filtered from the resulting stream.
-
toSingletonMaybeOfWholeResult
public <T> T toSingletonMaybeOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to one object, which may be null.
-
toSingletonOptionalOfWholeResult
public <T> Optional<T> toSingletonOptionalOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to oneOptional
.
-
toSingletonOfWholeResult
public <T> T toSingletonOfWholeResult(TupleQueryResultMapper<T> mapper)
Maps the wholeTupleQueryResult
to an object, throwing an exception if the mapper returnsnull
.- Throws:
IncorrectResultSetSizeException
-
toSingletonMaybe
public <T> T toSingletonMaybe(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result if one exists, throwing an exception if there are more. Returns null if there are no results or if there is one result that is mapped to null by the specified mapper.- Throws:
IncorrectResultSetSizeException
-
toSingletonOptional
public <T> Optional<T> toSingletonOptional(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result, throwing an exception if there are more than one. Returns an Optional, which is empty if there are no results or if there is one result that is mapped to null by the specified mapper.
-
toSingleton
public <T> T toSingleton(BindingSetMapper<T> mapper)
Maps the firstBindingSet
in the result, throwing an exception if there are no results or more than one.- Throws:
IncorrectResultSetSizeException
-
toSingletonMaybe
public <T,O> O toSingletonMaybe(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the firstBindingSet
in the result if one exists, throwing an exception if there are more.- Throws:
IncorrectResultSetSizeException
-
toSingletonOptional
public <T,O> Optional<O> toSingletonOptional(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
-
toSingleton
public <T,O> O toSingleton(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the firstBindingSet
in the result, throwing an exception if there are no results or more than one.- Throws:
IncorrectResultSetSizeException
-
mapAndCollect
public <T,A,R> R mapAndCollect(Function<BindingSet,T> mapper, Collector<T,A,R> collector)
-
toList
public <T> List<T> toList(BindingSetMapper<T> mapper)
Maps the query result to aList
.
-
toList
public <T,O> List<O> toList(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the query result to aList
.
-
toSet
public <T> Set<T> toSet(BindingSetMapper<T> mapper)
Maps the query result to aSet
.
-
toSet
public <T,O> Set<O> toSet(BindingSetMapper<T> mapper, MappingPostProcessor<T,O> postProcessor)
Maps the query result to aSet
.
-
toMap
public <K,V> Map<K,V> toMap(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.
-
toMapOfSet
public <K,V> Map<K,Set<V>> toMapOfSet(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
-
toMapOfList
public <K,V> Map<K,List<V>> toMapOfList(Function<BindingSet,K> keyMapper, Function<BindingSet,V> valueMapper)
-
toMap
public <T,K,V> Map<K,V> toMap(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.
-
toMap
public <K,V> Map<K,V> toMap(Function<BindingSet,Map.Entry<K,V>> entryMapper)
Maps the query result to aMap
, throwing an Exception if there are multiple values for one key.
-
toMapOfSet
public <T,K,V> Map<K,Set<V>> toMapOfSet(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
-
toMapOfList
public <T,K,V> Map<K,List<V>> toMapOfList(BindingSetMapper<T> mapper, Function<T,K> keyMapper, Function<T,V> valueMapper)
-
getBindingStream
public Stream<BindingSet> getBindingStream(TupleQueryResult result)
If the result has only one empty binding set, this method returns an empty stream, otherwise the stream of BindingSets
-
-