Taking a snapshot of an object

Primary tabs

I' m facing the problem to take a Snapshot of an object.
Like a Clone but to a different Storage.Think of 2 classes. My.Main and My.Snap that have exactly identic properties.
The major difference is the storage location of My.Main and My.Snap.

similar to INSERT into MY.SNAP SELECT TOP 1 * from MY.MAIN WHERE ID=? 

This has its limitations.

Brute force: MERGE ^My.SnapD(id)=^My.MainD(id)   ~works mostly

Double brute force: use indirection for the Storage Location.

I found %SYNC.Transporter class. I feel this is an overkill for a single object.

So what's your suggestion?


  • + 5
  • 0
  • 118
  • 1
  • 3


I'm using a custom Copyable class which allows creation of snapshots and arbitrary comparisons between objects.

Here's how to use it.

Let's say you have a model class:

Class Test.PersonBase
Property Name As %String;

And you store it using persistent trait:

Class  Test.Person Extends (%Persistent, Test.PersonBase)

If you want to enable snapshots for it create an additional snapshot class

Class Test.PersonSnapshot Extends (%Persistent, Test.PersonBase, Utils.Copyable)

Index parentIndex On parent;

/// Creation date time
Property createdOn As %TimeStamp [ InitialExpression = {$ZDATETIME($ZTIMESTAMP, 3, 1, 3)}, Required ];

/// Parent object
Property parent As Test.Person;

Method %OnNew(parentId As %Integer) As %Status [ Private, ServerOnly = 1 ]
    #dim sc As %Status = $$$OK
    set ..parent = ##class(Test.Person).%OpenId(parentId,, .sc)
    quit:$$$ISERR(sc) sc
    // Copy all properties
    quit ..copyFrom(..parent, ##class(Test.PersonBase).%ClassName(1))

And you're done.

Just create new snapshot object passing id (can easily modify to accept objects if that's your workflow) and save it.

Can you explain more about why you need to clone this global to separate storage? It feels like mirroring may be a more appropriate option depending on what your goals are.


Mirroring takes whatever is stored in the whole DB and creates a lot of journaling activity.
Here the snapshot is just taken based on a bunch of criteria and then forwarded to some other processing
while the initial object isn't changed except of a flag: passed / failed.