庫的初始化工作要首先調用的是方法DAVRepositoryFactory.setup()。SVNRepository類包含了所有直接訪問Subversion倉庫的方法,將Subversion倉庫樹狀結構的根路徑提供給SVNRepositoryFactory類后,就完成了這個類的初始化,而ISVNAuthenticationManager類的作用是向SVNRepository提供訪問Subversion倉庫的授權信息。
//initialize the system to work over http
DAVRepositoryFactory.setup();
............
//point to the root folder of repository
SVNURL svnUrl = SVNURL.parseURIEncoded
("http://localhost/repos/");
//initialize the SVNRepository
theRepository = SVNRepositoryFactory.
create(svnUrl);
//Creates the Auth manager with our user
//and password credentials
ISVNAuthenticationManager authManager =
new BasicAuthenticationManager
(name, password);
//provides the credentials to the
//SVNRepository
theManager.setAuthenticationManager
(authManager);
........
}
在Subversion中存儲數據
Subversion需要使用層次結構存儲數據,這樣我們先要設定一下領域實體的層次結構,這里使用一個命名為“DomainObjects”的文件夾來存放領域數據。領域對象類將會檢測這個目錄下存放領域對象的所有子目錄,而每個獨立的域對象被以XML格式進行存儲,并以其主鍵進行命名。
為存儲LoanData域對象,我們先要執行SVNManager對象的checkInObject方法,通過SVNRepository 執行的ISVNEditor對象來在Subversion倉庫中的建立和更新域對象的版本,但只有在closeEdit被調用后,才會提交所有的操作。SVNDeltaGenerator類用于獲取當前版本與被更新版本之間的差異,Subversion通過存儲版本間差異部分的形式存放新的版本,這樣會使提高網絡效率。
BaseTrackingObject obj){
.....
//Obtain the editor handle from the
//repository
ISVNEditor editor = theRepository.
getCommitEditor(obj.
getModificationReason(), null);
....
//create the file at the specified path
editor.addFile(path, null, -1);
}
else {
//file is already present, so open
//the file in the repository
editor.openFile(path, -1);
}
....
String checksum = deltaGenerator.
sendDelta(path,
new ByteArrayInputStream(
obj.getXmlRepresentation().
getBytes()),
editor, true);
.....
editor.closeEdit();
...
}
文章來源于領測軟件測試網 http://www.kjueaiud.com/