#include %occStatus
#include %syDataMove
#include %syConfig
#; Sample routine to illustrate using DataMove to move globals.
Example() {
#; New Mapping definition
Set NewMap = 1
Set NewMap(1, "name") = "ABC"
Set NewMap(1, "db") = "LIVE-CT"
Set NewMap = 2
Set NewMap(2, "name") = "DEF"
Set NewMap(2, "db") = "LIVE-CT"
#; Let's start initializing the edits space before moving the globals
Write "Initialize edits.........."
Set Namespace = "LIVE"
Set Status = ##class(DataMove.API).MapInitialize("DBNAME",Namespace)
#; Now we need to create the new mappings
Write "Create/Update maps.........."
#; Main loop to define mappings and operations to be done.
For i = 1:1:NewMap {
Kill Obj, Name, Prop, Status
Set Prop("Database")=NewMap(i, "db")
Set Name=NewMap(i, "name")
#; Write name after a new line
Write !, Name
#; Checking if the global exists
Do ##Class(Config.MapGlobals).Exists(Namespace, Name, .Obj)
If (Obj = "") {
#; Creating the global
Write !, " - Create.........."
Set Status = ##class(DataMove.API).MapGlobalsCreate("DBNAME",Namespace,Name,.Prop)
} Else {
#; Modifying the global
Write !, " - Modify.........."
Set Status = ##class(DataMove.API).MapGlobalsModify("DBNAME",Namespace,Name,.Prop)
}
}
#; We have everything set up, now we need to create the DM object
Write "Create DM.........."
Set Status = ##class(DataMove.API).Generate("DBNAME",.Properties, .Warnings, .Errors)
If $data(Warnings) Write ! Zwrite Warnings
If $data(Errors) Write ! Zwrite Errors
#; Creating the background job that needs to be run
Write "Creating the JOB.........."
Set Status = ##class(DataMove.API).StartCopy("DBNAME")
#; Monitor the DataMove until we can activate it.
For {
#; Monitor state every 5 seconds
Hang 5
Set Status=##Class(DataMove.API).GetProperties("DBNAME",.Properties)
#; Activate will only run if we are applying journals and have 5 MB or less of journal to apply.
If (Properties("State")=$$$DMStateJrnApply) {
If (Properties("JRNMBToApply")<=5) {
Quit
}
}
Write !,"MB to copy: "_Properties("MBToCopy")
Write !,"MB copied: "_Properties("MBCopied")
Write !,"Journal MB still to apply: "_Properties("JRNMBToApply")
}
Write !, "Activating the new Mappings..."
Set Display=1
Set Status=##Class(DataMove.API).Activate("DBNAME",Display)
#; Delete the source globals that have been copied in the DataMove
Write "Deleting the old Globals......."
Set Status = ##class(DataMove.API).DeleteSourceGlobals("DBNAME")
#; Stopping the DataMover
Write "Closing the DataMover......."
Set Status = ##class(DataMove.API).Finish("DBNAME")
#; Delete the DataMove and clean up any temporary storage
Write "Deleting the DataMover......."
Set Status = ##class(DataMove.API).Delete("DBNAME")
}