K
- public class GenericMapLoader<K> extends Object implements MapLoader<K,GenericRecord>, MapLoaderLifecycleSupport
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.
Modifier and Type | Field and Description |
---|---|
protected List<SqlColumnMetadata> |
columnMetadataList |
static String |
COLUMNS_PROPERTY
Property key to define column names in database
|
static String |
DATA_CONNECTION_REF_PROPERTY
Property key to define data connection
|
static String |
EXTERNAL_NAME_PROPERTY
Property key to define external name of the table
|
protected com.hazelcast.mapstore.GenericMapStoreProperties |
genericMapStoreProperties |
static String |
ID_COLUMN_PROPERTY
Property key to define id column name in database
|
static String |
LOAD_ALL_KEYS_PROPERTY
Property key to control loading of all keys when IMap is first created
|
static HazelcastProperty |
MAPSTORE_INIT_TIMEOUT
Timeout for initialization of GenericMapLoader
|
protected com.hazelcast.mapstore.Queries |
queries |
protected SqlService |
sqlService |
static String |
TYPE_NAME_PROPERTY
Property key to data connection type name
|
Constructor and Description |
---|
GenericMapLoader() |
Modifier and Type | Method and Description |
---|---|
protected void |
awaitSuccessfulInit()
Awaits successful initialization; if the initialization fails, throws an exception.
|
void |
destroy()
Hazelcast will call this method before shutting down.
|
void |
init(HazelcastInstance instance,
Properties properties,
String mapName)
Initializes this MapLoader implementation.
|
GenericRecord |
load(K key)
Loads the value of a given key.
|
Map<K,GenericRecord> |
loadAll(Collection<K> keys)
Size of the
keys collection is limited by ClusterProperty.MAP_LOAD_CHUNK_SIZE |
Iterable<K> |
loadAllKeys()
Loads all of the keys from the store.
|
public static final String DATA_CONNECTION_REF_PROPERTY
public static final String EXTERNAL_NAME_PROPERTY
public static final String ID_COLUMN_PROPERTY
public static final String COLUMNS_PROPERTY
public static final String TYPE_NAME_PROPERTY
public static final String LOAD_ALL_KEYS_PROPERTY
public static final HazelcastProperty MAPSTORE_INIT_TIMEOUT
protected SqlService sqlService
protected com.hazelcast.mapstore.GenericMapStoreProperties genericMapStoreProperties
protected com.hazelcast.mapstore.Queries queries
protected List<SqlColumnMetadata> columnMetadataList
public void init(HazelcastInstance instance, Properties properties, String mapName)
MapLoaderLifecycleSupport
MapLoader
is configured, can be obtained from the
hazelcastInstance
in this method's implementation.
On members joining a cluster, this method is executed during finalization
of the join operation, therefore care should be taken to adhere to the
rules for PostJoinAwareService.getPostJoinOperation()
.
If the implementation executes operations which may wait on locks or otherwise
block (e.g. waiting for network operations), this may result in a time-out and
obstruct the new member from joining the cluster. If blocking operations are
required for initialization of the MapLoader
, consider deferring them
with a lazy initialization scheme.
init
in interface MapLoaderLifecycleSupport
instance
- HazelcastInstance of this mapLoader.properties
- Properties set for this mapStore. see MapStoreConfigmapName
- name of the map.public void destroy()
MapLoaderLifecycleSupport
destroy
in interface MapLoaderLifecycleSupport
public GenericRecord load(K key)
MapLoader
load
in interface MapLoader<K,GenericRecord>
null
value signals value missing in the underlying storepublic Map<K,GenericRecord> loadAll(Collection<K> keys)
keys
collection is limited by ClusterProperty.MAP_LOAD_CHUNK_SIZE
loadAll
in interface MapLoader<K,GenericRecord>
keys
- keys of the values entries to loadpublic Iterable<K> loadAllKeys()
MapLoader
Iterable
may return the keys lazily
by loading them in batches. The Iterator
of this Iterable
may implement the
Closeable
interface in which case it will be closed once iteration is over.
This is intended for releasing resources such as closing a JDBC result set.
The returned Iterable should not contain any null
keys.
loadAllKeys
in interface MapLoader<K,GenericRecord>
null
.protected void awaitSuccessfulInit()
Copyright © 2023 Hazelcast, Inc.. All rights reserved.