X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FSqliteTable.java;h=98950f69b85433661c32307c711edca5f31324a6;hb=c173ef6beb59eca7da43b01632381a5dcf3235be;hp=085a9b6128a1bbfd6be9450f0798968292fe08c6;hpb=8f7212f973567b5caf9d8a4d7f9b5b400f53f44f;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/SqliteTable.java b/src/org/ibex/mail/SqliteTable.java index 085a9b6..98950f6 100644 --- a/src/org/ibex/mail/SqliteTable.java +++ b/src/org/ibex/mail/SqliteTable.java @@ -18,48 +18,64 @@ public class SqliteTable { private String reapTable; private String 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, String reapTable, String reapColumn) { + this(filename, tables, false, reapTable, reapColumn); + } + public SqliteTable(String filename, String[] tables, boolean fastButDangerous, + String reapTable, String reapColumn) { this.filename = filename; try { Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:"+filename); for(String s : tables) conn.prepareStatement(s).executeUpdate(); + conn.prepareStatement("PRAGMA temp_store = MEMORY").executeUpdate(); + conn.prepareStatement("PRAGMA page_size=4096").executeUpdate(); + conn.prepareStatement("PRAGMA cache_size=2000").executeUpdate(); + if (fastButDangerous) + conn.prepareStatement("PRAGMA synchronous = OFF").executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } 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+"