Class 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 Detail

      • toList

        public static <T> java.util.List<T> toList​(QueryResult<T> theResult)
        Return the results as a List
        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 result
        theHandler - 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 the QueryResult; 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 returns true if they are equal. Tuple query results are equal if they contain the same set of BindingSets 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 first SelectQueryResult to compare.
        tqr2 - the second SelectQueryResult 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.