Class GenericMapLoader<K,V>

java.lang.Object
com.hazelcast.mapstore.GenericMapLoader<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
Direct Known Subclasses:
GenericMapStore

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

It works with any SQL connector supporting SELECT statements.

Usage:

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

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

Then create a Map with MapLoader using the GenericMapLoader implementation:

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

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

  • Field Details

    • DATA_CONNECTION_REF_PROPERTY

      public static final String DATA_CONNECTION_REF_PROPERTY
      Property key to define data connection
      See Also:
    • EXTERNAL_NAME_PROPERTY

      public static final String EXTERNAL_NAME_PROPERTY
      Property key to define external name of the table
      See Also:
    • ID_COLUMN_PROPERTY

      public static final String ID_COLUMN_PROPERTY
      Property key to define id column name in database
      See Also:
    • COLUMNS_PROPERTY

      public static final String COLUMNS_PROPERTY
      Property key to define column names in database
      See Also:
    • TYPE_NAME_PROPERTY

      public static final String TYPE_NAME_PROPERTY
      Property key to data connection type name
      See Also:
    • LOAD_ALL_KEYS_PROPERTY

      public static final String LOAD_ALL_KEYS_PROPERTY
      Property key to control loading of all keys when IMap is first created
      See Also:
    • SINGLE_COLUMN_AS_VALUE

      public static final String SINGLE_COLUMN_AS_VALUE
      Property key to decide on getting a single column as the value
      See Also:
    • MAPSTORE_INIT_TIMEOUT

      public static final com.hazelcast.spi.properties.HazelcastProperty MAPSTORE_INIT_TIMEOUT
      Timeout for initialization of GenericMapLoader
    • sqlService

      protected com.hazelcast.sql.SqlService sqlService
    • columnMetadataList

      protected List<com.hazelcast.sql.SqlColumnMetadata> columnMetadataList
  • Constructor Details

    • GenericMapLoader

      public GenericMapLoader()
  • Method Details

    • init

      public void init(com.hazelcast.core.HazelcastInstance instance, Properties properties, String mapName)
      Specified by:
      init in interface com.hazelcast.map.MapLoaderLifecycleSupport
    • destroy

      public void destroy()
      Specified by:
      destroy in interface com.hazelcast.map.MapLoaderLifecycleSupport
    • load

      public V load(K key)
      Specified by:
      load in interface com.hazelcast.map.MapLoader<K,V>
    • loadAll

      public Map<K,V> loadAll(Collection<K> keys)
      Size of the keys collection is limited by ClusterProperty.MAP_LOAD_CHUNK_SIZE
      Specified by:
      loadAll in interface com.hazelcast.map.MapLoader<K,V>
    • loadAllKeys

      public Iterable<K> loadAllKeys()
      Specified by:
      loadAllKeys in interface com.hazelcast.map.MapLoader<K,V>
    • awaitSuccessfulInit

      protected void awaitSuccessfulInit()
      Awaits successful initialization; if the initialization fails, throws an exception.