写属性

如果存在的话,可以使用特定于属性的 set 方法,借助 ClearQuest® CM API 为代理对象中的属性设置一个新值。那些不能有 set 方法的属性不能用 ClearQuest CM API 来设置。

set 方法中指定新值时,这些值将存储在代理中。在客户机应用程序调用代理对象上的 do 方法(例如 doWriteProperties 方法)之前,这些值不会写入其存储库中的实际资源。

必须调用 do 方法(如 doWriteProperties 方法)来更新产品存储库中的底层资源。此方法将代理中已更新的属性全部作为一个事务写入产品资源。 在代理中设置属性值时不会发生错误,但是在调用 do 方法时可能发生错误。此时,可能抛出异常。

以下示例将某些文本附加到资源的 Comment 属性:
PropertyRequest requestComment =
   new PropertyRequest (Resource.COMMENT );
Location location = myProvider.location(...);
Resource myResource = myProvider.resource(location);
myResource = myResource.doReadProperties(requestComment);
String comment = myResource.getComment();
myResource.setComment(comment + "addition to comment");
myResource.doWriteProperties(null);
doWriteProperties() 方法 具有 PropertyRequest 参数。

如果不首先读取当前值的情况下就已知道要写入哪些属性值,那么在调用 doWriteProperties() 之前不需要调用 doReadProperties()。在以下示例中,样本数据库中 Defect SAMPL00000005所有者字段设置为 user = admin

以下是记录位置的位置字符串语法:
cq.record:<record-type>/<record-id>@<db-set-name>/<database-name>
在本示例中,记录位置字符串为:
"cq.record:Defect/SAMPL00000005@7.0.0/SAMPL"
其中: Resource.setProperty 方法用作特定于接口的 set 方法的备用方法。
CqRecord myRecord = myCqProvider.cqRecord(myProvider.stpLocation("cq.record:Defect/SAMPL00000005@7.0.0/SAMPL"));
PropertyName<CqRecord> OWNER = new FieldName<CqRecord>("Owner");

myRecord.setProperty(OWNER, myProvider.buildProxy(CqRecord.class, "cq.record:users/admin@7.0.0/SAMPL"));
myRecord.doWriteProperties(null);

请参阅位置语法以获取更多信息。


反馈