summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogSummary.java
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2011-08-28 19:52:02 +0200
committerDavid A. Madore <david+git@madore.org>2011-08-28 19:52:02 +0200
commit3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca (patch)
tree109f659090d4f08bc11f8da0f16fbff364dbbf9a /org/madore/damlengine/WeblogSummary.java
parent9c54e57c4a2e7029d8dbcd65ae63353135a18401 (diff)
downloaddamlengine-3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca.tar.gz
damlengine-3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca.tar.bz2
damlengine-3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca.zip
(Preliminary) handling of weblog entry selection and summary.
Diffstat (limited to 'org/madore/damlengine/WeblogSummary.java')
-rw-r--r--org/madore/damlengine/WeblogSummary.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/org/madore/damlengine/WeblogSummary.java b/org/madore/damlengine/WeblogSummary.java
new file mode 100644
index 0000000..ceaf28e
--- /dev/null
+++ b/org/madore/damlengine/WeblogSummary.java
@@ -0,0 +1,53 @@
+package org.madore.damlengine;
+
+import java.util.HashMap;
+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 title;
+ public EntrySummary(int id, String date, String title) {
+ this.id = id;
+ this.date = date;
+ this.title = title;
+ }
+ }
+
+ 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 , title FROM entries");
+ final ResultSet selRes = selSt.executeQuery();
+ while ( selRes.next() ) {
+ int id = selRes.getInt(1);
+ String date = selRes.getString(2);
+ String title = selRes.getString(3);
+ singleton.entries.put(new Integer(id), new EntrySummary(id, date, title));
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ // Well, we'll have no summary. Too bad, but better than abort.
+ // singleton = null;
+ }
+ return singleton;
+ }
+
+}