cQJREAD ; Read common format journal file ;cQJREAD; ; +--------------------------------------------------------+ ; | Copyright 1986-2000 by InterSystems Corporation, | ; | Cambridge, Massachusetts, U.S.A. | ; | All rights reserved. | ; | | ; | Confidential, unpublished property of InterSystems. | ; | | ; | This media contains an authorized copy or copies | ; | of material copyrighted by InterSystems and is the | ; | confidential, unpublished property of InterSystems. | ; | This copyright notice and any other copyright notices | ; | included in machine readable copies must be reproduced | ; | on all authorized copies. | ; +--------------------------------------------------------+ ; ;This routine will read a common journal file format and apply it to ;the system. The common journal file format is usually created by ;the ^JCONVERT routine which will take an existing Cache journal file ;and convert it to this common format. ; ;The file will have been written out with either Variable mode ;records, or Stream mode. The routine will try to detect the correct ;mode based on what is in the header in Record 1, and open the ;file with the appropriate format. ; ;The header format is as follows: ; ;Record 1 - "JCONVERT" ;Record 2 - Name of Journal file converted ;Record 3 - Date/Time of export ($H) ;Record 4 - 1:Directories exported, 0:Not exported ; ;Each entry in the converted journal will span 3 records as follows: ; ;Record 1 - Type of transaction 6:Set, 7:Kill, 8:Zkill ;Record 2 - Global reference, with or without directory specification ;Record 3 - Data value ; ;During import of the records, the routine cQZJREAD will be called for ;each journal transaction if it exists. This is a user written routine ;which will allow the user to examine and filter the journal ;transactions. The following variables can be looked at and manipulated ;in cZQJREAD: ; ; type - Transaction type ; gref - Global reference ; value - Global value ; %ZJREAD - 1:Apply transaction, 0:Don't apply transaction ; ;If the user decides to not apply the transaction, they can set the ;variable %ZJREAD to 0 to skip over it. Likewise they can modify the ;other variables (such as the directory specification in gref) to ;change how the transaction is applied. new s $zt="errloop" w !,"Restore from a common format journal file" w ! loop w !,"Enter common journal file name: " r file q:file="" q:file="^" ;If you want to modify this routine to run on another platform ;you will need to change the following open command to correct ;the syntax for that platform. o file:("rv"):1 i '$t w !,"Unable to open file ",jrnfile,! g loop s fmode="Variable" u file r jhdr ; If the first record isn't what we think it is, try using stream mode i jhdr'="JCONVERT" d i jhdr'="JCONVERT" c file u 0 w !,"Unknown file format" g loop . c file . o file:(jrnfile:"r"):1 i '$t q . u file r jhdr . s fmode="Stream" u file r jfile u file r jtime u file r jdir i jdir=0 s jdir="No" i jdir=1 s jdir="Yes" d jread u 0 w ! w !,"Common Journal file format:" w !,"Exported from: ",jfile s %DN=+jtime d INT^%DO s %TN=$p(jtime,",",2) d 200^%TO s jtime=%DS_" "_%TS w !,"Exported on: ",jtime w !,"File Mode: ",fmode w !,"Directory references: ",jdir w !,"Use %ZJREAD: ",zjreadout w ! w !,"Show or Apply? " r x w ! s show=1 i $ZCONVERT($e(x),"U")="A" s show=0 w !,"Confirm import? " r x w ! i (x="")!($ZCONVERT($e(x),"U")="Y") d restore c file g loop ; conv(x) ;convert global data n %DATA s %DATA=$g(x) i $l(%DATA) x GLOTR q %DATA ; restore ; s $ZT="errdata^"_$t(+0) s TRF="C",TRT="M" d RULES^%ABIE s tran=0 f i=1:1 d . i i#1000=0 u 0 w "." . i i#80000=0 u 0 w !,"Processing record "_i,! . u file r type,gref,value . i $ZEOF s $ZE="" g @$ZT . i zjread s %ZJREAD=1 d process q:%ZJREAD=0 . s tran=tran+1 . i $g(show) u 0 d .. i type=6 w !,"set ",gref," = ",value .. i type=7 w !,"kill ",gref .. i type=8 w !,"zkill ",gref . i '$g(show) d .. i type=6 s @gref=value .. i type=7 k @gref .. i type=8 zk @gref q process ; n (type,gref,value,%ZJREAD) d ^cQZJREAD q jread s $zt="jreaderr" s zjread=0,zjreadout="No" s x="zl cQZJREAD" ; test for object code x x s zjread=1,zjreadout="Yes" jreaderr q ; errdata s $zt="" c file u 0 i $ze["" s x=$g(^fout(0),1),^(0)=x+1,^(x,"gref")=gref,^("value")=v alue i ($ze'["ENDOFFILE") d q . w !,"Error: ",$ZE," while processing records" . w !,"File: ",file . w !,"Record: ",$g(i) . w !,"Action: ",$s($g(type)=6:"Set",$g(type)=7:"Kill",$g(type)=8:"Zkill",1:"Unknown - "_$g(type)) . w !,"Global: ",$g(gref) . w !,"Value: ",$g(value) . d BACK^%ETN w ! w !,"Done importing "_file w !,"Processed "_i_" journal records" w !,"Applied "_tran_" journal records" w ! q errloop s $zt="" i $d(file) c file u 0 i $ZE["INTERRUPT" q w !,"Error: ",$ZE d BACK^%ETN q ; The following is an example %ZJREAD routine. Cut and paste this into ; a new %ZJREAD, and modify as needed %ZJREAD ; ;This is a sample %ZJREAD file. If will look for transactions which ;contain updates to %SYS("JOURNAL", and will keep these transactions ;from being applied. ;The following variables are defined here and can be modified ;as needed before the transaction gets applied ; ; type - Transaction type ; gref - Global reference ; value - Global value ; %ZJREAD - 1:Apply transaction, 0:Don't apply transaction ; i gref["SYS(""JOURNAL""" s %ZJREAD=0 q ; ZZ ; 17.01.2012 - 15:58 * Cache-r6.4.9