Home > OS >  Avoiding database queries in Anylogic
Avoiding database queries in Anylogic

Time:10-01

I would like to avoid costly repeated data base queries in Anylogic. I have seen the following thread in Stack Overflow linkedhashmap

  • Create a class (you did that)

  • Your collection will take as the key a String (first last name) and as the value of the elment the class...

  • now, when you read your database you will have something like this:

    for(Tuple t : yourQueryResults){
        YourClass yc=new YourClass(t.get(db.var1),t.get(db.var2));
        String totalName=t.get(db.first_name) "_" t.get(db.last_name);
        yourCollection.put(totalName,yc);
    }
    

    Now every time you want to find someone with the a name, for example "John Doe", instead of making a query, you will do

    yourCollection.get("John_Doe").theVarYouWant;
    

    if you use an id instead of the name, you can set an int as the key, and then you will just do yourCollection.get(theId).theVarYouWant

    • Related