OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 ASSERT(m_objectStore); | 48 ASSERT(m_objectStore); |
49 ASSERT(m_transaction); | 49 ASSERT(m_transaction); |
50 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); | 50 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); |
51 ScriptWrappable::init(this); | 51 ScriptWrappable::init(this); |
52 } | 52 } |
53 | 53 |
54 IDBIndex::~IDBIndex() | 54 IDBIndex::~IDBIndex() |
55 { | 55 { |
56 } | 56 } |
57 | 57 |
58 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, Pas
sRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionCode& ec) | 58 IDBRequest* IDBIndex::openCursor(ScriptExecutionContext* context, PassRefPtr<IDB
KeyRange> keyRange, const String& directionString, ExceptionCode& ec) |
59 { | 59 { |
60 IDB_TRACE("IDBIndex::openCursor"); | 60 IDB_TRACE("IDBIndex::openCursor"); |
61 if (isDeleted()) { | 61 if (isDeleted()) { |
62 ec = IDBDatabaseException::InvalidStateError; | 62 ec = IDBDatabaseException::InvalidStateError; |
63 return 0; | 63 return 0; |
64 } | 64 } |
65 if (!m_transaction->isActive()) { | 65 if (!m_transaction->isActive()) { |
66 ec = IDBDatabaseException::TransactionInactiveError; | 66 ec = IDBDatabaseException::TransactionInactiveError; |
67 return 0; | 67 return 0; |
68 } | 68 } |
69 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); | 69 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); |
70 if (ec) | 70 if (ec) |
71 return 0; | 71 return 0; |
72 | 72 |
73 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 73 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); |
74 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 74 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
75 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques
t); | 75 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques
t); |
76 return request; | 76 return request; |
77 } | 77 } |
78 | 78 |
79 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, con
st ScriptValue& key, const String& direction, ExceptionCode& ec) | 79 IDBRequest* IDBIndex::openCursor(ScriptExecutionContext* context, const ScriptVa
lue& key, const String& direction, ExceptionCode& ec) |
80 { | 80 { |
81 IDB_TRACE("IDBIndex::openCursor"); | 81 IDB_TRACE("IDBIndex::openCursor"); |
82 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 82 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
83 if (ec) | 83 if (ec) |
84 return 0; | 84 return 0; |
85 return openCursor(context, keyRange.release(), direction, ec); | 85 return openCursor(context, keyRange.release(), direction, ec); |
86 } | 86 } |
87 | 87 |
88 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, PassRefP
tr<IDBKeyRange> keyRange, ExceptionCode& ec) | 88 IDBRequest* IDBIndex::count(ScriptExecutionContext* context, PassRefPtr<IDBKeyRa
nge> keyRange, ExceptionCode& ec) |
89 { | 89 { |
90 IDB_TRACE("IDBIndex::count"); | 90 IDB_TRACE("IDBIndex::count"); |
91 if (isDeleted()) { | 91 if (isDeleted()) { |
92 ec = IDBDatabaseException::InvalidStateError; | 92 ec = IDBDatabaseException::InvalidStateError; |
93 return 0; | 93 return 0; |
94 } | 94 } |
95 if (!m_transaction->isActive()) { | 95 if (!m_transaction->isActive()) { |
96 ec = IDBDatabaseException::TransactionInactiveError; | 96 ec = IDBDatabaseException::TransactionInactiveError; |
97 return 0; | 97 return 0; |
98 } | 98 } |
99 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 99 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); |
100 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, request); | 100 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, request); |
101 return request; | 101 return request; |
102 } | 102 } |
103 | 103 |
104 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, const Sc
riptValue& key, ExceptionCode& ec) | 104 IDBRequest* IDBIndex::count(ScriptExecutionContext* context, const ScriptValue&
key, ExceptionCode& ec) |
105 { | 105 { |
106 IDB_TRACE("IDBIndex::count"); | 106 IDB_TRACE("IDBIndex::count"); |
107 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 107 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
108 if (ec) | 108 if (ec) |
109 return 0; | 109 return 0; |
110 return count(context, keyRange.release(), ec); | 110 return count(context, keyRange.release(), ec); |
111 } | 111 } |
112 | 112 |
113 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context,
PassRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionCode&
ec) | 113 IDBRequest* IDBIndex::openKeyCursor(ScriptExecutionContext* context, PassRefPtr<
IDBKeyRange> keyRange, const String& directionString, ExceptionCode& ec) |
114 { | 114 { |
115 IDB_TRACE("IDBIndex::openKeyCursor"); | 115 IDB_TRACE("IDBIndex::openKeyCursor"); |
116 if (isDeleted()) { | 116 if (isDeleted()) { |
117 ec = IDBDatabaseException::InvalidStateError; | 117 ec = IDBDatabaseException::InvalidStateError; |
118 return 0; | 118 return 0; |
119 } | 119 } |
120 if (!m_transaction->isActive()) { | 120 if (!m_transaction->isActive()) { |
121 ec = IDBDatabaseException::TransactionInactiveError; | 121 ec = IDBDatabaseException::TransactionInactiveError; |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); | 124 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); |
125 if (ec) | 125 if (ec) |
126 return 0; | 126 return 0; |
127 | 127 |
128 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 128 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); |
129 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 129 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
130 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request
); | 130 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request
); |
131 return request; | 131 return request; |
132 } | 132 } |
133 | 133 |
134 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context,
const ScriptValue& key, const String& direction, ExceptionCode& ec) | 134 IDBRequest* IDBIndex::openKeyCursor(ScriptExecutionContext* context, const Scrip
tValue& key, const String& direction, ExceptionCode& ec) |
135 { | 135 { |
136 IDB_TRACE("IDBIndex::openKeyCursor"); | 136 IDB_TRACE("IDBIndex::openKeyCursor"); |
137 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 137 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
138 if (ec) | 138 if (ec) |
139 return 0; | 139 return 0; |
140 return openKeyCursor(context, keyRange.release(), direction, ec); | 140 return openKeyCursor(context, keyRange.release(), direction, ec); |
141 } | 141 } |
142 | 142 |
143 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, const Scri
ptValue& key, ExceptionCode& ec) | 143 IDBRequest* IDBIndex::get(ScriptExecutionContext* context, const ScriptValue& ke
y, ExceptionCode& ec) |
144 { | 144 { |
145 IDB_TRACE("IDBIndex::get"); | 145 IDB_TRACE("IDBIndex::get"); |
146 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 146 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
147 if (ec) | 147 if (ec) |
148 return 0; | 148 return 0; |
149 return get(context, keyRange.release(), ec); | 149 return get(context, keyRange.release(), ec); |
150 } | 150 } |
151 | 151 |
152 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, PassRefPtr
<IDBKeyRange> keyRange, ExceptionCode& ec) | 152 IDBRequest* IDBIndex::get(ScriptExecutionContext* context, PassRefPtr<IDBKeyRang
e> keyRange, ExceptionCode& ec) |
153 { | 153 { |
154 IDB_TRACE("IDBIndex::get"); | 154 IDB_TRACE("IDBIndex::get"); |
155 if (isDeleted()) { | 155 if (isDeleted()) { |
156 ec = IDBDatabaseException::InvalidStateError; | 156 ec = IDBDatabaseException::InvalidStateError; |
157 return 0; | 157 return 0; |
158 } | 158 } |
159 if (!m_transaction->isActive()) { | 159 if (!m_transaction->isActive()) { |
160 ec = IDBDatabaseException::TransactionInactiveError; | 160 ec = IDBDatabaseException::TransactionInactiveError; |
161 return 0; | 161 return 0; |
162 } | 162 } |
163 if (!keyRange) { | 163 if (!keyRange) { |
164 ec = IDBDatabaseException::DataError; | 164 ec = IDBDatabaseException::DataError; |
165 return 0; | 165 return 0; |
166 } | 166 } |
167 | 167 |
168 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 168 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); |
169 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, false, request); | 169 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, false, request); |
170 return request; | 170 return request; |
171 } | 171 } |
172 | 172 |
173 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, const S
criptValue& key, ExceptionCode& ec) | 173 IDBRequest* IDBIndex::getKey(ScriptExecutionContext* context, const ScriptValue&
key, ExceptionCode& ec) |
174 { | 174 { |
175 IDB_TRACE("IDBIndex::getKey"); | 175 IDB_TRACE("IDBIndex::getKey"); |
176 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 176 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
177 if (ec) | 177 if (ec) |
178 return 0; | 178 return 0; |
179 | 179 |
180 return getKey(context, keyRange.release(), ec); | 180 return getKey(context, keyRange.release(), ec); |
181 } | 181 } |
182 | 182 |
183 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, PassRef
Ptr<IDBKeyRange> keyRange, ExceptionCode& ec) | 183 IDBRequest* IDBIndex::getKey(ScriptExecutionContext* context, PassRefPtr<IDBKeyR
ange> keyRange, ExceptionCode& ec) |
184 { | 184 { |
185 IDB_TRACE("IDBIndex::getKey"); | 185 IDB_TRACE("IDBIndex::getKey"); |
186 if (isDeleted()) { | 186 if (isDeleted()) { |
187 ec = IDBDatabaseException::InvalidStateError; | 187 ec = IDBDatabaseException::InvalidStateError; |
188 return 0; | 188 return 0; |
189 } | 189 } |
190 if (!m_transaction->isActive()) { | 190 if (!m_transaction->isActive()) { |
191 ec = IDBDatabaseException::TransactionInactiveError; | 191 ec = IDBDatabaseException::TransactionInactiveError; |
192 return 0; | 192 return 0; |
193 } | 193 } |
194 if (!keyRange) { | 194 if (!keyRange) { |
195 ec = IDBDatabaseException::DataError; | 195 ec = IDBDatabaseException::DataError; |
196 return 0; | 196 return 0; |
197 } | 197 } |
198 | 198 |
199 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 199 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); |
200 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, true, request); | 200 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, true, request); |
201 return request; | 201 return request; |
202 } | 202 } |
203 | 203 |
204 IDBDatabaseBackendInterface* IDBIndex::backendDB() const | 204 IDBDatabaseBackendInterface* IDBIndex::backendDB() const |
205 { | 205 { |
206 return m_transaction->backendDB(); | 206 return m_transaction->backendDB(); |
207 } | 207 } |
208 | 208 |
209 bool IDBIndex::isDeleted() const | 209 bool IDBIndex::isDeleted() const |
210 { | 210 { |
211 return m_deleted || m_objectStore->isDeleted(); | 211 return m_deleted || m_objectStore->isDeleted(); |
212 } | 212 } |
213 | 213 |
214 } // namespace WebCore | 214 } // namespace WebCore |
OLD | NEW |