无法读取更新的AnyLogic数据库值

时间:2017-10-03 01:49:09

标签: database anylogic

我目前正在使用AnyLogic数据库存储二手停车容量。我编写了一个函数来读取数据库并为每个存储的容器或预告片分配一个id。之后,UPDATE查询用于更新阵列。

使用数据库查询工具指定的selectfrom()执行数据库读取。 UPDATE查询如下:

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

这是基于AnyLogic帮助中给出的示例。 storage是数据库,id是索引列,trailer是包含相关数据的列。

当我运行模拟时,数据库会按预期更新。但是,在同一函数内或稍后调用函数的select查询中,查询读取的值是模拟开始时的值。我的更新查询是否有问题,或者在模拟过程中AnyLogic是否无法读取更新值?

1 个答案:

答案 0 :(得分:2)

selectFrom和其他选择查询默认使用缓存表。缓存不受update函数的影响,它会更改原始表。您可以使用布尔参数的False值强制函数使用非缓存表。

对于SQL字符串,它是函数的第一个参数:

// 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;");

对于queryDSL Java代码,它是最终函数的第一个参数:

// 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 );