Class ResultSet<O>

    • Constructor Detail

      • ResultSet

        public ResultSet()
    • Method Detail

      • contains

        public abstract boolean contains​(O object)
        Returns true if this ResultSet contains the given object, false if it does not.

        Note that the cost of calling this method will most likely be cheaper than iterating all results to check if an object is contained. If indexes are available to support the query, this method will query indexes to check if the object is contained, instead of actually retrieving any data.

        See also the matches(Object) method, which provides a similar function but often with better performance than this method.

        Parameters:
        object - The object to check for containment in this ResultSet
        Returns:
        True if this ResultSet contains the given object, false if it does not
      • matches

        public abstract boolean matches​(O object)
        Similar to the contains(Object) method, but checks for logical containment in the ResultSet as opposed to physical containment in the ResultSet. Determines if the given object would be contained in the ResultSet, by testing if the given object matches the query for which this ResultSet was generated, instead of actually checking if the object is contained in appropriate indexes.

        This method will typically make the determination by evaluating the query on the given object on-the-fly without accessing indexes, however in some cases this method might delegate to the contains(Object) method to make the determination.

        This method will perform better than contains(Object) in cases where querying indexes is more expensive than querying attributes, which is usually the case.

        Parameters:
        object - The object to check for logical containment in this ResultSet
        Returns:
        True if this ResultSet logically contains the given object, false if it does not
      • getQuery

        public abstract Query<O> getQuery()
        Returns the query for which this ResultSet provides results.
        Returns:
        The query for which this ResultSet provides results.
      • getQueryOptions

        public abstract QueryOptions getQueryOptions()
        Returns the query options associated with the query.
        Returns:
        The query options associated with the query.
      • uniqueResult

        public O uniqueResult()
        Returns the first object returned by the iterator of this ResultSet, and throws an exception if the iterator does not provide exactly one object.
        Returns:
        The first object returned by the iterator of this ResultSet
        Throws:
        NoSuchObjectException - If the iterator indicates no object is available
        NonUniqueObjectException - If the iterator indicates more than one object is available
      • getRetrievalCost

        public abstract int getRetrievalCost()
        Returns an estimate of the cost of looking up objects matching the query underlying this ResultSet in the index.

        The query engine will use this to select the index with the lowest cost, when more than one index supporting the query exists for the same attribute.

        An example: a single-level hash index will typically have a lower retrieval cost than a tree-based index. Of course a hash index only supports equality-based retrieval whereas a sorted tree-based index might support equality/less than/greater than or range based retrieval. But for an equality-based query, supported by both indexes, retrieval cost allows the query engine to prefer the hash index.

        Returns:
        An estimate of the cost of looking up a particular query in the index
      • getMergeCost

        public abstract int getMergeCost()
        Returns an estimate of the cost of merging (or otherwise processing) objects matching the query.

        This will typically be based on the number of objects matching the query.

        • If the query specifies a simple retrieval from an index, this might be the number of objects matching the query
        • If the query specifies a union between multiple other sub-queries, this might be the sum of their merge costs
        • If the query specifies an intersection, this might be the based on the merge cost of the sub-query with the lowest merge cost
        The query engine will use this to optimize the order of intersections and unions, and to decide between merging versus filtering strategies.
        Returns:
        An estimate of the cost of merging (or otherwise processing) objects matching a query
      • size

        public abstract int size()
        Returns the number of objects which would be returned by this ResultSet if iterated.

        Note that the cost of calling this method depends on the query for which it was constructed.

        For simple queries where a single query is supplied and a matching index exists, or where several such simple queries are supplied and are connected using a simple Or query, calculating the size via this method will be cheaper than iterating through the ResultSet and counting the number of objects individually.

        For more complex queries, where intersections must be performed or where no suitable indexes exist, calling this method can be non-trivial, but it will always be at least as cheap as iterating through the ResultSet and counting the number of objects individually.

        Returns:
        The number of objects which would be returned by this ResultSet if iterated
      • isEmpty

        public boolean isEmpty()
        Checks if this ResultSet if iterated would not return any objects (i.e. the query does not match any objects).

        This method can be more efficient than calling #size() to check simply if no objects would be returned.

        Returns:
        True if this ResultSet if iterated would not return any objects; false if the ResultSet would return objects
      • isNotEmpty

        public boolean isNotEmpty()
        Checks if this ResultSet if iterated would return some objects (i.e. the query matches some objects).

        This method can be more efficient than calling #size() to check simply if some objects would be returned.

        Returns:
        True if this ResultSet if iterated would return some objects; false if the ResultSet would not return any objects
      • close

        public abstract void close()
        Releases any resources or closes the transaction which was opened for this ResultSet.

        Whether or not it is necessary to close the ResultSet depends on which implementation of IndexedCollection is in use and the types of indexes added to it.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable