Return $lb from Java Gateway call

I want to call java method and return $lb structure from it.

JDBC jar seems to contain relevant class -  com.intersys.jdbc.CacheListBuilder, but so far I only managed to return a string that looks like a list.

Here's my java code:

package isc.poi;

import com.intersys.jdbc.CacheListBuilder;
import java.sql.SQLException;

public class Test {

    public static String Test() throws SQLException
    {
        CacheListBuilder list = new CacheListBuilder("UTF8");
        list.set(123);
        list.set(456);
        list.set("\"abc\"");

        return list.toString();
    }
}

And Cache part:

Class POI.Utils [ Abstract ]
{

Parameter CLASSPATH = "C:\InterSystems\poi.jar";

Parameter GATEWAY = "POI";

/// Get JGW object
ClassMethod Connect(gatewayName As %String = {..#GATEWAY}, path As %String = {..#CLASSPATH}, Output sc As %Status) As %Net.Remote.Gateway
{
    Set gateway = ""
    Set sc = ##class(%Net.Remote.Service).OpenGateway(gatewayName, .gatewayConfig)
    Quit:$$$ISERR(sc) gateway
    Set sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, path, $$$YES)
    Quit gateway
}

/// Write $System.Status.GetErrorText(##class(POI.Utils).Test())
ClassMethod Test() As %Status
{
    #dim gateway as %Net.Remote.Gateway
    #dim exception as %Exception.AbstractException

    Set sc = $$$OK
    Try {
        
    Set gateway = ..Connect()
    Set result = ##class(isc.poi.Test).Test(gateway)
    Set exec = "set list = " _ result
        
    XECUTE exec
 
    ZWrite list, result

    Set sc = gateway.%Disconnect()

    } Catch ex {
        Set sc = $$$ADDSC(ex.AsStatus(), $g(%objlasterror))
    }

    Quit sc
}

}

As you can see in Test method, first I get what JGW returns into result and after that I need to rewrite it into list proper. Here's terminal output:

list=$lb(123,456,"abc")
result="$lb(123,456,""abc"")"

That seems rather inefficient as I need to:

  • Call Xecute
  • Escape string values manually

Is there a better way to return $lb from Java?

  • 0
  • 0
  • 142
  • 2
  • 1

Answers

instead of eXecute you may use Indirection

set @("mylist="_result)

.

It's a matter of taste  :
take care for ProcedureBlock = 0 ;  as for eXecute ; just in case 

Comments

Only out of curiosity:

What do you get back if you just do "return list"     without toString() ?
Whatever structure CacheListBuilder may have 

The object of com.intersys.jdbc.CacheListBuilder class is returned.