X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FSqliteTable.java;h=4d32c90a6e2d1e17ace353a9635773d63b8f1e58;hb=cb49b344eae8996a3c9e5ad728d8e7c84714280e;hp=91dcb536749565f001f8439de4b1a0ca98704b3e;hpb=06d1018911eb66f68543d230d8f5ed48301f5885;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/SqliteTable.java b/src/org/ibex/mail/SqliteTable.java index 91dcb53..4d32c90 100644 --- a/src/org/ibex/mail/SqliteTable.java +++ b/src/org/ibex/mail/SqliteTable.java @@ -18,11 +18,19 @@ public class SqliteTable { private String reapTable; private String reapColumn; - public SqliteTable(String filename, String[] tables, String reapTable, String reapColumn) { - this(filename, tables, false, reapTable, reapColumn); + // check upstream: PRAGMA encoding = "UTF-8"; + // create indices + // PRAGMA auto_vacuum=1 (can only be set before any tables are created) + // periodic "PRAGMA integrity_check; "? + + public void setCacheSize(int kilobytes) throws SQLException { + conn.prepareStatement("PRAGMA cache_size="+Math.ceil(kilobytes/1.5)+";").executeUpdate(); + } + + public SqliteTable(String filename, String[] tables) { + this(filename, tables, false); } - public SqliteTable(String filename, String[] tables, boolean fastButDangerous, - String reapTable, String reapColumn) { + public SqliteTable(String filename, String[] tables, boolean fastButDangerous) { this.filename = filename; try { Class.forName("org.sqlite.JDBC"); @@ -37,37 +45,40 @@ public class SqliteTable { } catch (SQLException e) { throw new RuntimeException(e); } 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) - new Reaper().start(); + Main.cron.executeLater(1000 * REAPER_INTERVAL_SECONDS, new Reaper()); } public static final int REAPER_INTERVAL_SECONDS = 60 * 60; - private class Reaper extends Thread { - + private class Reaper implements Runnable { public void run() { - while(true) { - try { - try { Thread.sleep(1000 * REAPER_INTERVAL_SECONDS); } catch (Exception e) { }; - Log.warn(Reaper.class, filename + " reaping..."); - long when = System.currentTimeMillis(); - when -= 5 * 24 * 60 * 60 * 1000; - synchronized(SqliteTable.this) { - PreparedStatement ps = conn.prepareStatement("select count(*) from "+reapTable+" where "+reapColumn+"