找回密码
 欢迎注册
搜索
热搜: 活动 交友 discuz
楼主: sbf2000

Cache系统数据类型剖析

[复制链接]
 楼主| 发表于 2003-4-7 10:32:42 | 显示全部楼层

Cache系统数据类型剖析

1.%Date的定义也和上面其它几个数据类型差不多,系统使用$ZDATE、$ZDATEH等多个函数来完成%Date数据类型的字面和语意的表达。
2.我们注意到,CodeMode = generator 的方法,在它生成的代码中还是使用了CodeMode = expression 的代码,也就是说,Cache表达式对数据类型的语意表达起了最跟本性的作用!
3.Cache ObjectScript是一种M语言的实现和超集,看来充分掌握和使用这种语言是在Cache中实现V3DT所必须的条件!否则可能难以用适当的表达式来实现V3DT的语意定义。
 楼主| 发表于 2003-4-7 10:35:51 | 显示全部楼层

Cache系统数据类型剖析

这里%Float的定义:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Float</b> data type class represents a floating point number.
///
The logical value of the <b>%Float</b> data type is a floating point value.
Class %Library.Float [ ClassType = datatype, ClientDataType = DOUBLE, OdbcType = DOUBLE, SqlCategory = DOUBLE ]
{
/// The format specification for the data type\'s display value.
///
The value of <var>FORMAT</var> corresponds to the formatting option
/// of the <code>$FNUMBER</code> function, which is used to perform the formatting.
Parameter FORMAT"
/// The scale value (number of digits following the decimal point) for this data type.
Parameter SCALE As INTEGER"
/// 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.
/// <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"
/// 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 = "double""
/// Converts the SOAP encoded input decimal value into a Cache numeric value.
/// Returns "" for error.
ClassMethod XSDToLogical(%val As %String) As %Float [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$number(%val,"""")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which is a string representing a floating point value,
/// into a logical floating point value.
///
Returns the logical floating point value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String) As %Float [ 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:1l(%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="$in(%val,"""_%parameter("FORMAT")_""","""")"
QUIT $$$OK
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Float [ CodeMode = expression ]
{
+%val
}
/// Tests if the logical value <var>%val</var>, which is a floating point value, 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 %Float) As %Integer [ CodeMode = generator ]
{
n sep,str,flag
s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("VALUELIST")\'="" d   QUIT $$$OK
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&amp;("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
s str="$isvalidnum(%val,,"_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical floating point format, into a display string.
/// The formatting is based on the value of the <a href="#FORMAT">FORMAT</a> parameter.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Float) As %String [ CodeMode = generator ]
{
n i,len,sep,temp
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:1l(%parameter("VALUELIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("VALUELIST"),sep,i))_" "_$$quote($p(%parameter("DISPLAYLIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("FORMAT")="",%parameter("SCALE")="" s %code="%val" QUIT $$$OK
s temp=""""_%parameter("FORMAT")_""""
i %parameter("SCALE")\'="" s temp=temp_","_%parameter("SCALE")
s %code="$s(%val="""":"""",1fn(%val,"_temp_"))"
QUIT $$$OK
}
}
 楼主| 发表于 2003-4-7 10:37:59 | 显示全部楼层

Cache系统数据类型剖析

这是%Currency的定义:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Currency</b> data type class represents a currency value.
///
<b>%Currency</b> is essentially the same as the <CLASS>%Numeric</CLASS> data type with
/// <b>clientdatatype</b> of CURRENCY and a fixed SCALE of 4.
Class %Library.Currency [ ClassType = datatype, ClientDataType = CURRENCY, OdbcType = NUMERIC, SqlCategory = NUMERIC ]
{
/// The format specification for the data type\'s display value.
///
The value of <var>FORMAT</var> corresponds to the formatting option
/// of the <code>$FNUMBER</code> function, which is used to perform the formatting.
Parameter FORMAT"
/// 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.
/// <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"
/// 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 = "decimal""
/// Converts the SOAP encoded input decimal value into a Cache %Currency value.
/// Returns "" for error.
ClassMethod XSDToLogical(%val As %String) As %Currency [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$inumber(%val,""L"","""")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which is a string representing
/// a currency value, into a logical currency value.
///
Returns the value of the input string <var>%val</var> as a currency (fixed point number).
ClassMethod DisplayToLogical(%val As %String) As %Currency [ 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:1l(%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="$in(%val,"""_%parameter("FORMAT")_""","""")"
QUIT $$$OK
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Numeric [ CodeMode = expression ]
{
+$fn(%val,"",4)
}
/// Tests if the logical value <var>%val</var>, which is a currency value, 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 %Currency) As %Integer [ CodeMode = generator ]
{
n sep,str,flag
s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("VALUELIST")\'="" d   QUIT $$$OK
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&amp;("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
s str="$isvalidnum(%val,4,"_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in currency format, into a display string.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Currency) As %String [ CodeMode = generator ]
{
n i,len,sep,temp
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:1l(%parameter("VALUELIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("VALUELIST"),sep,i))_" "_$$quote($p(%parameter("DISPLAYLIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
s temp=""""_%parameter("FORMAT")_""""
s temp=temp_",4"
s %code="$s(%val="""":"""",1fn(%val,"_temp_"))"
QUIT $$$OK
}
}
 楼主| 发表于 2003-4-7 10:39:45 | 显示全部楼层

Cache系统数据类型剖析

这是%Number的定义:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Numeric</b> data type class represents a fixed point number.
Class %Library.Numeric [ ClassType = datatype, ClientDataType = NUMERIC, OdbcType = NUMERIC, SqlCategory = NUMERIC ]
{
/// The format specification for the data type\'s display value.
///
The value of <var>FORMAT</var> corresponds to the formatting option
/// of the <code>$FNUMBER</code> function, which is used to perform the formatting.
Parameter FORMAT"
/// The scale value (number of digits following the decimal point) for this data type.
Parameter SCALE As INTEGER = 2"
/// 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.
/// <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"
/// 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 = "decimal""
/// Converts the SOAP encoded input decimal value into a Cache %Numeric value.
/// Returns "" for error.
ClassMethod XSDToLogical(%val As %String) As %Numeric [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$inumber(%val,""L"","""")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which is a string representing
/// a numeric (fixed point) value, into a logical numeric value.
///
Returns the value of the input string <var>%val</var> as a fixed point number.
ClassMethod DisplayToLogical(%val As %String) As %Numeric [ 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:1l(%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="$in(%val,"""_%parameter("FORMAT")_""","""")"
QUIT $$$OK
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Numeric [ CodeMode = generator ]
{
s %codemode=$$$cMETHCODEMODEEXPRESSION
s %code="+$fn(%val,"""","_+%parameter("SCALE")_")"
QUIT $$$OK
}
/// Tests if the logical value <var>%val</var>, which is a numeric value, 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 %Numeric) As %Integer [ CodeMode = generator ]
{
n sep,str,flag
s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("VALUELIST")\'="" d   QUIT $$$OK
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&amp;("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
s str="$isvalidnum(%val,"_%parameter("SCALE")_","_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical format, into a display string.
///
Returns the string value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Numeric) As %String [ CodeMode = generator ]
{
n i,len,sep,temp
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:1l(%parameter("VALUELIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("VALUELIST"),sep,i))_" "_$$quote($p(%parameter("DISPLAYLIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("FORMAT")="",%parameter("SCALE")="" s %code="%val" QUIT $$$OK
s temp=""""_%parameter("FORMAT")_""""
i %parameter("SCALE")\'="" s temp=temp_","_%parameter("SCALE")
s %code="$s(%val="""":"""",1fn(%val,"_temp_"))"
QUIT $$$OK
}
}
 楼主| 发表于 2003-4-7 10:41:33 | 显示全部楼层

Cache系统数据类型剖析

下面是%Time:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Time</b> data type class represents a time value.
///
The logical value of the <b>%Time</b> data type is the number of seconds past midnight.
Class %Library.Time [ ClassType = datatype, ClientDataType = TIME, OdbcType = TIME, SqlCategory = TIME ]
{
/// The format specification for the data type\'s display value.
/// The value of the <var>FORMAT</var> parameter corresponds to the
/// available parameters of the <code>$ZDATETIME</code> and <code>$ZDATETIMEH</code> functions,
/// which are used to perform the formatting.
Parameter FORMAT"
/// 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.
/// <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"
/// 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 = "time""
/// Converts the SOAP encoded input time value into a Cache %Time value.
ClassMethod XSDToLogical(%val As %String) As %Time [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
$$$GENERATE(" New len")
$$$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(" Quit $select(%val="""":"""",1ztimeh(%val,1,""""))")
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache %Time value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %Time) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$select(%val="""":"""",1ztime(%val,1))"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which represents a time value,
/// into a logical time value (number of seconds since midnight).
///
Returns the value of the input string <var>%val</var> as a
/// logical time value (number of seconds since midnight).
ClassMethod DisplayToLogical(%val As %String) As %Time [ 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:1l(%parameter("DISPLAYLIST"),sep) $$$GENERATE(" q:%val="_$$quote($p(%parameter("DISPLAYLIST"),sep,i))_" "_$$quote($p(%parameter("VALUELIST"),sep,i)))
. $$$GENERATE(" q """"")
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("FORMAT")="" s %code="$s(%val="""":"""",1:$zth(%val,,""""))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zth(%val,"_%parameter("FORMAT")_",""""))"
QUIT $$$OK
}
/// Tests if the logical value <var>%val</var>, which represents a time value
/// (number of seconds since midnight), 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 %Time) As %Integer [ CodeMode = generator ]
{
n sep,str
k %code s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("VALUELIST")\'="" d   QUIT $$$OK
. s sep=$e(%parameter("VALUELIST")) "for now
. s %code="(%val\'["""_sep_""")&amp;("_$$quote(%parameter("VALUELIST")_sep)_"[("""_sep_"""_%val_"""_sep_"""))"
s str="(%val=+%val)"
i %parameter("MAXVAL")\'="" s str=str_"&amp;(%val\'>"_(+%parameter("MAXVAL"))_")"
i %parameter("MINVAL")\'="" s str=str_"&amp;(%val\'<"_(+%parameter("MINVAL"))_")"
s str=str_"&amp;(%val\'<0)&amp;(%val<86400)"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is a logical time value
/// (number of seconds since midnight), into a display string. The formatting is based
/// on the value of the <var>FORMAT</var> parameter.
/// Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Time) As %String [ CodeMode = generator ]
{
n i,len,sep
k %code 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
i %parameter("FORMAT")="" s %code="$s(%val="""":"""",1:$zt(%val))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zt(%val,"_%parameter("FORMAT")_"))"
QUIT $$$OK
}
/// Converts <var>%val</var>, which represents a logical time value
/// (number of seconds since midnight), into ODBC time format.
///
Returns the ODBC time string for the logical time value <var>%val</var>.
ClassMethod LogicalToOdbc(%val As %Time = "") As %String [ CodeMode = expression ]
{
$s(%val="":"",1:$zt(%val))
}
/// Converts <var>%val</var>, which represents a time in ODBC format,
/// into a logical time value (number of seconds since midnight).
///
Returns the logical time value of the ODBC time string <var>%val</var>.
ClassMethod OdbcToLogical(%val As %String = "") As %Time [ CodeMode = expression ]
{
$s(%val="":"",1:$zth(%val,,"error"))
}
}
 楼主| 发表于 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:1l(%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_""")&amp;("_$$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)&amp;\'\'$zdth(%val,3,,,,,,,,"""")"
i %parameter("MAXVAL")\'="" s retexp=retexp_"&amp;(%val\']"""_%parameter("MAXVAL")_""")"
i %parameter("MINVAL")\'="" s retexp=retexp_"&amp;("""_%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)
}
}
 楼主| 发表于 2003-4-7 10:54:22 | 显示全部楼层

Cache系统数据类型剖析

以上这些数据类型都是非常基本的,大多数其它高级语言也都有。只是我们注意到了一点,他们虽然都有很相近的定义内容,但Cache没有进一步在其它数据类型上继承,比如从%Integer派生出%Number,而是直接定义新的DataType类型的新类。而V3DT的定义中,用了很多从底层数据类型类派生更高级数据类型类的抽象定义,这可能会增加我们在Cache实现V3DT的难度,同时,最底层数据类型的实现变的更为重要了,因为他会影响高级类型的定义!
 楼主| 发表于 2003-4-7 10:55:56 | 显示全部楼层

Cache系统数据类型剖析

我们再来看两个稍微“高级”一点的数据类型:
第一个是%Name:
IncludeGenerator %occInclude
/// The <b>%Name</b> data type class represents a string containing a name.
///
The logical value of the <b>%Name</b> data type is a string of the form "lastname,firstname".
///
The <b>%Name</b> data type has special indexing support when used in conjunction
/// with the <CLASS>%CacheStorage</CLASS> class
/// (see the <a href="#INDEXSUBSCRIPTS">INDEXSUBSCRIPTS</a> parameter).
Class %Library.Name [ ClassType = datatype, SqlCategory = NAME ]
{
/// The default collation value used for this data type.
Parameter COLLATION [ Constraint = ",ALPHAUP,EXACT,MINUS,PLUS,SPACE,SQLSTRING,SQLUPPER,STRING,UPPER", Flags = ENUMEDIT ] = "SQLUPPER""
/// The maximum number of characters the string can contain.
Parameter MAXLEN As INTEGER = 25"
/// The number of subscripts used by the attribute in indices.
/// This parameter, if present, tells the methods of the
/// <b>%CacheStorage</b> class (that is, the default storage structure) the
/// number of subscripts used by the attribute in indices, using a comma
/// as a delimiter in the property value.
///
The <b>%Name</b> data type has the value 2 for <var>INDEXSUBSCRIPTS</var>,
/// meaning the 1st comma piece of the name (the last name)
/// is stored as the first subscript and the 2nd comma piece of the name
/// (the first name) is stored as the second subscript.
Parameter INDEXSUBSCRIPTS = 2"
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "string""
/// Converts the input value <var>%val</var>, which is a string representing
/// a name, into the internal format.
///
Returns the internal value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String = "") As %Name [ CodeMode = expression ]
{
%val
}
/// Tests if the logical value <var>%val</var>, which is a string, is valid.
/// The validation is based on the class parameter settings used
/// for the class attribute this data type is associated with.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %Name) As %Integer [ CodeMode = generator ]
{
s %codemode=$$$cMETHCODEMODEEXPRESSION
s %code=1
i %parameter("MAXLEN")\'="" s %code="$l(%val)\'>"_%parameter("MAXLEN")
QUIT $$$OK
}
/// Converts the value of <var>%val</var> into a display string.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Name = "") As %String [ CodeMode = expression ]
{
%val
}
}
 楼主| 发表于 2003-4-7 11:00:28 | 显示全部楼层

Cache系统数据类型剖析

第二个是%Status:
/// The <b>%Status</b> data type class is used to represent an error status code.
///
///
Many of the methods provided by the <i>Cach&amp;eacute Class Library</i> return error status
/// information using the <b>%Status</b> data type. The include file, <i>%occStatus.INC</i>, contains several
/// macro definitions that are useful in testing the value of an error code in <b>%Status</b> format.
///
///
These macros include:
///
/// <ul>
/// <li><code>$$$ISOK(status:%Status)</code> returns true (1) if the status code <var>status</var>
/// does not represent an error condition.
/// <li><code>$$$ISERR(status:%Status)</code> returns true (1) if the status code <var>status</var>
/// represents an error condition.
/// </ul>
///
///
You can get a more detailed description of an error by using the system-provided
/// DecomposeStatus^%apiOBJ(status:%Status,&amp;err,flag) routine.
///
This routine takes a status code and returns an array of error strings.
///
For example:
/// <blockquote><code>
/// Set status=obj.%Save()
/// If $$$ISERR(status) Do DecomposeStatus^%apiOBJ(status,.err,"-d")
/// For i=1:1:err Write err(i),!
/// </blockquote></code>
///
///
A method returning a <b>%Status</b> code representing an error will throw an exception in
/// a client Visual Basic (ActiveX) or Java application.
Class %Library.Status [ ClassType = datatype, ClientDataType = STATUS ]
{
/// Converts the value of this data type from <code>$List</code> format to a delimited string
/// using the value of the <var>ODBCDELIMITER</var> parameter as a delimiter.
ClassMethod LogicalToOdbc(%val = "") As %String
{
n text,i,one
d $system.Status.DecomposeStatus(%val,.text,"-d")
s one="" f i=1:1g(text) s:i>1 one=one_$c(13,10) s one=one_$g(text(i))
q one
}
}
 楼主| 发表于 2003-4-7 11:16:21 | 显示全部楼层

Cache系统数据类型剖析

1.这俩个数据类型的定义和前面几个差别比较大,研究这个俩个定义可能为我们实现V3DT中的一些不常见的数据类型提供更多的参考思路。
2.%Name其实与%String区别不大,它的语意也主要从%String的基础上实现的,特别的是它有一个INDEXSUBSCRIPTS参数,这个参数对%CacheStorage类有用,这里我们看到了一个数据类型为某个特定类定义参数的情况,也就是说,要实现这个数据类型的语意表达,还要通过某个系统类(前面我们只发现了通过表达式和函数)来实现。我想这种方法可能在定义一些比较高级的数据类型语意时必须用到的,因为不常见的高级数据类型只有在特定的对象中才会用到,而底层的编程语句一般都用不到,所以Cache系统也没进行内部实现的可能。但高级的数据类型,为我们理解现实事物是非常我有和自然的,HL7V3DT是更接近应用层的定义,所以有一些在系统层不常用的数据类型定义。如果我们能合理地利用Cache的功能,正确地实现V3DT的所有功能,那么对进一步实现RIM、CMET和MIM等是非常关键的,对以后的基于Cache的医用软件开发也是意义重大的!
 楼主| 发表于 2003-4-7 11:31:42 | 显示全部楼层

Cache系统数据类型剖析

[这个贴子最后由sbf2000在 2003/04/07 03:04pm 第 1 次编辑]

%Status的功能主要由Cache系统使用和实现,它的定义对我们实现V3DT的作用应该不大。但他可以说明一点,数据类型类是比较特殊的类,在Cache中,并不是所有数据类型类都可以实现自定义,有些数据类型必须在系统级进行支持和实现。所有系统已有实现,是我们进一步实现自定义数据类型的基础,Cache所提供的功能,也将最终决定我们能否成功的实现V3DT的所有定义!
以上已将所Cache的数据类型定义进行了初步研究。下一步我们应该对V3DT的定义进行理解,并在Cache中找出适当的方法、表达式、参数、或对象来具体实现。下面还会对所有的Cache系统数据类型剖释结果作一个小结。
 楼主| 发表于 2003-4-7 15:36:48 | 显示全部楼层

Cache系统数据类型剖析

小结:
1.通过上面的分析,基本上了解了Cache本身支持的数据类型的定义情况,总的来说,数据类型是ClassType = datatype的类,它不能有属性!
2.一般来讲,数据值可以有概念值、显示值、标准值三种概念,定义一种数据类型要对这三种值的互相转化进行编程。同时,为了支持数据库和XML,还要定义对应的ODBC、SQL、XSD和客户端数据类型。
3.参数、特定的几个方法、Cache表达式、相关的函数及相关的类是表达数据类型语意的手段,较底层的数据类型,用表达式就可以表达其语意,而较高级的数据类型可能要用相关的函数或类来表达其语意及字面形式。
4.XSDToLogical,LogicalToXSD,DisplayToLogical,LogicalToDisplay,Normalize,IsValidDT,ODBCToLogical,LogicalToODBC这8人方法是自定义数据类型时最常用的特定方法。
5.全面掌握Cache ObjectScript是编写这些方法的必要条件,因为最终是由Cache表达来表达数据类型语意的。
6.DISPLAYVALUE和ValueLIST都同时出现,并用于大部分数据类型的定义,只有%Binary、%Boolean、%Name、%Status、%List这五个数据类型没用使用。
7.有些参数在方法中直接用到,但有些是在系统中使用的,不知自定义数据类型时能否使用这些参数?
8.确切地理解HL7V3DT中数据类型的语意定义和如何使用,是正确在Cache中实现的必要条件。接下来我们研究一下V3DT中的各种数据类型。
发表于 2003-4-7 17:40:12 | 显示全部楼层

Cache系统数据类型剖析

hoho,真佩服sbf2000的钻研精神,继续努力,也许我们就是国内最早一批应用M技术到医疗行业的人,:)
发表于 2003-4-8 08:04:31 | 显示全部楼层

Cache系统数据类型剖析

请问Cache的销售价格怎样?如何定价的。
 楼主| 发表于 2003-4-8 08:14:17 | 显示全部楼层

Cache系统数据类型剖析

Cache数据库国内有代理公司的,我google找到过。价格肯定比Oracle要便宜。其它我也不知道了。
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

快速回复 返回顶部 返回列表