无法读取更新的 AnyLogic DB 值
Failure to Read Updated AnyLogic DB Values
我目前正在使用 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 在模拟过程中无法读取更新值?
selectFrom
和其他 select 查询默认使用缓存表。缓存不受 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 );
我目前正在使用 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 在模拟过程中无法读取更新值?
selectFrom
和其他 select 查询默认使用缓存表。缓存不受 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 );