| 1 | |
package org.paneris.bibliomania.loadtest; |
| 2 | |
|
| 3 | |
import java.io.FileOutputStream; |
| 4 | |
import java.io.ObjectOutputStream; |
| 5 | |
import java.io.Serializable; |
| 6 | |
import java.util.Enumeration; |
| 7 | |
import java.util.Vector; |
| 8 | |
|
| 9 | |
import org.melati.poem.AccessToken; |
| 10 | |
import org.melati.poem.Persistent; |
| 11 | |
import org.melati.poem.PoemTask; |
| 12 | |
import org.melati.poem.util.EnumUtils; |
| 13 | |
import org.melati.util.UnexpectedExceptionException; |
| 14 | |
import org.paneris.bibliomania.BibliomaniaDatabase; |
| 15 | |
import org.paneris.bibliomania.Book; |
| 16 | |
import org.paneris.bibliomania.Chapter; |
| 17 | |
import org.paneris.bibliomania.Unit; |
| 18 | |
|
| 19 | 0 | public class ExtractTree implements Serializable { |
| 20 | |
|
| 21 | |
private static final long serialVersionUID = 847223626240878960L; |
| 22 | |
|
| 23 | 0 | public DiscreteDistribution books = new DiscreteDistribution(); |
| 24 | |
public int searchsectiongroup; |
| 25 | |
|
| 26 | |
public void readDB() { |
| 27 | 0 | final BibliomaniaDatabase bib = new BibliomaniaDatabase(false); |
| 28 | 0 | bib.connect("bibliomania", "org.melati.poem.dbms.Postgresql", |
| 29 | |
"jdbc:postgresql:bibliomania", "postgres", "*",8); |
| 30 | 0 | bib.inSession( |
| 31 | |
AccessToken.root, |
| 32 | 0 | new PoemTask() { |
| 33 | |
@SuppressWarnings("unchecked") |
| 34 | |
public void run() { |
| 35 | |
try { |
| 36 | 0 | searchsectiongroup = |
| 37 | |
bib.getSearchSectionGroup().troid().intValue(); |
| 38 | |
|
| 39 | 0 | dobooks: for (Enumeration<Unit> e = bib.getBookTable().selection(); |
| 40 | 0 | e.hasMoreElements();) { |
| 41 | 0 | Book book = (Book)e.nextElement(); |
| 42 | |
|
| 43 | 0 | Vector<Chapter> chapters = EnumUtils.vectorOf(book.getChapters()); |
| 44 | 0 | if (chapters.size() > 0) { |
| 45 | 0 | ChapterDesc[] chapterDescs = new ChapterDesc[chapters.size()]; |
| 46 | 0 | for (int i = 0; i < chapterDescs.length; ++i) { |
| 47 | 0 | Chapter chapter = (Chapter)chapters.elementAt(i); |
| 48 | 0 | int p = chapter.totalPages(); |
| 49 | 0 | if (p == 0) continue dobooks; |
| 50 | 0 | chapterDescs[i] = new ChapterDesc(chapter.troid().intValue(), |
| 51 | |
chapter.totalPages()); |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | books.add( |
| 55 | |
new BookDesc( |
| 56 | |
book.getSection().getGroupTroid().intValue(), |
| 57 | |
book.getSectionTroid().intValue(), |
| 58 | |
book.getAuthorTroid().intValue(), |
| 59 | |
book.troid().intValue(), |
| 60 | |
chapterDescs)); |
| 61 | |
} |
| 62 | 0 | } |
| 63 | |
} |
| 64 | 0 | catch (Exception e) { |
| 65 | 0 | throw new UnexpectedExceptionException(e); |
| 66 | 0 | } |
| 67 | 0 | } |
| 68 | |
}); |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public static void main(String[] args) throws Exception { |
| 72 | 0 | ExtractTree t = new ExtractTree(); |
| 73 | 0 | t.readDB(); |
| 74 | 0 | ObjectOutputStream o = |
| 75 | |
new ObjectOutputStream(new FileOutputStream("books.ser")); |
| 76 | 0 | o.writeObject(t); |
| 77 | 0 | o.close(); |
| 78 | 0 | } |
| 79 | |
} |