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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) | 67 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) |
68 indexNames->append(it->value.name); | 68 indexNames->append(it->value.name); |
69 indexNames->sort(); | 69 indexNames->sort(); |
70 return indexNames.release(); | 70 return indexNames.release(); |
71 } | 71 } |
72 | 72 |
73 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKeyRange> keyRange, ExceptionState& es) | 73 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKeyRange> keyRange, ExceptionState& es) |
74 { | 74 { |
75 IDB_TRACE("IDBObjectStore::get"); | 75 IDB_TRACE("IDBObjectStore::get"); |
76 if (isDeleted()) { | 76 if (isDeleted()) { |
77 es.throwDOMException(InvalidStateError); | 77 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
78 return 0; | 78 return 0; |
79 } | 79 } |
80 if (!keyRange) { | 80 if (!keyRange) { |
81 es.throwDOMException(DataError); | 81 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage
); |
| 82 return 0; |
| 83 } |
| 84 if (m_transaction->isFinished()) { |
| 85 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
82 return 0; | 86 return 0; |
83 } | 87 } |
84 if (!m_transaction->isActive()) { | 88 if (!m_transaction->isActive()) { |
85 es.throwDOMException(TransactionInactiveError); | 89 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
86 return 0; | 90 return 0; |
87 } | 91 } |
88 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 92 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
89 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key
Range, false, request); | 93 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key
Range, false, request); |
90 return request.release(); | 94 return request.release(); |
91 } | 95 } |
92 | 96 |
93 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons
t ScriptValue& key, ExceptionState& es) | 97 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons
t ScriptValue& key, ExceptionState& es) |
94 { | 98 { |
95 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 99 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ScriptExecutionContext* context = state->scriptExecutionContext(); | 142 ScriptExecutionContext* context = state->scriptExecutionContext(); |
139 DOMRequestState requestState(context); | 143 DOMRequestState requestState(context); |
140 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque
stState, keyValue); | 144 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque
stState, keyValue); |
141 return put(putMode, source, state, value, key.release(), es); | 145 return put(putMode, source, state, value, key.release(), es); |
142 } | 146 } |
143 | 147 |
144 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass
RefPtr<IDBKey> prpKey, ExceptionState& es) | 148 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass
RefPtr<IDBKey> prpKey, ExceptionState& es) |
145 { | 149 { |
146 RefPtr<IDBKey> key = prpKey; | 150 RefPtr<IDBKey> key = prpKey; |
147 if (isDeleted()) { | 151 if (isDeleted()) { |
148 es.throwDOMException(InvalidStateError); | 152 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 153 return 0; |
| 154 } |
| 155 if (m_transaction->isFinished()) { |
| 156 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
149 return 0; | 157 return 0; |
150 } | 158 } |
151 if (!m_transaction->isActive()) { | 159 if (!m_transaction->isActive()) { |
152 es.throwDOMException(TransactionInactiveError); | 160 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
153 return 0; | 161 return 0; |
154 } | 162 } |
155 if (m_transaction->isReadOnly()) { | 163 if (m_transaction->isReadOnly()) { |
156 es.throwDOMException(ReadOnlyError); | 164 es.throwDOMException(ReadOnlyError); |
157 return 0; | 165 return 0; |
158 } | 166 } |
159 | 167 |
160 // FIXME: Make serialize etc take an ExceptionState or use ScriptState::setD
OMException. | 168 // FIXME: Make serialize etc take an ExceptionState or use ScriptState::setD
OMException. |
161 bool didThrow = false; | 169 bool didThrow = false; |
162 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0,
didThrow); | 170 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0,
didThrow); |
163 if (didThrow) | 171 if (didThrow) |
164 return 0; | 172 return 0; |
165 | 173 |
166 if (serializedValue->blobURLs().size() > 0) { | 174 if (serializedValue->blobURLs().size() > 0) { |
167 // FIXME: Add Blob/File/FileList support | 175 // FIXME: Add Blob/File/FileList support |
168 es.throwDOMException(DataCloneError); | 176 es.throwDOMException(DataCloneError); |
169 return 0; | 177 return 0; |
170 } | 178 } |
171 | 179 |
172 const IDBKeyPath& keyPath = m_metadata.keyPath; | 180 const IDBKeyPath& keyPath = m_metadata.keyPath; |
173 const bool usesInLineKeys = !keyPath.isNull(); | 181 const bool usesInLineKeys = !keyPath.isNull(); |
174 const bool hasKeyGenerator = autoIncrement(); | 182 const bool hasKeyGenerator = autoIncrement(); |
175 | 183 |
176 ScriptExecutionContext* context = state->scriptExecutionContext(); | 184 ScriptExecutionContext* context = state->scriptExecutionContext(); |
177 DOMRequestState requestState(context); | 185 DOMRequestState requestState(context); |
178 | 186 |
179 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys &
& key) { | 187 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys &
& key) { |
180 es.throwDOMException(DataError); | 188 es.throwDOMException(DataError, "The object store uses in-line keys and
the key parameter was provided."); |
181 return 0; | 189 return 0; |
182 } | 190 } |
183 if (!usesInLineKeys && !hasKeyGenerator && !key) { | 191 if (!usesInLineKeys && !hasKeyGenerator && !key) { |
184 es.throwDOMException(DataError); | 192 es.throwDOMException(DataError, "The object store uses out-of-line keys
and has no key generator and the key parameter was not provided."); |
185 return 0; | 193 return 0; |
186 } | 194 } |
187 if (usesInLineKeys) { | 195 if (usesInLineKeys) { |
188 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque
stState, value, keyPath); | 196 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque
stState, value, keyPath); |
189 if (keyPathKey && !keyPathKey->isValid()) { | 197 if (keyPathKey && !keyPathKey->isValid()) { |
190 es.throwDOMException(DataError); | 198 es.throwDOMException(DataError, "Evaluating the object store's key p
ath yielded a value that is not a valid key."); |
191 return 0; | 199 return 0; |
192 } | 200 } |
193 if (!hasKeyGenerator && !keyPathKey) { | 201 if (!hasKeyGenerator && !keyPathKey) { |
194 es.throwDOMException(DataError); | 202 es.throwDOMException(DataError, "Evaluating the object store's key p
ath did not yield a value."); |
195 return 0; | 203 return 0; |
196 } | 204 } |
197 if (hasKeyGenerator && !keyPathKey) { | 205 if (hasKeyGenerator && !keyPathKey) { |
198 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath))
{ | 206 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath))
{ |
199 es.throwDOMException(DataError); | 207 es.throwDOMException(DataError, "A generated key could not be in
serted into the value."); |
200 return 0; | 208 return 0; |
201 } | 209 } |
202 } | 210 } |
203 if (keyPathKey) | 211 if (keyPathKey) |
204 key = keyPathKey; | 212 key = keyPathKey; |
205 } | 213 } |
206 if (key && !key->isValid()) { | 214 if (key && !key->isValid()) { |
207 es.throwDOMException(DataError); | 215 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); |
208 return 0; | 216 return 0; |
209 } | 217 } |
210 | 218 |
211 Vector<int64_t> indexIds; | 219 Vector<int64_t> indexIds; |
212 Vector<IndexKeys> indexKeys; | 220 Vector<IndexKeys> indexKeys; |
213 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 221 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { |
214 IndexKeys keys; | 222 IndexKeys keys; |
215 generateIndexKeysForValue(&requestState, it->value, value, &keys); | 223 generateIndexKeysForValue(&requestState, it->value, value, &keys); |
216 indexIds.append(it->key); | 224 indexIds.append(it->key); |
217 indexKeys.append(keys); | 225 indexKeys.append(keys); |
218 } | 226 } |
219 | 227 |
220 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); | 228 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); |
221 Vector<char> wireBytes; | 229 Vector<char> wireBytes; |
222 serializedValue->toWireBytes(wireBytes); | 230 serializedValue->toWireBytes(wireBytes); |
223 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 231 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
224 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat
ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index
Keys); | 232 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat
ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index
Keys); |
225 return request.release(); | 233 return request.release(); |
226 } | 234 } |
227 | 235 |
228 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionState& es) | 236 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionState& es) |
229 { | 237 { |
230 IDB_TRACE("IDBObjectStore::delete"); | 238 IDB_TRACE("IDBObjectStore::delete"); |
231 if (isDeleted()) { | 239 if (isDeleted()) { |
232 es.throwDOMException(InvalidStateError); | 240 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 241 return 0; |
| 242 } |
| 243 if (m_transaction->isFinished()) { |
| 244 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
233 return 0; | 245 return 0; |
234 } | 246 } |
235 if (!m_transaction->isActive()) { | 247 if (!m_transaction->isActive()) { |
236 es.throwDOMException(TransactionInactiveError); | 248 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
237 return 0; | 249 return 0; |
238 } | 250 } |
239 if (m_transaction->isReadOnly()) { | 251 if (m_transaction->isReadOnly()) { |
240 es.throwDOMException(ReadOnlyError); | 252 es.throwDOMException(ReadOnlyError); |
241 return 0; | 253 return 0; |
242 } | 254 } |
243 if (!keyRange) { | 255 if (!keyRange) { |
244 es.throwDOMException(DataError); | 256 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage
); |
245 return 0; | 257 return 0; |
246 } | 258 } |
247 | 259 |
248 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 260 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
249 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); | 261 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); |
250 return request.release(); | 262 return request.release(); |
251 } | 263 } |
252 | 264 |
253 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, const ScriptValue& key, ExceptionState& es) | 265 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, const ScriptValue& key, ExceptionState& es) |
254 { | 266 { |
255 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 267 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
256 if (es.hadException()) | 268 if (es.hadException()) |
257 return 0; | 269 return 0; |
258 return deleteFunction(context, keyRange.release(), es); | 270 return deleteFunction(context, keyRange.release(), es); |
259 } | 271 } |
260 | 272 |
261 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex
ceptionState& es) | 273 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex
ceptionState& es) |
262 { | 274 { |
263 IDB_TRACE("IDBObjectStore::clear"); | 275 IDB_TRACE("IDBObjectStore::clear"); |
264 if (isDeleted()) { | 276 if (isDeleted()) { |
265 es.throwDOMException(InvalidStateError); | 277 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 278 return 0; |
| 279 } |
| 280 if (m_transaction->isFinished()) { |
| 281 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
266 return 0; | 282 return 0; |
267 } | 283 } |
268 if (!m_transaction->isActive()) { | 284 if (!m_transaction->isActive()) { |
269 es.throwDOMException(TransactionInactiveError); | 285 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
270 return 0; | 286 return 0; |
271 } | 287 } |
272 if (m_transaction->isReadOnly()) { | 288 if (m_transaction->isReadOnly()) { |
273 es.throwDOMException(ReadOnlyError); | 289 es.throwDOMException(ReadOnlyError); |
274 return 0; | 290 return 0; |
275 } | 291 } |
276 | 292 |
277 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 293 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
278 backendDB()->clear(m_transaction->id(), id(), request); | 294 backendDB()->clear(m_transaction->id(), id(), request); |
279 return request.release(); | 295 return request.release(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 372 |
357 bool multiEntry = false; | 373 bool multiEntry = false; |
358 options.get("multiEntry", multiEntry); | 374 options.get("multiEntry", multiEntry); |
359 | 375 |
360 return createIndex(context, name, keyPath, unique, multiEntry, es); | 376 return createIndex(context, name, keyPath, unique, multiEntry, es); |
361 } | 377 } |
362 | 378 |
363 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E
xceptionState& es) | 379 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E
xceptionState& es) |
364 { | 380 { |
365 IDB_TRACE("IDBObjectStore::createIndex"); | 381 IDB_TRACE("IDBObjectStore::createIndex"); |
366 if (!m_transaction->isVersionChange() || isDeleted()) { | 382 if (!m_transaction->isVersionChange()) { |
367 es.throwDOMException(InvalidStateError); | 383 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); |
| 384 return 0; |
| 385 } |
| 386 if (isDeleted()) { |
| 387 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 388 return 0; |
| 389 } |
| 390 if (m_transaction->isFinished()) { |
| 391 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
368 return 0; | 392 return 0; |
369 } | 393 } |
370 if (!m_transaction->isActive()) { | 394 if (!m_transaction->isActive()) { |
371 es.throwDOMException(TransactionInactiveError); | 395 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
372 return 0; | 396 return 0; |
373 } | 397 } |
374 if (!keyPath.isValid()) { | 398 if (!keyPath.isValid()) { |
375 es.throwDOMException(SyntaxError); | 399 es.throwDOMException(SyntaxError, "The keyPath argument contains an inva
lid key path."); |
376 return 0; | 400 return 0; |
377 } | 401 } |
378 if (name.isNull()) { | 402 if (name.isNull()) { |
379 es.throwTypeError(); | 403 es.throwTypeError(); |
380 return 0; | 404 return 0; |
381 } | 405 } |
382 if (containsIndex(name)) { | 406 if (containsIndex(name)) { |
383 es.throwDOMException(ConstraintError); | 407 es.throwDOMException(ConstraintError, "An index with the specified name
already exists."); |
384 return 0; | 408 return 0; |
385 } | 409 } |
386 | 410 |
387 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { | 411 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { |
388 es.throwDOMException(InvalidAccessError); | 412 es.throwDOMException(InvalidAccessError, "The keyPath argument was an ar
ray and the multiEntry option is true."); |
389 return 0; | 413 return 0; |
390 } | 414 } |
391 | 415 |
392 int64_t indexId = m_metadata.maxIndexId + 1; | 416 int64_t indexId = m_metadata.maxIndexId + 1; |
393 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath,
unique, multiEntry); | 417 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath,
unique, multiEntry); |
394 | 418 |
395 ++m_metadata.maxIndexId; | 419 ++m_metadata.maxIndexId; |
396 | 420 |
397 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); | 421 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); |
398 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get(
)); | 422 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get(
)); |
(...skipping 15 matching lines...) Expand all Loading... |
414 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(),
m_transaction->id(), id(), metadata); | 438 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(),
m_transaction->id(), id(), metadata); |
415 indexRequest->setOnsuccess(indexPopulator); | 439 indexRequest->setOnsuccess(indexPopulator); |
416 | 440 |
417 return index.release(); | 441 return index.release(); |
418 } | 442 } |
419 | 443 |
420 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e
s) | 444 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e
s) |
421 { | 445 { |
422 IDB_TRACE("IDBObjectStore::index"); | 446 IDB_TRACE("IDBObjectStore::index"); |
423 if (isDeleted()) { | 447 if (isDeleted()) { |
424 es.throwDOMException(InvalidStateError); | 448 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
425 return 0; | 449 return 0; |
426 } | 450 } |
427 if (m_transaction->isFinished()) { | 451 if (m_transaction->isFinished()) { |
428 es.throwDOMException(InvalidStateError); | 452 es.throwDOMException(InvalidStateError, IDBDatabase::transactionFinished
ErrorMessage); |
429 return 0; | 453 return 0; |
430 } | 454 } |
431 | 455 |
432 IDBIndexMap::iterator it = m_indexMap.find(name); | 456 IDBIndexMap::iterator it = m_indexMap.find(name); |
433 if (it != m_indexMap.end()) | 457 if (it != m_indexMap.end()) |
434 return it->value; | 458 return it->value; |
435 | 459 |
436 int64_t indexId = findIndexId(name); | 460 int64_t indexId = findIndexId(name); |
437 if (indexId == IDBIndexMetadata::InvalidId) { | 461 if (indexId == IDBIndexMetadata::InvalidId) { |
438 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage); | 462 es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage
); |
439 return 0; | 463 return 0; |
440 } | 464 } |
441 | 465 |
442 const IDBIndexMetadata* indexMetadata(0); | 466 const IDBIndexMetadata* indexMetadata(0); |
443 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 467 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { |
444 if (it->value.name == name) { | 468 if (it->value.name == name) { |
445 indexMetadata = &it->value; | 469 indexMetadata = &it->value; |
446 break; | 470 break; |
447 } | 471 } |
448 } | 472 } |
449 ASSERT(indexMetadata); | 473 ASSERT(indexMetadata); |
450 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); | 474 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); |
451 | 475 |
452 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio
n.get()); | 476 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio
n.get()); |
453 m_indexMap.set(name, index); | 477 m_indexMap.set(name, index); |
454 return index.release(); | 478 return index.release(); |
455 } | 479 } |
456 | 480 |
457 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es) | 481 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es) |
458 { | 482 { |
459 IDB_TRACE("IDBObjectStore::deleteIndex"); | 483 IDB_TRACE("IDBObjectStore::deleteIndex"); |
460 if (!m_transaction->isVersionChange() || isDeleted()) { | 484 if (!m_transaction->isVersionChange()) { |
461 es.throwDOMException(InvalidStateError); | 485 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra
nsactionErrorMessage); |
| 486 return; |
| 487 } |
| 488 if (isDeleted()) { |
| 489 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 490 return; |
| 491 } |
| 492 if (m_transaction->isFinished()) { |
| 493 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
462 return; | 494 return; |
463 } | 495 } |
464 if (!m_transaction->isActive()) { | 496 if (!m_transaction->isActive()) { |
465 es.throwDOMException(TransactionInactiveError); | 497 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
466 return; | 498 return; |
467 } | 499 } |
468 int64_t indexId = findIndexId(name); | 500 int64_t indexId = findIndexId(name); |
469 if (indexId == IDBIndexMetadata::InvalidId) { | 501 if (indexId == IDBIndexMetadata::InvalidId) { |
470 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage); | 502 es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage
); |
471 return; | 503 return; |
472 } | 504 } |
473 | 505 |
474 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); | 506 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); |
475 | 507 |
476 m_metadata.indexes.remove(indexId); | 508 m_metadata.indexes.remove(indexId); |
477 m_transaction->db()->indexDeleted(id(), indexId); | 509 m_transaction->db()->indexDeleted(id(), indexId); |
478 IDBIndexMap::iterator it = m_indexMap.find(name); | 510 IDBIndexMap::iterator it = m_indexMap.find(name); |
479 if (it != m_indexMap.end()) { | 511 if (it != m_indexMap.end()) { |
480 it->value->markDeleted(); | 512 it->value->markDeleted(); |
481 m_indexMap.remove(name); | 513 m_indexMap.remove(name); |
482 } | 514 } |
483 } | 515 } |
484 | 516 |
485 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack
endInterface::TaskType taskType, ExceptionState& es) | 517 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack
endInterface::TaskType taskType, ExceptionState& es) |
486 { | 518 { |
487 IDB_TRACE("IDBObjectStore::openCursor"); | 519 IDB_TRACE("IDBObjectStore::openCursor"); |
488 if (isDeleted()) { | 520 if (isDeleted()) { |
489 es.throwDOMException(InvalidStateError); | 521 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 522 return 0; |
| 523 } |
| 524 if (m_transaction->isFinished()) { |
| 525 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
490 return 0; | 526 return 0; |
491 } | 527 } |
492 if (!m_transaction->isActive()) { | 528 if (!m_transaction->isActive()) { |
493 es.throwDOMException(TransactionInactiveError); | 529 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
494 return 0; | 530 return 0; |
495 } | 531 } |
496 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); | 532 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); |
497 if (es.hadException()) | 533 if (es.hadException()) |
498 return 0; | 534 return 0; |
499 | 535 |
500 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 536 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
501 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 537 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
502 | 538 |
503 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>(
taskType), request); | 539 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>(
taskType), request); |
504 return request.release(); | 540 return request.release(); |
505 } | 541 } |
506 | 542 |
507 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, const ScriptValue& key, const String& direction, ExceptionState& es) | 543 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, const ScriptValue& key, const String& direction, ExceptionState& es) |
508 { | 544 { |
509 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 545 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
510 if (es.hadException()) | 546 if (es.hadException()) |
511 return 0; | 547 return 0; |
512 return openCursor(context, keyRange.release(), direction, es); | 548 return openCursor(context, keyRange.release(), direction, es); |
513 } | 549 } |
514 | 550 |
515 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa
ssRefPtr<IDBKeyRange> range, ExceptionState& es) | 551 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa
ssRefPtr<IDBKeyRange> range, ExceptionState& es) |
516 { | 552 { |
517 IDB_TRACE("IDBObjectStore::count"); | 553 IDB_TRACE("IDBObjectStore::count"); |
518 if (isDeleted()) { | 554 if (isDeleted()) { |
519 es.throwDOMException(InvalidStateError); | 555 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE
rrorMessage); |
| 556 return 0; |
| 557 } |
| 558 if (m_transaction->isFinished()) { |
| 559 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
520 return 0; | 560 return 0; |
521 } | 561 } |
522 if (!m_transaction->isActive()) { | 562 if (!m_transaction->isActive()) { |
523 es.throwDOMException(TransactionInactiveError); | 563 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
524 return 0; | 564 return 0; |
525 } | 565 } |
526 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 566 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
527 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r
ange, request); | 567 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r
ange, request); |
528 return request.release(); | 568 return request.release(); |
529 } | 569 } |
530 | 570 |
531 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co
nst ScriptValue& key, ExceptionState& es) | 571 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co
nst ScriptValue& key, ExceptionState& es) |
532 { | 572 { |
533 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 573 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
(...skipping 20 matching lines...) Expand all Loading... |
554 } | 594 } |
555 return IDBIndexMetadata::InvalidId; | 595 return IDBIndexMetadata::InvalidId; |
556 } | 596 } |
557 | 597 |
558 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const | 598 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const |
559 { | 599 { |
560 return m_transaction->backendDB(); | 600 return m_transaction->backendDB(); |
561 } | 601 } |
562 | 602 |
563 } // namespace WebCore | 603 } // namespace WebCore |
OLD | NEW |