1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/cache/Connection.h"
9 #include "mozilla/dom/cache/DBSchema.h"
10 #include "mozStorageHelper.h"
12 namespace mozilla::dom::cache
{
14 using mozilla::dom::quota::QuotaObject
;
16 NS_IMPL_ISUPPORTS(cache::Connection
, mozIStorageAsyncConnection
,
17 mozIStorageConnection
);
19 Connection::Connection(mozIStorageConnection
* aBase
)
20 : mBase(aBase
), mClosed(false) {
21 MOZ_DIAGNOSTIC_ASSERT(mBase
);
24 Connection::~Connection() {
25 NS_ASSERT_OWNINGTHREAD(Connection
);
26 MOZ_ALWAYS_SUCCEEDS(Close());
31 NS_ASSERT_OWNINGTHREAD(Connection
);
38 // If we are closing here, then Cache must not have a transaction
39 // open anywhere else. This may fail if storage is corrupted.
40 Unused
<< NS_WARN_IF(NS_FAILED(db::IncrementalVacuum(*this)));
42 return mBase
->Close();
45 // The following methods are all boilerplate that either forward to the
46 // base connection or block the method. All the async execution methods
47 // are blocked because Cache does not use them and they would require more
48 // work to wrap properly.
50 // mozIStorageAsyncConnection methods
53 Connection::AsyncVacuum(mozIStorageCompletionCallback
*, bool, int32_t) {
54 // async methods are not supported
55 return NS_ERROR_NOT_IMPLEMENTED
;
59 Connection::AsyncClose(mozIStorageCompletionCallback
*) {
60 // async methods are not supported
61 return NS_ERROR_NOT_IMPLEMENTED
;
65 Connection::SpinningSynchronousClose() {
67 return NS_ERROR_NOT_IMPLEMENTED
;
71 Connection::AsyncClone(bool, mozIStorageCompletionCallback
*) {
72 // async methods are not supported
73 return NS_ERROR_NOT_IMPLEMENTED
;
77 Connection::GetDatabaseFile(nsIFile
** aFileOut
) {
78 return mBase
->GetDatabaseFile(aFileOut
);
82 Connection::CreateAsyncStatement(const nsACString
&,
83 mozIStorageAsyncStatement
**) {
84 // async methods are not supported
85 return NS_ERROR_NOT_IMPLEMENTED
;
89 Connection::ExecuteAsync(const nsTArray
<RefPtr
<mozIStorageBaseStatement
>>&,
90 mozIStorageStatementCallback
*,
91 mozIStoragePendingStatement
**) {
92 // async methods are not supported
93 return NS_ERROR_NOT_IMPLEMENTED
;
97 Connection::ExecuteSimpleSQLAsync(const nsACString
&,
98 mozIStorageStatementCallback
*,
99 mozIStoragePendingStatement
**) {
100 // async methods are not supported
101 return NS_ERROR_NOT_IMPLEMENTED
;
105 Connection::CreateFunction(const nsACString
& aFunctionName
,
106 int32_t aNumArguments
,
107 mozIStorageFunction
* aFunction
) {
108 // async methods are not supported
109 return NS_ERROR_NOT_IMPLEMENTED
;
113 Connection::RemoveFunction(const nsACString
& aFunctionName
) {
114 return mBase
->RemoveFunction(aFunctionName
);
118 Connection::SetProgressHandler(int32_t aGranularity
,
119 mozIStorageProgressHandler
* aHandler
,
120 mozIStorageProgressHandler
** aHandlerOut
) {
121 return mBase
->SetProgressHandler(aGranularity
, aHandler
, aHandlerOut
);
125 Connection::RemoveProgressHandler(mozIStorageProgressHandler
** aHandlerOut
) {
126 return mBase
->RemoveProgressHandler(aHandlerOut
);
129 // mozIStorageConnection methods
132 Connection::Clone(bool aReadOnly
, mozIStorageConnection
** aConnectionOut
) {
133 nsCOMPtr
<mozIStorageConnection
> conn
;
134 nsresult rv
= mBase
->Clone(aReadOnly
, getter_AddRefs(conn
));
135 if (NS_WARN_IF(NS_FAILED(rv
))) {
139 nsCOMPtr
<mozIStorageConnection
> wrapped
= new Connection(conn
);
140 wrapped
.forget(aConnectionOut
);
146 Connection::Interrupt() { return mBase
->Interrupt(); }
149 Connection::GetDefaultPageSize(int32_t* aSizeOut
) {
150 return mBase
->GetDefaultPageSize(aSizeOut
);
154 Connection::GetConnectionReady(bool* aReadyOut
) {
155 return mBase
->GetConnectionReady(aReadyOut
);
159 Connection::GetLastInsertRowID(int64_t* aRowIdOut
) {
160 return mBase
->GetLastInsertRowID(aRowIdOut
);
164 Connection::GetAffectedRows(int32_t* aCountOut
) {
165 return mBase
->GetAffectedRows(aCountOut
);
169 Connection::GetLastError(int32_t* aErrorOut
) {
170 return mBase
->GetLastError(aErrorOut
);
174 Connection::GetLastErrorString(nsACString
& aErrorOut
) {
175 return mBase
->GetLastErrorString(aErrorOut
);
179 Connection::GetSchemaVersion(int32_t* aVersionOut
) {
180 return mBase
->GetSchemaVersion(aVersionOut
);
184 Connection::SetSchemaVersion(int32_t aVersion
) {
185 return mBase
->SetSchemaVersion(aVersion
);
189 Connection::CreateStatement(const nsACString
& aQuery
,
190 mozIStorageStatement
** aStatementOut
) {
191 return mBase
->CreateStatement(aQuery
, aStatementOut
);
195 Connection::ExecuteSimpleSQL(const nsACString
& aQuery
) {
196 return mBase
->ExecuteSimpleSQL(aQuery
);
200 Connection::TableExists(const nsACString
& aTableName
, bool* aExistsOut
) {
201 return mBase
->TableExists(aTableName
, aExistsOut
);
205 Connection::IndexExists(const nsACString
& aIndexName
, bool* aExistsOut
) {
206 return mBase
->IndexExists(aIndexName
, aExistsOut
);
210 Connection::GetTransactionInProgress(bool* aResultOut
) {
211 return mBase
->GetTransactionInProgress(aResultOut
);
215 Connection::GetDefaultTransactionType(int32_t* aResultOut
) {
216 return mBase
->GetDefaultTransactionType(aResultOut
);
220 Connection::SetDefaultTransactionType(int32_t aType
) {
221 return mBase
->SetDefaultTransactionType(aType
);
225 Connection::GetVariableLimit(int32_t* aResultOut
) {
226 return mBase
->GetVariableLimit(aResultOut
);
230 Connection::BeginTransaction() { return mBase
->BeginTransaction(); }
233 Connection::CommitTransaction() { return mBase
->CommitTransaction(); }
236 Connection::RollbackTransaction() { return mBase
->RollbackTransaction(); }
239 Connection::CreateTable(const char* aTable
, const char* aSchema
) {
240 return mBase
->CreateTable(aTable
, aSchema
);
244 Connection::SetGrowthIncrement(int32_t aIncrement
,
245 const nsACString
& aDatabase
) {
246 return mBase
->SetGrowthIncrement(aIncrement
, aDatabase
);
250 Connection::EnableModule(const nsACString
& aModule
) {
251 return mBase
->EnableModule(aModule
);
255 Connection::GetQuotaObjects(QuotaObject
** aDatabaseQuotaObject
,
256 QuotaObject
** aJournalQuotaObject
) {
257 return mBase
->GetQuotaObjects(aDatabaseQuotaObject
, aJournalQuotaObject
);
260 mozilla::storage::SQLiteMutex
& Connection::GetSharedDBMutex() {
261 return mBase
->GetSharedDBMutex();
264 uint32_t Connection::GetTransactionNestingLevel(
265 const mozilla::storage::SQLiteMutexAutoLock
& aProofOfLock
) {
266 return mBase
->GetTransactionNestingLevel(aProofOfLock
);
269 uint32_t Connection::IncreaseTransactionNestingLevel(
270 const mozilla::storage::SQLiteMutexAutoLock
& aProofOfLock
) {
271 return mBase
->IncreaseTransactionNestingLevel(aProofOfLock
);
274 uint32_t Connection::DecreaseTransactionNestingLevel(
275 const mozilla::storage::SQLiteMutexAutoLock
& aProofOfLock
) {
276 return mBase
->DecreaseTransactionNestingLevel(aProofOfLock
);
279 } // namespace mozilla::dom::cache