Failure to Read Updated AnyLogic DB Values

2019-05-30 09:39发布

I am currently using an AnyLogic database to store used parking capacity. I have written a function that reads the database and assigns an id to each container or trailer that is stored. Afterward, an UPDATE query is used to update the array.

The database read is performed using selectfrom() as specified by the database query tool. The UPDATE query is as follows:

        update(storage)
        .where(storage.id.eq(ret%1000/10))
        .set(storage.trailer, 1)
        .execute();

This is based off of the example given in the AnyLogic help. storage is the database, id is the indexed column, trailer is the column with the relevant data.

When I run the simulation, the database updates as expected. However, in a select query within the same function or in a later call of the function, the value that the query reads is the value at the time of the beginning of the simulation. Is there a problem with my update query or can AnyLogic not read the update values while the simulation is ongoing?

1条回答
beautiful°
2楼-- · 2019-05-30 10:06

selectFrom and other select queries use cached tables by default. Cache is not affected by update function, it changes original tables. You may force the functions to use non-cached tables using False value of boolean argument.

In case of SQL string it is the first argument of the function:

// read from cache
selectUniqueValue( double.class, "SELECT processing_time FROM processing_times WHERE part = agent.name;"); // or
selectUniqueValue( true, double.class, "SELECT processing_time FROM processing_times WHERE part = agent.name;");

 // read from original
selectUniqueValue( false, double.class, "SELECT processing_time FROM processing_times WHERE part = agent.name;");

In case of queryDSL Java code, it is the first argument of the final function:

// read from cache
selectFrom(branches)
    .where(branches.al_id.eq(9))
    .firstResult( branches.branch ); // or
selectFrom(branches)
    .where(branches.al_id.eq(9))
    .firstResult( true, branches.branch );

// read from original
selectFrom(branches)
    .where(branches.al_id.eq(9))
    .firstResult( false, branches.branch );
查看更多
登录 后发表回答