void MemoryIDBBackingStore::unregisterObjectStore(MemoryObjectStore& objectStore) { ASSERT(m_objectStoresByIdentifier.contains(objectStore.info().identifier())); ASSERT(m_objectStoresByName.contains(objectStore.info().name())); m_objectStoresByName.remove(objectStore.info().name()); m_objectStoresByIdentifier.remove(objectStore.info().identifier()); }
void MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort(MemoryObjectStore& objectStore) { LOG(IndexedDB, "MemoryIDBBackingStore::removeObjectStoreForVersionChangeAbort"); ASSERT(m_objectStoresByIdentifier.contains(objectStore.info().identifier())); ASSERT(m_objectStoresByIdentifier.get(objectStore.info().identifier()) == &objectStore); unregisterObjectStore(objectStore); }
IDBError MemoryIDBBackingStore::keyExistsInObjectStore(const IDBResourceIdentifier&, uint64_t objectStoreIdentifier, const IDBKeyData& keyData, bool& keyExists) { LOG(IndexedDB, "MemoryIDBBackingStore::keyExistsInObjectStore"); ASSERT(objectStoreIdentifier); MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); RELEASE_ASSERT(objectStore); keyExists = objectStore->containsRecord(keyData); return { }; }
void MemoryBackingStoreTransaction::addExistingObjectStore(MemoryObjectStore& objectStore) { LOG(IndexedDB, "MemoryBackingStoreTransaction::addExistingObjectStore"); ASSERT(isWriting()); ASSERT(!m_objectStores.contains(&objectStore)); m_objectStores.add(&objectStore); objectStore.writeTransactionStarted(*this); m_originalKeyGenerators.add(&objectStore, objectStore.currentKeyGeneratorValue()); }
IDBError MemoryIDBBackingStore::revertGeneratedKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t keyNumber) { LOG(IndexedDB, "MemoryIDBBackingStore::revertGeneratedKeyNumber"); ASSERT(objectStoreIdentifier); ASSERT_UNUSED(transactionIdentifier, m_transactions.contains(transactionIdentifier)); ASSERT_UNUSED(transactionIdentifier, m_transactions.get(transactionIdentifier)->isWriting()); MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); RELEASE_ASSERT(objectStore); objectStore->setKeyGeneratorValue(keyNumber); return { }; }
IDBError MemoryIDBBackingStore::getIndexRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, IndexedDB::IndexRecordType recordType, const IDBKeyRangeData& range, IDBGetResult& outValue) { LOG(IndexedDB, "MemoryIDBBackingStore::getIndexRecord"); ASSERT(objectStoreIdentifier); if (!m_transactions.contains(transactionIdentifier)) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to get record") }; MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); if (!objectStore) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found") }; outValue = objectStore->indexValueForKeyRange(indexIdentifier, recordType, range); return { }; }
IDBError MemoryIDBBackingStore::addRecord(const IDBResourceIdentifier& transactionIdentifier, const IDBObjectStoreInfo& objectStoreInfo, const IDBKeyData& keyData, const IDBValue& value) { LOG(IndexedDB, "MemoryIDBBackingStore::addRecord"); ASSERT(objectStoreInfo.identifier()); auto transaction = m_transactions.get(transactionIdentifier); if (!transaction) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to put record") }; MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreInfo.identifier()); if (!objectStore) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found to put record") }; return objectStore->addRecord(*transaction, keyData, value); }
IDBError MemoryIDBBackingStore::deleteRange(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range) { LOG(IndexedDB, "MemoryIDBBackingStore::deleteRange"); ASSERT(objectStoreIdentifier); if (!m_transactions.contains(transactionIdentifier)) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to delete from") }; MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); if (!objectStore) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found") }; objectStore->deleteRange(range); return { }; }
IDBError MemoryIDBBackingStore::getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, ThreadSafeDataBuffer& outValue) { LOG(IndexedDB, "MemoryIDBBackingStore::getRecord"); ASSERT(objectStoreIdentifier); if (!m_transactions.contains(transactionIdentifier)) return IDBError(IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to get record")); MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); if (!objectStore) return IDBError(IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found")); outValue = objectStore->valueForKeyRange(range); return IDBError(); }
IDBError MemoryIDBBackingStore::getCount(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData& range, uint64_t& outCount) { LOG(IndexedDB, "MemoryIDBBackingStore::getCount"); ASSERT(objectStoreIdentifier); if (!m_transactions.contains(transactionIdentifier)) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to get count") }; MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); if (!objectStore) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found") }; outCount = objectStore->countForKeyRange(indexIdentifier, range); return { }; }
IDBError MemoryIDBBackingStore::generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) { LOG(IndexedDB, "MemoryIDBBackingStore::generateKeyNumber"); ASSERT(objectStoreIdentifier); ASSERT_UNUSED(transactionIdentifier, m_transactions.contains(transactionIdentifier)); ASSERT_UNUSED(transactionIdentifier, m_transactions.get(transactionIdentifier)->isWriting()); MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); RELEASE_ASSERT(objectStore); keyNumber = objectStore->currentKeyGeneratorValue(); if (keyNumber > maxGeneratedKeyValue) return { IDBDatabaseException::ConstraintError, "Cannot generate new key value over 2^53 for object store operation" }; objectStore->setKeyGeneratorValue(keyNumber + 1); return { }; }
void MemoryBackingStoreTransaction::addExistingObjectStore(MemoryObjectStore& objectStore) { LOG(IndexedDB, "MemoryBackingStoreTransaction::addExistingObjectStore"); ASSERT(isWriting()); ASSERT(!m_objectStores.contains(&objectStore)); m_objectStores.add(&objectStore); objectStore.writeTransactionStarted(*this); }
MemoryObjectStoreCursor::MemoryObjectStoreCursor(MemoryObjectStore& objectStore, const IDBCursorInfo& info) : MemoryCursor(info) , m_objectStore(objectStore) { m_remainingRange = m_info.range(); auto* orderedKeys = objectStore.orderedKeys(); if (!orderedKeys) return; setFirstInRemainingRange(*orderedKeys); }
void MemoryBackingStoreTransaction::addNewObjectStore(MemoryObjectStore& objectStore) { LOG(IndexedDB, "MemoryBackingStoreTransaction::addNewObjectStore()"); ASSERT(isVersionChange()); ASSERT(!m_objectStores.contains(&objectStore)); m_objectStores.add(&objectStore); m_versionChangeAddedObjectStores.add(&objectStore); objectStore.writeTransactionStarted(*this); }
MemoryObjectStoreCursor::MemoryObjectStoreCursor(MemoryObjectStore& objectStore, const IDBCursorInfo& info) : MemoryCursor(info) , m_objectStore(objectStore) , m_remainingRange(info.range()) { LOG(IndexedDB, "MemoryObjectStoreCursor::MemoryObjectStoreCursor %s", info.range().loggingString().utf8().data()); auto* orderedKeys = objectStore.orderedKeys(); if (!orderedKeys) return; setFirstInRemainingRange(*orderedKeys); }
IDBError MemoryIDBBackingStore::maybeUpdateKeyGeneratorNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, double newKeyNumber) { LOG(IndexedDB, "MemoryIDBBackingStore::maybeUpdateKeyGeneratorNumber"); ASSERT(objectStoreIdentifier); ASSERT_UNUSED(transactionIdentifier, m_transactions.contains(transactionIdentifier)); ASSERT_UNUSED(transactionIdentifier, m_transactions.get(transactionIdentifier)->isWriting()); MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); RELEASE_ASSERT(objectStore); if (newKeyNumber < objectStore->currentKeyGeneratorValue()) return { }; uint64_t newKeyInteger(newKeyNumber); if (newKeyInteger <= uint64_t(newKeyNumber)) ++newKeyInteger; ASSERT(newKeyInteger > uint64_t(newKeyNumber)); objectStore->setKeyGeneratorValue(newKeyInteger); return { }; }
IDBError MemoryIDBBackingStore::getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, IDBGetRecordDataType type, IDBGetResult& outValue) { LOG(IndexedDB, "MemoryIDBBackingStore::getRecord"); ASSERT(objectStoreIdentifier); if (!m_transactions.contains(transactionIdentifier)) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store transaction found to get record") }; MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier); if (!objectStore) return { IDBDatabaseException::UnknownError, ASCIILiteral("No backing store object store found") }; switch (type) { case IDBGetRecordDataType::KeyAndValue: outValue = objectStore->valueForKeyRange(range); break; case IDBGetRecordDataType::KeyOnly: outValue = objectStore->lowestKeyWithRecordInRange(range); break; } return { }; }
void MemoryBackingStoreTransaction::recordValueChanged(MemoryObjectStore& objectStore, const IDBKeyData& key) { ASSERT(m_objectStores.contains(&objectStore)); if (m_isAborting) return; auto originalAddResult = m_originalValues.add(&objectStore, nullptr); if (originalAddResult.isNewEntry) originalAddResult.iterator->value = std::make_unique<KeyValueMap>(); auto* map = originalAddResult.iterator->value.get(); auto addResult = map->add(key, ThreadSafeDataBuffer()); if (!addResult.isNewEntry) return; addResult.iterator->value = objectStore.valueForKey(key); }