From 3b1023c45a919f25ef38c080f2ac2c0dc5d5e7ca Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 28 Aug 2011 19:52:02 +0200 Subject: (Preliminary) handling of weblog entry selection and summary. --- org/madore/damlengine/WeblogSummary.java | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 org/madore/damlengine/WeblogSummary.java (limited to 'org/madore/damlengine/WeblogSummary.java') 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 entries; + + private static WeblogSummary singleton; + + private WeblogSummary() { + this.entries = new HashMap(); + } + + 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; + } + +} -- cgit v1.2.3