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; } }