Class GenericMapStore<K,V>
- Type Parameters:
K- type of the keyV- type of the value
- All Implemented Interfaces:
MapLoader<K,,V> MapLoaderLifecycleSupport,MapStore<K,V>
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
-
Field Summary
Fields inherited from class com.hazelcast.mapstore.GenericMapLoader
columnMetadataList, COLUMNS_PROPERTY, DATA_CONNECTION_REF_PROPERTY, EXTERNAL_NAME_PROPERTY, ID_COLUMN_PROPERTY, LOAD_ALL_KEYS_PROPERTY, MAPSTORE_INIT_TIMEOUT, SINGLE_COLUMN_AS_VALUE, sqlService, TYPE_NAME_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes the entry with the given key from the external store.voiddeleteAll(Collection<K> keys) Deletes multiple entries from the external store.voidStores the key-value pair in the external store.voidStores multiple entries in the external store.Methods inherited from class com.hazelcast.mapstore.GenericMapLoader
awaitSuccessfulInit, destroy, init, load, loadAll, loadAllKeysMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.hazelcast.map.MapLoader
load, loadAll, loadAllKeysMethods inherited from interface com.hazelcast.map.MapLoaderLifecycleSupport
destroy, init
-
Constructor Details
-
GenericMapStore
public GenericMapStore()
-
-
Method Details
-
store
Description copied from interface:MapStoreStores the key-value pair in the external store.Invocation semantics depend on configuration:
- Write-through (
writeDelaySeconds == 0): this method is invoked synchronously as part of theIMap.put()call. If this method throws an exception, the map operation fails. - Write-behind (
writeDelaySeconds > 0): this method may be invoked asynchronously on a background thread, potentially long after the original map operation has completed.
Under normal circumstances Hazelcast provides at-least-once delivery semantics for calls to this method. Implementations must therefore be idempotent and tolerate retries, reordering, and duplicate invocations.
- Write-through (
-
storeAll
Description copied from interface:MapStoreStores multiple entries in the external store.This method is primarily used with write-behind enabled (
writeDelaySeconds > 0) when batching is applicable. Hazelcast may still invokeMapStore.store(Object, Object)instead of this method depending on runtime conditions (for example, batch size, write coalescing, or number of distinct keys in the current write window). Implementations must not rely on this method being invoked for every flush.Error handling and retries:
- If this method throws an exception, Hazelcast treats the batch as failed and starts retry handling.
- If the provided
maphas not been modified (no entries removed to signal partial success), Hazelcast retriesstoreAll(map)up to three times, waiting about 1 second between attempts. - After the final batch attempt fails, Hazelcast falls back to calling
MapStore.store(Object, Object)for the remaining entries, one by one. - If the implementation removes entries from
mapas they are stored (before throwing), Hazelcast treats removed entries as successful and does not retry them; only the entries still present inmapare retried and/or passed to the per-entry fallback.
This allows implementations to signal partial success explicitly. Entries left in the
mapafter an exception will be retried individually; removed entries will not be passed to subsequent calls.Hazelcast does not provide transactional guarantees across entries. Batch boundaries do not imply atomicity.
-
delete
Description copied from interface:MapStoreDeletes the entry with the given key from the external store.Invocation semantics depend on configuration:
- Write-through: invoked synchronously as part of
IMap.remove(). - Write-behind: invoked asynchronously on a background thread.
Hazelcast provides at-least-once delivery semantics. Implementations must tolerate retries and duplicate invocations. Deleting a non-existent entry should be treated as a successful no-op.
- Write-through: invoked synchronously as part of
-
deleteAll
Description copied from interface:MapStoreDeletes multiple entries from the external store.This method is primarily used with write-behind enabled (
writeDelaySeconds > 0) when batching is applicable. Hazelcast may still invokeMapStore.delete(Object)instead of this method depending on configuration and runtime conditions. Implementations must not rely on this method being invoked for every flush.Error handling and retries:
- If this method throws an exception, Hazelcast initiates retry handling.
- On retry, Hazelcast invokes
MapStore.delete(Object)one-by-one for the remaining keys. - If the implementation removes successfully deleted keys from the
provided
keyscollection before throwing, those keys are treated as successful and are not retried.
This allows implementations to signal partial success explicitly. Keys left in the
keyscollection after an exception will be retried individually; removed keys will not be passed to subsequent calls.Batch deletion does not imply atomicity or ordering guarantees.
-