#ifndef SQLITE_STORAGE_H #define SQLITE_STORAGE_H #include #include #include #include "sqlite/CppSQLite3.h" #include "utility/file/FilePath.h" #include "utility/types.h" #include "data/location/TokenLocationFile.h" #include "data/location/TokenLocationCollection.h" #include "data/name/NameHierarchy.h" #include "data/StorageTypes.h" class TextAccess; class Version; struct ParseLocation; class SqliteStorage { public: SqliteStorage(const FilePath& dbFilePath); ~SqliteStorage(); void setup(); void clear(); void beginTransaction(); void commitTransaction(); void rollbackTransaction(); FilePath getDbFilePath() const; bool isEmpty() const; bool isIncompatible() const; void setVersion(); Id addEdge(int type, Id sourceNodeId, Id targetNodeId); Id addNode(int type, const std::string& serializedName, int definitionType); Id addFile(const std::string& serializedName, const std::string& filePath, const std::string& modificationTime); Id addLocalSymbol(const std::string& name); Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); Id addComponentAccess(Id nodeId, int type); Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); Id addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber); void removeElement(Id id); void removeElements(const std::vector& ids); void removeElementsWithLocationInFiles(const std::vector& fileIds); void removeErrorsInFiles(const std::vector& filePaths); bool isEdge(Id elementId) const; bool isNode(Id elementId) const; bool isFile(Id elementId) const; StorageEdge getEdgeById(Id edgeId) const; StorageEdge getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const; std::vector getEdgesByIds(const std::vector& edgeIds) const; std::vector getEdgesBySourceId(Id sourceId) const; std::vector getEdgesBySourceIds(const std::vector& sourceIds) const; std::vector getEdgesByTargetId(Id targetId) const; std::vector getEdgesByTargetIds(const std::vector& targetIds) const; std::vector getEdgesBySourceOrTargetId(Id id) const; std::vector getEdgesByType(int type) const; std::vector getEdgesBySourceType(Id sourceId, int type) const; std::vector getEdgesByTargetType(Id targetId, int type) const; StorageNode getNodeById(Id id) const; StorageNode getNodeBySerializedName(const std::string& serializedName) const; std::vector getNodesByIds(const std::vector& nodeIds) const; StorageLocalSymbol getLocalSymbolByName(const std::string& name) const; StorageFile getFileById(const Id id) const; StorageFile getFileByPath(const FilePath& filePath) const; std::vector getFilesByPaths(const std::vector& filePaths) const; std::shared_ptr getFileContentByPath(const std::string& filePath) const; std::shared_ptr getFileContentById(Id fileId) const; void setNodeType(int type, Id nodeId); void setNodeDefinitionType(int definitionType, Id nodeId); StorageSourceLocation getSourceLocationById(const Id id) const; std::shared_ptr getTokenLocationsForFile(const FilePath& filePath) const; std::vector getTokenLocationsForElementId(const Id elementId) const; std::vector getTokenLocationsForElementIds(const std::vector elementIds) const; Id getElementIdByLocationId(Id locationId) const; StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const; std::vector getComponentAccessesByNodeIds(const std::vector& memberEdgeIds) const; void optimizeMemory() const; std::vector getFullTextSearch(const std::string& searchTerm) const; std::vector getCommentLocationsInFile(const FilePath& filePath) const; std::vector getAllFiles() const; std::vector getAllNodes() const; std::vector getAllEdges() const; std::vector getAllLocalSymbols() const; std::vector getAllSourceLocations() const; std::vector getAllComponentAccesses() const; std::vector getAllCommentLocations() const; std::vector getAllErrors() const; int getNodeCount() const; int getEdgeCount() const; int getFileCount() const; int getFileLOCCount() const; int getSourceLocationCount() const; private: static const size_t STORAGE_VERSION; void clearTables(); void setupTables(); bool hasTable(const std::string& tableName) const; std::string getMetaValue(const std::string& key) const; void insertOrUpdateMetaValue(const std::string& key, const std::string& value); size_t getStorageVersion() const; void setStorageVersion(); Version getApplicationVersion() const; void setApplicationVersion(); template std::vector getAll(const std::string& query) const; template ResultType getFirst(const std::string& query) const { std::vector results = getAll(query + " LIMIT 1"); if (results.size() > 0) { return results[0]; } return ResultType(); } mutable CppSQLite3DB m_database; FilePath m_dbFilePath; }; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; template <> std::vector SqliteStorage::getAll(const std::string& query) const; #endif // SQLITE_STORAGE_H