Following the examples from Hazelcast reference manuals on Loading and Storing persistent data, we can implement a mapstore to store (insert) data to Oracle-DB. However there is no specific interface from Hazelcast that would allow us to do an update on an existing record. Since the MapStore interface only exposes : store/ storeAll . Is there anyway we can achieve updating existing records in Oracle-DB through the Hazelcast-MapStore interface.
Asked
Active
Viewed 639 times
1 Answers
0
Hazelcast's IMap
is a key-value store, thus it doesn't have insert/update separation. For updating your RDBMS using SQL, you need to implement your own logic in MapStore#store
/MapStore#storeAll
methods. In other words, you need to check the DB if the entry exists or not, and then decide to use insert/update accordingly.

Alparslan Avci
- 931
- 4
- 6
-
this would always be a 2 query to DB kind of transaction : 1) check "select" on rdbms based on IMap Key. 2) run update/insert. Is there a way i can access the map (currently cached values) in the MapStore implemenation so that i can quickly look into it rather than executing an RDBMS-SQL – Tarun Patel Mar 14 '18 at 11:55
-
@TarunPatel you don't need to. Hazelcast has 2 data loading types, when using MapLoader: EAGER and LAZY. In eager mode, when you first touch the map, `loadAllKeys` called. Then returning keys distributed to all members based on their hash, and each member call `loadAll` will those keys. This will load all the data to the map at once. – Gokhan Oner Mar 14 '18 at 19:11
-
But if you want, you can use LAZY mode. In this mode, when you call `map.get(key)`, Hazelcast first check if there is an associated value in memory for that key, If not found then `MapLoader.load(key)` method called, returned data stored in the in-memory map & returned to caller. Next time when you call it, unless it's expired or removed, it'll be returned from Hazelcast map directly. – Gokhan Oner Mar 14 '18 at 19:11
-
Additionally, if you use MapStore extension of MapLoader, when you call ‘map.put’ or ‘map.set’, this time MapStore.store(key, value) method will be called. Here you can update your database. If you don’t want to load/store all entries, then in load & store methods, you can check the keys/values and conditionally process them. It’s totally up to you. – Gokhan Oner Mar 15 '18 at 02:40
-
@TarunPatel, you can access `HazelcastInstance` implementing `HazelcastInstanceAware` on your `MapStore` and check for the entry in the map. However, the best way to do accomplish your request is using DB procedures and just calling them in `MapStore`. – Alparslan Avci Mar 15 '18 at 12:53