在設定方法中指定新的值時,該值會儲存在虛擬物件中。直到用戶端應用程式對虛擬物件呼叫執行方法(如: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 參數。
如果您不需先讀取現行值就知道要寫入什麼內容值,則不需要先呼叫 doReadProperties() 再呼叫 doWriteProperties()。在下列範例中,範例資料庫中「問題報告」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);
如需相關資訊,請參閱位置語法。