Package org.infinispan.persistence.jpa
Class JpaStore<K,V>
- java.lang.Object
-
- org.infinispan.persistence.jpa.JpaStore<K,V>
-
- All Implemented Interfaces:
Lifecycle
,AdvancedCacheLoader<K,V>
,AdvancedCacheWriter<K,V>
,AdvancedLoadWriteStore<K,V>
,CacheLoader<K,V>
,CacheWriter<K,V>
,ExternalStore<K,V>
public class JpaStore<K,V> extends Object implements AdvancedLoadWriteStore<K,V>
NOTE: This store can return expired keys or entries on any given operation ifJpaStoreConfiguration.storeMetadata()
was set to false.- Author:
- Ray Tsang
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.persistence.spi.AdvancedCacheWriter
AdvancedCacheWriter.PurgeListener<K>
-
-
Constructor Summary
Constructors Constructor Description JpaStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>
bulkUpdate(org.reactivestreams.Publisher<MarshallableEntry<? extends K,? extends V>> publisher)
Persist all provided entries to the store in chunks, with the size of each chunk determined by the store implementation.void
clear()
Removes all the data from the storage.boolean
contains(Object key)
Returns true if the storage contains an entry associated with the given key.boolean
delete(Object key)
void
deleteBatch(Iterable<Object> keys)
Remove all provided keys from the store in a single batch operation.io.reactivex.rxjava3.core.Flowable<MarshallableEntry<K,V>>
entryPublisher(Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata)
Publishes all entries from this store.void
init(InitializationContext ctx)
Used to initialize a cache loader.protected boolean
isValidKeyType(Object key)
MarshallableEntry
loadEntry(Object key)
Fetches an entry from the storage.io.reactivex.rxjava3.core.Flowable<K>
publishKeys(Predicate<? super K> filter)
Publishes all the keys from this store.void
purge(Executor threadPool, AdvancedCacheWriter.PurgeListener listener)
Using the thread in the pool, removed all the expired data from the persistence storage.int
size()
Returns the number of elements in the store.void
start()
Invoked on component startvoid
stop()
Invoked on component stopvoid
write(MarshallableEntry entry)
Persists the entry to the storage.-
Methods inherited from interface org.infinispan.persistence.spi.CacheWriter
isAvailable
-
Methods inherited from interface org.infinispan.persistence.spi.ExternalStore
destroy, isAvailable
-
-
-
-
Method Detail
-
init
public void init(InitializationContext ctx)
Description copied from interface:CacheLoader
Used to initialize a cache loader. Typically invoked by thePersistenceManager
when setting up cache loaders.- Specified by:
init
in interfaceCacheLoader<K,V>
- Specified by:
init
in interfaceCacheWriter<K,V>
-
start
public void start()
Description copied from interface:Lifecycle
Invoked on component start
-
stop
public void stop()
Description copied from interface:Lifecycle
Invoked on component stop
-
isValidKeyType
protected boolean isValidKeyType(Object key)
-
clear
public void clear()
Description copied from interface:AdvancedCacheWriter
Removes all the data from the storage.- Specified by:
clear
in interfaceAdvancedCacheWriter<K,V>
-
delete
public boolean delete(Object key)
- Specified by:
delete
in interfaceCacheWriter<K,V>
- Returns:
- true if the entry existed in the persistent store and it was deleted.
-
deleteBatch
public void deleteBatch(Iterable<Object> keys)
Description copied from interface:CacheWriter
Remove all provided keys from the store in a single batch operation. If this is not supported by the underlying store, then keys are removed from the store individually viaCacheWriter.delete(Object)
.- Specified by:
deleteBatch
in interfaceCacheWriter<K,V>
- Parameters:
keys
- an Iterable of entry Keys to be removed from the store.
-
write
public void write(MarshallableEntry entry)
Description copied from interface:CacheWriter
Persists the entry to the storage.- Specified by:
write
in interfaceCacheWriter<K,V>
- See Also:
MarshallableEntry
-
bulkUpdate
public CompletionStage<Void> bulkUpdate(org.reactivestreams.Publisher<MarshallableEntry<? extends K,? extends V>> publisher)
Description copied from interface:CacheWriter
Persist all provided entries to the store in chunks, with the size of each chunk determined by the store implementation. If chunking is not supported by the underlying store, then entries are written to the store individually viaCacheWriter.write(MarshallableEntry)
.- Specified by:
bulkUpdate
in interfaceCacheWriter<K,V>
- Parameters:
publisher
- aPublisher
ofMarshallableEntry
instances
-
contains
public boolean contains(Object key)
Description copied from interface:CacheLoader
Returns true if the storage contains an entry associated with the given key.- Specified by:
contains
in interfaceCacheLoader<K,V>
-
loadEntry
public MarshallableEntry loadEntry(Object key)
Description copied from interface:CacheLoader
Fetches an entry from the storage. If aMarshallableEntry
needs to be created here,InitializationContext.getMarshallableEntryFactory()
()} andInitializationContext.getByteBufferFactory()
should be used.- Specified by:
loadEntry
in interfaceCacheLoader<K,V>
- Returns:
- the entry, or null if the entry does not exist
-
publishKeys
public io.reactivex.rxjava3.core.Flowable<K> publishKeys(Predicate<? super K> filter)
Description copied from interface:AdvancedCacheLoader
Publishes all the keys from this store. The given publisher can be used by as manySubscriber
s as desired. Keys are not retrieved until a given Subscriber requests them from theSubscription
.Stores will return only non expired keys
- Specified by:
publishKeys
in interfaceAdvancedCacheLoader<K,V>
- Parameters:
filter
- a filter - null is treated as allowing all entries- Returns:
- a publisher that will provide the keys from the store
-
entryPublisher
public io.reactivex.rxjava3.core.Flowable<MarshallableEntry<K,V>> entryPublisher(Predicate<? super K> filter, boolean fetchValue, boolean fetchMetadata)
Description copied from interface:AdvancedCacheLoader
Publishes all entries from this store. The given publisher can be used by as manySubscriber
s as desired. Entries are not retrieved until a given Subscriber requests them from theSubscription
.If fetchMetadata is true this store must guarantee to not return any expired entries.
- Specified by:
entryPublisher
in interfaceAdvancedCacheLoader<K,V>
- Parameters:
filter
- a filter - null is treated as allowing all entriesfetchValue
- whether or not to fetch the value from the persistent store. E.g. if the iteration is intended only over the key set, no point fetching the values from the persistent store as wellfetchMetadata
- whether or not to fetch the metadata from the persistent store. E.g. if the iteration is intended only ove the key set, then no point fetching the metadata from the persistent store as well- Returns:
- a publisher that will provide the entries from the store
-
size
public int size()
Description copied from interface:AdvancedCacheLoader
Returns the number of elements in the store.- Specified by:
size
in interfaceAdvancedCacheLoader<K,V>
-
purge
public void purge(Executor threadPool, AdvancedCacheWriter.PurgeListener listener)
Description copied from interface:AdvancedCacheWriter
Using the thread in the pool, removed all the expired data from the persistence storage. For each removed entry, the supplied listener is invoked.When this method returns all entries will be purged and no tasks will be running due to this loader in the provided executor. If however an exception is thrown there could be tasks still pending or running in the executor.
- Specified by:
purge
in interfaceAdvancedCacheWriter<K,V>
-
-