我目前正在使用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是否无法读取更新值?
答案 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 );