本文整理汇总了C++中IDBTransaction::CreateObjectStore方法的典型用法代码示例。如果您正苦于以下问题:C++ IDBTransaction::CreateObjectStore方法的具体用法?C++ IDBTransaction::CreateObjectStore怎么用?C++ IDBTransaction::CreateObjectStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDBTransaction
的用法示例。
在下文中一共展示了IDBTransaction::CreateObjectStore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keyPath
already_AddRefed<IDBObjectStore>
IDBDatabase::CreateObjectStore(
const nsAString& aName,
const IDBObjectStoreParameters& aOptionalParameters,
ErrorResult& aRv)
{
AssertIsOnOwningThread();
IDBTransaction* transaction = IDBTransaction::GetCurrent();
if (!transaction ||
transaction->Database() != this ||
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return nullptr;
}
if (!transaction->IsOpen()) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
return nullptr;
}
KeyPath keyPath(0);
if (NS_FAILED(KeyPath::Parse(aOptionalParameters.mKeyPath, &keyPath))) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
}
nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
for (uint32_t count = objectStores.Length(), index = 0;
index < count;
index++) {
if (aName == objectStores[index].metadata().name()) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR);
return nullptr;
}
}
if (!keyPath.IsAllowedForObjectStore(aOptionalParameters.mAutoIncrement)) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return nullptr;
}
const ObjectStoreSpec* oldSpecElements =
objectStores.IsEmpty() ? nullptr : objectStores.Elements();
ObjectStoreSpec* newSpec = objectStores.AppendElement();
newSpec->metadata() =
ObjectStoreMetadata(transaction->NextObjectStoreId(), nsString(aName),
keyPath, aOptionalParameters.mAutoIncrement);
if (oldSpecElements &&
oldSpecElements != objectStores.Elements()) {
MOZ_ASSERT(objectStores.Length() > 1);
// Array got moved, update the spec pointers for all live objectStores and
// indexes.
RefreshSpec(/* aMayDelete */ false);
}
RefPtr<IDBObjectStore> objectStore =
transaction->CreateObjectStore(*newSpec);
MOZ_ASSERT(objectStore);
// Don't do this in the macro because we always need to increment the serial
// number to keep in sync with the parent.
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
"database(%s).transaction(%s).createObjectStore(%s)",
"IndexedDB %s: C T[%lld] R[%llu]: "
"IDBDatabase.createObjectStore()",
IDB_LOG_ID_STRING(),
transaction->LoggingSerialNumber(),
requestSerialNumber,
IDB_LOG_STRINGIFY(this),
IDB_LOG_STRINGIFY(transaction),
IDB_LOG_STRINGIFY(objectStore));
return objectStore.forget();
}