檢索變化歷史
為檢索指定領域對象的歷史版本,需要調用SVNManager類的getRevisionLog方法; SVNRepository類的getLatestRevision方法可以得到當前版本號;SVNManager.log方法可以檢索每個版本的日志,日志可以包含版本修訂的日期、修改人、修改的內容等信息;SVNManager.getFile方法可以從Subversion倉庫中取得領域對象指定版本的所有內容。
obj, long startRevision,
long endRevision) {
.....
if(endRevision==-1) {
//obtain the latest revision from
//the repository
endRevision =
theRepository.getLatestRevision();
}
//retrieve the various log entries for
//the particular object path
Collection revisionLogs = theRepository.
log(new String[] {path}, null,
startRevision, endRevision,
false, true);
....
//Obtain the contents of the object at
//the specified revision
theRepository.getFile(path, revisionInfo.
getRevisionNumber(),
new Properties(),
xmlFileContentsStream);
....
}
檢索版本間的差異
SVNManager.showDifferences方法用來檢測兩個版本之間的差異,是通過調用JavaSVN 的SVNDiffManager類來去的差異,也可以通過SVNClientManager來引用并執行這個類,SVNDiffManager的doDiff方法有一個默認的實現,可以通過參數指定輸出流參數的形式取得固定格式的差異結果,我們也可以使用ISVNEditor來實現一個自己的差異比較方法。在這個例子里,我們使用默認的實現。
BaseTrackingObject obj,long revision1,
long revision2) {
....
//Create an instance of SVNClientManager
//providing authentication
SVNClientManager ourClientManager =
SVNClientManager.newInstance(
options, "name", "password");
//Obtain the handle to DiffClient
//from the client manager
SVNDiffClient theDiff = ourClientManager
.getDiffClient();
....
theDiff.doDiff(svnUrl, SVNRevision.
create(revision1), svnUrl,
SVNRevision.create(revision2),
false, false, diffStream);
....
}
結論
在企業級應用里,不但要完成數據的存儲和檢索,還要實現對數據變化歷史的跟蹤。傳統方法是使用關系數據庫來完成這個工作,但是這不是一個“優雅”的方案。在我們的貸款數據處理的例子里,Subversion提供了跟蹤數據變化的支持。JavaSVN的API用來完成數據存儲、檢索、獲取版本間差異和日志等任務。
我們的例子只是一個簡單的性能演示,Subversion提供了豐富的功能支持,完全可以應用于企業級應用。祝你探索地更開心!
資源
+本文的范例代碼和相關的安裝介紹
+Matrix Java社區:http://www.matrix.org.cn
+在www.chq.name也可以得到部分相關資源和信息
關于作者
Swaminathan Radhakrishnan works as a senior technical architect for Infosys Technologies, Ltd.
Swaminathan Radhakrishnan 本文作者,Infosys技術有限公司的資深技術架構師
陳海青(joson),本文譯者,生活在中國的山東省煙臺市,先后從事軟件開發、數據庫管理、系統管理等工作,2001年獲得高級程序員資格。
文章來源于領測軟件測試網 http://www.kjueaiud.com/