1 | |
package org.paneris.bibliomania; |
2 | |
|
3 | |
import java.util.Vector; |
4 | |
|
5 | |
import org.melati.Melati; |
6 | |
import org.melati.poem.PoemThread; |
7 | |
import org.melati.poem.util.EnumUtils; |
8 | |
import org.melati.util.ThrowingPrintWriter; |
9 | |
import org.melati.util.UnexpectedExceptionException; |
10 | |
import org.webmacro.WebMacroException; |
11 | |
import org.webmacro.servlet.WebContext; |
12 | |
|
13 | 0 | public class FixTextID extends BibliomaniaServlet { |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
private static final long serialVersionUID = 1L; |
19 | |
|
20 | |
protected String bibliomaniaHandle(Melati melati, WebContext context) |
21 | |
throws WebMacroException { |
22 | |
|
23 | |
ThrowingPrintWriter p; |
24 | |
|
25 | |
try { |
26 | 0 | context.getResponse().setContentType("text/plain"); |
27 | 0 | p = new ThrowingPrintWriter(context.getResponse().getWriter(), |
28 | |
"servlet output"); |
29 | |
} |
30 | 0 | catch (Exception e) { |
31 | 0 | throw new UnexpectedExceptionException(e); |
32 | 0 | } |
33 | |
|
34 | 0 | Integer diag = null; |
35 | 0 | long what = 0; |
36 | |
|
37 | |
try { |
38 | 0 | ChapterTable chapters = |
39 | |
((BibliomaniaDatabase)melati.getDatabase()).getChapterTable(); |
40 | |
|
41 | 0 | Vector all = EnumUtils.vectorOf(chapters.selection("textid is null")); |
42 | |
|
43 | 0 | for (int i = 0; i < all.size(); ++i) { |
44 | 0 | if (i % 200 == 0) { |
45 | 0 | PoemThread.commit(); |
46 | 0 | p.println("Done " + i); |
47 | 0 | p.flush(); |
48 | |
} |
49 | |
|
50 | 0 | Chapter chapter = (Chapter)all.elementAt(i); |
51 | 0 | diag = chapter.troid(); |
52 | 0 | chapter.setTextid(what = chapter.ftiTextID()); |
53 | |
} |
54 | |
|
55 | 0 | PoemThread.commit(); |
56 | |
|
57 | 0 | p.println("Finished successfully"); |
58 | |
} |
59 | 0 | catch (Exception e) { |
60 | 0 | p.println("\nAt record " + diag + " " + what + " (" + Long.toString(what, 2) + "):\n"); |
61 | 0 | e.printStackTrace(p); |
62 | 0 | } |
63 | |
|
64 | 0 | return null; |
65 | |
} |
66 | |
} |