Package com.stardog.stark.query
Class QueryResults
- java.lang.Object
-
- com.stardog.stark.query.QueryResults
-
public final class QueryResults extends java.lang.Object
Utilities for working with QueryResults
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Michael Grove, Jeen Broekstra
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
closeQuietly(QueryResult<?> theResult)
"Quietly"close
theQueryResult
; any exception throw while closing will simply be logged.static void
consume(QueryResult<?> theResult)
Iterate over all of the results and close the result set.static boolean
equals(SelectQueryResult tqr1, SelectQueryResult tqr2)
Compares two tuple query results and returnstrue
if they are equal.static boolean
equalsWithOrder(SelectQueryResult tqr1, SelectQueryResult tqr2)
Similar toequals(SelectQueryResult, SelectQueryResult)
but also checks the order of binding sets.static boolean
isSubset(SelectQueryResult tqr1, SelectQueryResult tqr2)
Compares two tuple query results and returnstrue
if the the first is a subset of the other.static void
report(SelectQueryResult theResult, SelectQueryResultHandler theHandler)
Iterate over the query result and send the results to the given handlerstatic <T> java.util.Optional<T>
singleResult(QueryResult<T> theResult)
Return the next result from the results and close the results.static long
size(QueryResult<?> theResult)
Return the number of results present in this result setstatic <T> java.util.List<T>
toList(QueryResult<T> theResult)
Return theresults
as aList
-
-
-
Method Detail
-
toList
public static <T> java.util.List<T> toList(QueryResult<T> theResult)
Return theresults
as aList
- Parameters:
theResult
- the query result- Returns:
- the results as a `List`
- Implementation Notes:
- * This pulls all of the results into memory so it is not appropriate for a large result set.
* The side effect of this call is that `theResult` is
closed
.
-
report
public static void report(@Nonnull SelectQueryResult theResult, @Nonnull SelectQueryResultHandler theHandler)
Iterate over the query result and send the results to the given handler- Parameters:
theResult
- the resulttheHandler
- the result handler- Throws:
QueryExecutionFailure
- if the next result could not be computed- Implementation Notes:
- The side effect of this call is that `theResult` is
closed
.
-
singleResult
@Nonnull public static <T> java.util.Optional<T> singleResult(@Nonnull QueryResult<T> theResult)
Return the next result from the results and close the results.- Parameters:
theResult
- the result- Returns:
- the next result
- Throws:
QueryExecutionFailure
- if the next result could not be computed- Implementation Notes:
- The side effect of this call is that `theResult` is
closed
.
-
size
public static long size(@Nonnull QueryResult<?> theResult)
Return the number of results present in this result set- Parameters:
theResult
- the results- Returns:
- the number of results
- Throws:
QueryExecutionFailure
- if the results count not be computed- Implementation Notes:
- The side effect of this call is that `theResult` is exhausted and
closed
.
-
consume
public static void consume(@Nonnull QueryResult<?> theResult)
Iterate over all of the results and close the result set. The results of the query are simply thrown away.- Parameters:
theResult
- the results- Throws:
QueryExecutionFailure
- if the execution failed in any way
-
closeQuietly
public static void closeQuietly(@Nonnull QueryResult<?> theResult)
"Quietly"close
theQueryResult
; any exception throw while closing will simply be logged.- Parameters:
theResult
- the result to close
-
equals
public static boolean equals(@Nonnull SelectQueryResult tqr1, @Nonnull SelectQueryResult tqr2) throws QueryExecutionFailure
Compares two tuple query results and returnstrue
if they are equal. Tuple query results are equal if they contain the same set ofBindingSet
s and have the same headers. Blank nodes identifiers are not relevant for equality, they are matched by trying to find compatible mappings between BindingSets. Note that the method consumes both query results fully.- Parameters:
tqr1
- the firstSelectQueryResult
to compare.tqr2
- the secondSelectQueryResult
to compare.- Throws:
QueryExecutionFailure
- Implementation Notes:
- This will consume both sets of results and they will both be closed as a side effect of calling this method. The results are also pulled into memory for the comparison, so this may not be suitable for use for large result sets.
-
equalsWithOrder
public static boolean equalsWithOrder(@Nonnull SelectQueryResult tqr1, @Nonnull SelectQueryResult tqr2)
Similar toequals(SelectQueryResult, SelectQueryResult)
but also checks the order of binding sets.
-
isSubset
public static boolean isSubset(@Nonnull SelectQueryResult tqr1, @Nonnull SelectQueryResult tqr2) throws QueryExecutionFailure
Compares two tuple query results and returnstrue
if the the first is a subset of the other. Uses the same notion ofBindingSet
equality asequals(SelectQueryResult, SelectQueryResult)
.- Parameters:
tqr1
- the firstSelectQueryResult
to compare.tqr2
- the secondSelectQueryResult
to compare.- Throws:
QueryExecutionFailure
- Implementation Notes:
- This will consume both sets of results and they will both be closed as a side effect of calling this method. The results are also pulled into memory for the comparison, so this may not be suitable for use for large result sets.
-
-