+ private HashMap<Integer,Integer> imapToUid = new HashMap<Integer,Integer>();
+ private HashMap<Integer,Integer> uidToImap = new HashMap<Integer,Integer>();
+ private boolean imapNumberCacheValid = false;
+ public void updateImapNumberCache() throws SQLException {
+ synchronized(this) {
+ Log.warn(this+"", "rebuilding imapNumberCache...");
+ imapToUid.clear();
+ uidToImap.clear();
+ PreparedStatement q = conn.prepareStatement("select uid_ from mail");
+ ResultSet rs = q.executeQuery();
+ int num = 1;
+ while(rs.next()) {
+ imapToUid.put(num, rs.getInt(1));
+ uidToImap.put(rs.getInt(1), num);
+ num++;
+ }
+ imapNumberCacheValid = true;
+ }
+ }
+ public int queryImapNumberCache(int uid) throws SQLException {
+ synchronized(this) {
+ if (!imapNumberCacheValid) updateImapNumberCache();
+ Integer ret = uidToImap.get(uid);
+ if (ret == null) return -1;
+ return ret;
+ }
+ }
+ public int queryUidForImapNum(int imapNumber) throws SQLException {
+ synchronized(this) {
+ if (!imapNumberCacheValid) updateImapNumberCache();
+ Integer ret = imapToUid.get(imapNumber);
+ if (ret == null) return -1;
+ return ret;
+ }
+ }
+
+
+ public int maxuid() { return uidNext(); }