Okay, how do I make this work with methods?

On property get/set I need to call instance method.

I've tried this:

Class Test.String Extends %String
{

Method Get() As %String [ CodeMode = objectgenerator ]
{
    do %code.WriteLine($c(9) _ "Quit ..Test()")
    quit $$$OK
}

}

And class:

/// set obj = ##class(Test.Obj).%New()
/// w obj.prop
Class Test.Obj Extends %RegisteredObject
{

Property prop As Test.String;

Method Test()
{
    quit $random(100)
}

}

But it fails to compile.

Turns out it's much easier than I thought:

Class Test.String Extends %String
{

ClassMethod Get() As %String [ CodeMode = objectgenerator ]
{
    do %code.WriteLine($c(9) _ "Quit $g(^Test.String, 0)")
    quit $$$OK
}

ClassMethod Set(%val As %String) As %String [ CodeMode = objectgenerator ]
{
    do %code.WriteLine($c(9) _ "Set ^Test.String = %val")
    quit $$$OK
}

}

Example:

set obj = ##class(Test.Obj).%New()
write obj.prop
>0
set obj.prop=1
write obj.prop
>1

Here's what I've coded.

Property:

Class Test.String Extends %String
{

ClassMethod StorageToLogical(%val As %String) As %String [ CodeMode = objectgenerator ]
{
	set property = $g(%member)
	do %code.WriteLine($c(9) _ "Quit """ _ property _ """")
	quit $$$OK
}

ClassMethod LogicalToStorage(%val As %String) As %String [ CodeMode = objectgenerator ]
{
	set property = $g(%member)
	do %code.WriteLine($c(9) _ "Quit """ _ property _ """")
	quit $$$OK
}

}

Class:

Class Test.Obj Extends %RegisteredObject
{

Property prop As Test.String;

}

However reference to property does not return anything (expected to return property name):

w obj.prop
zw obj.prop
>""

Any ideas?

I would like to advise against this course of action, there are several reasons:

  1. Ensemble messages should be as small as possible. If you can pass id only, pass id only, etc. Minimizing message size keeps production efficient.
  2. ResultSet does not contain the data itself, it's more like a compiled instructions on how to get the data. Only when you're calling Next method the data is actually loaded into memory
  3. Results of SQL query should be immediately acted upon, because the older the SQL results, the more they differ with reality. it is best to pass parameters and execute query in-place.

If you want it for debugging purposes you can add a trace event which would store ids only for example, but if you actually need to pass a set of results between different business hosts it may be beneficial to you to rethink the production architecture.

Here's some questions:

  1. What business hosts do you have?
  2. What data do you pass between different hosts?
  3. Can you pass parameters between hosts and execute a query on a target host?
  4. Can you pass not a set between hosts, but rather elements individually?