Class GenericMapStore<K>
- java.lang.Object
-
- com.hazelcast.mapstore.GenericMapLoader<K>
-
- com.hazelcast.mapstore.GenericMapStore<K>
-
- Type Parameters:
K
-
- All Implemented Interfaces:
MapLoader<K,GenericRecord>
,MapLoaderLifecycleSupport
,MapStore<K,GenericRecord>
public class GenericMapStore<K> extends GenericMapLoader<K> implements MapStore<K,GenericRecord>, MapLoaderLifecycleSupport
GenericMapStore is an implementation ofMapStore
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 @{link
IMap
method call
-
-
Field Summary
-
Fields inherited from class com.hazelcast.mapstore.GenericMapLoader
columnMetadataList, COLUMNS_PROPERTY, DATA_CONNECTION_REF_PROPERTY, EXTERNAL_NAME_PROPERTY, genericMapStoreProperties, ID_COLUMN_PROPERTY, LOAD_ALL_KEYS_PROPERTY, MAPSTORE_INIT_TIMEOUT, queries, sqlService, TYPE_NAME_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description GenericMapStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
delete(K key)
Deletes the entry with a given key from the store.void
deleteAll(java.util.Collection<K> keys)
Deletes multiple entries from the store.void
store(K key, GenericRecord record)
Stores the key-value pair.void
storeAll(java.util.Map<K,GenericRecord> map)
Stores multiple entries.-
Methods inherited from class com.hazelcast.mapstore.GenericMapLoader
awaitSuccessfulInit, destroy, init, load, loadAll, loadAllKeys
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.hazelcast.map.MapLoader
load, loadAll, loadAllKeys
-
Methods inherited from interface com.hazelcast.map.MapLoaderLifecycleSupport
destroy, init
-
-
-
-
Method Detail
-
store
public void store(K key, GenericRecord record)
Description copied from interface:MapStore
Stores the key-value pair.If an exception is thrown then the put operation will fail.
- Specified by:
store
in interfaceMapStore<K,GenericRecord>
- Parameters:
key
- key of the entry to storerecord
- value of the entry to store
-
storeAll
public void storeAll(java.util.Map<K,GenericRecord> map)
Description copied from interface:MapStore
Stores multiple entries.Implementation of this method can optimize the store operation by storing all entries in one database connection. storeAll() is used when writeDelaySeconds is positive (write-behind).If an exception is thrown, the entries will try to be stored one by one using the store() method.
Note: on the retry phase only entries left in the map will be stored one-by-one. In this way a MapStore implementation can handle partial storeAll() cases when some entries were stored successfully before a failure happens. Entries removed from the map will be not passed to subsequent call to store() method any more.
- Specified by:
storeAll
in interfaceMapStore<K,GenericRecord>
- Parameters:
map
- map of entries to store
-
delete
public void delete(K key)
Description copied from interface:MapStore
Deletes the entry with a given key from the store.If an exception is thrown the remove operation will fail.
- Specified by:
delete
in interfaceMapStore<K,GenericRecord>
- Parameters:
key
- the key to delete from the store
-
deleteAll
public void deleteAll(java.util.Collection<K> keys)
Description copied from interface:MapStore
Deletes multiple entries from the store.If an exception is thrown the entries will try to be deleted one by one using the delete() method.
Note: on the retry phase only entries left in the keys will be deleted one-by-one. In this way a MapStore implementation can handle partial deleteAll() cases when some entries were deleted successfully before a failure happens. Entries removed from the keys will be not passed to subsequent call to delete() method any more. The intended usage is to delete items from the provided collection as they are deleted from the store.
- Specified by:
deleteAll
in interfaceMapStore<K,GenericRecord>
- Parameters:
keys
- the keys of the entries to delete.
-
-