找回密码
 欢迎注册
搜索
热搜: 活动 交友 discuz
查看: 11592|回复: 45

Cache系统数据类型剖析

[复制链接]
发表于 2003-4-6 09:16:15 | 显示全部楼层 |阅读模式
为了进一步研究HL7V3DT在Cache的实施,我们有必要对Cache的系统数据类型进行仔细分析。希望Cache高手给出指点,也希望朋友一起讨论。
 楼主| 发表于 2003-4-6 09:18:14 | 显示全部楼层

Cache系统数据类型剖析

首先研究%Library.Boolean,它的定义是这样的:
Class %Library.Boolean [ ClassType = datatype, ProcedureBlock ]
{
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "boolean""
/// Converts the SOAP encoded input value, which is true, false 1 or 0,
/// into a Cache %Boolean value.
ClassMethod XSDToLogical(%val As %String) As %Boolean [ CodeMode = generator ]
{
}
/// Converts the Cache %Boolean value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %Boolean) As %String [ CodeMode = generator ]
{
}
/// Converts the input value <var>%val</var>, which is a string representing
/// a boolean value, into a boolean value.
///
Returns the boolean value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String = "") As %Boolean [ CodeMode = expression ]
{
\'\'%val
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Integer [ CodeMode = generator ]
{
}
/// Tests if the boolean value <var>%val</var> is valid.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %Boolean = "") As %Integer [ CodeMode = expression ]
{
$isvalidnum(%val,0,0,2)&amp;&amp;(+%val\'=2)
}
/// Converts the value of <var>%val</var>, which is in boolean format, into a display string.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Boolean = "") As %String [ CodeMode = expression ]
{
%val
}
}
 楼主| 发表于 2003-4-6 09:40:35 | 显示全部楼层

Cache系统数据类型剖析

分析:
1.XSDTYPE参数定义了它对应的XSD数据类型是Boolean
2.XSDToLogical和LogicalToXSD的代码为空,但实现了%String和%Boolean的互换。
3.DisplayToLogical中用两个非“\'”运算实现了把%Val从%String转变为%Boolean。
4.Normalize实现了%String到实际上的%Integer的转化。
5.IsValidDT是它的值的验证,$isvalidnum函数的用法一直没有找到,不知是否有人能告诉我是什么意思?
6.LogicalToDisplay直接来值输出为%String。
以上定义可以看出,%Library.Boolean定义其字面形式,值的验证,值的正式化,还有于XSD的类型转化和于ODBC类型的对映。但没有直接定义布而数据类型的运算规则,我想,运算规则可能是在运算操作符的定义中才能看到吧。(那么,如果我们自定义一种数据类型,如果还有对应的特殊的运算法则,那么我们还必须定义一种运算符,把这种运算法则体现出来,对吗?Cache允许自定义操作符吗?)
 楼主| 发表于 2003-4-6 09:49:18 | 显示全部楼层

Cache系统数据类型剖析

Cache没有提到可以自定义操作符,所以,所有支持的表达式运算都是Cache已经定义好的,不能再扩充了。那么要想实现特定数据类型的运算法则,除了直接利用系统已有的运算规则来实现,其它只能是通过自定义方法或自定义函数了。在自定义方法或函数中可以实现特定的运算法则。
以上是我的自已的想法,不知对否?
 楼主| 发表于 2003-4-6 10:34:18 | 显示全部楼层

Cache系统数据类型剖析

更正:%Library.Boolean的定义是这样的:
IncludeGenerator (%occInclude, %occUtility)
/// The <B>%Boolean</B> data type class represents a boolean value.
///
The logical value of the <B>%Boolean</B> data type is an integer
/// with value of 0 (false) and 1 (true).
Class %Library.Boolean [ ClassType = datatype, ClientDataType = BOOLEAN, OdbcType = BIT, SqlCategory = INTEGER ]
{
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "boolean""
/// Converts the SOAP encoded input value, which is true, false 1 or 0,
/// into a Cache %Boolean value.
ClassMethod XSDToLogical(%val As %String) As %Boolean [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$case(%val,""true"":1,""false"":0,1:1,0:0,:"""")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache %Boolean value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %Boolean) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$select(%val:""true"",1:""false"")"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which is a string representing
/// a boolean value, into a boolean value.
///
Returns the boolean value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String = "") As %Boolean [ CodeMode = expression ]
{
\'\'%val
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Integer [ CodeMode = generator ]
{
Set %codemode=$$$cMETHCODEMODEEXPRESSION
set %code="%val\\1"
Quit $$$OK
}
/// Tests if the boolean value <var>%val</var> is valid.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %Boolean = "") As %Integer [ CodeMode = expression ]
{
$isvalidnum(%val,0,0,2)&amp;&amp;(+%val\'=2)
}
/// Converts the value of <var>%val</var>, which is in boolean format, into a display string.
///
Returns the formatted value of <var>%val</var>.
ClassMethod LogicalToDisplay(%val As %Boolean = "") As %String [ CodeMode = expression ]
{
%val
}
}
 楼主| 发表于 2003-4-6 10:49:05 | 显示全部楼层

Cache系统数据类型剖析

上面的定义中,我们看到了CodeMode = generator(也可以是objectgenerator)的方法代码, 这些代码中用了很多系统类、系统变量和系统方法,看来又要花时间去学了!
接下来弄清这段代码的含意:
ClassMethod XSDToLogical(%val As %String) As %Boolean [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$case(%val,""true"":1,""false"":0,1:1,0:0,:"""")"
} Else {
Set %code=0
}
Quit $$$OK
}
 楼主| 发表于 2003-4-6 11:37:25 | 显示全部楼层

Cache系统数据类型剖析

CodeMode = generator 的方法,需经过编译器才能生成正真的方法代码,需这里的定义只是告诉编译器怎样生成这个代码。
1.%class,%Dictionary.ClassDefinition类的一个实例,包含被编译类的原始定义。
2.%code,%Compiler.MethodGeneratorStream类的一个实例,包含的你所写的方法代码。
3.$$$OK返回一个方法成生成功的状态,对实际的方法没有任何作用。
4.$$$是对宏的调用,$$$comMemberKeyGet,$$$cCLASSparameter,$$$cPARAMdefault,$$$cMETHCODEMODEEXPRESSION应该是系统定义的宏,不知他们的确切定义在哪里?猜想是:
$$$comMemberKeyGet:获取成员参数的值
$$$cCLASSparameter:类的参数
$$$cPARAMdefault:类参数的默认值
$$$cMETHCODEMODEEXPRESSION:代表方法的模式表达式
5.%codemode,不知是哪个类的实例?应该是代表方法代码的代码模式,跟%code.CodeMode应该相同吧?
6.这些代码意思是如果这个类的参数“XMLENABLED”为真,那生成的表达式代码为:$case(%val,""true"":1,""false"":0,1:1,0:0,:""""),否则为 0 。
7.$case(%val,""true"":1,""false"":0,1:1,0:0,:"""")意思为如果%val为ture或1,返回1,如果为false或0返回0。也就是XSD中的Boolean数据类型支持1和0及ture和false两种值的形式,而Cache中,只认1和0。
8.另外,注意,方法的参数是%String类型的值,而返回则是%Boolean的值。
9.这里是否也说明了数据类型的定义可以嵌套使用这个类本身?也就是本身的定义,可以在定义在就使用。
 楼主| 发表于 2003-4-6 11:52:46 | 显示全部楼层

Cache系统数据类型剖析

那么为什么XSDToLogical的CodeMode = generator而DisplayToLogical的CodeMode = expression呢?
可能是因为XSDToLogical还有一个“XMLENABLED”参数要考虑吧,但Normalize却也使用CodeMode = expression,而不是直接用“%val\\1”这个表达式,这又是为何呢?
CodeMode = generator的数据类型方法在定义HL7V3DT时肯定要用到的,如何区分用generator还是直接用expression或code需要以后再摸索!
 楼主| 发表于 2003-4-6 12:14:33 | 显示全部楼层

Cache系统数据类型剖析

接下来再研究一个比较有用的类:
IncludeGenerator %occInclude
/// The <b>%List</b> data type class is used to represent data that is in <code>$List</code> format.
/// The logical value for <b>%List</b> is a list of elements in <code>$List</code> format.
///
///
When the <i>Cach&amp;eacute Object Server for ActiveX</i> projects a <b>%List</b> data type
/// value to a client application, it exposes it as a Cach&amp;eacute <b>syslist</b> object.
/// This allows the client application to efficiently manipulate the contents of the list.
/// Similarly, the <i>Cach&amp;eacute Object Server for Java</i> projects a <b>%List</b> data type
/// value as a <b>com.intersys.utils.SysList</b> object.
///
///
Refer to the documentation on <code>$List</code> in the <i>Cach&amp;eacute ObjectScript Reference Manual</i>
/// for more information.
Class %Library.List [ ClassType = datatype, ClientDataType = LIST ]
{
/// A <b>%List</b> value is converted to a delimited string when
/// it is projected via ODBC. <var>ODBCDELIMITER</var> is the delimiter character
/// used to construct the delimited string.
Parameter ODBCDELIMITER = ",""
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "string""
/// Converts the SOAP encoded input list value into a Cache $list value.
ClassMethod XSDToLogical(%val As %String) As %List [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
New odbcdelim
Set odbcdelim=%parameter("ODBCDELIMITER")
#" Quote the delimiter. If odbcdelimiter was not specified, default to ","
s odbcdelim=""""_$s(odbcdelim\'=""dbcdelim,1:",")_""""
$$$GENERATE(" If $get(%val)="""" Quit """"")
$$$GENERATE(" New i,list")
$$$GENERATE(" For i=1:1length(%val,"_odbcdelim_") Set $list(list,i)=$piece(%val,"_odbcdelim_",i)")
$$$GENERATE(" Quit list")
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache $list value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %List) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
New odbcdelim
Set odbcdelim=%parameter("ODBCDELIMITER")
#" Quote the delimiter. If odbcdelimiter was not specified, default to ","
s odbcdelim=""""_$s(odbcdelim\'=""dbcdelim,1:",")_""""
$$$GENERATE(" If $get(%val)="""" Quit """"")
$$$GENERATE(" New i,odbc")
$$$GENERATE(" Set odbc=$list(%val,1)")
$$$GENERATE(" For i=2:1listlength(%val) Set odbc=odbc_"_odbcdelim_"_$list(%val,i)")
$$$GENERATE(" Quit odbc")
} Else {
Set %code=0
}
Quit $$$OK
}
/// 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 [ CodeMode = generator ]
{
"n list,i
"s list="" f i=1:1ll(%val) s:i\'=1 list=list_..#ODBCDELIMITER s list=list_$lg(%val,i)
"q list
s %code=0
n odbcdelim
s odbcdelim=%parameter("ODBCDELIMITER")
#" Quote the delimiter. If odbcdelimiter was not specified, default to ","
s odbcdelim=""""_$s(odbcdelim\'=""dbcdelim,1:",")_""""
#" now loop through list elements and build the result
$$$GENERATE(" n i,loop,odbc")
$$$GENERATE(" s loop=$ll(%val)-1")
$$$GENERATE(" s odbc=$li(%val,1)_"_odbcdelim)
$$$GENERATE(" f i=2:1:loop s odbc=odbc_$li(%val,i)_"_odbcdelim)
$$$GENERATE(" s odbc=odbc_$li(%val,(loop+1))")
$$$GENERATE(" q odbc")
QUIT $$$OK
}
/// Converts the value of an incoming delimited string to <code>$List</code> format
/// using the value of the <var>ODBCDELIMITER</var> parameter as a delimiter.
ClassMethod OdbcToLogical(%val = "") As %String [ CodeMode = generator ]
{
"n list,i
"f i=1:1:$l(%val,..#ODBCDELIMITER) s $li(list,i)=$p(%val,..#ODBCDELIMITER,i)
"q list
n odbcdelim
s odbcdelim=%parameter("ODBCDELIMITER")
#" Quote the delimiter. If odbcdelimiter was not specified, default to ","
s odbcdelim=""""_$s(odbcdelim\'="":odbcdelim,1:",")_""""
$$$GENERATE(" n list,i")
$$$GENERATE(" f i=1:1:$l(%val,"_odbcdelim_") s $li(list,i)=$p(%val,"_odbcdelim_",i)")
$$$GENERATE(" q list")
}
}
 楼主| 发表于 2003-4-7 09:00:31 | 显示全部楼层

Cache系统数据类型剖析

%List之所以比较重要,是因为HL7中,很多数据类型是从List继承的,比如BIN、OID、AD、EN、GLIST、SLIST等,定义好了LIST,就很容易派生出很多其它数据类型和中间数据类型。分析Cache中的%List是否能表达的HL7V3DT的定义是很重要一步。
从上面的代码可以看出:
1.%List的定义集中在三个关键字和XML支持上:客户端类型CLIENTDATATYPE、ODBC类型ODBCTYPE、SQL类型SQLCATEGORY。从注释中可知,客户端类型是Cache进行对象绑定时自动转化的,而与ODBC和SQL类型的转化是通过OdbcToLogical、LogicalToOdbc两个方法实现的,而与XSD类型的转化是通过LogicalToXSD、XSDToLogical两个方法实现的。这些其实就是Cache所关心的数据类型在不同环境上的字面表达形式。
2.%List没有定义象%Boolean那样的LogicalToDisplay和DisplayToLogical两个方法,这两个方法应该是实现它在Cache系统内部的字面表达形式的,而它却没有被定义!这是为什么呢?
3.在%Boolean中,我们还看到了值的正式化Normalize和值的验证IsValidDT两个方法,在%List中也同样没有定义,这又是为什么呢?
4.我们看到的代码,大多都是字面形式和使用界面的定义,而数据类型的语意最终都是通过Cache的表达式来实现在(看方法的代码表达式),%List的语意是通过$List函数来实现的。
5.HL7V3DT是对数据类型语意的定义,而字面表达和使用界面必须自已定义,所以我们要在Cache中实现V3DT,必须使用Cache的表达式来实现V3DT的语意表达,必须按Cache的要求,定义他所关心的字面形式和使用界面(包括客户端、OBDC、SQL、XSD)。
6.我们还注意到,在使用%Boolean等系统数据类型时,我们没有显式地调用过DisplayToLogical这样的方法,这些方法定义好之后,好象是系统自动进行调用的,不知这样认为对吗?如果是这样,那么我们在定义HL7V3DT时,就要适当的利用这些特定的方法去实现数据类型的一些特性。所以仔细研究所有系统数据类型使用过的方法,对我们定义V3DT很有用。
 楼主| 发表于 2003-4-7 09:17:41 | 显示全部楼层

Cache系统数据类型剖析

接下来看一下%String:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%String</b> data type class represents a string.
///
The logical value of the <b>%String</b> data type is a string.
Class %Library.String [ ClassType = datatype ]
{
/// The default collation value used for this data type.
Parameter COLLATION [ Constraint = ",ALPHAUP,EXACT,MINUS,PLUS,SPACE,SQLSTRING,SQLUPPER,STRING,UPPER", Flags = ENUMEDIT ]"
/// The maximum number of characters the string can contain.
Parameter MAXLEN As INTEGER = 50"
/// The minimum number of characters the string can contain.
Parameter MINLEN As INTEGER"
/// A pattern which the string should match.
///
The value of <var>ATTERN</var> should be a valid
/// <i>Cacheacute</i> pattern match expression.
Parameter PATTERN"
/// Determines whether to truncate the string to MAXLEN characters.
Parameter TRUNCATE As BOOLEAN = 1"
/// 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"
/// XML element content "MIXED" for mixed="true" and "STRING" for mixed="false".
Parameter CONTENT [ Constraint = "MIXED,STRING", Flags = ENUM ] = "STRING""
/// Declares the XSD type used when projecting XML Schemas.
Parameter XSDTYPE = "string""
/// Converts the input value <var>%val</var>, which is a string, into the logical string format.
/// Returns the logical value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String) As %String [ 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
}
/// Truncates value <var>%val</var> to <a href="#MAXLEN">MAXLEN</a>, characters.
ClassMethod Normalize(%val As %String) As %String [ CodeMode = generator ]
{
n str
s str=""
s %code=0
s %codemode=$$$cMETHCODEMODEEXPRESSION
i %parameter("TRUNCATE"),%parameter("MAXLEN")\'="" s str="$e(%val,1,"_(+%parameter("MAXLEN"))_")"
i str="" s %code="%val" QUIT $$$OK
s %code=str
QUIT $$$OK
}
/// 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.
/// In this case, <a href="#MINLEN">MINLEN</a>, and <a href="#PATTERN">ATTERN</a>.
///
Returns true (1) if the value <var>%val</var> is valid, otherwise false (0).
ClassMethod IsValidDT(%val As %String) 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=""
i %parameter("MINLEN")\'="" s str=str_"($l(%val)\'<"_(+%parameter("MINLEN"))_")"
i \'%parameter("TRUNCATE"),%parameter("MAXLEN")\'="" s str=str_"&amp;($l(%val)\'>"_(+%parameter("MAXLEN"))_")"
i %parameter("ATTERN")\'="" s str=str_"&amp;(%val?"_%parameter("PATTERN")_")"
i str="" s %code=1 QUIT $$$OK
i $e(str)="&amp;" s str=$e(str,2,999)
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 %String) 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: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 %code="%val"
QUIT $$$OK
}
}
 楼主| 发表于 2003-4-7 09:48:16 | 显示全部楼层

Cache系统数据类型剖析

1.%String定义了DisplayToLogical、LogicalToDisplay、Normalize、IsValidDT这些基本的数据字面形式和界面,还定义了几个参数。
2.我们发现,这里定义的参数有的没有直接在它的方法用到,那么,这些参数会在Cache系统内部其它的表达式或命令中用到。这样推理,在我们自定数据类型时,这些参数也就成了特定的参数,使用这些参数可以使系统自动地处理某些功能了。因此,对所有系统数据类型使用过的参数进行全面研究也是实现V3DT的重要内容。
3.从为%String定义的参数还可以看出,这些参数可以对数据系统进行进一步的(在Cache表达式之上)语意限定,如这里的MAXLEN、MINLEN等。因此V3DT的一些语意定义也要靠参数和方法去进行限定。
4.在类定义内部使用的参,应该可以自定义,而要系统处理的参数,一定要使用那些已有的特定参数。而方法一般都要求系统自动调用,以获取系统的透明支持。所以方法一般都使用特定的方法,而自定义方法在数据类型的定义中应该很少用致到。这是我的推测,不知是否正确?
 楼主| 发表于 2003-4-7 09:51:46 | 显示全部楼层

Cache系统数据类型剖析

这里是%Integer的定义:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Integer</b> data type class represents an integer value.
///
The logical value of the <b>%Integer</b> data type is an integer.
Class %Library.Integer [ ClassType = datatype, ClientDataType = INTEGER, OdbcType = INTEGER, SqlCategory = INTEGER ]
{
/// 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 As INTEGER"
/// The minimum allowed logical value for the data type.
Parameter MINVAL As INTEGER"
/// 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 = "long""
/// Converts the SOAP encoded input decimal value into a Cache numeric value.
/// Returns "" for error.
ClassMethod XSDToLogical(%val As %String) As %Integer [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$select((%val="""")||(%val["".""):"""",1inumber(%val,""L"",""""))"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which is a string representing an integer,
/// into a logical integer value.
///
Returns the logical integer value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String) As %Integer [ 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 %Integer [ CodeMode = expression ]
{
%val\\1
}
/// Tests if the logical value <var>%val</var>, which is an integer 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 %Integer) 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,0,"_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical integer format, 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 %Integer) 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: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")="" s %code="%val" QUIT $$$OK
s %code="$s(%val="""":"""",1:$fn(%val,"""_%parameter("FORMAT")_"""))"
QUIT $$$OK
}
}
 楼主| 发表于 2003-4-7 10:11:29 | 显示全部楼层

Cache系统数据类型剖析

1.这里可以看出,系统为%Integer的格式化输出准备了$FNUMBER 函数,这跟$List函数与%List数据类型的关系差不多,自定义函数来表达个别数据类型的语意或界面是比较灵活的,在实现V3DT中可能也要用到!
2.这里同样看到了DisplayToLogical、LogicalToDisplay、IsValidDT、Normalize这四个方法,这证明,这四个方法是实现底层的数据类型的最重要的方法。
3.从上面的几个数据类型定义还可以看出,从概念上,数据类型有“概念值”、“显示值”、“标准值”之分。概念值是表达其语意的,显示值是简单数据类型都必有显示界面,而标准值是系统对它进行处理时,系统所使用的值。标准值还可以用ValueLIST来限定,并用DISPLAYLIST指定特定的对应显示值,而默认的标准值和显示值是在定义时使用DisplayToLogical、LogicalToDisplay两个方法定义的,使用数据类型时如果不设定DISPLAYLIST,就使用默认关系。
 楼主| 发表于 2003-4-7 10:22:47 | 显示全部楼层

Cache系统数据类型剖析

再看一下%Date:
IncludeGenerator (%occInclude, %occUtility)
/// The <b>%Date</b> data type class represents a date.
/// The logical value of the <b>%Date</b> data type is in <i>Cach&amp;eacute</i> <code>$H</code> format.
Class %Library.Date [ ClassType = datatype, ClientDataType = DATE, OdbcType = DATE, SqlCategory = DATE ]
{
/// 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>$ZDATE</code> and <code>$ZDATEH</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 = "date""
/// Converts the SOAP encoded input date value into a Cache %Date value.
ClassMethod XSDToLogical(%val As %String) As %Date [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
$$$GENERATE(" New len")
$$$GENERATE(" Set len=$length(%val)")
$$$GENERATE(" If len\'=10 {")
$$$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(" }")
$$$GENERATE(" Quit $select(%val="""":"""",1zdateh(%val,3,,,,,,,""""))")
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the Cache %Date value to the canonical SOAP encoded value.
ClassMethod LogicalToXSD(%val As %Date) As %String [ CodeMode = generator ]
{
If $$$comMemberKeyGet(%class,$$$cCLASSparameter,"XMLENABLED",$$$cPARAMdefault) {
Set %codemode=$$$cMETHCODEMODEEXPRESSION
Set %code="$select(%val="""":"""",1zdate(%val,3))"
} Else {
Set %code=0
}
Quit $$$OK
}
/// Converts the input value <var>%val</var>, which represents a date, into <code>$H</code> format.
///
Returns the logical (<code>$H</code>) value of the input string <var>%val</var>.
ClassMethod DisplayToLogical(%val As %String) As %Date [ 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:$zdh(%val,,,5,80,20,,,""""))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zdh(%val,"_%parameter("FORMAT")_",,5,80,20,,,""""))"
QUIT $$$OK
}
/// Converts <var>%val</var> to a normalized value.
ClassMethod Normalize(%val As %String) As %Date [ CodeMode = expression ]
{
%val\\1
}
/// Tests if the logical value <var>%val</var>, which represents a date in <code>$H</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 %Date) As %Integer [ CodeMode = generator ]
{
n sep,str
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,0,"_%parameter("MINVAL")_","_%parameter("MAXVAL")_")"
s %code=str
QUIT $$$OK
}
/// Converts the value of <var>%val</var>, which is in logical <code>$H</code> 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 %Date) 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:$zd(%val,,,4))" QUIT $$$OK
s %code="$s(%val="""":"""",1:$zd(%val,"_%parameter("FORMAT")_",,4))"
QUIT $$$OK
}
/// Converts <var>%val</var>, which represents a date in logical <code>$H</code> format, into ODBC date format.
///
Returns the ODBC date string for the logical (<code>$H</code>) value <var>%val</var>.
ClassMethod LogicalToOdbc(%val As %Date = "") As %String [ CodeMode = expression ]
{
$s(%val="":"",1:$zd(%val,3))
}
/// Converts <var>%val</var>, which represents a date in ODBC format, into <code>$H</code> format.
///
Returns the <code>$H</code> value of the ODBC date string <var>%val</var>.
ClassMethod OdbcToLogical(%val As %String = "") As %Date [ CodeMode = expression ]
{
$s(%val="":"",1:$zdh(%val,3,,,,,,,"error: \'"_%val_"\' is an invalid date value"))
}
}
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

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