QmlDesigner: Add extension to projectstorage

Types have not only prototypes but extensions too.

Task-number: QDS-7382
Change-Id: Iae39b69be7e2254d3ad156910cd2de8c9c5345cb
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marco Bubke
2022-08-23 16:55:43 +02:00
committed by Thomas Hartmann
parent b99bc1a055
commit bba8cef73b
4 changed files with 879 additions and 63 deletions

View File

@@ -75,6 +75,7 @@ public:
AliasPropertyDeclarations relinkableAliasPropertyDeclarations; AliasPropertyDeclarations relinkableAliasPropertyDeclarations;
PropertyDeclarations relinkablePropertyDeclarations; PropertyDeclarations relinkablePropertyDeclarations;
Prototypes relinkablePrototypes; Prototypes relinkablePrototypes;
Prototypes relinkableExtensions;
TypeIds deletedTypeIds; TypeIds deletedTypeIds;
TypeIds updatedTypeIds; TypeIds updatedTypeIds;
@@ -98,6 +99,7 @@ public:
relinkableAliasPropertyDeclarations, relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes, relinkablePrototypes,
relinkableExtensions,
package.updatedSourceIds); package.updatedSourceIds);
deleteNotUpdatedTypes(updatedTypeIds, deleteNotUpdatedTypes(updatedTypeIds,
@@ -106,11 +108,13 @@ public:
relinkableAliasPropertyDeclarations, relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes, relinkablePrototypes,
relinkableExtensions,
deletedTypeIds); deletedTypeIds);
relink(relinkableAliasPropertyDeclarations, relink(relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes, relinkablePrototypes,
relinkableExtensions,
deletedTypeIds); deletedTypeIds);
linkAliases(insertedAliasPropertyDeclarations, updatedAliasPropertyDeclarations); linkAliases(insertedAliasPropertyDeclarations, updatedAliasPropertyDeclarations);
@@ -229,6 +233,8 @@ public:
return commonTypeCache.template builtinTypeId<builtinType>(); return commonTypeCache.template builtinTypeId<builtinType>();
} }
auto prototypes(TypeId type) const {}
PropertyDeclarationId fetchPropertyDeclarationByTypeIdAndName(TypeId typeId, PropertyDeclarationId fetchPropertyDeclarationByTypeIdAndName(TypeId typeId,
Utils::SmallStringView name) Utils::SmallStringView name)
{ {
@@ -640,6 +646,7 @@ private:
AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations,
Prototypes &relinkablePrototypes, Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions,
const SourceIds &updatedSourceIds) const SourceIds &updatedSourceIds)
{ {
Storage::Synchronization::ExportedTypes exportedTypes; Storage::Synchronization::ExportedTypes exportedTypes;
@@ -680,9 +687,10 @@ private:
exportedTypes, exportedTypes,
relinkableAliasPropertyDeclarations, relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes); relinkablePrototypes,
relinkableExtensions);
syncPrototypes(types, relinkablePrototypes); syncPrototypesAndExtensions(types, relinkablePrototypes, relinkableExtensions);
resetDefaultPropertiesIfChanged(types); resetDefaultPropertiesIfChanged(types);
resetRemovedAliasPropertyDeclarationsToNull(types, relinkableAliasPropertyDeclarations); resetRemovedAliasPropertyDeclarationsToNull(types, relinkableAliasPropertyDeclarations);
syncDeclarations(types, syncDeclarations(types,
@@ -930,14 +938,27 @@ private:
updatePrototypeIdToNullStatement.readCallback(callback, prototypeId); updatePrototypeIdToNullStatement.readCallback(callback, prototypeId);
} }
void handleExtensions(TypeId extensionId, Prototypes &relinkableExtensions)
{
auto callback = [&](TypeId typeId, ImportedTypeNameId extensionNameId) {
relinkableExtensions.emplace_back(typeId, extensionNameId);
return Sqlite::CallbackControl::Continue;
};
updateExtensionIdToNullStatement.readCallback(callback, extensionId);
}
void deleteType(TypeId typeId, void deleteType(TypeId typeId,
AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations,
Prototypes &relinkablePrototypes) Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions)
{ {
handlePropertyDeclarationWithPropertyType(typeId, relinkablePropertyDeclarations); handlePropertyDeclarationWithPropertyType(typeId, relinkablePropertyDeclarations);
handleAliasPropertyDeclarationsWithPropertyType(typeId, relinkableAliasPropertyDeclarations); handleAliasPropertyDeclarationsWithPropertyType(typeId, relinkableAliasPropertyDeclarations);
handlePrototypes(typeId, relinkablePrototypes); handlePrototypes(typeId, relinkablePrototypes);
handleExtensions(typeId, relinkableExtensions);
deleteTypeNamesByTypeIdStatement.write(typeId); deleteTypeNamesByTypeIdStatement.write(typeId);
deleteEnumerationDeclarationByTypeIdStatement.write(typeId); deleteEnumerationDeclarationByTypeIdStatement.write(typeId);
deletePropertyDeclarationByTypeIdStatement.write(typeId); deletePropertyDeclarationByTypeIdStatement.write(typeId);
@@ -995,8 +1016,10 @@ private:
}, },
TypeCompare<PropertyDeclaration>{}); TypeCompare<PropertyDeclaration>{});
} }
template<typename Callable>
void relinkPrototypes(Prototypes &relinkablePrototypes, const TypeIds &deletedTypeIds) void relinkPrototypes(Prototypes &relinkablePrototypes,
const TypeIds &deletedTypeIds,
Callable updateStatement)
{ {
std::sort(relinkablePrototypes.begin(), relinkablePrototypes.end()); std::sort(relinkablePrototypes.begin(), relinkablePrototypes.end());
@@ -1011,7 +1034,7 @@ private:
if (!prototypeId) if (!prototypeId)
throw TypeNameDoesNotExists{}; throw TypeNameDoesNotExists{};
updateTypePrototypeStatement.write(prototype.typeId, prototypeId); updateStatement(prototype.typeId, prototypeId);
checkForPrototypeChainCycle(prototype.typeId); checkForPrototypeChainCycle(prototype.typeId);
}, },
TypeCompare<Prototype>{}); TypeCompare<Prototype>{});
@@ -1023,6 +1046,7 @@ private:
AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations,
Prototypes &relinkablePrototypes, Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions,
TypeIds &deletedTypeIds) TypeIds &deletedTypeIds)
{ {
auto callback = [&](TypeId typeId) { auto callback = [&](TypeId typeId) {
@@ -1030,7 +1054,8 @@ private:
deleteType(typeId, deleteType(typeId,
relinkableAliasPropertyDeclarations, relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations, relinkablePropertyDeclarations,
relinkablePrototypes); relinkablePrototypes,
relinkableExtensions);
return Sqlite::CallbackControl::Continue; return Sqlite::CallbackControl::Continue;
}; };
@@ -1044,11 +1069,17 @@ private:
void relink(AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, void relink(AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations,
Prototypes &relinkablePrototypes, Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions,
TypeIds &deletedTypeIds) TypeIds &deletedTypeIds)
{ {
std::sort(deletedTypeIds.begin(), deletedTypeIds.end()); std::sort(deletedTypeIds.begin(), deletedTypeIds.end());
relinkPrototypes(relinkablePrototypes, deletedTypeIds); relinkPrototypes(relinkablePrototypes, deletedTypeIds, [&](TypeId typeId, TypeId prototypeId) {
updateTypePrototypeStatement.write(typeId, prototypeId);
});
relinkPrototypes(relinkableExtensions, deletedTypeIds, [&](TypeId typeId, TypeId prototypeId) {
updateTypeExtensionStatement.write(typeId, prototypeId);
});
relinkPropertyDeclarations(relinkablePropertyDeclarations, deletedTypeIds); relinkPropertyDeclarations(relinkablePropertyDeclarations, deletedTypeIds);
relinkAliasPropertyDeclarations(relinkableAliasPropertyDeclarations, deletedTypeIds); relinkAliasPropertyDeclarations(relinkableAliasPropertyDeclarations, deletedTypeIds);
} }
@@ -1119,7 +1150,8 @@ private:
Storage::Synchronization::ExportedTypes &exportedTypes, Storage::Synchronization::ExportedTypes &exportedTypes,
AliasPropertyDeclarations &relinkableAliasPropertyDeclarations, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations,
Prototypes &relinkablePrototypes) Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions)
{ {
std::sort(exportedTypes.begin(), exportedTypes.end(), [](auto &&first, auto &&second) { std::sort(exportedTypes.begin(), exportedTypes.end(), [](auto &&first, auto &&second) {
if (first.moduleId < second.moduleId) if (first.moduleId < second.moduleId)
@@ -1192,6 +1224,7 @@ private:
handleAliasPropertyDeclarationsWithPropertyType(view.typeId, handleAliasPropertyDeclarationsWithPropertyType(view.typeId,
relinkableAliasPropertyDeclarations); relinkableAliasPropertyDeclarations);
handlePrototypes(view.typeId, relinkablePrototypes); handlePrototypes(view.typeId, relinkablePrototypes);
handleExtensions(view.typeId, relinkableExtensions);
updateExportedTypeNameTypeIdStatement.write(view.exportedTypeNameId, type.typeId); updateExportedTypeNameTypeIdStatement.write(view.exportedTypeNameId, type.typeId);
return Sqlite::UpdateChange::Update; return Sqlite::UpdateChange::Update;
} }
@@ -1203,6 +1236,7 @@ private:
handleAliasPropertyDeclarationsWithPropertyType(view.typeId, handleAliasPropertyDeclarationsWithPropertyType(view.typeId,
relinkableAliasPropertyDeclarations); relinkableAliasPropertyDeclarations);
handlePrototypes(view.typeId, relinkablePrototypes); handlePrototypes(view.typeId, relinkablePrototypes);
handleExtensions(view.typeId, relinkableExtensions);
deleteExportedTypeNameStatement.write(view.exportedTypeNameId); deleteExportedTypeNameStatement.write(view.exportedTypeNameId);
}; };
@@ -1926,39 +1960,57 @@ private:
propertyDeclarationId); propertyDeclarationId);
} }
void syncPrototype(Storage::Synchronization::Type &type, TypeIds &typeIds) std::pair<TypeId, ImportedTypeNameId> fetchImportedTypeNameIdAndTypeId(
const Storage::Synchronization::ImportedTypeName &typeName, SourceId sourceId)
{
TypeId typeId;
ImportedTypeNameId typeNameId;
if (!std::visit([](auto &&typeName) -> bool { return typeName.name.isEmpty(); }, typeName)) {
typeNameId = fetchImportedTypeNameId(typeName, sourceId);
typeId = fetchTypeId(typeNameId);
if (!typeId)
throw TypeNameDoesNotExists{};
}
return {typeId, typeNameId};
}
void syncPrototypeAndExtension(Storage::Synchronization::Type &type, TypeIds &typeIds)
{ {
if (type.changeLevel == Storage::Synchronization::ChangeLevel::Minimal) if (type.changeLevel == Storage::Synchronization::ChangeLevel::Minimal)
return; return;
if (std::visit([](auto &&typeName) -> bool { return typeName.name.isEmpty(); }, auto [prototypeId, prototypeTypeNameId] = fetchImportedTypeNameIdAndTypeId(type.prototype,
type.prototype)) { type.sourceId);
updatePrototypeStatement.write(type.typeId, Sqlite::NullValue{}, Sqlite::NullValue{}); auto [extensionId, extensionTypeNameId] = fetchImportedTypeNameIdAndTypeId(type.extension,
} else {
ImportedTypeNameId prototypeTypeNameId = fetchImportedTypeNameId(type.prototype,
type.sourceId); type.sourceId);
TypeId prototypeId = fetchTypeId(prototypeTypeNameId); updatePrototypeAndExtensionStatement.write(type.typeId,
prototypeId,
prototypeTypeNameId,
extensionId,
extensionTypeNameId);
if (!prototypeId) if (prototypeId || extensionId)
throw TypeNameDoesNotExists{};
updatePrototypeStatement.write(type.typeId, prototypeId, prototypeTypeNameId);
checkForPrototypeChainCycle(type.typeId); checkForPrototypeChainCycle(type.typeId);
}
typeIds.push_back(type.typeId); typeIds.push_back(type.typeId);
} }
void syncPrototypes(Storage::Synchronization::Types &types, Prototypes &relinkablePrototypes) void syncPrototypesAndExtensions(Storage::Synchronization::Types &types,
Prototypes &relinkablePrototypes,
Prototypes &relinkableExtensions)
{ {
TypeIds typeIds; TypeIds typeIds;
typeIds.reserve(types.size()); typeIds.reserve(types.size());
for (auto &type : types) for (auto &type : types)
syncPrototype(type, typeIds); syncPrototypeAndExtension(type, typeIds);
removeRelinkableEntries(relinkablePrototypes, typeIds, TypeCompare<Prototype>{}); removeRelinkableEntries(relinkablePrototypes, typeIds, TypeCompare<Prototype>{});
removeRelinkableEntries(relinkableExtensions, typeIds, TypeCompare<Prototype>{});
} }
ImportId fetchImportId(SourceId sourceId, const Storage::Synchronization::Import &import) const ImportId fetchImportId(SourceId sourceId, const Storage::Synchronization::Import &import) const
@@ -2257,6 +2309,11 @@ private:
Sqlite::ForeignKeyAction::NoAction, Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Restrict); Sqlite::ForeignKeyAction::Restrict);
typesTable.addColumn("prototypeNameId", Sqlite::StrictColumnType::Integer); typesTable.addColumn("prototypeNameId", Sqlite::StrictColumnType::Integer);
typesTable.addForeignKeyColumn("extensionId",
typesTable,
Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Restrict);
typesTable.addColumn("extensionNameId", Sqlite::StrictColumnType::Integer);
auto &defaultPropertyIdColumn = typesTable.addColumn("defaultPropertyId", auto &defaultPropertyIdColumn = typesTable.addColumn("defaultPropertyId",
Sqlite::StrictColumnType::Integer); Sqlite::StrictColumnType::Integer);
@@ -2543,9 +2600,10 @@ public:
"UPDATE SET traits=excluded.traits WHERE traits IS NOT " "UPDATE SET traits=excluded.traits WHERE traits IS NOT "
"excluded.traits RETURNING typeId", "excluded.traits RETURNING typeId",
database}; database};
WriteStatement<3> updatePrototypeStatement{ WriteStatement<5> updatePrototypeAndExtensionStatement{
"UPDATE types SET prototypeId=?2, prototypeNameId=?3 WHERE typeId=?1 AND (prototypeId IS " "UPDATE types SET prototypeId=?2, prototypeNameId=?3, extensionId=?4, extensionNameId=?5 "
"NOT ?2 OR prototypeNameId IS NOT ?3)", "WHERE typeId=?1 AND (prototypeId IS NOT ?2 OR extensionId IS NOT ?3 AND prototypeId "
"IS NOT ?4 OR extensionNameId IS NOT ?5)",
database}; database};
mutable ReadStatement<1, 1> selectTypeIdByExportedNameStatement{ mutable ReadStatement<1, 1> selectTypeIdByExportedNameStatement{
"SELECT typeId FROM exportedTypeNames WHERE name=?1", database}; "SELECT typeId FROM exportedTypeNames WHERE name=?1", database};
@@ -2570,41 +2628,57 @@ public:
mutable ReadStatement<1, 2> selectPrototypeIdStatement{ mutable ReadStatement<1, 2> selectPrototypeIdStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeSelection(typeId) AS (" " typeSelection(typeId) AS ("
" VALUES(?1) " " VALUES(?1) "
" UNION ALL " " UNION ALL "
" SELECT prototypeId FROM types JOIN typeSelection USING(typeId) WHERE prototypeId " " SELECT prototypeId FROM all_prototype_and_extension JOIN typeSelection "
" IS NOT NULL)" " USING(typeId))"
"SELECT typeId FROM typeSelection WHERE typeId=?2 LIMIT 1", "SELECT typeId FROM typeSelection WHERE typeId=?2 LIMIT 1",
database}; database};
mutable ReadStatement<1, 2> selectPropertyDeclarationIdByTypeIdAndNameStatement{ mutable ReadStatement<1, 2> selectPropertyDeclarationIdByTypeIdAndNameStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeSelection(typeId, level) AS (" " typeSelection(typeId, level) AS ("
" VALUES(?1, 0) " " VALUES(?1, 0) "
" UNION ALL " " UNION ALL "
" SELECT prototypeId, typeSelection.level+1 FROM types JOIN typeSelection " " SELECT prototypeId, typeSelection.level+1 FROM all_prototype_and_extension JOIN "
" USING(typeId) WHERE prototypeId IS NOT NULL) " " typeSelection USING(typeId)) "
"SELECT propertyDeclarationId FROM propertyDeclarations JOIN typeSelection USING(typeId) " "SELECT propertyDeclarationId FROM propertyDeclarations JOIN typeSelection USING(typeId) "
" WHERE name=?2 ORDER BY level LIMIT 1", " WHERE name=?2 ORDER BY level LIMIT 1",
database}; database};
mutable ReadStatement<3, 2> selectPropertyDeclarationByTypeIdAndNameStatement{ mutable ReadStatement<3, 2> selectPropertyDeclarationByTypeIdAndNameStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeSelection(typeId, level) AS (" " typeSelection(typeId, level) AS ("
" VALUES(?1, 0) " " VALUES(?1, 0) "
" UNION ALL " " UNION ALL "
" SELECT prototypeId, typeSelection.level+1 FROM types JOIN typeSelection " " SELECT prototypeId, typeSelection.level+1 FROM all_prototype_and_extension JOIN "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " typeSelection USING(typeId))"
"SELECT propertyTypeId, propertyDeclarationId, propertyTraits " "SELECT propertyTypeId, propertyDeclarationId, propertyTraits "
" FROM propertyDeclarations JOIN typeSelection USING(typeId) " " FROM propertyDeclarations JOIN typeSelection USING(typeId) "
" WHERE name=?2 ORDER BY level LIMIT 1", " WHERE name=?2 ORDER BY level LIMIT 1",
database}; database};
mutable ReadStatement<1, 1> selectPrototypeIdsStatement{ mutable ReadStatement<1, 1> selectPrototypeIdsStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeSelection(typeId, level) AS (" " typeSelection(typeId, level) AS ("
" VALUES(?1, 0) " " VALUES(?1, 0) "
" UNION ALL " " UNION ALL "
" SELECT prototypeId, typeSelection.level+1 FROM types JOIN typeSelection " " SELECT prototypeId, typeSelection.level+1 FROM all_prototype_and_extension JOIN "
" USING(typeId) WHERE prototypeId IS NOT NULL) " " typeSelection USING(typeId) WHERE prototypeId IS NOT NULL) "
"SELECT typeId FROM typeSelection ORDER BY level DESC", "SELECT typeId FROM typeSelection ORDER BY level DESC",
database}; database};
mutable ReadStatement<1, 1> selectSourceContextIdFromSourceContextsBySourceContextPathStatement{ mutable ReadStatement<1, 1> selectSourceContextIdFromSourceContextsBySourceContextPathStatement{
@@ -2625,8 +2699,8 @@ public:
"INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database}; "INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database};
mutable ReadStatement<3> selectAllSourcesStatement{ mutable ReadStatement<3> selectAllSourcesStatement{
"SELECT sourceName, sourceContextId, sourceId FROM sources", database}; "SELECT sourceName, sourceContextId, sourceId FROM sources", database};
mutable ReadStatement<6, 1> selectTypeByTypeIdStatement{ mutable ReadStatement<7, 1> selectTypeByTypeIdStatement{
"SELECT sourceId, t.name, t.typeId, prototypeId, traits, pd.name " "SELECT sourceId, t.name, t.typeId, prototypeId, extensionId, traits, pd.name "
"FROM types AS t LEFT JOIN propertyDeclarations AS pd " "FROM types AS t LEFT JOIN propertyDeclarations AS pd "
" ON defaultPropertyId=propertyDeclarationId WHERE t.typeId=?", " ON defaultPropertyId=propertyDeclarationId WHERE t.typeId=?",
database}; database};
@@ -2634,8 +2708,8 @@ public:
"SELECT moduleId, name, majorVersion, minorVersion FROM " "SELECT moduleId, name, majorVersion, minorVersion FROM "
"exportedTypeNames WHERE typeId=?", "exportedTypeNames WHERE typeId=?",
database}; database};
mutable ReadStatement<6> selectTypesStatement{ mutable ReadStatement<7> selectTypesStatement{
"SELECT sourceId, t.name, t.typeId, prototypeId, traits, pd.name " "SELECT sourceId, t.name, t.typeId, prototypeId, extensionId, traits, pd.name "
"FROM types AS t LEFT JOIN propertyDeclarations AS pd " "FROM types AS t LEFT JOIN propertyDeclarations AS pd "
" ON defaultPropertyId=propertyDeclarationId", " ON defaultPropertyId=propertyDeclarationId",
database}; database};
@@ -2816,11 +2890,15 @@ public:
"DELETE FROM documentImports WHERE sourceId IN carray(?1)", database}; "DELETE FROM documentImports WHERE sourceId IN carray(?1)", database};
ReadStatement<1, 2> selectPropertyDeclarationIdPrototypeChainDownStatement{ ReadStatement<1, 2> selectPropertyDeclarationIdPrototypeChainDownStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeSelection(typeId, level) AS (" " typeSelection(typeId, level) AS ("
" SELECT prototypeId, 0 FROM types WHERE typeId=?1 AND prototypeId IS NOT NULL" " SELECT prototypeId, 0 FROM types WHERE typeId=?1 AND prototypeId IS NOT NULL"
" UNION ALL " " UNION ALL "
" SELECT prototypeId, typeSelection.level+1 FROM types JOIN typeSelection " " SELECT prototypeId, typeSelection.level+1 FROM all_prototype_and_extension JOIN "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " typeSelection USING(typeId))"
"SELECT propertyDeclarationId FROM typeSelection JOIN propertyDeclarations " "SELECT propertyDeclarationId FROM typeSelection JOIN propertyDeclarations "
" USING(typeId) WHERE name=?2 ORDER BY level LIMIT 1", " USING(typeId) WHERE name=?2 ORDER BY level LIMIT 1",
database}; database};
@@ -2876,16 +2954,26 @@ public:
"UPDATE types SET prototypeId=NULL WHERE prototypeId=?1 RETURNING " "UPDATE types SET prototypeId=NULL WHERE prototypeId=?1 RETURNING "
"typeId, prototypeNameId", "typeId, prototypeNameId",
database}; database};
ReadWriteStatement<2, 1> updateExtensionIdToNullStatement{
"UPDATE types SET extensionId=NULL WHERE extensionId=?1 RETURNING "
"typeId, extensionNameId",
database};
WriteStatement<2> updateTypePrototypeStatement{ WriteStatement<2> updateTypePrototypeStatement{
"UPDATE types SET prototypeId=?2 WHERE typeId=?1", database}; "UPDATE types SET prototypeId=?2 WHERE typeId=?1", database};
WriteStatement<2> updateTypeExtensionStatement{
"UPDATE types SET extensionId=?2 WHERE typeId=?1", database};
mutable ReadStatement<1, 1> selectTypeIdsForPrototypeChainIdStatement{ mutable ReadStatement<1, 1> selectTypeIdsForPrototypeChainIdStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" prototypes(typeId) AS (" " all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT prototypeId FROM types WHERE typeId=? AND prototypeId IS NOT NULL" " SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL " " UNION ALL "
" SELECT prototypeId FROM types JOIN prototypes USING(typeId) WHERE prototypeId " " SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" IS NOT NULL)" " prototype_and_extension(typeId) AS ("
"SELECT typeId FROM prototypes", " SELECT prototypeId FROM all_prototype_and_extension WHERE typeId=?"
" UNION ALL "
" SELECT prototypeId FROM all_prototype_and_extension JOIN prototype_and_extension "
" USING(typeId)) "
"SELECT typeId FROM prototype_and_extension",
database}; database};
WriteStatement<3> updatePropertyDeclarationAliasIdAndTypeNameIdStatement{ WriteStatement<3> updatePropertyDeclarationAliasIdAndTypeNameIdStatement{
"UPDATE propertyDeclarations SET aliasPropertyDeclarationId=?2, " "UPDATE propertyDeclarations SET aliasPropertyDeclarationId=?2, "
@@ -3057,11 +3145,15 @@ public:
database}; database};
mutable ReadStatement<1, 1> selectPropertyDeclarationIdsForTypeStatement{ mutable ReadStatement<1, 1> selectPropertyDeclarationIdsForTypeStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeChain(typeId) AS (" " typeChain(typeId) AS ("
" VALUES(?1)" " VALUES(?1)"
" UNION ALL " " UNION ALL "
" SELECT prototypeId FROM types JOIN typeChain " " SELECT prototypeId FROM all_prototype_and_extension JOIN typeChain "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " USING(typeId))"
"SELECT propertyDeclarationId FROM typeChain JOIN propertyDeclarations " "SELECT propertyDeclarationId FROM typeChain JOIN propertyDeclarations "
" USING(typeId) ORDER BY propertyDeclarationId", " USING(typeId) ORDER BY propertyDeclarationId",
database}; database};
@@ -3073,11 +3165,15 @@ public:
database}; database};
mutable ReadStatement<1, 2> selectPropertyDeclarationIdForTypeAndPropertyNameStatement{ mutable ReadStatement<1, 2> selectPropertyDeclarationIdForTypeAndPropertyNameStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeChain(typeId, level) AS (" " typeChain(typeId, level) AS ("
" VALUES(?1, 0)" " VALUES(?1, 0)"
" UNION ALL " " UNION ALL "
" SELECT prototypeId, typeChain.level + 1 FROM types JOIN typeChain " " SELECT prototypeId, typeChain.level + 1 FROM all_prototype_and_extension JOIN "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " typeChain USING(typeId))"
"SELECT propertyDeclarationId FROM typeChain JOIN propertyDeclarations " "SELECT propertyDeclarationId FROM typeChain JOIN propertyDeclarations "
" USING(typeId) WHERE name=?2 ORDER BY level LIMIT 1", " USING(typeId) WHERE name=?2 ORDER BY level LIMIT 1",
database}; database};
@@ -3093,21 +3189,29 @@ public:
database}; database};
mutable ReadStatement<1, 1> selectSignalDeclarationNamesForTypeStatement{ mutable ReadStatement<1, 1> selectSignalDeclarationNamesForTypeStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeChain(typeId) AS (" " typeChain(typeId) AS ("
" VALUES(?1)" " VALUES(?1)"
" UNION ALL " " UNION ALL "
" SELECT prototypeId FROM types JOIN typeChain " " SELECT prototypeId FROM all_prototype_and_extension JOIN typeChain "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " USING(typeId)) "
"SELECT name FROM typeChain JOIN signalDeclarations " "SELECT name FROM typeChain JOIN signalDeclarations "
" USING(typeId) ORDER BY name", " USING(typeId) ORDER BY name",
database}; database};
mutable ReadStatement<1, 1> selectFuncionDeclarationNamesForTypeStatement{ mutable ReadStatement<1, 1> selectFuncionDeclarationNamesForTypeStatement{
"WITH RECURSIVE " "WITH RECURSIVE "
" all_prototype_and_extension(typeId, prototypeId) AS ("
" SELECT typeId, prototypeId FROM types WHERE prototypeId IS NOT NULL"
" UNION ALL "
" SELECT typeId, extensionId FROM types WHERE extensionId IS NOT NULL),"
" typeChain(typeId) AS (" " typeChain(typeId) AS ("
" VALUES(?1)" " VALUES(?1)"
" UNION ALL " " UNION ALL "
" SELECT prototypeId FROM types JOIN typeChain " " SELECT prototypeId FROM all_prototype_and_extension JOIN typeChain "
" USING(typeId) WHERE prototypeId IS NOT NULL)" " USING(typeId))"
"SELECT name FROM typeChain JOIN functionDeclarations " "SELECT name FROM typeChain JOIN functionDeclarations "
" USING(typeId) ORDER BY name", " USING(typeId) ORDER BY name",
database}; database};

View File

@@ -689,6 +689,7 @@ public:
explicit Type() = default; explicit Type() = default;
explicit Type(Utils::SmallStringView typeName, explicit Type(Utils::SmallStringView typeName,
ImportedTypeName prototype, ImportedTypeName prototype,
ImportedTypeName extension,
TypeTraits traits, TypeTraits traits,
SourceId sourceId, SourceId sourceId,
ExportedTypes exportedTypes = {}, ExportedTypes exportedTypes = {},
@@ -701,6 +702,7 @@ public:
: typeName{typeName} : typeName{typeName}
, defaultPropertyName{defaultPropertyName} , defaultPropertyName{defaultPropertyName}
, prototype{std::move(prototype)} , prototype{std::move(prototype)}
, extension{std::move(extension)}
, exportedTypes{std::move(exportedTypes)} , exportedTypes{std::move(exportedTypes)}
, propertyDeclarations{std::move(propertyDeclarations)} , propertyDeclarations{std::move(propertyDeclarations)}
, functionDeclarations{std::move(functionDeclarations)} , functionDeclarations{std::move(functionDeclarations)}
@@ -711,11 +713,16 @@ public:
, changeLevel{changeLevel} , changeLevel{changeLevel}
{} {}
explicit Type(Utils::SmallStringView typeName, TypeId prototypeId, TypeTraits traits, SourceId sourceId) explicit Type(Utils::SmallStringView typeName,
TypeId prototypeId,
TypeId extensionId,
TypeTraits traits,
SourceId sourceId)
: typeName{typeName} : typeName{typeName}
, traits{traits} , traits{traits}
, sourceId{sourceId} , sourceId{sourceId}
, prototypeId{prototypeId} , prototypeId{prototypeId}
, extensionId{extensionId}
{} {}
explicit Type(Utils::SmallStringView typeName, explicit Type(Utils::SmallStringView typeName,
@@ -732,10 +739,12 @@ public:
explicit Type(Utils::SmallStringView typeName, explicit Type(Utils::SmallStringView typeName,
Utils::SmallStringView prototype, Utils::SmallStringView prototype,
Utils::SmallStringView extension,
TypeTraits traits, TypeTraits traits,
SourceId sourceId) SourceId sourceId)
: typeName{typeName} : typeName{typeName}
, prototype{ImportedType{prototype}} , prototype{ImportedType{prototype}}
, extension{ImportedType{extension}}
, traits{traits} , traits{traits}
, sourceId{sourceId} , sourceId{sourceId}
@@ -745,6 +754,7 @@ public:
Utils::SmallStringView typeName, Utils::SmallStringView typeName,
TypeId typeId, TypeId typeId,
TypeId prototypeId, TypeId prototypeId,
TypeId extensionId,
TypeTraits traits, TypeTraits traits,
Utils::SmallStringView defaultPropertyName) Utils::SmallStringView defaultPropertyName)
: typeName{typeName} : typeName{typeName}
@@ -753,13 +763,15 @@ public:
, sourceId{sourceId} , sourceId{sourceId}
, typeId{typeId} , typeId{typeId}
, prototypeId{prototypeId} , prototypeId{prototypeId}
, extensionId{extensionId}
{} {}
friend bool operator==(const Type &first, const Type &second) noexcept friend bool operator==(const Type &first, const Type &second) noexcept
{ {
return first.typeName == second.typeName return first.typeName == second.typeName
&& first.defaultPropertyName == second.defaultPropertyName && first.defaultPropertyName == second.defaultPropertyName
&& first.prototype == second.prototype && first.exportedTypes == second.exportedTypes && first.prototype == second.prototype && first.extension == second.extension
&& first.exportedTypes == second.exportedTypes
&& first.propertyDeclarations == second.propertyDeclarations && first.propertyDeclarations == second.propertyDeclarations
&& first.functionDeclarations == second.functionDeclarations && first.functionDeclarations == second.functionDeclarations
&& first.signalDeclarations == second.signalDeclarations && first.signalDeclarations == second.signalDeclarations
@@ -770,6 +782,7 @@ public:
TypeNameString typeName; TypeNameString typeName;
Utils::SmallString defaultPropertyName; Utils::SmallString defaultPropertyName;
ImportedTypeName prototype; ImportedTypeName prototype;
ImportedTypeName extension;
ExportedTypes exportedTypes; ExportedTypes exportedTypes;
PropertyDeclarations propertyDeclarations; PropertyDeclarations propertyDeclarations;
FunctionDeclarations functionDeclarations; FunctionDeclarations functionDeclarations;
@@ -779,6 +792,7 @@ public:
SourceId sourceId; SourceId sourceId;
TypeId typeId; TypeId typeId;
TypeId prototypeId; TypeId prototypeId;
TypeId extensionId;
ChangeLevel changeLevel = ChangeLevel::Full; ChangeLevel changeLevel = ChangeLevel::Full;
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -256,11 +256,13 @@ protected:
Storage::Synchronization::Type objectType{ Storage::Synchronization::Type objectType{
"QObject", "QObject",
Storage::Synchronization::ImportedType{}, Storage::Synchronization::ImportedType{},
Storage::Synchronization::ImportedType{},
Storage::TypeTraits::Reference, Storage::TypeTraits::Reference,
qmltypesPathSourceId, qmltypesPathSourceId,
{Storage::Synchronization::ExportedType{exampleModuleId, "Object"}, {Storage::Synchronization::ExportedType{exampleModuleId, "Object"},
Storage::Synchronization::ExportedType{exampleModuleId, "Obj"}}}; Storage::Synchronization::ExportedType{exampleModuleId, "Obj"}}};
Storage::Synchronization::Type itemType{"QItem", Storage::Synchronization::Type itemType{"QItem",
Storage::Synchronization::ImportedType{},
Storage::Synchronization::ImportedType{}, Storage::Synchronization::ImportedType{},
Storage::TypeTraits::Reference, Storage::TypeTraits::Reference,
qmltypes2PathSourceId, qmltypes2PathSourceId,