/src/mozilla-central/dom/cache/Connection.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozilla/dom/cache/Connection.h" |
8 | | |
9 | | #include "mozilla/dom/cache/DBSchema.h" |
10 | | #include "mozStorageHelper.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | namespace cache { |
15 | | |
16 | | using mozilla::dom::quota::QuotaObject; |
17 | | |
18 | | NS_IMPL_ISUPPORTS(cache::Connection, mozIStorageAsyncConnection, |
19 | | mozIStorageConnection); |
20 | | |
21 | | Connection::Connection(mozIStorageConnection* aBase) |
22 | | : mBase(aBase) |
23 | | , mClosed(false) |
24 | 0 | { |
25 | 0 | MOZ_DIAGNOSTIC_ASSERT(mBase); |
26 | 0 | } |
27 | | |
28 | | Connection::~Connection() |
29 | 0 | { |
30 | 0 | NS_ASSERT_OWNINGTHREAD(Connection); |
31 | 0 | MOZ_ALWAYS_SUCCEEDS(Close()); |
32 | 0 | } |
33 | | |
34 | | NS_IMETHODIMP |
35 | | Connection::Close() |
36 | 0 | { |
37 | 0 | NS_ASSERT_OWNINGTHREAD(Connection); |
38 | 0 |
|
39 | 0 | if (mClosed) { |
40 | 0 | return NS_OK; |
41 | 0 | } |
42 | 0 | mClosed = true; |
43 | 0 |
|
44 | 0 | // If we are closing here, then Cache must not have a transaction |
45 | 0 | // open anywhere else. This should be guaranteed to succeed. |
46 | 0 | MOZ_ALWAYS_SUCCEEDS(db::IncrementalVacuum(this)); |
47 | 0 |
|
48 | 0 | return mBase->Close(); |
49 | 0 | } |
50 | | |
51 | | // The following methods are all boilerplate that either forward to the |
52 | | // base connection or block the method. All the async execution methods |
53 | | // are blocked because Cache does not use them and they would require more |
54 | | // work to wrap properly. |
55 | | |
56 | | // mozIStorageAsyncConnection methods |
57 | | |
58 | | NS_IMETHODIMP |
59 | | Connection::AsyncClose(mozIStorageCompletionCallback*) |
60 | 0 | { |
61 | 0 | // async methods are not supported |
62 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
63 | 0 | } |
64 | | |
65 | | NS_IMETHODIMP |
66 | | Connection::SpinningSynchronousClose() |
67 | 0 | { |
68 | 0 | // not supported |
69 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
70 | 0 | } |
71 | | |
72 | | NS_IMETHODIMP |
73 | | Connection::AsyncClone(bool, mozIStorageCompletionCallback*) |
74 | 0 | { |
75 | 0 | // async methods are not supported |
76 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
77 | 0 | } |
78 | | |
79 | | NS_IMETHODIMP |
80 | | Connection::GetDatabaseFile(nsIFile** aFileOut) |
81 | 0 | { |
82 | 0 | return mBase->GetDatabaseFile(aFileOut); |
83 | 0 | } |
84 | | |
85 | | NS_IMETHODIMP |
86 | | Connection::CreateAsyncStatement(const nsACString&, mozIStorageAsyncStatement**) |
87 | 0 | { |
88 | 0 | // async methods are not supported |
89 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
90 | 0 | } |
91 | | |
92 | | NS_IMETHODIMP |
93 | | Connection::ExecuteAsync(mozIStorageBaseStatement**, uint32_t, |
94 | | mozIStorageStatementCallback*, |
95 | | mozIStoragePendingStatement**) |
96 | 0 | { |
97 | 0 | // async methods are not supported |
98 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
99 | 0 | } |
100 | | |
101 | | NS_IMETHODIMP |
102 | | Connection::ExecuteSimpleSQLAsync(const nsACString&, |
103 | | mozIStorageStatementCallback*, |
104 | | mozIStoragePendingStatement**) |
105 | 0 | { |
106 | 0 | // async methods are not supported |
107 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
108 | 0 | } |
109 | | |
110 | | NS_IMETHODIMP |
111 | | Connection::CreateFunction(const nsACString& aFunctionName, |
112 | | int32_t aNumArguments, |
113 | | mozIStorageFunction* aFunction) |
114 | 0 | { |
115 | 0 | // async methods are not supported |
116 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
117 | 0 | } |
118 | | |
119 | | NS_IMETHODIMP |
120 | | Connection::CreateAggregateFunction(const nsACString& aFunctionName, |
121 | | int32_t aNumArguments, |
122 | | mozIStorageAggregateFunction* aFunction) |
123 | 0 | { |
124 | 0 | return mBase->CreateAggregateFunction(aFunctionName, aNumArguments, |
125 | 0 | aFunction); |
126 | 0 | } |
127 | | |
128 | | NS_IMETHODIMP |
129 | | Connection::RemoveFunction(const nsACString& aFunctionName) |
130 | 0 | { |
131 | 0 | return mBase->RemoveFunction(aFunctionName); |
132 | 0 | } |
133 | | |
134 | | NS_IMETHODIMP |
135 | | Connection::SetProgressHandler(int32_t aGranularity, |
136 | | mozIStorageProgressHandler* aHandler, |
137 | | mozIStorageProgressHandler** aHandlerOut) |
138 | 0 | { |
139 | 0 | return mBase->SetProgressHandler(aGranularity, aHandler, aHandlerOut); |
140 | 0 | } |
141 | | |
142 | | NS_IMETHODIMP |
143 | | Connection::RemoveProgressHandler(mozIStorageProgressHandler** aHandlerOut) |
144 | 0 | { |
145 | 0 | return mBase->RemoveProgressHandler(aHandlerOut); |
146 | 0 | } |
147 | | |
148 | | // mozIStorageConnection methods |
149 | | |
150 | | NS_IMETHODIMP |
151 | | Connection::Clone(bool aReadOnly, mozIStorageConnection** aConnectionOut) |
152 | 0 | { |
153 | 0 | nsCOMPtr<mozIStorageConnection> conn; |
154 | 0 | nsresult rv = mBase->Clone(aReadOnly, getter_AddRefs(conn)); |
155 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } |
156 | 0 | |
157 | 0 | nsCOMPtr<mozIStorageConnection> wrapped = new Connection(conn); |
158 | 0 | wrapped.forget(aConnectionOut); |
159 | 0 |
|
160 | 0 | return rv; |
161 | 0 | } |
162 | | |
163 | | NS_IMETHODIMP |
164 | | Connection::Interrupt() |
165 | 0 | { |
166 | 0 | return mBase->Interrupt(); |
167 | 0 | } |
168 | | |
169 | | NS_IMETHODIMP |
170 | | Connection::GetDefaultPageSize(int32_t* aSizeOut) |
171 | 0 | { |
172 | 0 | return mBase->GetDefaultPageSize(aSizeOut); |
173 | 0 | } |
174 | | |
175 | | NS_IMETHODIMP |
176 | | Connection::GetConnectionReady(bool* aReadyOut) |
177 | 0 | { |
178 | 0 | return mBase->GetConnectionReady(aReadyOut); |
179 | 0 | } |
180 | | |
181 | | NS_IMETHODIMP |
182 | | Connection::GetLastInsertRowID(int64_t* aRowIdOut) |
183 | 0 | { |
184 | 0 | return mBase->GetLastInsertRowID(aRowIdOut); |
185 | 0 | } |
186 | | |
187 | | NS_IMETHODIMP |
188 | | Connection::GetAffectedRows(int32_t* aCountOut) |
189 | 0 | { |
190 | 0 | return mBase->GetAffectedRows(aCountOut); |
191 | 0 | } |
192 | | |
193 | | NS_IMETHODIMP |
194 | | Connection::GetLastError(int32_t* aErrorOut) |
195 | 0 | { |
196 | 0 | return mBase->GetLastError(aErrorOut); |
197 | 0 | } |
198 | | |
199 | | NS_IMETHODIMP |
200 | | Connection::GetLastErrorString(nsACString& aErrorOut) |
201 | 0 | { |
202 | 0 | return mBase->GetLastErrorString(aErrorOut); |
203 | 0 | } |
204 | | |
205 | | NS_IMETHODIMP |
206 | | Connection::GetSchemaVersion(int32_t* aVersionOut) |
207 | 0 | { |
208 | 0 | return mBase->GetSchemaVersion(aVersionOut); |
209 | 0 | } |
210 | | |
211 | | NS_IMETHODIMP |
212 | | Connection::SetSchemaVersion(int32_t aVersion) |
213 | 0 | { |
214 | 0 | return mBase->SetSchemaVersion(aVersion); |
215 | 0 | } |
216 | | |
217 | | NS_IMETHODIMP |
218 | | Connection::CreateStatement(const nsACString& aQuery, |
219 | | mozIStorageStatement** aStatementOut) |
220 | 0 | { |
221 | 0 | return mBase->CreateStatement(aQuery, aStatementOut); |
222 | 0 | } |
223 | | |
224 | | NS_IMETHODIMP |
225 | | Connection::ExecuteSimpleSQL(const nsACString& aQuery) |
226 | 0 | { |
227 | 0 | return mBase->ExecuteSimpleSQL(aQuery); |
228 | 0 | } |
229 | | |
230 | | NS_IMETHODIMP |
231 | | Connection::TableExists(const nsACString& aTableName, bool* aExistsOut) |
232 | 0 | { |
233 | 0 | return mBase->TableExists(aTableName, aExistsOut); |
234 | 0 | } |
235 | | |
236 | | NS_IMETHODIMP |
237 | | Connection::IndexExists(const nsACString& aIndexName, bool* aExistsOut) |
238 | 0 | { |
239 | 0 | return mBase->IndexExists(aIndexName, aExistsOut); |
240 | 0 | } |
241 | | |
242 | | NS_IMETHODIMP |
243 | | Connection::GetTransactionInProgress(bool* aResultOut) |
244 | 0 | { |
245 | 0 | return mBase->GetTransactionInProgress(aResultOut); |
246 | 0 | } |
247 | | |
248 | | NS_IMETHODIMP |
249 | | Connection::GetDefaultTransactionType(int32_t* aResultOut) |
250 | 0 | { |
251 | 0 | return mBase->GetDefaultTransactionType(aResultOut); |
252 | 0 | } |
253 | | |
254 | | NS_IMETHODIMP |
255 | | Connection::SetDefaultTransactionType(int32_t aType) |
256 | 0 | { |
257 | 0 | return mBase->SetDefaultTransactionType(aType); |
258 | 0 | } |
259 | | |
260 | | NS_IMETHODIMP |
261 | | Connection::BeginTransaction() |
262 | 0 | { |
263 | 0 | return mBase->BeginTransaction(); |
264 | 0 | } |
265 | | |
266 | | NS_IMETHODIMP |
267 | | Connection::CommitTransaction() |
268 | 0 | { |
269 | 0 | return mBase->CommitTransaction(); |
270 | 0 | } |
271 | | |
272 | | NS_IMETHODIMP |
273 | | Connection::RollbackTransaction() |
274 | 0 | { |
275 | 0 | return mBase->RollbackTransaction(); |
276 | 0 | } |
277 | | |
278 | | NS_IMETHODIMP |
279 | | Connection::CreateTable(const char* aTable, const char* aSchema) |
280 | 0 | { |
281 | 0 | return mBase->CreateTable(aTable, aSchema); |
282 | 0 | } |
283 | | |
284 | | NS_IMETHODIMP |
285 | | Connection::SetGrowthIncrement(int32_t aIncrement, const nsACString& aDatabase) |
286 | 0 | { |
287 | 0 | return mBase->SetGrowthIncrement(aIncrement, aDatabase); |
288 | 0 | } |
289 | | |
290 | | NS_IMETHODIMP |
291 | | Connection::EnableModule(const nsACString& aModule) |
292 | 0 | { |
293 | 0 | return mBase->EnableModule(aModule); |
294 | 0 | } |
295 | | |
296 | | NS_IMETHODIMP |
297 | | Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject, |
298 | | QuotaObject** aJournalQuotaObject) |
299 | 0 | { |
300 | 0 | return mBase->GetQuotaObjects(aDatabaseQuotaObject, aJournalQuotaObject); |
301 | 0 | } |
302 | | |
303 | | } // namespace cache |
304 | | } // namespace dom |
305 | | } // namespace mozilla |