Converting a list of non persistent objects into a ResultSet
Hello,
I'm using ZEN report to generate a PDF file out a table.
Although, I need to display data from two tables splitted into two different namespaces.
So, I created a process that fetches all the data I need and then calls the PDF class and generates the stream out of it.
My question is, once I've got my list of objects. How can I transform it into a ResultSet, in order to display in the report ?
Thanks for your answer.
Comments
I think the easier solution would be to map classes and data to a target namespace and just execute the query in the same namespace. Documentation.
Actually, I tried that.
But since, the two packages have the same name. Once I map namespace A to namespace B, I can't access the package in namespace B
Okay, even if the classes/globals are the same there's a solution. Let's say you have Sample.Person class in namespaces SAMPLES and USER, each with their own data:
Class Sample.Person Extends %Persistent
{
Property Name;
Storage Default
{
<Data name="PersonDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
</Data>
<DataLocation>^Sample.PersonD</DataLocation>
<DefaultData>PersonDefaultData</DefaultData>
<IdLocation>^Sample.PersonD</IdLocation>
<IndexLocation>^Sample.PersonI</IndexLocation>
<StreamLocation>^Sample.PersonS</StreamLocation>
<Type>%Library.CacheStorage</Type>
}
}
And you want to query both from the USER namespace. In that case create a new class extending Sample.Person in the USER namespace and modify storage like this:
Class Utils.SamplesPerson Extends (%Persistent, Sample.Person)
{
Storage Default
{
<Data name="PersonDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
</Data>
<DataLocation>^["SAMPLES"]Sample.PersonD</DataLocation>
<DefaultData>PersonDefaultData</DefaultData>
<ExtentSize>200</ExtentSize>
<IdLocation>^["SAMPLES"]Sample.PersonD</IdLocation>
<IndexLocation>^["SAMPLES"]Sample.PersonI</IndexLocation>
<StreamLocation>^["SAMPLES"]Sample.PersonS</StreamLocation>
<Type>%Library.CacheStorage</Type>
}Note that DataLocation, IndexLocation, IdLocation and StreamLocation point to the SAMPLES namespace.
Now query:
SELECT *
FROM Utils.SamplePersonWould fetch data from SAMPLES namespace.
Yes, it works.
Thank you ![]()
In the past when I've had to do something like this I've leveraged https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…. In the custom Execute method I would accumulate all of the data and place in a process private global. In the Fetch method, I get one row out of the process private global at a time.
The easiest solution here is to link the table from another namespace. Only takes a second and you don't need to screw around getting the storage right (note: do NOT start editing storage defs if you can avoid it - that is not an easily maintained solution). This solution does not work if you have to JOIN the two tables together (we call this a heterogeneous JOIN), however. The next best solution is to write your own class query as @Stephen Canzano & @Michael Smart have recommended. It's a little work up front but you can make some easy changes, such as creating a temp table and populating it with data from the other namespace or using a process private global.