Renier
Renier

Reputation: 540

How do I Refresh AnyLogic ModelDatabase from code?

I have linked many parameters in my model to values in the internal ModelDatabase. This works great.

Now I want to allow the user to import a new "Input File" for a specific scenario. I have added a fileChooser element on the Simulation Experiment screen and in the onUpload action I use the ModelDatabase.importFromExternalDB to upload the relevant sheet to the relevant table.

However, this does not seem to work. Initially I thought that the update simply did not happen but when I stop the model in the AnyLogic IDE and start it again in the IDE, the new values are used.

It appears as if the update only happens on startup/close and that the database is "static" while running. I did set the auto-commit parameter to true on the importFromExternalDB function, but this made no difference.

Is there a function I can call to force a "refresh" of the internal database?

Upvotes: 1

Views: 535

Answers (1)

Benjamin
Benjamin

Reputation: 12785

You probably load the data at runtime using the default code such as selectFrom("some String with query")

However, these always load from the cached dbase to speed things up.

Instead, you must force AnyLogic to load from the live dbase using an additional argument. In this example, it would be selectFrom(false, "some String query")

This is also documented in the help: enter image description here

So go through all queries in your model and add the appropriate boolean arg to force-load from the non-cached dbase.

Upvotes: 1

Related Questions