Class WrappingPersistence<O,A extends Comparable<A>>
- java.lang.Object
-
- com.googlecode.cqengine.persistence.wrapping.WrappingPersistence<O,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 theCollection.contains(Object)
method. If the implementation of this method in the given collection is slow, then it may slow down some queries on theIndexedCollection
. As such, it is recommended, although not required, that the wrapped collection is aSet
. The time complexity of theSet.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 inResultSet
s even if deduplication was requested. Thread-safety
CQEngine will depend on the wrapped collection to be thread-safe, if anIndexedCollection
is configured with this persistence, and it will be accessed concurrently. If the application needs to access the theIndexedCollection
concurrently but it cannot supply a thread-safe collection to wrap, then it is recommended to use theOnHeapPersistence
instead.- Author:
- niall.gallagher
-
-
Constructor Summary
Constructors Constructor Description WrappingPersistence(Collection<O> backingCollection)
WrappingPersistence(Collection<O> backingCollection, SimpleAttribute<O,A> primaryKeyAttribute)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <O> WrappingPersistence<O,? extends Comparable>
aroundCollection(Collection<O> collection)
Creates aWrappingPersistence
object which persists to the given collection, without specifying a primary key.static <O,A extends Comparable<A>>
WrappingPersistence<O,A>aroundCollectionOnPrimaryKey(Collection<O> collection, SimpleAttribute<O,A> primaryKeyAttribute)
Creates aWrappingPersistence
object which persists to the given collection.void
closeRequestScopeResources(QueryOptions queryOptions)
Currently does nothing in this implementation ofPersistence
.ObjectStore<O>
createObjectStore()
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.SimpleAttribute<O,A>
getPrimaryKeyAttribute()
void
openRequestScopeResources(QueryOptions queryOptions)
Currently does nothing in this implementation ofPersistence
.boolean
supportsIndex(Index<O> index)
Returns true if the given index implements theOnHeapTypeIndex
marker interface.
-
-
-
Constructor Detail
-
WrappingPersistence
public WrappingPersistence(Collection<O> backingCollection)
-
WrappingPersistence
public WrappingPersistence(Collection<O> backingCollection, SimpleAttribute<O,A> primaryKeyAttribute)
-
-
Method Detail
-
supportsIndex
public boolean supportsIndex(Index<O> index)
Returns true if the given index implements theOnHeapTypeIndex
marker interface.- Specified by:
supportsIndex
in interfacePersistence<O,A extends Comparable<A>>
- Parameters:
index
- TheIndex
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 interfacePersistence<O,A extends Comparable<A>>
- Returns:
- An ObjectStore which persists objects added to the collection.
-
openRequestScopeResources
public void openRequestScopeResources(QueryOptions queryOptions)
Currently does nothing in this implementation ofPersistence
.- Specified by:
openRequestScopeResources
in interfacePersistence<O,A extends Comparable<A>>
- Parameters:
queryOptions
- The query options supplied with the request into CQEngine.
-
closeRequestScopeResources
public void closeRequestScopeResources(QueryOptions queryOptions)
Currently does nothing in this implementation ofPersistence
.- Specified by:
closeRequestScopeResources
in interfacePersistence<O,A extends Comparable<A>>
- Parameters:
queryOptions
- The query options supplied with the request into CQEngine, and which has earlier been supplied to thePersistence.openRequestScopeResources(QueryOptions)
method.
-
getPrimaryKeyAttribute
public SimpleAttribute<O,A> getPrimaryKeyAttribute()
- Specified by:
getPrimaryKeyAttribute
in interfacePersistence<O,A extends Comparable<A>>
- Returns:
- the primary key attribute, if configured. This may be null for some persistence implementations especially on-heap persistence.
-
aroundCollectionOnPrimaryKey
public static <O,A extends Comparable<A>> WrappingPersistence<O,A> aroundCollectionOnPrimaryKey(Collection<O> collection, SimpleAttribute<O,A> primaryKeyAttribute)
Creates aWrappingPersistence
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 aWrappingPersistence
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.
-
-