Class JdbcStringBasedStore<K,V>
- All Implemented Interfaces:
NonBlockingStore<K,
V>
AdvancedCacheLoader
implementation that stores the entries in a database.
This cache store will store each entry within a row in the table. This assures a finer grained granularity for all
operation, and better performance. In order to be able to store non-string keys, it relies on an Key2StringMapper
.
Note that only the keys are stored as strings, the values are still saved as binary data. Using a character
data type for the value column will result in unmarshalling errors.
The actual storage table is defined through configuration JdbcStringBasedStoreConfiguration
.
The table can be created/dropped on-the-fly, at deployment time. For more details consult javadoc for JdbcStringBasedStoreConfiguration
.
Preload.In order to support preload functionality the store needs to read the string keys from the database and transform them
into the corresponding key objects. Key2StringMapper
only supports
key to string transformation(one way); in order to be able to use preload one needs to specify an
TwoWayKey2StringMapper
, which extends Key2StringMapper
and
allows bidirectional transformation.
Rehashing. When a node leaves/joins, Infinispan moves around persistent state as part of rehashing process.
For this it needs access to the underlaying key objects, so if distribution is used, the mapper needs to be an
TwoWayKey2StringMapper
otherwise the cache won't start (same constraint as with preloading).- Author:
- Mircea.Markus@jboss.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.infinispan.persistence.spi.NonBlockingStore
NonBlockingStore.Characteristic, NonBlockingStore.SegmentedPublisher<Type>
-
Field Summary
Fields inherited from class org.infinispan.persistence.jdbc.common.impl.BaseJdbcStore
blockingManager, config, connectionFactory, tableOperations, transactionConnectionMap
Fields inherited from interface org.infinispan.persistence.spi.NonBlockingStore
SIZE_UNAVAILABLE_FUTURE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddSegments
(IntSet segments) Invoked when a node becomes an owner of the given segments.approximateSize
(IntSet segments) Returns an estimation of the amount of entries that map to the given segments in the store.Returns a set of characteristics for this store and its elements.protected TableOperations<K,
V> createTableOperations
(InitializationContext ctx, JdbcStringBasedStoreConfiguration configuration) Extension point to allow for initializing and creating a table operations object.protected void
Method to extend to add additional steps when the store is shutting down.org.reactivestreams.Publisher<MarshallableEntry<K,
V>> Returns a Publisher that, after it is subscribed to, removes any expired entries from the store and publishes them to the returned Publisher.removeSegments
(IntSet segments) Invoked when a node loses ownership of the given segments.Returns the amount of entries that map to the given segments in the store.Methods inherited from class org.infinispan.persistence.jdbc.common.impl.BaseJdbcStore
batch, clear, commit, delete, destroyTxConnection, getTxConnection, isAvailable, load, prepareWithModifications, publishEntries, publishKeys, rollback, start, stop, write
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
containsKey, destroy, ignoreCommandWithFlags
-
Constructor Details
-
JdbcStringBasedStore
public JdbcStringBasedStore()
-
-
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> - Overrides:
characteristics
in classBaseJdbcStore<K,
V, JdbcStringBasedStoreConfiguration> - Returns:
- the set of characteristics that this store supports.
-
createTableOperations
protected TableOperations<K,V> createTableOperations(InitializationContext ctx, JdbcStringBasedStoreConfiguration configuration) Description copied from class:BaseJdbcStore
Extension point to allow for initializing and creating a table operations object. All variables in theBaseJdbcStore
will be initialized except forBaseJdbcStore.tableOperations
when this is invoked.- Specified by:
createTableOperations
in classBaseJdbcStore<K,
V, JdbcStringBasedStoreConfiguration> - Parameters:
ctx
- store contextconfiguration
- configuration of the store- Returns:
- the table operations to use for future calls
-
getTableManager
-
extraStopSteps
protected void extraStopSteps()Description copied from class:BaseJdbcStore
Method to extend to add additional steps when the store is shutting down. This is invoked before theBaseJdbcStore.connectionFactory
is shut down and should not do so.- Overrides:
extraStopSteps
in classBaseJdbcStore<K,
V, JdbcStringBasedStoreConfiguration>
-
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> - Overrides:
size
in classBaseJdbcStore<K,
V, JdbcStringBasedStoreConfiguration> - 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> - Overrides:
approximateSize
in classBaseJdbcStore<K,
V, JdbcStringBasedStoreConfiguration> - 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.
-
addSegments
Description copied from interface:NonBlockingStore
Invoked when a node becomes an owner of the given segments. Some store implementations may require initializing additional resources when a new segment is required. For example a store could store entries in a different file per segment.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.SHAREABLE
If the store has this characteristic and is configured to be StoreConfiguration.shared()
, this method will never be invoked.NonBlockingStore.Characteristic.SEGMENTABLE
This method is invoked only if the store has this characteristic and is configured to be segmented
.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Parameters:
segments
- the segments to add.- Returns:
- a stage that, when complete, indicates that the segments have been added.
-
removeSegments
Description copied from interface:NonBlockingStore
Invoked when a node loses ownership of the given segments. A store must then remove any entries that map to the given segments and can remove any resources related to the given segments. For example, a database store can delete rows of the given segment or a file-based store can delete files related to the given segments.Summary of Characteristics Effects
Characteristic Effect NonBlockingStore.Characteristic.SHAREABLE
If the store has this characteristic and is configured to be shared
, this method will never be invoked.NonBlockingStore.Characteristic.SEGMENTABLE
This method is invoked only if the store has this characteristic and is configured to be segmented
.If a problem is encountered, it is recommended to wrap any created/caught Throwable in a
PersistenceException
and the stage be completed exceptionally.- Parameters:
segments
- the segments to remove.- Returns:
- a stage that, when complete, indicates that the segments have been removed.
-
getConnectionFactory
-
purgeExpired
Description copied from interface:NonBlockingStore
Returns a Publisher that, after it is subscribed to, removes any expired entries from the store and publishes them to the returned Publisher.When the Publisher is subscribed to, it is expected to do point-in-time expiration and should not return a Publisher that has infinite entries or never completes.
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.EXPIRATION
This method is only invoked 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.- Returns:
- a Publisher that publishes the entries that are expired at the time of subscription.
-