|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
|
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 "mozStorageBindingParamsArray.h" |
|
8 #include "mozStorageBindingParams.h" |
|
9 #include "StorageBaseStatementInternal.h" |
|
10 |
|
11 namespace mozilla { |
|
12 namespace storage { |
|
13 |
|
14 //////////////////////////////////////////////////////////////////////////////// |
|
15 //// BindingParamsArray |
|
16 |
|
17 BindingParamsArray::BindingParamsArray( |
|
18 StorageBaseStatementInternal *aOwningStatement |
|
19 ) |
|
20 : mOwningStatement(aOwningStatement) |
|
21 , mLocked(false) |
|
22 { |
|
23 } |
|
24 |
|
25 void |
|
26 BindingParamsArray::lock() |
|
27 { |
|
28 NS_ASSERTION(mLocked == false, "Array has already been locked!"); |
|
29 mLocked = true; |
|
30 |
|
31 // We also no longer need to hold a reference to our statement since it owns |
|
32 // us. |
|
33 mOwningStatement = nullptr; |
|
34 } |
|
35 |
|
36 const StorageBaseStatementInternal * |
|
37 BindingParamsArray::getOwner() const |
|
38 { |
|
39 return mOwningStatement; |
|
40 } |
|
41 |
|
42 NS_IMPL_ISUPPORTS( |
|
43 BindingParamsArray, |
|
44 mozIStorageBindingParamsArray |
|
45 ) |
|
46 |
|
47 /////////////////////////////////////////////////////////////////////////////// |
|
48 //// mozIStorageBindingParamsArray |
|
49 |
|
50 NS_IMETHODIMP |
|
51 BindingParamsArray::NewBindingParams(mozIStorageBindingParams **_params) |
|
52 { |
|
53 NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
|
54 |
|
55 nsCOMPtr<mozIStorageBindingParams> params( |
|
56 mOwningStatement->newBindingParams(this)); |
|
57 NS_ENSURE_TRUE(params, NS_ERROR_UNEXPECTED); |
|
58 |
|
59 params.forget(_params); |
|
60 return NS_OK; |
|
61 } |
|
62 |
|
63 NS_IMETHODIMP |
|
64 BindingParamsArray::AddParams(mozIStorageBindingParams *aParameters) |
|
65 { |
|
66 NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
|
67 |
|
68 BindingParams *params = static_cast<BindingParams *>(aParameters); |
|
69 |
|
70 // Check to make sure that this set of parameters was created with us. |
|
71 if (params->getOwner() != this) |
|
72 return NS_ERROR_UNEXPECTED; |
|
73 |
|
74 NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY); |
|
75 |
|
76 // Lock the parameters only after we've successfully added them. |
|
77 params->lock(); |
|
78 |
|
79 return NS_OK; |
|
80 } |
|
81 |
|
82 NS_IMETHODIMP |
|
83 BindingParamsArray::GetLength(uint32_t *_length) |
|
84 { |
|
85 *_length = length(); |
|
86 return NS_OK; |
|
87 } |
|
88 |
|
89 } // namespace storage |
|
90 } // namespace mozilla |