Exemple #1
0
        public DB GetDB(string filePath, Dictionary <string, string> options = null)
        {
            DB db = null;

            if (dbCache.ContainsKey(filePath))
            {
                DBLock lockObj = dbCache[filePath];
                // inc the lockcount
                lockObj.lockCount = lockObj.lockCount + 1;
                // save it back in the list
                dbCache[filePath] = lockObj;
                // store the db obj for return
                db = lockObj.DB;
            }
            else
            {
                // create the new DB
                Options levelDBOptions = new Options();
                levelDBOptions.CreateIfMissing = true;

                db = DB.Open(filePath, levelDBOptions);
                // create the new lock object
                DBLock lockObj = new DBLock();
                lockObj.DB = db;
                // store the new lock obj
                dbCache[filePath] = lockObj;
            }

            return(db);
        }
Exemple #2
0
        public void Close(string filePath)
        {
            if (dbCache.ContainsKey(filePath))
            {
                DBLock lockObj = dbCache[filePath];
                lockObj.lockCount -= 1;

                if (lockObj.lockCount > 0)
                {
                    dbCache[filePath] = lockObj;
                }
                else
                {
                    dbCache.Remove(filePath);
                    lockObj.DB.Dispose();
                }
            }
            else
            {
                throw new DBNotFoundException("Requested DB not found or already closed: " + filePath);
            }
        }
Exemple #3
0
        public DB GetDB(string filePath, Dictionary<string, string> options = null)
        {
            DB db = null;

            if (dbCache.ContainsKey(filePath))
            {
                DBLock lockObj = dbCache[filePath];
                // inc the lockcount
                lockObj.lockCount = lockObj.lockCount + 1;
                // save it back in the list
                dbCache[filePath] = lockObj;
                // store the db obj for return
                db = lockObj.DB;
            }
            else
            {
                // create the new DB
                Options levelDBOptions = new Options();
                levelDBOptions.CreateIfMissing = true;

                db = DB.Open(filePath, levelDBOptions);
                // create the new lock object
                DBLock lockObj = new DBLock();
                lockObj.DB = db;
                // store the new lock obj
                dbCache[filePath] = lockObj;
            }

            return db;
        }