What might cause BIRT to lose an object reference between fetch and render?

眉间皱痕 提交于 2020-01-07 05:23:25

问题


See update at end of text

I have a scripted data source. The datasets are based on a Java object which contains a number of collections.

My report contains a header, body and footer all of which have items bound to this data set. The top-level dataset stores a reference to the Java object. This is passed to sub-datasets which return various lists.

POJO

public class Protocol {
    String name;
    int id;
    List<Device> devices;
    List<TestResult> results;
    ...
}

DAO

public class DAO {
    public List<Protocol> getProtocols(String filePath) {
        return deserialise(filePath);
    }
}

Protocol Dataset

open:
model = new Packages.com.acme.atf.model.dao.AtfObjects();

path = inputParams["ProtocolPath"];

iterP = model.getProtocols(path).iterator();
countP = 0;

fetch:
if(iterP.hasNext()) {
    var p = iterP.next();
    row["ProductId"] = p.getId();
    row["ProductVersion"] = p.getProductVersion();
    row["ProtocolObject"] = p;
    log("po=" + p);
    return true;
}
return false;

Devices Dataset

open:
protocol = inputParams["ProtocolObject"];
if(protocol == null) {
    log("Protocol is NULL");
    return;
}
iterD = protocol.getDevices().iterator();

The log output records:

po=com.acme.atf.model.Protocol@5a5901
Protocol is NULL

which indicates that the object is not null when added to the result but null when passed to the second dataset.

I also tried pulling the Protocol dataset into the report, thereby creating a table. The value of ProtocolObject is already null. (Just to be clear, the other attributes are filled with sensible values)

What could be causing row['ProtocolObject'] to become null?

UPDATE I created a simple report based on a library containing the above scripts. I pulled in the Protocol dataset as a table and the cell with ProtocolObject is not null! I pulled in a second table and both cells with ProtocolObject are null. In the logs I can see that 2 fetches are done and each gets a different Protocol instance:

Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  ===========================================
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  Open protocol: testcase.protocol
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  exit open P
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  po=com.acme.atf.model.Protocol@2892c0
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  Protocol: no more records
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  ===========================================
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  Open protocol: testcase.protocol
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  exit open P
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  po=com.acme.atf.model.Protocol@13ea352
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST)  Protocol: no more records

回答1:


I think I have found the reason.

It might be obvious to some, but the cause seems to be that the Protocol object was not fully serialisable. I found that one of the contained classes did not implement java.io.Serializable.

It's probably in the docs somewhere but, if you want to include a Java Object in your result set, it must be completely serialisable.



来源:https://stackoverflow.com/questions/24890653/what-might-cause-birt-to-lose-an-object-reference-between-fetch-and-render

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!