0

I'm doing a conditional entity-find and want to save the results somewhere to iterate through it later. I searched around and found 2 solutions. I'm using mySql btw.

1-create a temp table and insert results into it 2-saving results in a file (csv, ...)

now my question is:

1-which solution is preferable or maybe suggest another solution (common/trusted pattern)

2- how to do it? (for example I don't know how to create a table on the fly or drop it in moqui.Suggesting a resource/example source code etc. would be awesome)

thanks in advance

hoper
  • 1,043
  • 7
  • 15

1 Answers1

0

One possible approach would be to convert the list that your entity-find gives you to binary data and store it as a DbResourceFile using the moqui.resource.DbResource entities, and using the utilities from org.apache.commons.io etc.

EDIT - To expound in response to comment below, I was thinking along such lines as

    <set field="fileData" from="yourList.toString().getBytes()" />
    <service-call name="create#moqui.resource.DbResource" in-map="[filename:'ExampleListFrom01012019.bin', isFile:'N']" out-map="context" />
    <service-call name="create#moqui.resource.DbResourceFile" in-map="context + [mimeType:'application/octet-stream', fileData:fileData]" />

Then bring it back after a find on the DBResource with something like

    <set field="convertedBack" from="x.fileData.getBinaryStream()" type="NewList" />

I haven't tried this, and there are no near samples in the code that I know of.

This type of conversion between types is not best practice, but storing lists to iterate through them later is probably not either.

Perhaps it would help if you elaborated on your business requirement.

Ronan Keane
  • 189
  • 8
  • thanks for response. could you provide me some code for storing binary data as DbResourceFile. I haven't find a piece of code from moqui doc that runs properly on my machine. – hoper May 22 '19 at 07:32