SQL calculated property rollback
Greetings all,
I have a quick SQL question. I am working with a class, which has a calculated property, which in turned indexed.
The calculation for this property is created based on another property value via:
SqlComputeOnChange = attributes - so basically every time I add a property attribute to my class, my new property
is calculated based on some SqlComputeCode which calls some class method.
That initial setup works as designed.
Question: If my code for whatever reason gets to a ROLLBACK, does the calculated property always rolls back,
and it's index always cleared? I assume so, and looking for confirmation.
Thank you,
Alex
Comments
ROLLBACK should revert any changes in data which was done in a transaction, with some exceptions like $increment on Global.
You can look at this example.
Class User.Test Extends %Persistent
{
Property Name As %String;
Property CalcName As %String [ Calculated, SqlComputeCode = { set {*} = {Name} }, SqlComputed, SqlComputeOnChange = Name ];
Index ByName On CalcName;
Storage Default
{
<Data name="TestDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>Name</Value>
</Value>
</Data>
<DataLocation>^User.TestD</DataLocation>
<DefaultData>TestDefaultData</DefaultData>
<IdLocation>^User.TestD</IdLocation>
<IndexLocation>^User.TestI</IndexLocation>
<StreamLocation>^User.TestS</StreamLocation>
<Type>%Storage.Persistent</Type>
}
}
Let's create first object
USER>s o=##class(Test).%New() USER>set o.Name="testname" USER>w o.%Save() 1
check saved in globals
USER>zw ^User.TestD,^User.TestI
^User.TestD=1
^User.TestD(1)=$lb("","testname")
^User.TestI("ByName"," TESTNAME",1)=""and now open transaction, and do some changes.
USER>k
USER>TSTART
TL1:USER>set o=##class(Test).%OpenId(1)
TL1:USER>s o.Name="testname2"
TL1:USER>w o.%Save()
1
TL1:USER>zw ^User.TestD,^User.TestI
^User.TestD=1
^User.TestD(1)=$lb("","testname2")
^User.TestI("ByName"," TESTNAME2",1)=""
So, changes there, let's do rollback, and check data again.
TL1:USER>TROLLBACK
USER>zw ^User.TestD,^User.TestI
^User.TestD=1
^User.TestD(1)=$lb("","testname")
^User.TestI("ByName"," TESTNAME",1)=""