X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FSqliteDB.java;h=6167eecca06debee9c4e8d09e9877591e802b29f;hb=4b76a31e8f86bc8de673899bbb45252c01e9a0f6;hp=0ee1401ed0432d00f1b7a696310356b7446ec9cc;hpb=dc35603a5653271ba1fe5381c472e88c916a4b32;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/SqliteDB.java b/src/org/ibex/mail/SqliteDB.java index 0ee1401..6167eec 100644 --- a/src/org/ibex/mail/SqliteDB.java +++ b/src/org/ibex/mail/SqliteDB.java @@ -19,6 +19,8 @@ public class SqliteDB { private HashMap tables = new HashMap(); public static final int REAPER_INTERVAL_SECONDS = 60 * 60; + private static final int DAYS = 24 * 60 * 60 * 1000; + public static final int REAP_EXPIRATION = 5 * DAYS; public Connection getConnection() { return conn; } @@ -36,18 +38,29 @@ public class SqliteDB { conn.prepareStatement("PRAGMA cache_size="+Math.ceil(kilobytes/1.5)+";").executeUpdate(); } + + public void close(ResultSet rs) { + if (rs==null) return; + try { + rs.close(); + } catch (SQLException s) { + Log.error(ResultSet.class, s); + } + } + public SqliteDB(String filename) { this.filename = filename; try { + Log.error("start", "initializing " + filename); Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:"+filename); conn.prepareStatement("PRAGMA auto_vacuum = 1").executeUpdate(); - conn.prepareStatement("VACUUM").executeUpdate(); + //conn.prepareStatement("VACUUM").executeUpdate(); // until we have better assurances about locking on network filesystems... conn.prepareStatement("PRAGMA locking_mode = EXCLUSIVE").executeQuery(); - conn.prepareStatement("PRAGMA temp_store = MEMORY").executeUpdate(); + //conn.prepareStatement("PRAGMA temp_store = MEMORY").executeUpdate(); conn.prepareStatement("PRAGMA page_size=4096").executeUpdate(); conn.prepareStatement("PRAGMA cache_size=2000").executeUpdate(); ResultSet rs = conn.prepareStatement("PRAGMA integrity_check").executeQuery(); @@ -55,6 +68,7 @@ public class SqliteDB { String result = rs.getString(1); if (!result.equals("ok")) throw new RuntimeException("PRAGMA integrity_check returned \""+result+"\""); + Log.error(".", "done initializing " + filename); } catch (SQLException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } @@ -78,8 +92,9 @@ public class SqliteDB { ps.executeUpdate(); tables.put(name, this); } - public void createIndex(String name, String column) throws SQLException { - PreparedStatement ps = conn.prepareStatement("create index if not exists "+name+" on "+column); + public void createIndex(String column) throws SQLException { createIndex(column, column+"_index"); } + public void createIndex(String indexName, String column) throws SQLException { + PreparedStatement ps = conn.prepareStatement("create index if not exists "+column+" on "+name+" ("+indexName+")"); ps.executeUpdate(); } protected void reap(String reapColumn) { @@ -101,7 +116,7 @@ public class SqliteDB { try { Log.warn(Reaper.class, filename + " reaping..."); long when = System.currentTimeMillis(); - when -= 5 * 24 * 60 * 60 * 1000; + when -= REAP_EXPIRATION; synchronized(SqliteDB.this) { PreparedStatement ps = conn.prepareStatement("select count(*) from "+reapTable+" where "+reapColumn+"