可使用特定于属性的 set 方法设置属性的新值,从而设置代理对象中的属性值。(不具有 set 方法的属性无法使用 Rational® CM API 进行设置。)在 set 方法中指定新值时,这些值将存储在代理中。在客户机应用程序调用代理对象上的 do 方法(例如 doWriteProperties 方法)之前,这些值不会写入其存储库中的实际资源。
必须调用 do 方法(如 doWriteProperties 方法)来更新产品存储库中的底层资源。此方法将代理中已更新的属性全部作为一个事务写入产品资源。 在代理中设置属性值时不会发生错误,但是在调用 do 方法时可能发生错误。此时,可能抛出异常。
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"其中:
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);
请参阅位置语法以获取更多信息。