Class BaseJdbcStore<K,V,C extends AbstractJdbcStoreConfiguration>
- All Implemented Interfaces:
NonBlockingStore<K,
V>
- Direct Known Subclasses:
AbstractSchemaJdbcStore
,JdbcStringBasedStore
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.infinispan.persistence.spi.NonBlockingStore
NonBlockingStore.Characteristic, NonBlockingStore.SegmentedPublisher<Type>
-
Field Summary
Modifier and TypeFieldDescriptionprotected BlockingManager
protected C
protected ConnectionFactory
protected static final Log
protected TableOperations
<K, V> protected final Map
<jakarta.transaction.Transaction, Connection> Fields inherited from interface org.infinispan.persistence.spi.NonBlockingStore
SIZE_UNAVAILABLE_FUTURE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionapproximateSize
(IntSet segments) Returns an estimation of the amount of entries that map to the given segments in the store.batch
(int publisherCount, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<Object>> removePublisher, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<MarshallableEntry<K, V>>> writePublisher) Writes and removes the entries provided by the Publishers into the store.Returns a set of characteristics for this store and its elements.clear()
Clears all entries from the store.commit
(jakarta.transaction.Transaction tx) Commit changes in the provided transaction to the underlying store.protected abstract TableOperations
<K, V> createTableOperations
(InitializationContext ctx, C config) Extension point to allow for initializing and creating a table operations object.Removes the entry for given key and segment from the store and optionally report if the entry was actually removed or not.protected void
destroyTxConnection
(jakarta.transaction.Transaction tx) protected void
Method to extend to add additional steps when the store is shutting down.protected Connection
getTxConnection
(jakarta.transaction.Transaction tx) Returns a stage that, when complete, returns a boolean indicating whether the current store can be accessed for requests.Returns a stage that will contain the value loaded from the store.prepareWithModifications
(jakarta.transaction.Transaction tx, int publisherCount, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<Object>> removePublisher, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<MarshallableEntry<K, V>>> writePublisher) Write remove and put modifications to the store in the prepare phase, which should not yet persisted until the same transaction is committed viaNonBlockingStore.commit(Transaction)
or they are discarded if the transaction is rolled back viaNonBlockingStore.rollback(Transaction)
.org.reactivestreams.Publisher
<MarshallableEntry<K, V>> publishEntries
(IntSet segments, Predicate<? super K> filter, boolean includeValues) Publishes entries from this store that are in one of the provided segments and also pass the provided filter.org.reactivestreams.Publisher
<K> publishKeys
(IntSet segments, Predicate<? super K> filter) Publishes keys from this store that are in one of the provided segments and also pass the provided filter.rollback
(jakarta.transaction.Transaction tx) Roll back the changes from the provided transaction to the underlying store.Returns the amount of entries that map to the given segments in the store.The first method to invoke so that the store can be configured and additional steps, such as connecting through a socket or opening file descriptors, are performed.stop()
This method is invoked when the cache is being shutdown.write
(int segment, MarshallableEntry<? extends K, ? extends V> entry) Writes the entry to the store for the given segment returning a stage that completes normally when it is finished.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.infinispan.persistence.spi.NonBlockingStore
addSegments, containsKey, destroy, ignoreCommandWithFlags, purgeExpired, removeSegments
-
Field Details
-
log
-
connectionFactory
-
blockingManager
-
config
-
tableOperations
-
transactionConnectionMap
-
-
Constructor Details
-
BaseJdbcStore
public BaseJdbcStore()
-
-
Method Details
-
characteristics
Description copied from interface:NonBlockingStore
Returns a set of characteristics for this store and its elements. This method may be invoked multiple times to determine which methods of the store can be used and how the data in the store can be handled.Refer to
NonBlockingStore.Characteristic
and its values for descriptions of each characteristic for stores.- Specified by:
characteristics
in interfaceNonBlockingStore<K,
V> - Returns:
- the set of characteristics that this store supports.
-
createTableOperations
protected abstract TableOperations<K,V> createTableOperations(InitializationContext ctx, C config) throws SQLException Extension point to allow for initializing and creating a table operations object. All variables in theBaseJdbcStore
will be initialized except fortableOperations
when this is invoked.- Parameters:
ctx
- store contextconfig
- configuration of the store- Returns:
- the table operations to use for future calls
- Throws:
SQLException
- if any database exception occurs during creation
-
start
Description copied from interface:NonBlockingStore
The first method to invoke so that the store can be configured and additional steps, such as connecting through a socket or opening file descriptors, are performed.The provided
InitializationContext
contains many helpful objects, including the configuration of the cache and store, concurrency utilities such asBlockingManager
or an executor reserved for non-blocking operations onlyInitializationContext.getNonBlockingExecutor()
.This method is guaranteed not to be invoked concurrently with other operations. This means other methods are not invoked on this store until after the returned Stage completes.
It is expected that an implementation should be able to "restart" by invoking
start
a second time ifNonBlockingStore.stop()
has been invoked and allowed for its stage to complete.- Specified by:
start
in interfaceNonBlockingStore<K,
V> - Parameters:
ctx
- initialization context used to initialize this store.- Returns:
- a stage that, when complete, indicates that this store has started successfully.
-
extraStopSteps
protected void extraStopSteps()Method to extend to add additional steps when the store is shutting down. This is invoked before theconnectionFactory
is shut down and should not do so. -
stop
Description copied from interface:NonBlockingStore
This method is invoked when the cache is being shutdown. It is expected that all resources related to the store are freed when the returned stage is complete.This method is guaranteed not to be invoked concurrently with other operations. This means other methods are not invoked on this store until after the returned Stage completes.
It is expected that an implementation should be able to "restart" by invoking
NonBlockingStore.start(InitializationContext)
a second time ifstop
has been invoked and allowed for its stage to complete.- Specified by:
stop
in interfaceNonBlockingStore<K,
V> - Returns:
- a stage that, when complete, indicates that this store has stopped.
-
isAvailable
Description copied from interface:NonBlockingStore
Returns a stage that, when complete, returns a boolean indicating whether the current store can be accessed for requests. This can be useful for store implementations that rely on an external source, such as a remote database, that may become unreachable. This can reduce sending requests to a store that is not available, as subsequent cache requests will result in aStoreUnavailableException
being thrown until the store becomes available again.Store availability is polled periodically to update the status of stores if their availability changes. This method is not invoked concurrently with itself. In other words, this method is not invoked until after the previous stage has completed. However, this method is invoked concurrently with other operations, except for
NonBlockingStore.start(InitializationContext)
andNonBlockingStore.stop()
.If a store is configured to be
StoreConfiguration.async()
and the store becomes unavailable, then it is possible for the cache operations to be accepted in the interim period between the loss of availability and the modification-queue becoming full. This allows for this store to be unavailable for short periods of time without aStoreUnavailableException
being thrown; however if the store does not become available before the queue fills, then aStoreUnavailableException
is thrown.- Specified by:
isAvailable
in interfaceNonBlockingStore<K,
V> - Returns:
- stage that, when complete, indicates if the store is available.
-
load
Description copied from interface:NonBlockingStore
Returns a stage that will contain the value loaded from the store. If aMarshallableEntry
needs to be created here,InitializationContext.getMarshallableEntryFactory()
andInitializationContext.getByteBufferFactory()
should be used.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.WRITE_ONLY
This method will never be invoked. NonBlockingStore.Characteristic.EXPIRATION
When set this method must not return expired entries. NonBlockingStore.Characteristic.SEGMENTABLE
When this is not set or segmentation is disabled in the configuration
, thesegment
parameter may be ignored.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
load
in interfaceNonBlockingStore<K,
V> - Parameters:
segment
- the segment for the given key if segmentation is enabled, otherwise 0.key
- key of the entry to load.- Returns:
- a stage that, when complete, contains the store value or null if not present.
-
write
Description copied from interface:NonBlockingStore
Writes the entry to the store for the given segment returning a stage that completes normally when it is finished.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.READ_ONLY
This method will never be invoked. NonBlockingStore.Characteristic.EXPIRATION
When set, this method must store the expiration metadata. NonBlockingStore.Characteristic.SEGMENTABLE
When set and segmentation is not disabled in the configuration
, this method must ensure the segment is stored with the entry.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
write
in interfaceNonBlockingStore<K,
V> - Parameters:
segment
- the segment for the given key if segmentation is enabled, otherwise 0.entry
- the entry to persist to the store.- Returns:
- a stage that when complete indicates that the store has written the value.
-
delete
Description copied from interface:NonBlockingStore
Removes the entry for given key and segment from the store and optionally report if the entry was actually removed or not.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.READ_ONLY
This method will never be invoked. NonBlockingStore.Characteristic.SEGMENTABLE
When this is not set or segmentation is disabled in the configuration
, thesegment
parameter may be ignored.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
delete
in interfaceNonBlockingStore<K,
V> - Parameters:
segment
- the segment for the given key if segmentation is enabled, otherwise 0.key
- key of the entry to delete from the store.- Returns:
- a stage that completes with
TRUE
if the key existed in the store,FALSE
if the key did not exist in the store, ornull
if the store does not report this information.
-
clear
Description copied from interface:NonBlockingStore
Clears all entries from the store.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.READ_ONLY
This method will never be invoked. If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
clear
in interfaceNonBlockingStore<K,
V> - Returns:
- a stage that, when complete, indicates that the store has been cleared.
-
batch
public CompletionStage<Void> batch(int publisherCount, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<Object>> removePublisher, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<MarshallableEntry<K, V>>> writePublisher) Description copied from interface:NonBlockingStore
Writes and removes the entries provided by the Publishers into the store. Both are provided in the same method so that a batch may be performed as a single atomic operation if desired, although it is up to the store to manage its batching. If needed a store may generate batches of a configured size by using theStoreConfiguration.maxBatchSize()
setting.Each of the
Publisher
s may publish up topublisherCount
publishers where each publisher is separated by the segment each entry maps to. Failure to request at leastpublisherCount
publishers from the Publisher may cause a deadlock. Many reactive tools have methods such asflatMap
that take an argument of how many concurrent subscriptions it manages, which is perfectly matched with this argument.WARNING: For performance reasons neither Publisher will emit any
NonBlockingStore.SegmentedPublisher
s until both write and remove Publishers are subscribed to. These Publishers should also be only subscribed once.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.READ_ONLY
This method will never be invoked. NonBlockingStore.Characteristic.SEGMENTABLE
If not set or segmentation is disabled in the configuration
, thepublisherCount
parameter has a value of 1, which means there is only be oneSegmentedPublisher
to subscribe to.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
batch
in interfaceNonBlockingStore<K,
V> - Parameters:
publisherCount
- the maximum number ofSegmentPublisher
s either publisher will publishremovePublisher
- publishes what keys should be removed from the storewritePublisher
- publishes the entries to write to the store- Returns:
- a stage that when complete signals that the store has written the values
-
prepareWithModifications
public CompletionStage<Void> prepareWithModifications(jakarta.transaction.Transaction tx, int publisherCount, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<Object>> removePublisher, org.reactivestreams.Publisher<NonBlockingStore.SegmentedPublisher<MarshallableEntry<K, V>>> writePublisher) Description copied from interface:NonBlockingStore
Write remove and put modifications to the store in the prepare phase, which should not yet persisted until the same transaction is committed viaNonBlockingStore.commit(Transaction)
or they are discarded if the transaction is rolled back viaNonBlockingStore.rollback(Transaction)
.Each of the
Publisher
s may publish up topublisherCount
publishers where each publisher is separated by the segment each entry maps to. Failure to request at leastpublisherCount
publishers from the Publisher may cause a deadlock. Many reactive tools have methods such asflatMap
that take an argument of how many concurrent subscriptions it manages, which is perfectly matched with this argument.WARNING: For performance reasons neither Publisher will emit any
NonBlockingStore.SegmentedPublisher
s until both write and remove Publishers are subscribed to. These Publishers should also be only subscribed once.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.TRANSACTIONAL
This method is invoked only if the store has this characteristic. If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
prepareWithModifications
in interfaceNonBlockingStore<K,
V> - Parameters:
tx
- the current transactional context.publisherCount
- the maximum number ofSegmentPublisher
s either publisher will publishremovePublisher
- publishes what keys should be removed from the storewritePublisher
- publishes the entries to write to the store- Returns:
- a stage that when complete signals that the store has written the values
-
commit
Description copied from interface:NonBlockingStore
Commit changes in the provided transaction to the underlying store.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.TRANSACTIONAL
This method is invoked only if the store has this characteristic. If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
commit
in interfaceNonBlockingStore<K,
V> - Parameters:
tx
- the current transactional context.- Returns:
- a stage that, when completed, indicates that the transaction was committed.
-
rollback
Description copied from interface:NonBlockingStore
Roll back the changes from the provided transaction to the underlying store.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.TRANSACTIONAL
This method is invoked only if the store has this characteristic. If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
rollback
in interfaceNonBlockingStore<K,
V> - Parameters:
tx
- the current transactional context.- Returns:
- a stage that, when completed, indicates that the transaction was rolled back.
-
getTxConnection
-
destroyTxConnection
protected void destroyTxConnection(jakarta.transaction.Transaction tx) -
publishEntries
public org.reactivestreams.Publisher<MarshallableEntry<K,V>> publishEntries(IntSet segments, Predicate<? super K> filter, boolean includeValues) Description copied from interface:NonBlockingStore
Publishes entries from this store that are in one of the provided segments and also pass the provided filter. The returned publisher must support being subscribed to any number of times. That is subsequent invocations ofPublisher.subscribe(Subscriber)
should provide independent views of the underlying entries to the Subscribers. Entries should not be retrieved until a given Subscriber requests them via theSubscription.request(long)
method.Subscribing to the returned
Publisher
should not block the invoking thread. It is the responsibility of the store implementation to ensure this occurs. If however the store must block to perform an operation it is recommended to wrap your Publisher before returning with theBlockingManager.blockingPublisher(Publisher)
method and it will handle subscription and observation on the blocking and non-blocking executors respectively.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.BULK_READ
This method is only invoked if the store has this characteristic. NonBlockingStore.Characteristic.EXPIRATION
When set the returned publisher must not return expired entries. NonBlockingStore.Characteristic.SEGMENTABLE
When this is not set or segmentation is disabled in the configuration
, thesegment
parameter may be ignored.- Specified by:
publishEntries
in interfaceNonBlockingStore<K,
V> - Parameters:
segments
- a set of segments to filter entries by. This will always be non-null.filter
- a filter to filter the keys by. If this is null then no additional filtering should be done after segments.- Returns:
- a publisher that provides the keys from the store.
-
publishKeys
Description copied from interface:NonBlockingStore
Publishes keys from this store that are in one of the provided segments and also pass the provided filter. The returned publisher must support being subscribed to any number of times. That is subsequent invocations ofPublisher.subscribe(Subscriber)
should provide independent views of the underlying keys to the Subscribers. Keys should not be retrieved until a given Subscriber requests them via theSubscription.request(long)
method.Subscribing to the returned
Publisher
should not block the invoking thread. It is the responsibility of the store implementation to ensure this occurs. If however the store must block to perform an operation it is recommended to wrap your Publisher before returning with theBlockingManager.blockingPublisher(Publisher)
method and it will handle subscription and observation on the blocking and non-blocking executors respectively.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.BULK_READ
This method is only invoked if the store has this characteristic. NonBlockingStore.Characteristic.EXPIRATION
When set the returned publisher must not return expired keys. NonBlockingStore.Characteristic.SEGMENTABLE
When this is not set or segmentation is disabled in the configuration
, thesegment
parameter may be ignored.- Specified by:
publishKeys
in interfaceNonBlockingStore<K,
V> - Parameters:
segments
- a set of segments to filter keys by. This will always be non-null.filter
- a filter to filter the keys by. If this is null then no additional filtering should be done after segments.- Returns:
- a publisher that provides the keys from the store.
-
size
Description copied from interface:NonBlockingStore
Returns the amount of entries that map to the given segments in the store.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.BULK_READ
This method is only invoked if the store has this characteristic. NonBlockingStore.Characteristic.SEGMENTABLE
When this is not set or segmentation is disabled in the configuration
, thesegments
parameter may be ignored.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
size
in interfaceNonBlockingStore<K,
V> - Parameters:
segments
- the segments for which the entries are counted.- Returns:
- a stage that, when complete, contains the count of how many entries are present for the given segments.
-
approximateSize
Description copied from interface:NonBlockingStore
Returns an estimation of the amount of entries that map to the given segments in the store. This is similar toNonBlockingStore.size(IntSet)
except that it is not strict about the returned size. For instance, this method might ignore if an entry is expired or if the store has some underlying optimizations to eventually have a consistent size.The implementations should be O(1). If a size approximation cannot be returned without iterating over all the entries in the store, the implementation should return
-1L
.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.BULK_READ
This method is only invoked if the store has this characteristic. NonBlockingStore.Characteristic.SEGMENTABLE
When the store does not have this characteristic or segmentation is disabled in the configuration
, thesegment
parameter is alwaysIntSets.immutableRangeSet(numSegments)
.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Specified by:
approximateSize
in interfaceNonBlockingStore<K,
V> - Parameters:
segments
- the segments for which the entries are counted.- Returns:
- a stage that, when complete, contains the approximate count of the entries in the given segments,
or
-1L
if an approximate count cannot be provided.
-