Dear Members,
I need to feed my database base with som input files (initially I have flat file, that I have converted to XML using
XMLConvert). I have now XML files like this:
Code:
<bookstore>
<book></book>
<book></book>
<book></book>
....
</bookstore>
I don't need to store the bookstores information just all the books information. So I don't need to load in memory the whole bookstore information at time, just each time the book information then to the database and again to take the next book.
Using Castor I don't see the way to do that without loading the hole XML file and I would like to unmarshal a
<book> node or a limit number of
<book> nodes for avoiding overflow then to store into the database.
The
<book> element has a very similar information to my Book class (generated using Hibernate Tool).
On Hibernate User Manual there is a section about XML mapping but they talk about the inverse process (marshal), so asking to the database and then having the result in XML format, but there is no comment about the inverse process.
I was looking into HyberJaxB:
http://www.hibernate.org/218.htmlbut it uses annotation and I have the constraint to use 1.4.* jdk version only.
My idea is to do something like this:
Code:
open file()
List books;
Book book;
int counter = 0;
int maxCounter = 0; // Maximum Bath size
while(there are book nodes pending for unmarshal) {
book = unmarshal();
books.add(book);
counter++;
if (counter == maxCounter) {
save (books)
counter = 0;
clear books list
}
}
close file()
so
1. open file
2. unmarshal books until the maximum batch size
3. Save the books into database
4. Go to 2 while there are books pending to unmarshal on the file.
5. Close file
Thanks in advance for any help,
David Leal