Class GenericMapStore<K,V>

java.lang.Object
com.hazelcast.mapstore.GenericMapLoader<K,V>
com.hazelcast.mapstore.GenericMapStore<K,V>
Type Parameters:
K - type of the key
V - type of the value
All Implemented Interfaces:
com.hazelcast.map.MapLoader<K,V>, com.hazelcast.map.MapLoaderLifecycleSupport, com.hazelcast.map.MapStore<K,V>

public class GenericMapStore<K,V> extends GenericMapLoader<K,V> implements com.hazelcast.map.MapStore<K,V>, com.hazelcast.map.MapLoaderLifecycleSupport
GenericMapStore is an implementation of MapStore built on top of Hazelcast SQL engine.

It works with any SQL connector supporting SELECT, INSERT, UPDATE and DELETE statements.

Usage:

First define data connection, e.g. for JDBC use JdbcDataConnection:

Config config = new Config();
 config.addDataConnectionConfig(
   new DataConnectionConnection("mysql-ref")
     .setType("Jdbc")
     .setProperty("jdbcUrl", dbConnectionUrl)
 );

Then create a Map with MapStore using the GenericMapStore implementation:

MapConfig mapConfig = new MapConfig(mapName);
 MapStoreConfig mapStoreConfig = new MapStoreConfig();
 mapStoreConfig.setClassName(GenericMapStore.class.getName());
 mapStoreConfig.setProperty(GenericMapStore.DATA_CONNECTION_REF_PROPERTY, "mysql-name");
 mapConfig.setMapStoreConfig(mapStoreConfig);
 instance().getConfig().addMapConfig(mapConfig);

The GenericMapStore creates a SQL mapping with name "__map-store." + mapName. This mapping is removed when the map is destroyed.

Note : When GenericMapStore uses GenericRecord as value, even if the GenericRecord contains the primary key as a field, the primary key is still received from IMap method call

  • Constructor Details

    • GenericMapStore

      public GenericMapStore()
  • Method Details

    • store

      public void store(K key, V value)
      Specified by:
      store in interface com.hazelcast.map.MapStore<K,V>
    • storeAll

      public void storeAll(Map<K,V> map)
      Specified by:
      storeAll in interface com.hazelcast.map.MapStore<K,V>
    • delete

      public void delete(K key)
      Specified by:
      delete in interface com.hazelcast.map.MapStore<K,V>
    • deleteAll

      public void deleteAll(Collection<K> keys)
      Specified by:
      deleteAll in interface com.hazelcast.map.MapStore<K,V>