Class WrappingPersistence<O,​A extends Comparable<A>>

  • All Implemented Interfaces:
    Persistence<O,​A>

    public class WrappingPersistence<O,​A extends Comparable<A>>
    extends Object
    implements Persistence<O,​A>
    Specifies to wrap and use a given collection for persistence.

    Note that, as the implementation of the given collection is outside of CQEngine's control, the following points should be considered with respect to performance and query processing.

    Collection.contains() method
    As CQEngine evaluates queries using set theory, it relies heavily on the performance of the Collection.contains(Object) method. If the implementation of this method in the given collection is slow, then it may slow down some queries on the IndexedCollection.

    As such, it is recommended, although not required, that the wrapped collection is a Set. The time complexity of the Set.contains(Object) method is usually O(1).

    Duplicate objects
    CQEngine does not expect the given collection to contain duplicate objects. If the given collection does contain duplicates, then it is possible that duplicate objects may be returned in ResultSets even if deduplication was requested.

    Thread-safety
    CQEngine will depend on the wrapped collection to be thread-safe, if an IndexedCollection is configured with this persistence, and it will be accessed concurrently.

    If the application needs to access the the IndexedCollection concurrently but it cannot supply a thread-safe collection to wrap, then it is recommended to use the OnHeapPersistence instead.

    Author:
    niall.gallagher
    • Constructor Detail

      • WrappingPersistence

        public WrappingPersistence​(Collection<O> backingCollection)
    • Method Detail

      • supportsIndex

        public boolean supportsIndex​(Index<O> index)
        Returns true if the given index implements the OnHeapTypeIndex marker interface.
        Specified by:
        supportsIndex in interface Persistence<O,​A extends Comparable<A>>
        Parameters:
        index - The Index to check.
        Returns:
        true if this persistence manages the given index. False otherwise.
      • createObjectStore

        public ObjectStore<O> createObjectStore()
        Description copied from interface: Persistence
        Creates an ObjectStore which can store the objects added to the collection, either on-heap off-heap or on disk, depending on the persistence implementation.
        Specified by:
        createObjectStore in interface Persistence<O,​A extends Comparable<A>>
        Returns:
        An ObjectStore which persists objects added to the collection.
      • aroundCollectionOnPrimaryKey

        public static <O,​A extends Comparable<A>> WrappingPersistence<O,​A> aroundCollectionOnPrimaryKey​(Collection<O> collection,
                                                                                                                    SimpleAttribute<O,​A> primaryKeyAttribute)
        Creates a WrappingPersistence object which persists to the given collection.
        Parameters:
        primaryKeyAttribute - An attribute which returns the primary key of objects in the collection
        Returns:
        A WrappingPersistence object which persists to the given collection.
      • aroundCollection

        public static <O> WrappingPersistence<O,​? extends Comparable> aroundCollection​(Collection<O> collection)
        Creates a WrappingPersistence object which persists to the given collection, without specifying a primary key. As such, this persistence implementation will be compatible with on-heap indexes only.

        This persistence will not work with composite persistence configurations, where some indexes are located on heap, and some off-heap etc. To use this persistence in those configurations, it is necessary to specify a primary key - see: aroundCollectionOnPrimaryKey(Collection, SimpleAttribute).

        Returns:
        A WrappingPersistence object which persists to the given collection, and which is not configured with a primary key.