more folder cache stuff, not part of build

This commit is contained in:
bienvenu%netscape.com 1999-07-16 02:25:24 +00:00
parent b9d0bec0ea
commit 4af5914b55
4 changed files with 75 additions and 7 deletions

View File

@ -125,6 +125,7 @@ nsresult nsMsgFolderCache::InitExistingDB()
if (NS_FAILED(rv) || !hdrRow)
break;
rv = AddCacheElement(nsnull, hdrRow, nsnull);
// rv = mDB->CreateMsgHdr(hdrRow, key, &mResultHdr);
if (NS_FAILED(rv))
return rv;
@ -257,7 +258,14 @@ NS_IMETHODIMP nsMsgFolderCache::Init(nsIFileSpec *dbFileSpec)
if (NS_SUCCEEDED(rv))
{
// if (!m_dbFileSpec->Exists())
if (!m_dbFileSpec.Exists())
{
InitNewDB();
}
else
{
InitExistingDB();
}
}
}
@ -298,7 +306,7 @@ NS_IMETHODIMP nsMsgFolderCache::GetCacheElement(char *uri, PRBool createIfMissin
if (NS_SUCCEEDED(err) && hdrRow)
{
m_mdbAllFoldersTable->AddRow(GetEnv(), hdrRow);
nsresult ret = AddCacheElement(uri, result);
nsresult ret = AddCacheElement(uri, hdrRow, result);
if (*result)
(*result)->SetStringProperty("uri", uri);
return ret;
@ -338,13 +346,23 @@ nsMsgFolderCache::FindCacheElementByURI(nsISupports *aElement, void *data)
return PR_TRUE;
}
nsresult nsMsgFolderCache::AddCacheElement(const char *uri, nsIMsgFolderCacheElement **result)
nsresult nsMsgFolderCache::AddCacheElement(const char *uri, nsIMdbRow *row, nsIMsgFolderCacheElement **result)
{
nsMsgFolderCacheElement *cacheElement = new nsMsgFolderCacheElement;
if (cacheElement)
{
cacheElement->SetURI((char *) uri);
cacheElement->SetMDBRow(row);
// if caller didn't pass in URI, try to get it from row.
if (!uri)
{
char *existingURI = nsnull;
cacheElement->GetStringProperty("uri", &existingURI);
cacheElement->SetURI(existingURI);
PR_Free(existingURI);
}
else
cacheElement->SetURI((char *) uri);
nsCOMPtr<nsISupports> supports(do_QueryInterface(cacheElement));
if(supports)
m_cacheElements->AppendElement(supports);
@ -355,3 +373,31 @@ nsresult nsMsgFolderCache::AddCacheElement(const char *uri, nsIMsgFolderCacheEle
else
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult nsMsgFolderCache::RowCellColumnToCharPtr(nsIMdbRow *hdrRow, mdb_token columnToken, char **resultPtr)
{
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)
{
nsCRT::memcpy(result, yarn.mYarn_Buf, yarn.mYarn_Fill);
result[yarn.mYarn_Fill] = '\0';
}
else
err = NS_ERROR_OUT_OF_MEMORY;
*resultPtr = result;
hdrCell->CutStrongRef(GetEnv()); // always release ref
}
}
return err;
}

View File

@ -30,6 +30,8 @@ class nsMsgFolderCache : public nsIMsgFolderCache
{
public:
friend class nsMsgFolderCacheElement;
nsMsgFolderCache();
virtual ~nsMsgFolderCache();
@ -46,7 +48,9 @@ protected:
static PRBool FindCacheElementByURI(nsISupports *aElement, void *data);
static nsIMdbFactory *GetMDBFactory();
nsresult AddCacheElement(const char *uri, nsIMsgFolderCacheElement **result);
nsresult AddCacheElement(const char *uri, nsIMdbRow *row, nsIMsgFolderCacheElement **result);
nsresult RowCellColumnToCharPtr(nsIMdbRow *hdrRow, mdb_token columnToken, char **resultPtr);
nsresult InitMDBInfo();
nsresult InitNewDB();
nsresult InitExistingDB();

View File

@ -41,10 +41,17 @@ NS_IMPL_SETTER_STR(nsMsgFolderCacheElement::SetURI, m_folderURI)
NS_IMETHODIMP nsMsgFolderCacheElement::GetStringProperty(const char *propertyName, char **result)
{
if (!propertyName || !result || !m_mdbRow)
if (!propertyName || !result || !m_mdbRow || !m_owningCache)
return NS_ERROR_NULL_POINTER;
return NS_ERROR_NOT_IMPLEMENTED;
mdb_token property_token;
nsresult ret = m_owningCache->GetStore()->StringToToken(m_owningCache->GetEnv(), propertyName, &property_token);
if (ret == NS_OK)
{
ret = m_owningCache->RowCellColumnToCharPtr(m_mdbRow, property_token, result);
}
return ret;
}
NS_IMETHODIMP nsMsgFolderCacheElement::GetInt32Property(const char *propertyName, PRInt32 *result)
@ -68,3 +75,11 @@ NS_IMETHODIMP nsMsgFolderCacheElement::SetInt32Property(const char *propertyName
return NS_ERROR_NOT_IMPLEMENTED;
}
void nsMsgFolderCacheElement::SetMDBRow(nsIMdbRow *row)
{
if (m_mdbRow)
NS_RELEASE(m_mdbRow);
m_mdbRow = row;
if (row)
NS_ADDREF(row);
}

View File

@ -43,8 +43,11 @@ public:
NS_IMETHOD GetURI(char * *aURI);
NS_IMETHOD SetURI(char *aURI);
void SetMDBRow(nsIMdbRow *row);
protected:
nsIMdbRow *m_mdbRow;
nsMsgFolderCache *m_owningCache; // this will be ref-counted. Is this going to be a problem?
// I want to avoid circular references, but since this is
// scriptable, I think I have to ref-count it.