IDBObjectStoreInfo.cpp [plain text]
#include "config.h"
#include "IDBObjectStoreInfo.h"
#if ENABLE(INDEXED_DATABASE)
namespace WebCore {
IDBObjectStoreInfo::IDBObjectStoreInfo()
{
}
IDBObjectStoreInfo::IDBObjectStoreInfo(uint64_t identifier, const String& name, const IDBKeyPath& keyPath, bool autoIncrement)
: m_identifier(identifier)
, m_name(name)
, m_keyPath(keyPath)
, m_autoIncrement(autoIncrement)
{
}
IDBIndexInfo IDBObjectStoreInfo::createNewIndex(const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry)
{
IDBIndexInfo info(++m_maxIndexID, m_identifier, name, keyPath, unique, multiEntry);
m_indexMap.set(info.identifier(), info);
return info;
}
void IDBObjectStoreInfo::addExistingIndex(const IDBIndexInfo& info)
{
ASSERT(!m_indexMap.contains(info.identifier()));
if (info.identifier() > m_maxIndexID)
m_maxIndexID = info.identifier();
m_indexMap.set(info.identifier(), info);
}
bool IDBObjectStoreInfo::hasIndex(const String& name) const
{
for (auto& index : m_indexMap.values()) {
if (index.name() == name)
return true;
}
return false;
}
bool IDBObjectStoreInfo::hasIndex(uint64_t indexIdentifier) const
{
return m_indexMap.contains(indexIdentifier);
}
IDBIndexInfo* IDBObjectStoreInfo::infoForExistingIndex(const String& name)
{
for (auto& index : m_indexMap.values()) {
if (index.name() == name)
return &index;
}
return nullptr;
}
IDBObjectStoreInfo IDBObjectStoreInfo::isolatedCopy() const
{
IDBObjectStoreInfo result = { m_identifier, m_name.isolatedCopy(), m_keyPath.isolatedCopy(), m_autoIncrement };
for (auto& iterator : m_indexMap) {
result.m_indexMap.set(iterator.key, iterator.value.isolatedCopy());
if (iterator.key > result.m_maxIndexID)
result.m_maxIndexID = iterator.key;
}
ASSERT(result.m_maxIndexID == m_maxIndexID);
return result;
}
Vector<String> IDBObjectStoreInfo::indexNames() const
{
Vector<String> names;
names.reserveCapacity(m_indexMap.size());
for (auto& index : m_indexMap.values())
names.uncheckedAppend(index.name());
return names;
}
void IDBObjectStoreInfo::deleteIndex(const String& indexName)
{
auto* info = infoForExistingIndex(indexName);
if (!info)
return;
m_indexMap.remove(info->identifier());
}
void IDBObjectStoreInfo::deleteIndex(uint64_t indexIdentifier)
{
m_indexMap.remove(indexIdentifier);
}
#if !LOG_DISABLED
String IDBObjectStoreInfo::loggingString(int indent) const
{
String indentString;
for (int i = 0; i < indent; ++i)
indentString.append(" ");
String top = makeString(indentString, "Object store: ", m_name, String::format(" (%" PRIu64 ") \n", m_identifier));
for (auto index : m_indexMap.values())
top.append(makeString(index.loggingString(indent + 1), "\n"));
return top;
}
#endif
}
#endif // ENABLE(INDEXED_DATABASE)