X-Git-Url: http://git.megacz.com/?p=org.ibex.mail.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FSqliteDB.java;h=e5fbc683fa4d082de1a096603742ecc46304e207;hp=39acded579675401d3f2d715f83a14fecb0d2c78;hb=24ff72d2529147b2dcbda9bfed28836bb674c6ad;hpb=4ca1c5dde661520f29ec5faf80db43e1a68aeb5f diff --git a/src/org/ibex/mail/SqliteDB.java b/src/org/ibex/mail/SqliteDB.java index 39acded..e5fbc68 100644 --- a/src/org/ibex/mail/SqliteDB.java +++ b/src/org/ibex/mail/SqliteDB.java @@ -15,8 +15,18 @@ public class SqliteDB { protected Connection conn; private String filename; - private String reapTable; - private String reapColumn; + + private HashMap tables = new HashMap(); + + public static final int REAPER_INTERVAL_SECONDS = 60 * 60; + + public Connection getConnection() { return conn; } + + public synchronized SqliteTable getTable(String name) { + SqliteTable ret = tables.get(name); + if (ret==null) ret = new SqliteTable(name); + return ret; + } // check upstream: PRAGMA encoding = "UTF-8"; // create indices @@ -47,18 +57,28 @@ public class SqliteDB { catch (ClassNotFoundException e) { throw new RuntimeException(e); } } - protected void reap(String reapTable, String reapColumn) { - if (this.reapTable != null || this.reapColumn != null) - throw new RuntimeException("reapTable/reapColumn already set"); - this.reapTable = reapTable; - this.reapColumn = reapColumn; - if (reapTable != null && reapColumn != null) - Main.cron.executeLater(1000 * REAPER_INTERVAL_SECONDS, new Reaper()); + public class SqliteTable { + public final String name; + private String reapColumn = null; + private SqliteTable(String name) { + this.name = name; + tables.put(name, this); + } + protected void reap(String reapColumn) { + if (this.reapColumn != null) throw new RuntimeException("reapColumn already set"); + this.reapColumn = reapColumn; + Main.cron.executeLater(1000 * REAPER_INTERVAL_SECONDS, new Reaper(name, reapColumn)); + } } - public static final int REAPER_INTERVAL_SECONDS = 60 * 60; - + // FIXME: desynchronized access to the conn? private class Reaper implements Runnable { + public Reaper(String reapTable, String reapColumn) { + this.reapTable = reapTable; + this.reapColumn = reapColumn; + } + private String reapTable; + private String reapColumn; public void run() { try { Log.warn(Reaper.class, filename + " reaping...");