/***********************************************************************\
| File: gen.cdl |
| Author: Cache Objects Version 4.0.836.0 |
| Date: Oct 2 2001 15:53:23 |
| Description: This File is Generated by Export Utility |
\***********************************************************************/
class GEN.Audit
{
description = "generic audit class";
super = %Library.Persistent;
persistent;
index Class { attributes = auditClass,auditTime; extent = 0; idkey = 0; primarykey = 0; unique = 0; }
index Object { attributes = auditClass,auditID,auditTime; extent = 0; idkey = 0; primarykey = 0; unique = 0; }
index Time { attributes = auditTime; extent = 0; idkey = 0; primarykey = 0; unique = 0; }
attribute auditClass { type = %Library.String; calculated = 0; not final; multidimensional = 0; public; required; sqlcomputed = 0; transient = 0; }
array attribute auditData { type = %Library.String(MAXLEN="500"); calculated = 0; description = "The new property values"; not final; multidimensional = 0; public; not required; sqlcomputed = 0; transient = 0; }
attribute auditID { type = %Library.String; calculated = 0; not final; multidimensional = 0; public; required; sqlcomputed = 0; transient = 0; }
attribute auditTime { type = %Library.String; calculated = 0; not final; multidimensional = 0; public; required; sqlcomputed = 0; transient = 0; }
attribute newRecord { type = %Library.Boolean; calculated = 0; not final; initialexpression = 0; multidimensional = 0; public; not required; sqlcomputed = 0; transient = 0; }
storage Default
{
type = %Library.CacheStorage;
datalocation = ^GEN.AuditD;
indexlocation = ^GEN.AuditI;
idlocation = ^GEN.AuditD;
defaultdata = AuditDefaultData;
data AuditDefaultData
{
structure = listnode;
value (1) = auditClass;
value (2) = auditID;
value (3) = auditTime;
value (4) = newRecord;
}
data auditData
{
structure = subnode;
value = auditData;
subscript = "auditData";
}
}
}
class GEN.AuditHelper
{
description = "Additional methods for auditing property changes";
include
{
code = %occInclude;
generator = %occInclude;
}
parameter AUDITPROPERTIES { description =
{
a comma delimited list of property names to be stored when the object is opened.
} not final; }
attribute auditStored { type = %Library.String; calculated = 0; not final; multidimensional; private; not required; sqlcomputed = 0; transient; }
method auditSave()
{
classmethod = 0;
description = "If any of the properties have changed, create a GEN.Audit record";
not final;
public;
sqlproc = 0;
generator =
[
#; Generate code to create audit record for the class
Set %code=0
Q:'$G($$$CLASSpersistent($$$pCOM,%class)) $$$OK
N P,I,Z,C
S P=$G($$$PARAMdefault($$$MGINFO,%class,"AUDITPROPERTIES"))
I P="" Q $$$OK
$$$GENERATE(" N qa,mod")
#; build a new instance of the audit record
$$$GENERATE(" s qa=##class(GEN.Audit).%New()")
#; Generate a line for each property - only update if changed
F I=1:1:$L(P,",") S Z=$P(P,",",I) I Z'="" D
. $$$GENERATE(" I $g(i%auditStored("""_Z_"""))'=.."_Z_" S mod=1 d qa.auditData.SetAt(.."_Z_","""_Z_""")")
$$$GENERATE(" I '$d(i%auditStored) S qa.newRecord=1,mod=1")
#; Nothing modified ?
$$$GENERATE(" I 'mod d qa.%Close() Q")
#; Update other pieces
$$$GENERATE(" s qa.auditID=..%Id(),qa.auditClass=..%ClassName(),qa.auditTime=$h")
$$$GENERATE(" d qa.%Save(),qa.%Close()")
#; don’t forget to reset your stored values here…
$$$GENERATE(" d ..auditStart()")
q $$$OK
]
}
method auditStart()
{
classmethod = 0;
description = "Save the stored property values into the auditStored array";
not final;
public;
sqlproc = 0;
generator =
[
#; Generate code to store values for audit record.
Set %code=0
#; remember this code is also run for the helper class
Q:'$G($$$CLASSpersistent($$$pCOM,%class)) $$$OK
N P,I,Z
S P=$G($$$PARAMdefault($$$MGINFO,%class,"AUDITPROPERTIES"))
I P="" Q $$$OK
F I=1:1:$L(P,",") S Z=$P(P,",",I) I Z'="" D
. $$$GENERATE(" S i%auditStored("""_Z_""")=.."_Z)
q $$$OK
]
}
}
class GEN.GetList
{
abstract;
description = "Display/Value List exposure";
include
{
code = %occInclude;
generator = %occInclude;
}
method getList(property:%String)
{
returntype = %List;
classmethod;
description = "Generate a class method that returns dis/value pairs list. Pass in property name, returns list of pairs in a list.";
not final;
public;
sqlproc = 0;
generator =
[
; Return display/value pairs for properties with display/value lists
; 22/7/1998 - P Gausden
; Return display/value pairs for properties with display/value lists
; Returns a list of 2 item lists for a property
; each item contains the value & corresponding display value
; if no display value, second item = first item
; if no value list, first item is ""
;
; Class Method
; requires property name as parameter
;
s %code=0
N P,codeLine,dispList,valList,DDelim,VDelim,S,SDEL,KEY
$$$FOREACHproperty($$$MGINFO,%class,P) D
#;
#; ignore certain types of property
. If $$$PROPprivate($$$MGINFO,%class,P) Q
. If $$$PROPmultidimensional($$$MGINFO,%class,P) Q
. If $$$PROPcalculated($$$MGINFO,%class,P) Q
#;
#; DISPLAY AND VALUE LIST parameter for property P ?
. S dispList=$G($$$PROPPARAM($$$MGINFO,%class,P,"DISPLAYLIST"))
. S valList=$G($$$PROPPARAM($$$MGINFO,%class,P,"VALUELIST"))
#;
#; Do we have a list ?
. I dispList="",valList="" Q
. S VDelim=$E(valList),DDelim=$E(dispList)
#;
#; Find longest list
. S codeLine=" I Property="""_P_""" Q $LB("
. S S=valList,SDEL=VDelim I $L(dispList,DDelim)>$L(valList,VDelim) S S=dispList,SDEL=Ddelim
#;
#; For each element in the list generate:
#; $LB(valueListItem,displayListItem)[,]
. F I=2:1:$L(S,SDEL) D
. . S KEY=$P(dispList,DDelim,I) I KEY="" S KEY=$P(valList,VDelim,I)
. . I KEY'="" S codeLine=codeLine_"$LB("""_$P(valList,VDelim,I)_""","""_KEY_""")"
. . I I<$L(S,SDEL) S codeLine=codeLine_","
. ;
. $$$GENERATE(codeLine_")")
#; by default Q "" is automatically generated at the end
Q $$$OK
]
}
}
class GEN.OpenIndex
{
description = "Open an instance of an object by using it's unique indices.
";
include
{
code = %occInclude;
generator = %occInclude;
}
method openIndex(Name:%Library.String,Code:%Library.CacheString,Concurrency:%Library.Integer=$zu(115,10))
{
returntype = %Library.CacheString;
classmethod;
description =
{
Generate an openIndex Method for a class
Inputs are:
Name : Index name - as defined for the class, this must be a "unique" index
Code : Index key(s) (data delimited by ||)
and Concurrency.
Returns an open object if a match is found. } not final; public; sqlproc = 0; generator = [ #; Paul Gausden, 30th July 2001 s %code=0 #; only on persistent classes QUIT:'$g($$$CLASSpersistent($$$pDEF,%class)) $$$OK #; I could put code in here to check the storage class is SQL enabled #; but I doubt many people have written their own storage classes yet #; this approach should work with the storage strategies provided by Intersystems n index,indexname,type,isidkey,unq,sc,cnt,ia,z,l,wc,tn,idv s sc=$$$OK,cnt=0 #; get class sql table name s tn=%class i $g($$$CLASSsqltablename($$$pCOM,%class))'="" s tn=$$$CLASSsqltablename($$$pCOM,%class) s idv="ID" i $g($$$CLASSsqlrowidname($$$pCOM,%class))'="" s idv=$$$CLASSsqlrowidname($$$pCOM,%class) s index="" #; Loop through each INDEX definition... $$$FOREACHindex($$$pCOM,%class,index) DO QUIT:$$$ISERR(sc) . s indexname=$g($$$INDEXname($$$pCOM,%class,index)) . s type=$$$INDEXtype($$$pCOM,%class,index) #; ignore key indices (should be using %Open instead) . s isidkey=+$g($$$INDEXidkey($$$pCOM,%class,index)) i isidkey q #; only works with unique indices . s unq=+$g($$$INDEXunique($$$pCOM,%class,index)) i 'unq q #; get list of fields in the index . s ia=$$$INDEXattributes($$$pCOM,%class,index) #; first time around ? . i 'cnt d . . $$$GENERATE(" n oid,ref s oid=$$$NULLOID") . . $$$GENERATE(" i Code="""" QUIT $$$NULLOREF") . . s cnt=1 #; is the list more than one field ? split it up . I $l(ia,",")>1 D . . s wc=" S " . . f l=1:1:$l(ia,",") s z=$p(ia,",",l) s wc="ref("_l_")=$p(Code,""||"","_l_")" i l'=$l(ia,",") s wc=wc_"," . . $$$GENERATE(wc) . . s wc="" . . f l=1:1:$l(ia,",") s z=$p(ia,",",l) s wc=wc_z_"=:ref("_l_")" i l'=$l(ia,",") s wc=wc_"," . E D #; only one field . . s wc=ia_"=:Code" . $$$GENERATE(" I Name="""_indexname_""" &SQL(SELECT "_idv_" INTO :oid FROM "_tn_" WHERE "_wc_") Q:SQLCODE $$$NULLOREF") i cnt d . $$$GENERATE(" i oid=$$$NULLOID q $$$NULLOREF") . $$$GENERATE(" Q ..%Open($$$oidForm(oid),Concurrency)") e d . $$$GENERATE(" Q $$$NULLOREF") QUIT $$$OK ] } }