Beispiel #1
0
        /// <summary>
        /// Don't call any of the above when this one is called
        /// </summary>
        internal static void close(SqlFsLocker locker)
        {
            lock (typeof(SqlFsLocker))
            {
                if (lockerTable == null)
                {
                    return;
                }

                string tableKey = locker.TableKey;
                int?   count    = refCountTable[tableKey];
                if (count == null)
                {
                    return;
                }

                int newCount = (int)count - 1;
                if (newCount == 0)
                {
                    // remove all references
                    lockerTable.Remove(tableKey);
                    refCountTable.Remove(tableKey);
                    locker.close();
                }
                else
                {
                    // decrease reference count by 1
                    refCountTable[tableKey] = newCount;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get/create a named lock based on 'dbFullPath'
        /// Same 'dbFullPath' will get the same lock
        ///
        /// </summary>
        internal static SqlFsLocker getFsLocker(string dbFullPath)
        {
            lock (typeof(SqlFsLocker))
            {
                if (lockerTable == null)
                {
                    lockerTable = new Dictionary <string, SqlFsLocker>();
                }

                if (refCountTable == null)
                {
                    refCountTable = new Dictionary <string, int?>();
                }

                string      tableKey = SqlFsFunc.genHash(dbFullPath);
                SqlFsLocker locker   = lockerTable[tableKey];
                if (locker == null)
                {
                    locker = new SqlFsLocker(tableKey);
                    lockerTable[tableKey]   = locker;
                    refCountTable[tableKey] = 1;               // reference count 1
                }
                else
                {
                    // increase reference count by 1
                    int?count = refCountTable[tableKey];
                    refCountTable[tableKey] = (int)count + 1;
                }

                return(locker);
            }
        }
Beispiel #3
0
        //////////////////////////FS operations ///////////////////////////////////

        ///  @param [in] id -- get entry using ID directly </param>
        internal static SqlFsNode getFsNodeByID(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id)
        {
            SqlFsNode fsNode = null;

            string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsID.ToString(), "=", id));
            Cursor c      = null;

            try
            {
                c = db.query(SqlFs.DBNAMES.FsBlock.ToString(), new string[] { SqlFs.FSBLOCK.fsID.ToString(), SqlFs.FSBLOCK.fsType.ToString() }, @where, null, null, null, null);

                if (c.moveToFirst())
                {
                    fsNode = SqlFsNode.getFsNode(db, fsLocker, c);
                }
            }
            catch (Exception e)
            {
                SqlFsLog.debug(e);
                SqlFsErrCode.CurrentError = FsErr.GetFieldError;
            }
            finally
            {
                SqlFsFunc.close(c);
            }

            return(fsNode);
        }
Beispiel #4
0
 private void open()
 {
     this.db = SQLiteDatabase.openOrCreateDatabase(this.dbPath, null);
     if (this.fsLocker == null)
     {
         this.fsLocker = SqlFsLocker.getFsLocker(this.dbPath);
     }
 }
Beispiel #5
0
        private SqlFs(Context ctxt, string dbPath)
        {
            if (dbPath.StartsWith(SqlFsConst.STRPATHSEP))
            {
                this.dbPath = dbPath;           // use full path already
            }
            else
            {
                this.dbPath = ctxt.getDatabasePath(dbPath).AbsolutePath;
            }

            this.fsLocker = SqlFsLocker.getFsLocker(this.dbPath);
        }
Beispiel #6
0
        /// <summary>
        ///  Should close the DB after use.
        /// </summary>
        public virtual void close()
        {
            SqlFsErrCode.unset();

            SqlFsLocker.close(fsLocker);
            fsLocker = null;

            if (this.db != null)
            {
                this.db.close();
                this.db = null;
            }
        }
Beispiel #7
0
        /// <summary>
        ///  Get a fsNode from the result
        /// </summary>
        internal static SqlFsNode getFsNode(SQLiteDatabase db, SqlFsLocker fsLocker, Cursor c)
        {
            SqlFsNode fsNode = null;

            SqlFsConst.FSTYPE type = SqlFsConst.FSTYPE.toFSTYPE(c.getInt(SqlFs.FSBLOCK.fsType.ordinal()));

            if (type == SqlFsConst.FSTYPE.DIR)
            {
                fsNode = SqlDir.getDir(db, fsLocker, c);
            }
            else if (type == SqlFsConst.FSTYPE.FILE)
            {
                fsNode = SqlFile.getFile(db, fsLocker, c);
            }

            return(fsNode);
        }
Beispiel #8
0
 private SqlDir(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id) : base(db, fsLocker, id)
 {
 }
Beispiel #9
0
        internal static SqlDir getDir(SQLiteDatabase db, SqlFsLocker fsLocker, Cursor c)
        {
            FsID id = SqlFsFunc.getID(c, SqlFs.FSBLOCK.fsID.ordinal());

            return(SqlDir.getDir(db, fsLocker, id));
        }
Beispiel #10
0
        internal static SqlDir getDir(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id)
        {
            SqlDir d = new SqlDir(db, fsLocker, id);

            return(d);
        }
Beispiel #11
0
        internal static SqlFile getFile(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id)
        {
            SqlFile f = new SqlFile(db, fsLocker, id);

            return(f);
        }
Beispiel #12
0
 protected internal SqlFsNode(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id)
 {
     this.db       = db;
     this.fsLocker = fsLocker;
     this.id       = id;
 }