Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
nsMsgFolderCache Class Reference

#include <nsMsgFolderCache.h>

Inheritance diagram for nsMsgFolderCache:
Inheritance graph
[legend]
Collaboration diagram for nsMsgFolderCache:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgFolderCache ()
virtual ~nsMsgFolderCache ()
void Init (in nsIFileSpec fileSpec)
nsIMsgFolderCacheElement GetCacheElement (in string key, in boolean createIfMissing)
void clear ()
void close ()
void commit (in boolean compress)
void removeElement (in string key)

Protected Member Functions

nsresult AddCacheElement (const char *key, nsIMdbRow *row, nsIMsgFolderCacheElement **result)
nsresult RowCellColumnToCharPtr (nsIMdbRow *hdrRow, mdb_token columnToken, char **resultPtr)
nsresult InitMDBInfo ()
nsresult InitNewDB ()
nsresult InitExistingDB ()
nsresult OpenMDB (const char *dbName, PRBool create)
nsIMdbEnvGetEnv ()
nsIMdbStoreGetStore ()

Static Protected Member Functions

static nsIMdbFactoryGetMDBFactory ()

Protected Attributes

nsFileSpec m_dbFileSpec
nsSupportsHashtable * m_cacheElements
nsIMdbEnvm_mdbEnv
nsIMdbStorem_mdbStore
nsIMdbTablem_mdbAllFoldersTable
mdb_token m_folderRowScopeToken
mdb_token m_folderTableKindToken

Friends

class nsMsgFolderCacheElement

Detailed Description

Definition at line 49 of file nsMsgFolderCache.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsMsgFolderCache.cpp.


Member Function Documentation

nsresult nsMsgFolderCache::AddCacheElement ( const char *  key,
nsIMdbRow row,
nsIMsgFolderCacheElement **  result 
) [protected]

Definition at line 439 of file nsMsgFolderCache.cpp.

{
       nsMsgFolderCacheElement *cacheElement = new nsMsgFolderCacheElement;

       if (cacheElement)
       {
              cacheElement->SetMDBRow(row);
              cacheElement->SetOwningCache(this);
              nsCAutoString hashStrKey(key);
              // if caller didn't pass in key, try to get it from row.
              if (!key)
              {
                     char *existingKey = nsnull;
                     cacheElement->GetStringProperty("key", &existingKey);   
                     cacheElement->SetKey(existingKey);
                     hashStrKey = existingKey;
                     PR_Free(existingKey);
              }
              else
                     cacheElement->SetKey((char *) key);
              nsCOMPtr<nsISupports> supports(do_QueryInterface(cacheElement));
              if(supports)
              {
                     nsCStringKey hashKey(hashStrKey);
                     m_cacheElements->Put(&hashKey, supports);
              }
              if (result)
              {
                     *result = cacheElement;
                     NS_ADDREF(*result);
              }
              return NS_OK;
       }
       else
              return NS_ERROR_OUT_OF_MEMORY;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgFolderCache::clear ( ) [inherited]
void nsIMsgFolderCache::close ( ) [inherited]
void nsIMsgFolderCache::commit ( in boolean  compress) [inherited]
nsIMsgFolderCacheElement nsIMsgFolderCache::GetCacheElement ( in string  key,
in boolean  createIfMissing 
) [inherited]
nsIMdbEnv* nsMsgFolderCache::GetEnv ( ) [inline, protected]

Definition at line 71 of file nsMsgFolderCache.h.

{return m_mdbEnv;}

Here is the caller graph for this function:

Definition at line 109 of file nsMsgFolderCache.cpp.

{
       if (!gMDBFactory)
       {
              nsresult rv;
              nsCOMPtr <nsIMdbFactoryFactory> factoryfactory = do_CreateInstance(kMorkCID, &rv);
              if (NS_SUCCEEDED(rv) && factoryfactory)
                rv = factoryfactory->GetMdbFactory(&gMDBFactory);
       }
       return gMDBFactory;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIMdbStore* nsMsgFolderCache::GetStore ( ) [inline, protected]

Definition at line 72 of file nsMsgFolderCache.h.

{return m_mdbStore;}

Here is the caller graph for this function:

void nsIMsgFolderCache::Init ( in nsIFileSpec  fileSpec) [inherited]

Definition at line 162 of file nsMsgFolderCache.cpp.

{
       nsresult err = NS_OK;

       err = InitMDBInfo();
       if (err == NS_OK)
       {
              err = GetStore()->GetTable(GetEnv(), &m_allFoldersTableOID, &m_mdbAllFoldersTable);
              if (NS_SUCCEEDED(err) && m_mdbAllFoldersTable)
              {
                     nsIMdbTableRowCursor* rowCursor = nsnull;
                     err = m_mdbAllFoldersTable->GetTableRowCursor(GetEnv(), -1, &rowCursor);
                     if (NS_SUCCEEDED(err) && rowCursor)
                     {
                            // iterate over the table rows and create nsMsgFolderCacheElements for each.
                            while (PR_TRUE)
                            {
                                   nsresult rv;
                                   nsIMdbRow* hdrRow;
                                   mdb_pos rowPos;

                                   rv = rowCursor->NextRow(GetEnv(), &hdrRow, &rowPos);
                                   if (NS_FAILED(rv) || !hdrRow)
                                          break;

                                   rv = AddCacheElement(nsnull, hdrRow, nsnull);
                                        hdrRow->Release();
                                   if (NS_FAILED(rv))
                                          return rv;
                            }
                            rowCursor->Release();
                     }
              }
    else
      err = NS_ERROR_FAILURE;
       }
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 122 of file nsMsgFolderCache.cpp.

{
       nsresult err = NS_OK;

       if (GetStore())
       {
              err    = GetStore()->StringToToken(GetEnv(), kFoldersScope, &m_folderRowScopeToken); 
              if (err == NS_OK)
              {
                     err = GetStore()->StringToToken(GetEnv(), kFoldersTableKind, &m_folderTableKindToken); 
                     if (err == NS_OK)
                     {
                            // The table of all message hdrs will have table id 1.
                            m_allFoldersTableOID.mOid_Scope = m_folderRowScopeToken;
                            m_allFoldersTableOID.mOid_Id = 1;
                     }
              }
       }
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 144 of file nsMsgFolderCache.cpp.

{
       nsresult err = NS_OK;

       err = InitMDBInfo();
       if (err == NS_OK)
       {
              nsIMdbStore *store = GetStore();
              // create the unique table for the dbFolderInfo.
              mdb_err mdberr;

        mdberr = (nsresult) store->NewTable(GetEnv(), m_folderRowScopeToken, 
                     m_folderTableKindToken, PR_FALSE, nsnull, &m_mdbAllFoldersTable);

       }
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgFolderCache::OpenMDB ( const char *  dbName,
PRBool  create 
) [protected]

Definition at line 201 of file nsMsgFolderCache.cpp.

{
       nsresult ret=NS_OK;
       nsIMdbFactory *myMDBFactory = GetMDBFactory();
       if (myMDBFactory)
       {
              ret = myMDBFactory->MakeEnv(nsnull, &m_mdbEnv);
              if (NS_SUCCEEDED(ret))
              {
                     nsIMdbThumb *thumb = nsnull;
                     char   *nativeFileName = nsCRT::strdup(dbName);
                     nsIMdbHeap* dbHeap = 0;
                     mdb_bool dbFrozen = mdbBool_kFalse; // not readonly, we want modifiable

                     if (!nativeFileName)
                            return NS_ERROR_OUT_OF_MEMORY;

                     if (m_mdbEnv)
                            m_mdbEnv->SetAutoClear(PR_TRUE);
                     if (exists)
                     {
                            mdbOpenPolicy inOpenPolicy;
                            mdb_bool      canOpen;
                            mdbYarn              outFormatVersion;
                            
                            nsIMdbFile* oldFile = 0;
                            ret = myMDBFactory->OpenOldFile(m_mdbEnv, dbHeap, nativeFileName,
                                    dbFrozen, &oldFile);
                            if ( oldFile )
                            {
                                   if ( ret == NS_OK )
                                   {
                                          ret = myMDBFactory->CanOpenFilePort(m_mdbEnv, oldFile, // file to investigate
                                                 &canOpen, &outFormatVersion);
                                          if (ret == 0 && canOpen)
                                          {
                                                 inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
                                                 inOpenPolicy.mOpenPolicy_MinMemory = 0;
                                                 inOpenPolicy.mOpenPolicy_MaxLazy = 0;

                                                 ret = myMDBFactory->OpenFileStore(m_mdbEnv, NULL, oldFile, &inOpenPolicy, 
                                                                             &thumb); 
                                          }
                                          else
                                                 ret = NS_MSG_ERROR_FOLDER_SUMMARY_OUT_OF_DATE;
                                   }
                                   NS_RELEASE(oldFile); // always release our file ref, store has own
                            }
                     }
                     if (NS_SUCCEEDED(ret) && thumb)
                     {
                            mdb_count outTotal;    // total somethings to do in operation
                            mdb_count outCurrent;  // subportion of total completed so far
                            mdb_bool outDone = PR_FALSE;      // is operation finished?
                            mdb_bool outBroken;     // is operation irreparably dead and broken?
                            do
                            {
                                   ret = thumb->DoMore(m_mdbEnv, &outTotal, &outCurrent, &outDone, &outBroken);
                                   if (ret != 0)
                                   {// mork isn't really doing NS erorrs yet.
                                          outDone = PR_TRUE;
                                          break;
                                   }
                            }
                            while (NS_SUCCEEDED(ret) && !outBroken && !outDone);
//                          m_mdbEnv->ClearErrors(); // ### temporary...
                            if (NS_SUCCEEDED(ret) && outDone)
                            {
                                   ret = myMDBFactory->ThumbToOpenStore(m_mdbEnv, thumb, &m_mdbStore);
                                   if (ret == NS_OK && m_mdbStore)
                                          ret = InitExistingDB();
                            }
#ifdef DEBUG_bienvenu1
                            DumpContents();
#endif
                     }
                     else // ### need error code saying why open file store failed
                     {
                            nsIMdbFile* newFile = 0;
                            ret = myMDBFactory->CreateNewFile(m_mdbEnv, dbHeap, dbName, &newFile);
                            if ( newFile )
                            {
                                   if (ret == NS_OK)
                                   {
                                          mdbOpenPolicy inOpenPolicy;

                                          inOpenPolicy.mOpenPolicy_ScopePlan.mScopeStringSet_Count = 0;
                                          inOpenPolicy.mOpenPolicy_MinMemory = 0;
                                          inOpenPolicy.mOpenPolicy_MaxLazy = 0;

                                          ret = myMDBFactory->CreateNewFileStore(m_mdbEnv, dbHeap,
                                                  newFile, &inOpenPolicy, &m_mdbStore);
                                          if (ret == NS_OK)
                                                 ret = InitNewDB();
                                   }
                                   NS_RELEASE(newFile); // always release our file ref, store has own
                            }

                     }
                     NS_IF_RELEASE(thumb);
                     nsCRT::free(nativeFileName);
              }
       }
       return ret;
}

Here is the call graph for this function:

nsresult nsMsgFolderCache::RowCellColumnToCharPtr ( nsIMdbRow hdrRow,
mdb_token  columnToken,
char **  resultPtr 
) [protected]

Definition at line 476 of file nsMsgFolderCache.cpp.

{
       nsresult      err = NS_OK;
       nsIMdbCell    *hdrCell;

       if (hdrRow)   // ### probably should be an error if hdrRow is NULL...
       {
              err = hdrRow->GetCell(GetEnv(), columnToken, &hdrCell);
              if (err == NS_OK && hdrCell)
              {
                     struct mdbYarn yarn;
                     hdrCell->AliasYarn(GetEnv(), &yarn);
                     char *result = (char *) PR_Malloc(yarn.mYarn_Fill + 1);
                     if (result)
                     {
                            memcpy(result, yarn.mYarn_Buf, yarn.mYarn_Fill);
                            result[yarn.mYarn_Fill] = '\0';
                     }
                     else
                            err = NS_ERROR_OUT_OF_MEMORY;

                     *resultPtr = result;
                     hdrCell->Release(); // always release ref
              }
       }
       return err;
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class nsMsgFolderCacheElement [friend]

Definition at line 53 of file nsMsgFolderCache.h.


Member Data Documentation

nsSupportsHashtable* nsMsgFolderCache::m_cacheElements [protected]

Definition at line 75 of file nsMsgFolderCache.h.

Definition at line 74 of file nsMsgFolderCache.h.

Definition at line 80 of file nsMsgFolderCache.h.

Definition at line 81 of file nsMsgFolderCache.h.

Definition at line 79 of file nsMsgFolderCache.h.

Definition at line 77 of file nsMsgFolderCache.h.

Definition at line 78 of file nsMsgFolderCache.h.


The documentation for this class was generated from the following files: