0
我是存在db的初學者。我正在通過Java構建一個XML文檔。我通過JAXB處理數據,然後通過插入更新插入到exists-db資源。目前我正在測試大約500個節點,並且在幾十個執行完成後,每插入一次最多需要10秒。我的XML具有以下一般結構。存在db更新插入很慢
<realestatedata>
<agents>
<author id="1">
<name>Author_A</name>
</author>
<author id="2">
<name>Author_B</name>
</author>
<portal id="1">
<name>Portal_A</name>
</portal>
</agents>
<artifacts>
<document id="1">
<latitude>51.37392</latitude>
<longitude>-0.00866</longitude>
<bathroom_number>1</bathroom_number>
<bedroom_number>3</bedroom_number>
<price>365000</price>
</document>
<theme id="1">
<name>Garden</name>
</theme>
<place id="1">
<name>BR4</name>
<location>
<lat>51.37392</lat>
<lon>-0.00866</lon>
</location>
</place>
</artifacts>
</realestatedata>
爲了確保元件被放置在正確的順序中,我使用的嵌件更新下面的代碼,以便它的類型的一個新的記錄是第一一個或基於IDS相似的元件的端部被附加。
public void saveAuthor(Author author) {
XQueryService xQueryService = null;
CompiledExpression compiled = null;
int currentId = authorIdSequence.get();
StringWriter authorXml = new StringWriter();
try {
xQueryService = Utils.getXQeuryService();
if (getAuthorByName(author.getName()) == null) {
author.setId(String.valueOf(authorIdSequence.incrementAndGet()));
marshaller.marshal(author, authorXml);
if(currentId == 0){
compiled = xQueryService
.compile("update insert " + authorXml.toString()
+ " into //agents");
}
else{
compiled = xQueryService
.compile("update insert " + authorXml.toString()
+ " following //author[@id = '"+String.valueOf(currentId)+"']");
}
xQueryService.execute(compiled);
}
} catch (XMLDBException e) {
e.printStackTrace();
} catch (JAXBException e) {
e.printStackTrace();
}
}
對文檔,地點等其他元素執行相同的方法。在幾次更新後,它變得非常緩慢。它開始需要長達十秒鐘來插入一條記錄。
只有我能找到的相關鏈接沒有回答。