Class JdbcStringBasedStore<K,V>

java.lang.Object
org.infinispan.persistence.jdbc.common.impl.BaseJdbcStore<K,V,JdbcStringBasedStoreConfiguration>
org.infinispan.persistence.jdbc.stringbased.JdbcStringBasedStore<K,V>
All Implemented Interfaces:
NonBlockingStore<K,V>

public class JdbcStringBasedStore<K,V> extends BaseJdbcStore<K,V,JdbcStringBasedStoreConfiguration>
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:
  • Constructor Details

    • JdbcStringBasedStore

      public JdbcStringBasedStore()
  • Method Details

    • characteristics

      public Set<NonBlockingStore.Characteristic> 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 interface NonBlockingStore<K,V>
      Overrides:
      characteristics in class BaseJdbcStore<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 the BaseJdbcStore will be initialized except for BaseJdbcStore.tableOperations when this is invoked.
      Specified by:
      createTableOperations in class BaseJdbcStore<K,V,JdbcStringBasedStoreConfiguration>
      Parameters:
      ctx - store context
      configuration - configuration of the store
      Returns:
      the table operations to use for future calls
    • getTableManager

      public org.infinispan.persistence.jdbc.impl.table.TableManager<K,V> 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 the BaseJdbcStore.connectionFactory is shut down and should not do so.
      Overrides:
      extraStopSteps in class BaseJdbcStore<K,V,JdbcStringBasedStoreConfiguration>
    • size

      public CompletionStage<Long> size(IntSet segments)
      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, the segments 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 interface NonBlockingStore<K,V>
      Overrides:
      size in class BaseJdbcStore<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

      public CompletionStage<Long> approximateSize(IntSet segments)
      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 to NonBlockingStore.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, the segment parameter is always IntSets.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 interface NonBlockingStore<K,V>
      Overrides:
      approximateSize in class BaseJdbcStore<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

      public CompletionStage<Void> addSegments(IntSet segments)
      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

      public CompletionStage<Void> removeSegments(IntSet segments)
      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

      public ConnectionFactory getConnectionFactory()
    • purgeExpired

      public org.reactivestreams.Publisher<MarshallableEntry<K,V>> 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 the BlockingManager.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.