Back to index

lightning-sunbird  0.9+nobinonly
mozSqlService.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is Jan Varga
00017  * Portions created by the Initial Developer are Copyright (C) 2003
00018  * the Initial Developer. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPL"), or
00024  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00025  * in which case the provisions of the GPL or the LGPL are applicable instead
00026  * of those above. If you wish to allow use of your version of this file only
00027  * under the terms of either the GPL or the LGPL, and not to allow others to
00028  * use your version of this file under the terms of the MPL, indicate your
00029  * decision by deleting the provisions above and replace them with the notice
00030  * and other provisions required by the GPL or the LGPL. If you do not delete
00031  * the provisions above, a recipient may use your version of this file under
00032  * the terms of any one of the MPL, the GPL or the LGPL.
00033  *
00034  * ***** END LICENSE BLOCK ***** */
00035 
00036 #include "nsReadableUtils.h"
00037 #include "nsXPIDLString.h"
00038 #include "nsCRT.h"
00039 #include "nsIAtom.h"
00040 #include "nsISupportsUtils.h"
00041 #include "nsIServiceManager.h"
00042 #include "rdf.h"
00043 #include "nsRDFCID.h"
00044 #include "nsAppDirectoryServiceDefs.h"
00045 #include "nsNetUtil.h"
00046 #include "nsIRDFXMLSink.h"
00047 #include "nsIWindowWatcher.h"
00048 #include "nsIPrompt.h"
00049 #include "mozSqlService.h"
00050 #include "mozSqlConnection.h"
00051 
00052 #define SQL_NAMESPACE_URI "http://www.mozilla.org/SQL-rdf#"
00053 
00054 static NS_DEFINE_CID(kRDFServiceCID,            NS_RDFSERVICE_CID);
00055 static NS_DEFINE_CID(kRDFContainerUtilsCID,     NS_RDFCONTAINERUTILS_CID);
00056 
00057 nsIRDFService*          mozSqlService::gRDFService;
00058 nsIRDFContainerUtils*   mozSqlService::gRDFContainerUtils;
00059 
00060 nsIRDFResource*         mozSqlService::kSQL_AliasesRoot;
00061 nsIRDFResource*         mozSqlService::kSQL_Name;
00062 nsIRDFResource*         mozSqlService::kSQL_Type;
00063 nsIRDFResource*         mozSqlService::kSQL_Hostname;
00064 nsIRDFResource*         mozSqlService::kSQL_Port;
00065 nsIRDFResource*         mozSqlService::kSQL_Database;
00066 nsIRDFResource*         mozSqlService::kSQL_Priority;
00067 
00068 
00069 mozSqlService::mozSqlService()
00070   : mConnectionCache(nsnull)
00071 {
00072 }
00073 
00074 mozSqlService::~mozSqlService()
00075 {
00076   gRDFService->UnregisterDataSource(this);
00077 
00078   delete mConnectionCache;
00079 
00080   NS_IF_RELEASE(kSQL_AliasesRoot);
00081   NS_IF_RELEASE(kSQL_Name);
00082   NS_IF_RELEASE(kSQL_Type);
00083   NS_IF_RELEASE(kSQL_Hostname);
00084   NS_IF_RELEASE(kSQL_Port);
00085   NS_IF_RELEASE(kSQL_Database);
00086   NS_IF_RELEASE(kSQL_Priority);
00087 
00088   NS_IF_RELEASE(gRDFContainerUtils);
00089   NS_IF_RELEASE(gRDFService);
00090 }
00091 
00092 NS_IMPL_ISUPPORTS3(mozSqlService,
00093                    mozISqlService,
00094                    nsIRDFDataSource,
00095                    nsIRDFRemoteDataSource)
00096 
00097 NS_IMETHODIMP
00098 mozSqlService::GetErrorMessage(nsAString& aErrorMessage)
00099 {
00100   aErrorMessage = mErrorMessage;
00101   return NS_OK;
00102 }
00103 
00104 nsresult
00105 mozSqlService::Init()
00106 {
00107   nsresult rv;
00108 
00109   rv = CallGetService(kRDFServiceCID, &gRDFService);
00110   if (NS_FAILED(rv)) return rv;
00111 
00112   rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils);
00113   if (NS_FAILED(rv)) return rv;
00114 
00115   gRDFService->GetResource(NS_LITERAL_CSTRING("SQL:AliasesRoot"),
00116                            &kSQL_AliasesRoot);
00117   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "name"),
00118                            &kSQL_Name);
00119   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "type"),
00120                            &kSQL_Type);
00121   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "hostname"),
00122                            &kSQL_Hostname);
00123   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "port"),
00124                            &kSQL_Port);
00125   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "database"),
00126                            &kSQL_Database);
00127   gRDFService->GetResource(NS_LITERAL_CSTRING(SQL_NAMESPACE_URI "priority"),
00128                            &kSQL_Priority);
00129 
00130   nsCOMPtr<nsIFile> file;
00131   rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
00132   if (NS_FAILED(rv)) return rv;
00133   rv = file->AppendNative(NS_LITERAL_CSTRING("sql.rdf"));
00134   if (NS_FAILED(rv)) return rv;
00135 
00136   nsCAutoString sql;
00137   NS_GetURLSpecFromFile(file, sql);
00138 
00139   rv = gRDFService->GetDataSourceBlocking(sql.get(), getter_AddRefs(mInner));
00140   if (NS_FAILED(rv)) return rv;
00141   nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mInner);
00142   if (sink) {
00143     nsCOMPtr<nsIAtom> prefix = do_GetAtom("SQL");
00144     sink->AddNameSpace(prefix, NS_ConvertASCIItoUCS2(SQL_NAMESPACE_URI));
00145   }
00146 
00147   return gRDFService->RegisterDataSource(this, PR_FALSE);
00148 }
00149 
00150 NS_IMETHODIMP
00151 mozSqlService::AddAlias(const nsAString& aName,
00152                         const nsAString& aType,
00153                         const nsAString& aHostname,
00154                         PRInt32 aPort,
00155                         const nsAString& aDatabase,
00156                      PRInt32 aPriority,
00157                         nsIRDFResource** aResult)
00158 {
00159   nsCOMPtr<nsIRDFResource> alias;
00160   gRDFService->GetAnonymousResource(getter_AddRefs(alias));
00161 
00162   nsCOMPtr<nsIRDFLiteral> rdfLiteral;
00163   nsCOMPtr<nsIRDFInt> rdfInt;
00164 
00165   gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
00166   mInner->Assert(alias, kSQL_Name, rdfLiteral, PR_TRUE);
00167 
00168   gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
00169   mInner->Assert(alias, kSQL_Type, rdfLiteral, PR_TRUE);
00170 
00171   gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
00172   mInner->Assert(alias, kSQL_Hostname, rdfLiteral, PR_TRUE);
00173 
00174   gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
00175   mInner->Assert(alias, kSQL_Port, rdfInt, PR_TRUE);
00176 
00177   gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
00178   mInner->Assert(alias, kSQL_Database, rdfLiteral, PR_TRUE);
00179 
00180   gRDFService->GetIntLiteral(aPriority, getter_AddRefs(rdfInt));
00181   mInner->Assert(alias, kSQL_Priority, rdfInt, PR_TRUE);
00182 
00183   nsresult rv = EnsureAliasesContainer();
00184   if (NS_FAILED(rv))
00185     return rv;
00186   mAliasesContainer->AppendElement(alias);
00187 
00188   Flush();
00189 
00190   NS_ADDREF(*aResult = alias);
00191 
00192   return NS_OK;
00193 }
00194 
00195 
00196 NS_IMETHODIMP
00197 mozSqlService::FetchAlias(nsIRDFResource* aAlias,
00198                           nsAString& aName,
00199                           nsAString& aType,
00200                           nsAString& aHostname,
00201                           PRInt32* aPort,
00202                           nsAString& aDatabase,
00203                           PRInt32* aPriority)
00204 {
00205   nsCOMPtr<nsIRDFNode> rdfNode;
00206   nsCOMPtr<nsIRDFLiteral> rdfLiteral;
00207   nsCOMPtr<nsIRDFInt> rdfInt;
00208   const PRUnichar* value;
00209   
00210   mInner->GetTarget(aAlias, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
00211   if (rdfNode) {
00212     rdfLiteral = do_QueryInterface(rdfNode);
00213     rdfLiteral->GetValueConst(&value);
00214     aName.Assign(value);
00215   }
00216 
00217   mInner->GetTarget(aAlias, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
00218   if (rdfNode) {
00219     rdfLiteral = do_QueryInterface(rdfNode);
00220     rdfLiteral->GetValueConst(&value);
00221     aType.Assign(value);
00222   }
00223 
00224   mInner->GetTarget(aAlias, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
00225   if (rdfNode) {
00226     rdfLiteral = do_QueryInterface(rdfNode);
00227     rdfLiteral->GetValueConst(&value);
00228     aHostname.Assign(value);
00229   }
00230 
00231   mInner->GetTarget(aAlias, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
00232   if (rdfNode) {
00233     rdfInt = do_QueryInterface(rdfNode);
00234     rdfInt->GetValue(aPort);
00235   }
00236 
00237   mInner->GetTarget(aAlias, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
00238   if (rdfNode) {
00239     rdfLiteral = do_QueryInterface(rdfNode);
00240     rdfLiteral->GetValueConst(&value);
00241     aDatabase.Assign(value);
00242   }
00243 
00244   mInner->GetTarget(aAlias, kSQL_Priority, PR_TRUE, getter_AddRefs(rdfNode));
00245   if (rdfNode) {
00246     rdfInt = do_QueryInterface(rdfNode);
00247     rdfInt->GetValue(aPriority);
00248   }
00249 
00250   return NS_OK;
00251 }
00252 
00253 NS_IMETHODIMP
00254 mozSqlService::UpdateAlias(nsIRDFResource* aAlias,
00255                            const nsAString& aName,
00256                            const nsAString& aType,
00257                            const nsAString& aHostname,
00258                            PRInt32 aPort,
00259                            const nsAString& aDatabase,
00260                            PRInt32 aPriority)
00261 {
00262   nsCOMPtr<nsIRDFNode> rdfNode;
00263   nsCOMPtr<nsIRDFLiteral> rdfLiteral;
00264   nsCOMPtr<nsIRDFInt> rdfInt;
00265 
00266   mInner->GetTarget(aAlias, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
00267   gRDFService->GetLiteral(PromiseFlatString(aName).get(), getter_AddRefs(rdfLiteral));
00268   mInner->Change(aAlias, kSQL_Name, rdfNode, rdfLiteral);
00269 
00270   mInner->GetTarget(aAlias, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
00271   gRDFService->GetLiteral(PromiseFlatString(aType).get(), getter_AddRefs(rdfLiteral));
00272   mInner->Change(aAlias, kSQL_Type, rdfNode, rdfLiteral);
00273 
00274   mInner->GetTarget(aAlias, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
00275   gRDFService->GetLiteral(PromiseFlatString(aHostname).get(), getter_AddRefs(rdfLiteral));
00276   mInner->Change(aAlias, kSQL_Hostname, rdfNode, rdfLiteral);
00277 
00278   mInner->GetTarget(aAlias, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
00279   gRDFService->GetIntLiteral(aPort, getter_AddRefs(rdfInt));
00280   mInner->Change(aAlias, kSQL_Port, rdfNode, rdfInt);
00281 
00282   mInner->GetTarget(aAlias, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
00283   gRDFService->GetLiteral(PromiseFlatString(aDatabase).get(), getter_AddRefs(rdfLiteral));
00284   mInner->Change(aAlias, kSQL_Database, rdfNode, rdfLiteral);
00285 
00286   mInner->GetTarget(aAlias, kSQL_Priority, PR_TRUE, getter_AddRefs(rdfNode));
00287   gRDFService->GetIntLiteral(aPriority, getter_AddRefs(rdfInt));
00288   if (rdfNode)
00289     mInner->Change(aAlias, kSQL_Priority, rdfNode, rdfInt);
00290   else
00291     mInner->Assert(aAlias, kSQL_Priority, rdfInt, PR_TRUE);
00292 
00293   Flush();
00294 
00295   return NS_OK;
00296 }
00297 
00298 NS_IMETHODIMP
00299 mozSqlService::RemoveAlias(nsIRDFResource* aAlias)
00300 {
00301   nsCOMPtr<nsIRDFNode> rdfNode;
00302 
00303   mInner->GetTarget(aAlias, kSQL_Name, PR_TRUE, getter_AddRefs(rdfNode));
00304   mInner->Unassert(aAlias, kSQL_Name, rdfNode);
00305 
00306   mInner->GetTarget(aAlias, kSQL_Type, PR_TRUE, getter_AddRefs(rdfNode));
00307   mInner->Unassert(aAlias, kSQL_Type, rdfNode);
00308 
00309   mInner->GetTarget(aAlias, kSQL_Hostname, PR_TRUE, getter_AddRefs(rdfNode));
00310   mInner->Unassert(aAlias, kSQL_Hostname, rdfNode);
00311 
00312   mInner->GetTarget(aAlias, kSQL_Port, PR_TRUE, getter_AddRefs(rdfNode));
00313   mInner->Unassert(aAlias, kSQL_Port, rdfNode);
00314 
00315   mInner->GetTarget(aAlias, kSQL_Database, PR_TRUE, getter_AddRefs(rdfNode));
00316   mInner->Unassert(aAlias, kSQL_Database, rdfNode);
00317 
00318   mInner->GetTarget(aAlias, kSQL_Priority, PR_TRUE, getter_AddRefs(rdfNode));
00319   mInner->Unassert(aAlias, kSQL_Priority, rdfNode);
00320 
00321   nsresult rv = EnsureAliasesContainer();
00322   if (NS_FAILED(rv))
00323     return rv;
00324   mAliasesContainer->RemoveElement(aAlias, PR_TRUE);
00325 
00326   Flush();
00327 
00328   return NS_OK;
00329 }
00330 
00331 NS_IMETHODIMP
00332 mozSqlService::GetAlias(const nsAString& aName, nsIRDFResource** _retval)
00333 {
00334   nsCOMPtr<nsIRDFLiteral> nameLiteral;
00335   nsresult rv = gRDFService->GetLiteral(PromiseFlatString(aName).get(),
00336                                         getter_AddRefs(nameLiteral));
00337   if (NS_FAILED(rv))
00338     return rv;
00339 
00340   nsCOMPtr<nsIRDFResource> alias;
00341   rv = mInner->GetSource(kSQL_Name, nameLiteral, PR_TRUE, getter_AddRefs(alias));
00342   if (NS_FAILED(rv))
00343     return rv;
00344 
00345   NS_IF_ADDREF(*_retval = alias);
00346 
00347   return NS_OK;
00348 }
00349 
00350 NS_IMETHODIMP
00351 mozSqlService::GetAliases(const nsAString& aName, nsISimpleEnumerator** _retval)
00352 {
00353   nsCOMPtr<nsIRDFLiteral> nameLiteral;
00354   nsresult rv = gRDFService->GetLiteral(PromiseFlatString(aName).get(),
00355                                         getter_AddRefs(nameLiteral));
00356   if (NS_FAILED(rv))
00357     return rv;
00358 
00359   nsCOMPtr<nsISimpleEnumerator> aliases;
00360   rv = mInner->GetSources(kSQL_Name, nameLiteral, PR_TRUE, getter_AddRefs(aliases));
00361   if (NS_FAILED(rv))
00362     return rv;
00363 
00364   NS_IF_ADDREF(*_retval = aliases);
00365 
00366   return NS_OK;
00367 }
00368 
00369 NS_IMETHODIMP
00370 mozSqlService::GetConnection(nsIRDFResource* aAlias, mozISqlConnection **_retval)
00371 {
00372   nsISupportsKey key(aAlias);
00373   nsCOMPtr<nsIWeakReference> weakRef;
00374   nsCOMPtr<mozISqlConnection> conn;
00375 
00376   if (mConnectionCache) {
00377     weakRef = getter_AddRefs(NS_STATIC_CAST(nsIWeakReference*, mConnectionCache->Get(&key)));
00378     if (weakRef) {
00379       conn = do_QueryReferent(weakRef);
00380       if (conn)
00381         NS_ADDREF(*_retval = conn);
00382     }
00383   }
00384 
00385   if (! *_retval) {
00386     nsresult rv = GetNewConnection(aAlias, getter_AddRefs(conn));
00387     if (NS_FAILED(rv))
00388       return rv;
00389 
00390     weakRef = do_GetWeakReference(conn);
00391 
00392     if (! mConnectionCache) {
00393       mConnectionCache = new nsSupportsHashtable(16);
00394       if (! mConnectionCache)
00395         return NS_ERROR_OUT_OF_MEMORY;
00396     }
00397     mConnectionCache->Put(&key, weakRef);
00398 
00399     NS_ADDREF(*_retval = conn);
00400   }
00401 
00402   return NS_OK;
00403 }
00404 
00405 NS_IMETHODIMP
00406 mozSqlService::GetNewConnection(nsIRDFResource* aAlias, mozISqlConnection **_retval)
00407 {
00408   nsAutoString name;
00409   nsAutoString type;
00410   nsAutoString hostname;
00411   PRInt32 port;
00412   nsAutoString database;
00413   PRInt32 priority;
00414   nsresult rv = FetchAlias(aAlias, name, type, hostname, &port, database, &priority);
00415   if (NS_FAILED(rv))
00416     return rv;
00417 
00418   nsCAutoString contractID("@mozilla.org/sql/connection;1?type=");
00419   AppendUTF16toUTF8(type, contractID);
00420 
00421   nsCOMPtr<mozISqlConnection> conn = do_CreateInstance(contractID.get());
00422   if (! conn)
00423     return NS_ERROR_FAILURE;
00424 
00425   nsCOMPtr<nsIWindowWatcher> watcher(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
00426   nsCOMPtr<nsIPrompt> prompter;
00427   watcher->GetNewPrompter(0, getter_AddRefs(prompter));
00428 
00429   PRBool retval;
00430   do {
00431     nsXPIDLString username;
00432     nsXPIDLString password;
00433     prompter->PromptUsernameAndPassword(
00434       nsnull, // in wstring dialogTitle
00435       nsnull, // in wstring text
00436       getter_Copies(username),
00437       getter_Copies(password),
00438       nsnull, // in wstring checkMsg
00439       nsnull, // inout boolean checkValue
00440       &retval
00441     );
00442 
00443     if (retval) {
00444       rv = conn->Init(hostname, port, database, username, password);
00445       if (NS_FAILED(rv)) {
00446         conn->GetErrorMessage(mErrorMessage);
00447         prompter->Alert(nsnull, mErrorMessage.get());
00448       }
00449     }
00450   } while(retval && NS_FAILED(rv));
00451 
00452   NS_IF_ADDREF(*_retval = conn);
00453 
00454   return rv;
00455 }
00456 
00457 NS_IMETHODIMP
00458 mozSqlService::GetURI(char** aURI)
00459 {
00460   if (!aURI)
00461     return NS_ERROR_NULL_POINTER;
00462   
00463   *aURI = nsCRT::strdup("rdf:sql");
00464   if (!(*aURI))
00465     return NS_ERROR_OUT_OF_MEMORY;
00466   
00467   return NS_OK;
00468 }
00469 
00470 NS_IMETHODIMP 
00471 mozSqlService::GetSource(nsIRDFResource* aProperty,
00472                          nsIRDFNode* aTarget,
00473                          PRBool aTruthValue,
00474                          nsIRDFResource** aSource) 
00475 {
00476   return mInner->GetSource(aProperty, aTarget, aTruthValue, aSource);
00477 }
00478    
00479 NS_IMETHODIMP
00480 mozSqlService::GetSources(nsIRDFResource* aProperty,
00481                           nsIRDFNode* aTarget,
00482                           PRBool aTruthValue,
00483                           nsISimpleEnumerator** aSources) {
00484   return mInner->GetSources(aProperty, aTarget, aTruthValue, aSources);
00485 }
00486    
00487 NS_IMETHODIMP
00488 mozSqlService::GetTarget(nsIRDFResource* aSource,
00489                          nsIRDFResource* aProperty,
00490                          PRBool aTruthValue,
00491                          nsIRDFNode** aTarget) {
00492   return mInner->GetTarget(aSource, aProperty, aTruthValue, aTarget);
00493 }
00494    
00495 NS_IMETHODIMP
00496 mozSqlService::GetTargets(nsIRDFResource* aSource,
00497                           nsIRDFResource* aProperty,
00498                           PRBool aTruthValue,
00499                           nsISimpleEnumerator** aTargets) {
00500   return mInner->GetTargets(aSource, aProperty, aTruthValue, aTargets);
00501 }
00502    
00503 NS_IMETHODIMP 
00504 mozSqlService::Assert(nsIRDFResource* aSource,
00505                       nsIRDFResource* aProperty,
00506                       nsIRDFNode* aTarget,
00507                       PRBool aTruthValue) 
00508 {
00509   return mInner->Assert(aSource, aProperty, aTarget, aTruthValue);
00510 }
00511    
00512 NS_IMETHODIMP 
00513 mozSqlService::Unassert(nsIRDFResource* aSource,
00514                         nsIRDFResource* aProperty,
00515                         nsIRDFNode* aTarget) 
00516 {
00517   return mInner->Unassert(aSource, aProperty, aTarget);
00518 }
00519    
00520 NS_IMETHODIMP 
00521 mozSqlService::Change(nsIRDFResource* aSource,
00522                       nsIRDFResource* aProperty,
00523                       nsIRDFNode* aOldTarget,
00524                       nsIRDFNode* aNewTarget) 
00525 {
00526   return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
00527 }
00528    
00529 NS_IMETHODIMP 
00530 mozSqlService::Move(nsIRDFResource* aOldSource,
00531                     nsIRDFResource* aNewSource,
00532                     nsIRDFResource* aProperty,
00533                     nsIRDFNode* aTarget) 
00534 {
00535   return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
00536 }
00537    
00538 NS_IMETHODIMP 
00539 mozSqlService::HasAssertion(nsIRDFResource* aSource,
00540                             nsIRDFResource* aProperty,
00541                             nsIRDFNode* aTarget,
00542                             PRBool aTruthValue,
00543                             PRBool* hasAssertion) 
00544 {
00545   return mInner->HasAssertion(aSource, aProperty, aTarget, aTruthValue, hasAssertion);
00546 }
00547    
00548 NS_IMETHODIMP 
00549 mozSqlService::AddObserver(nsIRDFObserver* aObserver) 
00550 {
00551   return mInner->AddObserver(aObserver);
00552 }
00553    
00554 NS_IMETHODIMP 
00555 mozSqlService::RemoveObserver(nsIRDFObserver* aObserver) 
00556 {
00557   return mInner->RemoveObserver(aObserver);
00558 }
00559    
00560 NS_IMETHODIMP 
00561 mozSqlService::HasArcIn(nsIRDFNode* aNode,
00562                        nsIRDFResource* aArc,
00563                        PRBool* _retval) 
00564 {
00565   return mInner->HasArcIn(aNode, aArc, _retval);
00566 }
00567 
00568 NS_IMETHODIMP 
00569 mozSqlService::HasArcOut(nsIRDFResource* aSource,
00570                          nsIRDFResource* aArc,
00571                          PRBool* _retval) 
00572 {
00573   return mInner->HasArcOut(aSource, aArc, _retval);
00574 }
00575 
00576 NS_IMETHODIMP 
00577 mozSqlService::ArcLabelsIn(nsIRDFNode* aNode,
00578                            nsISimpleEnumerator** aLabels) 
00579 {
00580   return mInner->ArcLabelsIn(aNode, aLabels);
00581 }
00582 
00583 NS_IMETHODIMP 
00584 mozSqlService::ArcLabelsOut(nsIRDFResource* aSource,
00585                             nsISimpleEnumerator** aLabels) 
00586 {
00587   return mInner->ArcLabelsIn(aSource, aLabels);
00588 }
00589 
00590 NS_IMETHODIMP 
00591 mozSqlService::GetAllResources(nsISimpleEnumerator** aResult) 
00592 {
00593   return mInner->GetAllResources(aResult);
00594 }
00595 
00596 NS_IMETHODIMP 
00597 mozSqlService::GetAllCmds(nsIRDFResource* aSource,
00598                           nsISimpleEnumerator** aCommands) 
00599 {
00600   return mInner->GetAllCmds(aSource, aCommands);
00601 }
00602 
00603 NS_IMETHODIMP 
00604 mozSqlService::IsCommandEnabled(nsISupportsArray* aSources,
00605                                 nsIRDFResource* aCommand,
00606                                 nsISupportsArray* aArguments,
00607                                 PRBool* aResult) 
00608 {
00609   return mInner->IsCommandEnabled(aSources, aCommand, aArguments, aResult);
00610 }
00611 
00612 NS_IMETHODIMP 
00613 mozSqlService::DoCommand(nsISupportsArray* aSources,
00614                          nsIRDFResource* aCommand,
00615                          nsISupportsArray* aArguments) 
00616 {
00617   return mInner->DoCommand(aSources, aCommand, aArguments);
00618 }
00619 
00620 NS_IMETHODIMP 
00621 mozSqlService::BeginUpdateBatch()
00622 {
00623   return mInner->BeginUpdateBatch();
00624 }
00625 
00626 NS_IMETHODIMP 
00627 mozSqlService::EndUpdateBatch()
00628 {
00629   return mInner->EndUpdateBatch();
00630 }
00631 
00632 
00633 // nsIRDFRemoteDataSource
00634 NS_IMETHODIMP
00635 mozSqlService::GetLoaded(PRBool* aResult)
00636 {
00637   nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
00638   return remote->GetLoaded(aResult);
00639 }
00640 
00641 NS_IMETHODIMP
00642 mozSqlService::Init(const char* aURI)
00643 {
00644   return NS_OK;
00645 }
00646 
00647 NS_IMETHODIMP
00648 mozSqlService::Refresh(PRBool aBlocking)
00649 {
00650   nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
00651   return remote->Refresh(aBlocking);
00652 }
00653 
00654 NS_IMETHODIMP
00655 mozSqlService::Flush()
00656 {
00657   nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
00658   return remote->Flush();
00659 }
00660 
00661 NS_IMETHODIMP
00662 mozSqlService::FlushTo(const char *aURI)
00663 {
00664   nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
00665   return remote->FlushTo(aURI);
00666 }
00667 
00668 
00669 nsresult
00670 mozSqlService::EnsureAliasesContainer()
00671 {
00672   if (! mAliasesContainer) {
00673     PRBool isContainer;
00674     nsresult rv = gRDFContainerUtils->IsContainer(mInner, kSQL_AliasesRoot, &isContainer);
00675     if (NS_FAILED(rv)) return rv;
00676 
00677     if (!isContainer) {
00678       rv = gRDFContainerUtils->MakeSeq(mInner, kSQL_AliasesRoot, getter_AddRefs(mAliasesContainer));
00679       if (NS_FAILED(rv)) return rv;
00680     }
00681     else {
00682       mAliasesContainer = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv);
00683       if (NS_FAILED(rv)) return rv;
00684       rv = mAliasesContainer->Init(mInner, kSQL_AliasesRoot);
00685       if (NS_FAILED(rv)) return rv;
00686     }
00687   }
00688 
00689   return NS_OK;
00690 }