Class JdbcStringBasedStore<K,​V>

  • All Implemented Interfaces:
    NonBlockingStore<K,​V>

    public class JdbcStringBasedStore<K,​V>
    extends org.infinispan.persistence.jdbc.common.impl.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:
    Key2StringMapper, DefaultTwoWayKey2StringMapper
    • Constructor Detail

      • JdbcStringBasedStore

        public JdbcStringBasedStore()
    • Method Detail

      • 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.

        Returns:
        the set of characteristics that this store supports.
      • getTableManager

        public org.infinispan.persistence.jdbc.impl.table.TableManager<K,​V> getTableManager()
      • extraStopSteps

        protected void extraStopSteps()
      • 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 org.infinispan.persistence.jdbc.common.connectionfactory.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.