HashMapUtil

Content Type: Module
Categories: Utility,Data

Overview

This module provides HashMap functionality.
- Useful for data cache mechanisms in mass data processing.
- Supports java.util.HashMap and java.util.LinkedHashMap.
- Also supports LRU cache mode on java.util.LinkedHashMap. So you can limit cache size automatically.
- Automatically prevent memory leaks.
- As Mendix itself does not provide HashMap functionality, so it's very useful.
- Furthermore, from ver2.0.0, it supports the function to keep application scope cache data.

Documentation

Description

HashMapUtil provides java.util.HashMap and java.util.LinkedHashMap functionality to your App.

 

This module stores your HashMap instance into internal WeakHashMap on ThreadLocal with handle-string.  So when all reference to handle-string is gone, your HashMap instance will be automatically freed. 

 

Typical usage scenario

You can use HashMapUtil instead of Mendix’s List Object, if you need to reduce greatly searching time.

 

Features and limitations

ClearHashMap Action

 

Remove all mappings from the map. When this call returns, the map will be empty.

 

ContainsKeyInHashMap Action

 

It returns value of Map.containsKey().

 

ContainsValueInHashMap Action

 

It returns value of Map.containsValue().

 

Note:This operation will probably require time linear in the map size for most implementations of the Map interface.

CreateHashMap Action

 

Creates a new HashMap instance and returns its handle-string.

 

You can use other actions by returned handle-string.

CreateStaticHashMap Action (from ver2.0.0)

 

Creates a new HashMap as static resource for app-scope entity cache. You can cache the entities by it beyond the request scope and retrieve them by key value super fast.

 

The data stored in it is not automatically garbage collected, so be careful with memory leaks. And it does not ensure about consistency of the writable entries between the DB and HashMap or between the clustered-nodes. It should be ensured by the App own. Because it could not know when and which the entities was updated.

 

It should normally be called from ASU microflow and used to cache read-only data for use throughout the app.

CreateHashMapFromList Action

 

Creates a new HashMap instance and put objects from specified list. Then returns its handle-string.

 

You can use other actions by returned handle-string.

CreateLinkedHashMap Action

 

Creates a new LinkedHashMap instance and returns its handle-string.

 

You can use other actions by returned handle-string.

CreateStaticLinkedHashMap Action (from ver2.0.1)

 

Creates a new LinkedHashMap as static resource for app-scope entity cache. You can cache the entities by it beyond the request scope and retrieve them by key value super fast. See CreateStaticHashMap for notes on static HashMaps.

 

CreateLinkedHashMapAsLRUCache Action

 

Creates a new LRU cache mode LinkedHashMap instance with specified cache size then returns its handle-string.

 

You can use other actions by returned handle-string.

CreateStaticLinkedHashMapAsLRUCache Action (from ver2.0.1)

 

Creates a new LRU cache mode LinkedHashMap instance as static resource for app-scope entity cache. You can cache the entities by it beyond the request scope and retrieve them by key value super fast. See CreateStaticHashMap for notes on static HashMaps.

 

DeleteHashMap Action

 

Deletes the HashMap instance specified by the handle-string.

 

GetFromHashMap Action

 

Get a value object by key from a HashMap that specified by the handle-string.

 

GetListFromHashMap Action

 

Get a value-list by key from a hashmap that specified by the handle.

 

PutListToHashMap Action

 

Put a key-value-list pair into the hashmap that specified by the handle.

 

You can get handle by CreateHashMap action.

 

Once you put the entity-list by this action,  you can't use ToValueListFromHashMap action to that Map hereafter, because Mendix can't handle list's list.

 

It returns always 'true'.

PutToHashMap, PutToHashMapAndGet Action

 

Put a key-value pair into the HashMap that specified by the handle-string.

 

You can put different type entities into one HashMap instance , but in that case you can't use ToValueListFromHashMap action.

PutToHashMapFromList Action

 

Put key-value pairs list into the hashmap that specified by the handle.

 

You can get handle by CreateHashMap action.

 

It returns count that it did put.

RemoveFromHashMap, RemoveFromHashMapAndGet Action

 

Remove a key-value pair from the HashMap that specified by the handle-string.

 

SizeOfHashMap Action

 

Get size of the HashMap that specified by the handle-string.

 

ToKeyListFromHashMap Action

 

Get key list of the HashMap that specified by the handle-string.

 

ToValueListFromHashMap Action

 

Get value list of the HashMap that specified by the handle-string.

 

GetFromContext Action

 

Get a value by key from the Context(the scope of the current request).

 

PutToContext, PutToContextAndGet Action

 

Put a key-value pair into the Context(the scope of the current request).

 

RemoveFromContext, RemoveFromContextAndGet  Action

 

Remove a key-value pair from the Context(the scope of the current request).

Releases

Version: 2.2.0
Framework Version: 9.24.2
Release Notes: Compatible with v9.24.2 or higher. Added PutToContextAndGet, RemoveFromContextAndGet action for usability.
Version: 2.1.0
Framework Version: 8.12.6
Release Notes: Added PutToHashMapAndGet, RemoveFromHashMapAndGet action for usability. Improved CreateHashMapFromList,PutToHashMapFromList action for adaptability of non-string key attribute.
Version: 2.0.1
Framework Version: 8.12.7
Release Notes: Added support for static LinkedHashMap and its LRU mode.
Version: 2.0.0
Framework Version: 8.12.7
Release Notes: Added support for keeping application-scoped cached data.
Version: 1.6.0
Framework Version: 8.12.7
Release Notes: Added ability to store key-value pairs in Context (request scope).