Font size

Key value table

An object that maps keys to values. It works in the following way: you choose one column of the database table as the key column and tell what column contains values that should be mapped to this key. A map cannot contain duplicate keys; each key can map to at most one value.

Key-value mappings are loaded from database via execute() function or on first call of any data-retrieving function.

The value mapping for given key can be obtained using get(Object) function call.

Creating a mapping object

To add key-value object

  1. Drag the Key Value Table  element from the Connectivity stencil of the Palette onto the graphical diagram.
  2. In the Properties view, modify the Name of the element. This name will be used to identify and access this object.
  3. Specify the database this object will work with. Type the name of the AnyLogic database in the Database edit box.
  4. In the Table edit box, type the name of the database table this object will access.
  5. Type the name of the table column that contains keys in the Key Column field.
  6. Specify the type of the keys in the Key Column Type drop-down list.
  7. In the Value Column field, type the name of the column that contains values you want to map with keys.
  8. Specify the type of the value column in the Value Column Type drop-down list.

Working with key value table via API

You work with created mapping object using the corresponding API of the KeyValueTable class.

The most frequently needed function is the following:

  • V get(K key) — The function returns the value to which the specified key is mapped, or null if this key value table contains no mapping for the key.
How can we improve this article?