diff --git a/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactQuery.java b/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactQuery.java index 3ebc045d9..c03225dae 100644 --- a/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactQuery.java +++ b/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactQuery.java @@ -50,77 +50,87 @@ public ThunderbirdContactQuery(ThunderbirdContactSourceService owner, @Override protected void run() { - String file = super.getContactSource().getFilename(); + String filename = super.getContactSource().getFilename(); + File file = new File(filename); try { - // parse the Thunderbird Mork database - InputStreamReader sr = - new InputStreamReader(new FileInputStream(file)); - MorkDocument md = new MorkDocument(sr); - sr.close(); - - // We now have rows in their tables and additional rows at - // transaction level. Put the to a better format: - // DB -> Tables -> Rows - Map> db = - new HashMap>(); - for (Table t : md.getTables()) + if (file.lastModified() > getContactSource().lastDatabaseFileChange) { - String tableId = t.getTableId() + "/" + t.getScopeName(); - Map table = db.get(tableId); - if (table == null) + // parse the Thunderbird Mork database + InputStreamReader sr = + new InputStreamReader(new FileInputStream(filename)); + MorkDocument md = new MorkDocument(sr); + sr.close(); + + // We now have rows in their tables and additional rows at + // transaction level. Put the to a better format: + // DB -> Tables -> Rows + Map> db = + new HashMap>(); + for (Table t : md.getTables()) { - table = new HashMap(); - db.put(tableId, table); + String tableId = t.getTableId() + "/" + t.getScopeName(); + Map table = db.get(tableId); + if (table == null) + { + table = new HashMap(); + db.put(tableId, table); + } + + for (Row r : t.getRows()) + { + String scope = r.getScopeName(); + if (scope == null) + { + scope = t.getScopeName(); + } + + table.put(r.getRowId() + "/" + scope, r); + } } - - for (Row r : t.getRows()) + + // The additional rows at the root-level update/replace the ones + // in the tables. There's usually neither a table nor a scope + // defined, so lets just use the default. + String defaultScope = md.getDicts().get(0).dereference("^80"); + for (Row r : md.getRows()) { String scope = r.getScopeName(); if (scope == null) { - scope = t.getScopeName(); + scope = defaultScope; } - - table.put(r.getRowId() + "/" + scope, r); - } - } - - // The additional rows at the root-level update/replace the ones in - // the tables. There's usually neither a table nor a scope defined, - // so lets just use the default. - String defaultScope = md.getDicts().get(0).dereference("^80"); - for (Row r : md.getRows()) - { - String scope = r.getScopeName(); - if (scope == null) - { - scope = defaultScope; - } - - String tableId = "1/" + scope; - Map table = db.get(tableId); - if (table == null) - { - table = new HashMap(); - db.put(tableId, table); - } - - String rowId = r.getRowId() + "/" + scope; - if (rowId.startsWith("-")) - { - rowId = rowId.substring(1); + + String tableId = "1/" + scope; + Map table = db.get(tableId); + if (table == null) + { + table = new HashMap(); + db.put(tableId, table); + } + + String rowId = r.getRowId() + "/" + scope; + if (rowId.startsWith("-")) + { + rowId = rowId.substring(1); + } + + table.put(rowId, r); } - table.put(rowId, r); + super.getContactSource().database = db; + super.getContactSource().defaultScope = defaultScope; + super.getContactSource().lastDatabaseFileChange = + file.lastModified(); } // okay, "transactions" are applied, now perform the search - for (Entry> table : db.entrySet()) + for (Entry> table + : super.getContactSource().database.entrySet()) { for (Map.Entry e : table.getValue().entrySet()) { - if (e.getKey().endsWith(defaultScope)) + if (e.getKey().endsWith(getContactSource().defaultScope)) { readEntry(e.getValue()); } diff --git a/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactSourceService.java b/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactSourceService.java index 5d3ed1e1e..b60492d56 100644 --- a/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactSourceService.java +++ b/src/net/java/sip/communicator/plugin/thunderbird/ThunderbirdContactSourceService.java @@ -6,10 +6,12 @@ */ package net.java.sip.communicator.plugin.thunderbird; +import java.util.Map; import java.util.regex.*; import org.jitsi.service.configuration.*; +import mork.Row; import net.java.sip.communicator.service.contactsource.*; /** @@ -72,6 +74,19 @@ public class ThunderbirdContactSourceService /** Value of property {@link #PNAME_PREFIX} */ private String prefix; + /** Date/time when the Thunderbird database file was last changed. */ + long lastDatabaseFileChange = 0; + + /** + * The parsed Thunderbird database. This field is used as a cache and set by + * the query. It is re-set when the file date is newer than + * {@link #lastDatabaseFileChange} + */ + Map> database; + + /** Name of the default namespace in the Thunderbird database. */ + String defaultScope; + /** * Creates a new instance of this class. *