public static SqliteDictionary FromPath(string path) { // Handle cases where paths are not normalized. path = System.IO.Path.GetFullPath(path); NullWeakReference<SqliteDictionary> weakRef; if(openDicts.TryGetValue(path, out weakRef) && weakRef.IsAlive && weakRef.Target.Connection.State == ConnectionState.Open) return weakRef.Target; var dict = new SqliteDictionary(path); openDicts[path] = new NullWeakReference<SqliteDictionary>(dict); return dict; }
public SqliteWordList CreateSet(string name, string author, string language, string url, DateTime?date) { long setID; using (var txn = Connection.BeginTransaction()) { ExecuteSQL("INSERT INTO Sets (Name, Author, Language, Url, Created) VALUES (?, ?, ?, ?, ?)", name, author, language, url, date.HasValue ? (object)date.Value : (object)DBNull.Value); setID = GetLastInsertRowID(); txn.Commit(); } var wl = SqliteWordList.FromSetID(this, setID); if (wl == null) { return(null); } wordLists[setID] = new NullWeakReference <SqliteWordList>(wl); return(wl); }
/// <param name="setID">The SetID of the word list</param> /// <returns>An existing SqliteWordList instance, if one exists, otherwise a newly-created SqliteWordList.</returns> public SqliteWordList GetWordList(long setID) { SqliteWordList wl = null; NullWeakReference <SqliteWordList> list; if (wordLists.TryGetValue(setID, out list)) { wl = list.Target; } if (wl != null) { return(wl); } wl = SqliteWordList.FromSetID(this, setID); if (wl == null) { return(null); } wordLists[setID] = new NullWeakReference <SqliteWordList>(wl); return(wl); }
private SimpleDictionary FromWeak(NullWeakReference<SimpleDictionary> weak) { var dict = weak.Target; if (dict != null) { if(!dict.Disposed) return dict; } return new SimpleDictionary(Path); }
public Info(SimpleDictionary dict) { Load(dict); // Keep a weak reference to the dictionary. This way we don't have to load the // dictionary again if we re-open it soon after we close it. var weak = new NullWeakReference<SimpleDictionary>(dict); GetFullInstance = () => FromWeak(weak); }
public SqliteWordList CreateSet(string name, string author, string language, string url, DateTime? date) { long setID; using (var txn = Connection.BeginTransaction()) { ExecuteSQL("INSERT INTO Sets (Name, Author, Language, Url, Created) VALUES (?, ?, ?, ?, ?)", name, author, language, url, date.HasValue ? (object)date.Value : (object)DBNull.Value); setID = GetLastInsertRowID(); txn.Commit(); } var wl = SqliteWordList.FromSetID(this, setID); if (wl == null) return null; wordLists[setID] = new NullWeakReference<SqliteWordList>(wl); return wl; }
/// <param name="setID">The SetID of the word list</param> /// <returns>An existing SqliteWordList instance, if one exists, otherwise a newly-created SqliteWordList.</returns> public SqliteWordList GetWordList(long setID) { SqliteWordList wl = null; NullWeakReference<SqliteWordList> list; if (wordLists.TryGetValue(setID, out list)) wl = list.Target; if (wl != null) return wl; wl = SqliteWordList.FromSetID(this, setID); if (wl == null) return null; wordLists[setID] = new NullWeakReference<SqliteWordList>(wl); return wl; }