summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogSummary.java
blob: 50ab14315678f52bfa26e2a0707462d06dd6e2b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.madore.damlengine;

import java.util.HashMap;
import java.util.HashSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public final class WeblogSummary {

    public static final class EntrySummary {
	int id;
	String date;
	String lang;
	String title;  String titleXml;
	String doSinglePage;
	HashSet<String> catSet;
	public EntrySummary(int id, String date, String lang,
			    String title, String titleXml,
			    String doSinglePage) {
	    this.id = id;
	    this.date = date;
	    this.lang = lang;
	    this.title = title;
	    this.titleXml = titleXml;
	    this.doSinglePage = doSinglePage;
	    this.catSet = null;
	}
    }

    public HashMap<Integer,EntrySummary> entries;

    private static WeblogSummary singleton;

    private WeblogSummary() {
	this.entries = new HashMap<Integer,EntrySummary>();
    }

    public static WeblogSummary getSummary() {
	if ( singleton != null )
	    return singleton;
	singleton = new WeblogSummary();
	try {
	    final Connection conn = WeblogDatabaseConnection.getConnection();
	    final PreparedStatement selSt
		= conn.prepareStatement("SELECT id , edate , lang , title , title_xml , do_single_page FROM entries");
	    final ResultSet selRes = selSt.executeQuery();
	    while ( selRes.next() ) {
		int id = selRes.getInt(1);
		String date = selRes.getString(2);
		String lang = selRes.getString(3);
		String title = selRes.getString(4);
		String titleXml = selRes.getString(5);
		String doSinglePage = selRes.getString(6);
		singleton.entries.put(id, new EntrySummary(id, date, lang, title, titleXml, doSinglePage));
	    }
	    final PreparedStatement catSt
		= conn.prepareStatement("SELECT id , code FROM incat");
	    final ResultSet catRes = catSt.executeQuery();
	    while ( catRes.next() ) {
		int id = catRes.getInt(1);
		String code = catRes.getString(2);
		HashSet<String> catSet = singleton.entries.get(id).catSet;
		if ( catSet == null ) {
		    catSet = new HashSet<String>();
		    singleton.entries.get(id).catSet = catSet;
		}
		catSet.add(code);
	    }
	} catch (SQLException e) {
	    // Well, we'll have no summary.  Too bad, but better than abort.
	    singleton = null;
	}
	return singleton;
    }

}