Home > Blockchain >  AnyLogic - Using the Key-Value database connectivity object
AnyLogic - Using the Key-Value database connectivity object

Time:11-29

I'm using a database to pass data to my model. This is very convenient if a little slow (as I need to constantly query the DB during the run) but that is another story.

AnyLogic has a great looking object on the "Connectivity" pallet called a Key-Value Table which enables you to create a key-value (hashmap?) by simply specifying things like the table name and the key and value fields. It also requires you to specify the database - which is where my problem arises...

The database I am using is the internal database which is accessible from getEngine().getModelDatabase() however this is of type ModelDatabase whereas the Key-Value object expects a database of the type Database. Database and ModelDatabase seem to be from different inheritance trees so I am unable to cast the ModelDatabase to Database.

This is what I tried:

enter image description here

But I get the error "Cannot cast from ModelDatabase to Database" when compiling.

My database table looks like this:

enter image description here

I'd prefer to not have to import the database as a separate database object if possible.

Has anyone tried to use this object with the ModelDatabase and come across a solution to this problem?

CodePudding user response:

No need to use the key-value table if you use the internal database (which I use all the time :D ). Just use the "database query wizard" (see help) to read data and turn it into a LHM yourself. The key-value object is a remnant from before the internal dbase was even around... enter image description here

  • Related