#ifndef PERSISTENT_STORAGE_H #define PERSISTENT_STORAGE_H #include #include #include "data/access/StorageAccess.h" #include "data/fulltextsearch/FullTextSearchIndex.h" #include "data/search/SearchIndex.h" #include "data/HierarchyCache.h" #include "data/storage/sqlite/SqliteIndexStorage.h" #include "data/storage/sqlite/SqliteBookmarkStorage.h" #include "data/storage/Storage.h" class PersistentStorage : public Storage , public StorageAccess { public: PersistentStorage(const FilePath& dbPath, const FilePath& bookmarkPath); Id addNode(const StorageNodeData& data) override; void addSymbol(const StorageSymbol& data) override; void addFile(const StorageFile& data) override; Id addEdge(const StorageEdgeData& data) override; Id addLocalSymbol(const StorageLocalSymbolData& data) override; Id addSourceLocation(const StorageSourceLocationData& data) override; void addOccurrence(const StorageOccurrence& data) override; void addOccurrences(const std::vector& occurrences) override; void addComponentAccess(const StorageComponentAccessData& data) override; void addCommentLocation(const StorageCommentLocationData& data) override; void addError(const StorageErrorData& data) override; void forEachNode(std::function callback) const override; void forEachFile(std::function callback) const override; void forEachSymbol(std::function callback) const override; void forEachEdge(std::function callback) const override; void forEachLocalSymbol(std::function callback) const override; void forEachSourceLocation(std::function callback) const override; void forEachOccurrence(std::function callback) const override; void forEachComponentAccess(std::function callback) const override; void forEachCommentLocation(std::function callback) const override; void forEachError(std::function callback) const override; void startInjection() override; void finishInjection() override; void setMode(const SqliteIndexStorage::StorageModeType mode); FilePath getIndexDbFilePath() const; FilePath getBookmarkDbFilePath() const; bool isEmpty() const; bool isIncompatible() const; std::string getProjectSettingsText() const; void setProjectSettingsText(std::string text); void setup(); void updateVersion(); void clear(); void clearCaches(); std::set getReferenced(const std::set& filePaths) const; std::set getReferencing(const std::set& filePaths) const; void clearAllErrors(); void clearFileElements(const std::vector& filePaths, std::function updateStatusCallback); std::vector getFileInfoForAllIndexedFiles() const; std::set getIncompleteFiles() const; bool getFilePathIndexed(const FilePath& path) const; void buildCaches(); void optimizeMemory(); // StorageAccess implementation Id getNodeIdForFileNode(const FilePath& filePath) const override; Id getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const override; std::vector getNodeIdsForNameHierarchies(const std::vector nameHierarchies) const override; NameHierarchy getNameHierarchyForNodeId(Id nodeId) const override; std::vector getNameHierarchiesForNodeIds(const std::vector& nodeIds) const override; std::map> getNodeIdToParentFileMap(const std::vector& nodeIds) const override; NodeType getNodeTypeForNodeWithId(Id nodeId) const override; Id getIdForEdge( Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const override; StorageEdge getEdgeById(Id edgeId) const override; std::shared_ptr getFullTextSearchLocations( const std::wstring& searchTerm, bool caseSensitive) const override; std::vector getAutocompletionMatches(const std::wstring& query, NodeTypeSet acceptedNodeTypes) const override; std::vector getAutocompletionSymbolMatches( const std::wstring& query, const NodeTypeSet& acceptedNodeTypes, size_t maxResultsCount, size_t maxBestScoredResultsLength) const; std::vector getAutocompletionFileMatches(const std::wstring& query, size_t maxResultsCount) const; std::vector getAutocompletionCommandMatches(const std::wstring& query, NodeTypeSet acceptedNodeTypes) const; std::vector getSearchMatchesForTokenIds(const std::vector& elementIds) const override; std::shared_ptr getGraphForAll() const override; std::shared_ptr getGraphForNodeTypes(NodeTypeSet nodeTypes) const override; std::shared_ptr getGraphForActiveTokenIds( const std::vector& tokenIds, const std::vector& expandedNodeIds, bool* isActiveNamespace = nullptr) const override; std::shared_ptr getGraphForChildrenOfNodeId(Id nodeId) const override; std::shared_ptr getGraphForTrail(Id originId, Id targetId, Edge::TypeMask trailType, size_t depth) const override; std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const override; std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const override; std::shared_ptr getSourceLocationsForTokenIds(const std::vector& tokenIds) const override; std::shared_ptr getSourceLocationsForLocationIds(const std::vector& locationIds) const override; std::shared_ptr getSourceLocationsForFile(const FilePath& filePath) const override; std::shared_ptr getSourceLocationsForLinesInFile( const FilePath& filePath, size_t startLine, size_t endLine) const override; std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const override; std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; std::shared_ptr getFileContent(const FilePath& filePath) const override; FileInfo getFileInfoForFileId(Id id) const override; FileInfo getFileInfoForFilePath(const FilePath& filePath) const override; std::vector getFileInfosForFilePaths(const std::vector& filePaths) const override; StorageStats getStorageStats() const override; ErrorCountInfo getErrorCount() const override; std::vector getErrorsLimited(const ErrorFilter& filter) const override; std::vector getErrorsForFileLimited( const ErrorFilter& filter, const FilePath& filePath) const override; std::shared_ptr getErrorSourceLocations( const std::vector& errors) const override; Id addNodeBookmark(const NodeBookmark& bookmark) override; Id addEdgeBookmark(const EdgeBookmark& bookmark) override; Id addBookmarkCategory(const std::wstring& categoryName) override; void updateBookmark(const Id bookmarkId, const std::wstring& name, const std::wstring& comment, const std::wstring& categoryName) override; void removeBookmark(const Id id) override; void removeBookmarkCategory(const Id id) override; std::vector getAllNodeBookmarks() const override; std::vector getAllEdgeBookmarks() const override; std::vector getAllBookmarkCategories() const override; TooltipInfo getTooltipInfoForTokenIds(const std::vector& tokenIds, TooltipOrigin origin) const override; TooltipSnippet getTooltipSnippetForNode(const StorageNode& node) const; TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds( const std::vector& locationIds, const std::vector& localSymbolIds) const override; private: Id getFileNodeId(const FilePath& filePath) const; std::vector getFileNodeIds(const std::vector& filePaths) const; std::set getFileNodeIds(const std::set& filePaths) const; FilePath getFileNodePath(Id fileId) const; bool getFileNodeComplete(Id fileId) const; bool getFileNodeIndexed(Id fileId) const; std::unordered_map> getFileIdToIncludingFileIdMap() const; std::unordered_map> getFileIdToIncludedFileIdMap() const; std::unordered_map> getFileIdToImportingFileIdMap() const; std::set getReferenced(const std::set& filePaths, std::unordered_map> idToReferencingIdMap) const; std::set getReferencing(const std::set& filePaths, std::unordered_map> idToReferencingIdMap) const; std::set getReferencedByIncludes(const std::set& filePaths) const; std::set getReferencedByImports(const std::set& filePaths) const; std::set getReferencingByIncludes(const std::set& filePaths) const; std::set getReferencingByImports(const std::set& filePaths) const; void addNodesToGraph(const std::vector& nodeIds, Graph* graph, bool addChildCount) const; void addEdgesToGraph(const std::vector& edgeIds, Graph* graph) const; void addNodesWithParentsAndEdgesToGraph( const std::vector& nodeIds, const std::vector& edgeIds, Graph* graphh, bool addChildCount) const; void addAggregationEdgesToGraph(Id nodeId, const std::vector& edgesToAggregate, Graph* graph) const; void addFileContentsToGraph(Id fileId, Graph* graph) const; void addComponentAccessToGraph(Graph* graph) const; void addCompleteFlagsToSourceLocationCollection(SourceLocationCollection* collection) const; void addInheritanceChainsToGraph(const std::vector& nodeIds, Graph* graph) const; void buildFilePathMaps(); void buildSearchIndex(); void buildFullTextSearchIndex() const; void buildMemberEdgeIdOrderMap(); void buildHierarchyCache(); size_t m_preInjectionErrorCount = 0; SearchIndex m_commandIndex; SearchIndex m_symbolIndex; SearchIndex m_fileIndex; mutable FullTextSearchIndex m_fullTextSearchIndex; mutable std::string m_fullTextSearchCodec; SqliteIndexStorage m_sqliteIndexStorage; SqliteBookmarkStorage m_sqliteBookmarkStorage; std::map m_fileNodeIds; std::map m_lowerCasefileNodeIds; std::map m_fileNodePaths; std::map m_fileNodeComplete; std::map m_fileNodeIndexed; std::map m_symbolDefinitionKinds; std::map m_memberEdgeIdOrderMap; HierarchyCache m_hierarchyCache; bool m_hasJavaFiles = false; }; #endif // PERSISTENT_STORAGE_H