Class JdbcStringBasedStore<K,​V>

  • All Implemented Interfaces:
    org.infinispan.commons.api.Lifecycle, org.infinispan.persistence.spi.AdvancedCacheLoader<K,​V>, org.infinispan.persistence.spi.AdvancedCacheWriter<K,​V>, org.infinispan.persistence.spi.AdvancedLoadWriteStore<K,​V>, org.infinispan.persistence.spi.CacheLoader<K,​V>, org.infinispan.persistence.spi.CacheWriter<K,​V>, org.infinispan.persistence.spi.ExternalStore<K,​V>, org.infinispan.persistence.spi.TransactionalCacheWriter<K,​V>

    public class JdbcStringBasedStore<K,​V>
    extends Object
    implements org.infinispan.persistence.spi.AdvancedLoadWriteStore<K,​V>, org.infinispan.persistence.spi.TransactionalCacheWriter<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:
    Key2StringMapper, DefaultTwoWayKey2StringMapper
    • Constructor Detail

      • JdbcStringBasedStore

        public JdbcStringBasedStore()
    • Method Detail

      • init

        public void init​(org.infinispan.persistence.spi.InitializationContext ctx)
        Specified by:
        init in interface org.infinispan.persistence.spi.CacheLoader<K,​V>
        Specified by:
        init in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
      • start

        public void start()
        Specified by:
        start in interface org.infinispan.commons.api.Lifecycle
      • stop

        public void stop()
        Specified by:
        stop in interface org.infinispan.commons.api.Lifecycle
      • isAvailable

        public boolean isAvailable()
        Specified by:
        isAvailable in interface org.infinispan.persistence.spi.CacheLoader<K,​V>
        Specified by:
        isAvailable in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
        Specified by:
        isAvailable in interface org.infinispan.persistence.spi.ExternalStore<K,​V>
      • write

        public void write​(org.infinispan.marshall.core.MarshalledEntry entry)
        Specified by:
        write in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
      • writeBatch

        public void writeBatch​(Iterable<org.infinispan.marshall.core.MarshalledEntry<? extends K,​? extends V>> marshalledEntries)
        Specified by:
        writeBatch in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
      • deleteBatch

        public void deleteBatch​(Iterable<Object> keys)
        Specified by:
        deleteBatch in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
      • load

        public org.infinispan.marshall.core.MarshalledEntry<K,​V> load​(Object key)
        Specified by:
        load in interface org.infinispan.persistence.spi.CacheLoader<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface org.infinispan.persistence.spi.AdvancedCacheWriter<K,​V>
      • delete

        public boolean delete​(Object key)
        Specified by:
        delete in interface org.infinispan.persistence.spi.CacheWriter<K,​V>
      • purge

        public void purge​(Executor executor,
                          org.infinispan.persistence.spi.AdvancedCacheWriter.PurgeListener purgeListener)
        Specified by:
        purge in interface org.infinispan.persistence.spi.AdvancedCacheWriter<K,​V>
      • contains

        public boolean contains​(Object key)
        Specified by:
        contains in interface org.infinispan.persistence.spi.CacheLoader<K,​V>
      • publishKeys

        public io.reactivex.Flowable<K> publishKeys​(Predicate<? super K> filter)
        Specified by:
        publishKeys in interface org.infinispan.persistence.spi.AdvancedCacheLoader<K,​V>
      • publishEntries

        public io.reactivex.Flowable<org.infinispan.marshall.core.MarshalledEntry<K,​V>> publishEntries​(Predicate<? super K> filter,
                                                                                                             boolean fetchValue,
                                                                                                             boolean fetchMetadata)
        Specified by:
        publishEntries in interface org.infinispan.persistence.spi.AdvancedCacheLoader<K,​V>
      • prepareWithModifications

        public void prepareWithModifications​(Transaction transaction,
                                             org.infinispan.persistence.support.BatchModification batchModification)
                                      throws org.infinispan.persistence.spi.PersistenceException
        Specified by:
        prepareWithModifications in interface org.infinispan.persistence.spi.TransactionalCacheWriter<K,​V>
        Throws:
        org.infinispan.persistence.spi.PersistenceException
      • commit

        public void commit​(Transaction tx)
        Specified by:
        commit in interface org.infinispan.persistence.spi.TransactionalCacheWriter<K,​V>
      • rollback

        public void rollback​(Transaction tx)
        Specified by:
        rollback in interface org.infinispan.persistence.spi.TransactionalCacheWriter<K,​V>
      • size

        public int size()
        Specified by:
        size in interface org.infinispan.persistence.spi.AdvancedCacheLoader<K,​V>