【问题标题】:Failure to Read Updated AnyLogic DB Values未能读取更新的 AnyLogic DB 值
【发布时间】:2018-03-14 03:32:35
【问题描述】:

我目前正在使用 AnyLogic 数据库来存储已使用的停车容量。我编写了一个函数来读取数据库并为每个存储的容器或拖车分配一个 ID。之后,使用 UPDATE 查询来更新数组。

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

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

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

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

【问题讨论】:

    标签: database anylogic


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-06-18
      • 2019-09-05
      • 2021-05-11
      • 1970-01-01
      • 2021-07-15
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      相关资源
      最近更新 更多