public virtual bool saveFileData(IFileData fileData) { SqlFsErrCode.CurrentError = FsErr.OK; bool isOK = false; fsLocker.FsLock; SqlFsTransaction fsTran = new SqlFsTransaction(db); try { isOK = __saveFileData(fileData); if (isOK) { fsTran.fsOpSuccess(); } } finally { fsTran.dispose(); fsLocker.dispose(); } return(isOK); }
/// <summary> /// Save data to data block table /// </summary> private bool __saveFileData(IFileData fileData) { bool isOK = false; do { FsID dataBlockID = this.getDataBlockID(); if (dataBlockID.compare(SqlFsConst.INVALIDID) == 0) // new file without data will be -1 { SqlFsErrCode.CurrentError = FsErr.DataBlockIDNotValid; break; } FsID newDataBlockID = fileData.saveData(db, dataBlockID); if (newDataBlockID.compare(SqlFsConst.INVALIDID) <= 0) { SqlFsErrCode.CurrentError = FsErr.SaveFileDataErr; break; } // update file size this.setField(FSBLOCK.fsFileSize, fileData.DataSizeInByte); // update itself (data block table) so that last mod time can be updated this.setDataBlockID(newDataBlockID); isOK = true; } while (false); return(isOK); }
public static SqlFs create(string dbPath, IFileData dummyInst, Context ctxt, AtomicBoolean isNewTableCreated) { SqlFsErrCode.CurrentError = FsErr.OK; SqlFs fs = null; try { if (dbPath != null) { fs = new SqlFs(ctxt, dbPath); if (fs != null) { fs.fsLocker.FsLock; try { fs.open(); fs.prepare(dummyInst, isNewTableCreated); } finally { fs.fsLocker.dispose(); } } } } catch (Exception e) { SqlFsLog.debug("ERROR: Cannot open database, " + e.Message); SqlFsErrCode.CurrentError = FsErr.CannotOpenDB; } return(fs); }
/// <summary> /// Retrieve data from data block table /// </summary> private bool __getFileData(IFileData fileData) { FsID dataBlockID = this.getDataBlockID(); if (dataBlockID.compare(SqlFsConst.INVALIDID) <= 0) { SqlFsErrCode.CurrentError = FsErr.DataBlockIDNotValid; return(false); } return(fileData.getData(db, dataBlockID)); }
public virtual bool getFileData(IFileData fileData) { SqlFsErrCode.CurrentError = FsErr.OK; fsLocker.FsLock; try { return(__getFileData(fileData)); } finally { fsLocker.dispose(); } }
/// <summary> /// Prepare database tables if not already exists /// </summary> private void prepare(IFileData dummyInst, AtomicBoolean isNewTableCreated) { if (!checkTables()) { // create new tables db.execSQL(SqlStr.genCreateTable(DBNAMES.FsBlock.ToString(), COLFSBLOCK)); db.execSQL(SqlStr.genCreateTable(DBNAMES.FsInfo.ToString(), COLFSINFO)); db.execSQL(SqlStr.genCreateTable(IFileData.DTABLENAME, dummyInst.ColSchema)); // create root dir, too createRootDir(); // Write default info writeInfo(FSINFOFIELDS.version.ToString(), SqlFsVersion.SqlFsVersion); writeInfo(FSINFOFIELDS.createTimeUtc.ToString(), TimeConverter.calendarToReadableDateTime(DateTime.getInstance(TimeZone.getTimeZone("GMT+00:00")))); writeInfo(FSINFOFIELDS.fsLabel.ToString(), SqlFsConst.DEFFSLABEL); writeInfo(FSINFOFIELDS.IDSize.ToString(), Convert.ToString(FsID.IDSize)); isNewTableCreated.set(true); } }
/// /// @param [in] dbPath -- absolute or relative path (inside phone memory) to the db file </param> /// @param [in] dummyInst -- a dummy instance of a class inherited from IFileData. </param> public static SqlFs create(string dbPath, IFileData dummyInst, Context ctxt) { AtomicBoolean isNewTableCreated = new AtomicBoolean(false); return(SqlFs.create(dbPath, dummyInst, ctxt, isNewTableCreated)); }