|
楼主 |
发表于 2003-4-7 10:43:22
|
显示全部楼层
Cache系统数据类型剖析
%TimeStamp:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%TimeStamp</b> data type class represents a time stamp value.
///
The logical value of the <b>%TimeStamp</b> data type is in <code>YYYY-MM-DD HH:MM:SS.nnnnnnnnn</code> format.
Class %Library.TimeStamp [ ClassType = datatype, ClientDataType = TIMESTAMP, OdbcType = TIMESTAMP, SqlCategory = TIMESTAMP ]
{
/// Used for enumerated (multiple-choice) attributes.
/// <var>VALUELIST</var> is either a null string ("") or a delimiter
/// separated list (where the delimiter is the first character) of logical values.
/// If a non-null value is present, then the attribute is restricted to values
/// in the list, and the validation code simply checks to see if the value is in the list.
Parameter VALUELIST"
/// The maximum allowed logical value for the data type.
Parameter MAXVAL"
/// The minimum allowed logical value for the data type.
Parameter MINVAL"
/// Used for enumerated (multiple-choice) attributes.
/// Used in conjunction with the <a href="#VALUELIST">VALUELIST</a> parameter for enumerated
/// (multiple-choice) attributes. <var>DISPLAYLIST</var>, if not null,
/// represents the display values for the attribute corresponding with
/// the logical values listed in <var>VALUELIST</var>.
///
The display values are returned by the <a href="#LogicalToDisplay">LogicalToDisplay</a> method.
Parameter DISPLAYLIST"
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "dateTime""
/// Converts the SOAP encoded input dateTime value into a Cache %TimeStamp value.
ClassMethod XSDToLogical(%val As %String) As %TimeStamp [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
$$$GENERATE(" New len,dt")
$$$GENERATE(" Set len=$length(%val)")
$$$GENERATE(" If $extract(%val,len)=""Z"" {")
$$$GENERATE(" Set %val=$extract(%val,1,len-1)")
$$$GENERATE(" } ElseIf $case($extract(%val,len-5),""+"":1,""-"":1,:0) {")
$$$GENERATE(" Set %val=$extract(%val,1,len-6)")
$$$GENERATE(" }")
$$$GENERATE(" If $get(%val)="""" Quit """"")
$$$GENERATE(" If $length(%val,""T"")\'=2 Quit """"")
$$$GENERATE(" Set dt=$translate(%val,""T"","" "")")
$$$GENERATE(" If $zdatetimeh(dt,3,1,,,,,,,"""")="""" Quit """"")
$$$GENERATE(" Quit dt")
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache %TimeStamp value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %TimeStamp) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$translate(%val,"" "",""T"")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts <var>%val</var>, which represents either a Timestamp in ODBC format,
/// or a Date in ODBC format, into a logical Timestamp value.
///
Returns the logical Timestamp value of the ODBC Timestamp string <var>%val</var>.
ClassMethod OdbcToLogical(%val As %String) As %TimeStamp [ CodeMode = expression ]
{
$s(%val="":"",$zdth(%val,3,,,,,,,,"")\'="" zdt($zdth(%val,3),3),$zdth(%val,-1,,,,,,,,"")\'="" zdt($zdth(%val,-1),3),1:%val)
}
/// Converts the input value <var>%val</var>, which represents a timestamp value,
/// to <code>YYYY-MM-DD HH:MM:SS</code> format.
///
Returns the value of the input string <var>%val</var> as a timestamp
/// value (<code>YYYY-MM-DD HH:MM:SS</code> format).
ClassMethod DisplayToLogical(%val As %String) As %TimeStamp [ CodeMode = generator ]
{
n i,len,sep
s %code=0
i %parameter("VALUELIST")\'="",%parameter("DISPLAYLIST")\'="" d QUIT $$$OK
. s sep=$e(%parameter("DISPLAYLIST"))
. s len=$l(%parameter("DISPLAYLIST"),sep)
. f i=2:1 l(%parameter("DISPLAYLIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("DISPLAYLIST"),sep,i))_" "_$$quote($p(%parameter("VALUELIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
s %code="%val"
QUIT $$$OK
}
/// Tests if the logical value <var>%val</var>, which represents a timestamp
/// value in <code>YYYY-MM-DD HH:MM:SS.nnnnnnnn</code> format, is valid.
/// The validation is based on the class parameter settings used for the
/// class attribute this data type is associated with.
/// In this case, <a href="#MAXVAL">MAXVAL</a> and <a href="#MINVAL">MINVAL</a>.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %TimeStamp) As %Integer [ CodeMode = generator ]
{
n sep,retexp
s %code=0
i %parameter("VALUELIST")\'="" d QUIT $$$OK
. s %codemode=$$$cMETHCODEMODEEXPRESSION
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
$$$GENERATE(" i %val=(%val\\1) s %val=$zd(%val,3,,,,,,,""error"")_"" 00:00:00""")
$$$GENERATE(" i $l(%val)=10 s %val=%val_"" 00:00:00""")
$$$GENERATE(" i $l(%val)=8 s %val=$zd($h,3)_"" ""_%val")
s retexp="($l(%val)>18)&\'\'$zdth(%val,3,,,,,,,,"""")"
i %parameter("MAXVAL")\'="" s retexp=retexp_"&(%val\']"""_%parameter("MAXVAL")_""")"
i %parameter("MINVAL")\'="" s retexp=retexp_"&("""_%parameter("MINVAL")_"""\']%val)"
$$$GENERATE(" q "_retexp)
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical format <code>YYYY-MM-DD HH:MM:SS.nnnnnnnnn</code>,
/// into a display string.
/// The formatting is based on the value of the FORMAT parameter.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %TimeStamp) As %String [ CodeMode = generator ]
{
n i,len,sep
s %code=0
i %parameter("VALUELIST")\'="",%parameter("DISPLAYLIST")\'="" d QUIT $$$OK
. s sep=$e(%parameter("VALUELIST"))
. s len=$l(%parameter("VALUELIST"),sep)
. f i=2:1:$l(%parameter("VALUELIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("VALUELIST"),sep,i))_" "_$$quote($p(%parameter("DISPLAYLIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
s %code="%val"
QUIT $$$OK
}
/// Transorms integer values into timestamp.
ClassMethod Normalize(%val As %TimeStamp) As %TimeStamp [ CodeMode = expression ]
{
$s(%val="":"",%val=(%val\\1):$zd(%val,3,,,,,,,"error")_" 00:00:00",$l(%val)=8:$zd($h,3)_" "_%val,$l(%val)=10:%val_" 00:00:00",1:%val)
}
}
|
|