#ifndef SQLITE_INDEX_STORAGE_H #define SQLITE_INDEX_STORAGE_H #include #include #include #include "data/location/SourceLocationFile.h" #include "data/storage/sqlite/SqliteDatabaseIndex.h" #include "data/storage/sqlite/SqliteStorage.h" #include "data/storage/type/StorageCommentLocation.h" #include "data/storage/type/StorageComponentAccess.h" #include "data/storage/type/StorageEdge.h" #include "data/storage/type/StorageError.h" #include "data/storage/type/StorageFile.h" #include "data/storage/type/StorageLocalSymbol.h" #include "data/storage/type/StorageNode.h" #include "data/storage/type/StorageOccurrence.h" #include "data/storage/type/StorageSourceLocation.h" #include "data/storage/type/StorageSymbol.h" #include "utility/types.h" #include "utility/utility.h" #include "utility/utilityString.h" class TextAccess; class Version; struct ParseLocation; class SqliteIndexStorage : public SqliteStorage { public: SqliteIndexStorage(const FilePath& dbFilePath); virtual ~SqliteIndexStorage(); virtual size_t getStaticVersion() const; std::string getProjectSettingsText() const; void setProjectSettingsText(std::string text); StorageNode addNode(const StorageNodeData& data); void addSymbol(const StorageSymbol& data); void addFile(const StorageFile& data); StorageEdge addEdge(const StorageEdgeData& data); StorageLocalSymbol addLocalSymbol(const StorageLocalSymbolData& data); StorageSourceLocation addSourceLocation(const StorageSourceLocationData& data); bool addOccurrence(const StorageOccurrence& data); StorageComponentAccess addComponentAccess(const StorageComponentAccessData& data); StorageCommentLocation addCommentLocation(const StorageCommentLocationData& data); StorageError addError(const StorageErrorData& data); void removeElement(Id id); void removeElements(const std::vector& ids); void removeElementsWithLocationInFiles(const std::vector& fileIds, std::function updateStatusCallback); 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 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 getEdgesBySourcesType(const std::vector& sourceIds, int type) const; std::vector getEdgesByTargetType(Id targetId, int type) const; std::vector getEdgesByTargetsType(const std::vector& targetIds, int type) const; StorageNode getNodeById(Id id) const; StorageNode getNodeBySerializedName(const std::wstring& serializedName) const; StorageLocalSymbol getLocalSymbolByName(const std::wstring& name) const; StorageFile getFileByPath(const std::wstring& filePath) const; std::vector getFilesByPaths(const std::vector& filePaths) const; std::shared_ptr getFileContentByPath(const std::wstring& filePath) const; std::shared_ptr getFileContentById(Id fileId) const; void setFileComplete(bool complete, Id fileId); void setNodeType(int type, Id nodeId); std::shared_ptr getSourceLocationsForFile( const FilePath& filePath, const std::string& query = "") const; std::shared_ptr getSourceLocationsForLinesInFile( const FilePath& filePath, size_t startLine, size_t endLine) const; std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const; std::vector getOccurrencesForLocationId(Id locationId) const; std::vector getOccurrencesForLocationIds(const std::vector& locationIds) const; std::vector getOccurrencesForElementIds(const std::vector& elementIds) const; StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const; std::vector getComponentAccessesByNodeIds(const std::vector& memberEdgeIds) const; std::vector getCommentLocationsInFile(const FilePath& filePath) const; template std::vector getAll() const { return doGetAll(""); } template ResultType getFirstById(const Id id) const { if (id != 0) { return doGetFirst("WHERE id == " + std::to_string(id)); } return ResultType(); } template std::vector getAllByIds(const std::vector& ids) const { if (ids.size()) { return doGetAll("WHERE id IN (" + utility::join(utility::toStrings(ids), ',') + ")"); } return std::vector(); } int getNodeCount() const; int getEdgeCount() const; int getFileCount() const; int getCompletedFileCount() const; int getFileLineSum() const; int getSourceLocationCount() const; private: static const size_t s_storageVersion; virtual std::vector> getIndices() const; virtual void clearTables(); virtual void setupTables(); virtual void setupPrecompiledStatements(); template std::vector doGetAll(const std::string& query) const; template ResultType doGetFirst(const std::string& query) const { std::vector results = doGetAll(query + " LIMIT 1"); if (results.size() > 0) { return results[0]; } return ResultType(); } CppSQLite3Statement m_insertElementStmt; CppSQLite3Statement m_insertEdgeStmt; CppSQLite3Statement m_inserNodeStmt; CppSQLite3Statement m_insertSymbolStmt; CppSQLite3Statement m_insertFileStmt; CppSQLite3Statement m_insertFileContentStmt; CppSQLite3Statement m_inserLocalSymbolStmt; CppSQLite3Statement m_checkSourceLocationExistsStmt; CppSQLite3Statement m_insertSourceLocationStmt; CppSQLite3Statement m_checkOccurrenceExistsStmt; CppSQLite3Statement m_insertOccurrenceStmt; CppSQLite3Statement m_insertComponentAccessStmt; CppSQLite3Statement m_checkCommentLocationExistsStmt; CppSQLite3Statement m_insertCommentLocationStmt; CppSQLite3Statement m_checkErrorExistsStmt; CppSQLite3Statement m_insertErrorStmt; }; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; #endif // SQLITE_INDEX_STORAGE_H