Files
Sourcetrail/src/lib/data/storage/sqlite/SqliteIndexStorage.h
T
malte_langkabel cad595a32c logic: add storage transformation to merge anonymous types and the respective typedef
* moved storage related classes to data/storage folder
* implemented recording c++ unions as NODE_UNION instead of just using NODE_TYPE
* added transformation to merge anonymous classes/structs/enums/unions and typedef nodes
* added tests for this transformation
* added setting for enabling/disabling this transformation
2017-07-18 15:14:43 +02:00

189 lines
7.2 KiB
C++

#ifndef SQLITE_INDEX_STORAGE_H
#define SQLITE_INDEX_STORAGE_H
#include <memory>
#include <string>
#include <vector>
#include "data/location/SourceLocationFile.h"
#include "data/storage/sqlite/SqliteDatabaseIndex.h"
#include "data/storage/sqlite/SqliteStorage.h"
#include "data/storage/StorageTypes.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);
Id addEdge(int type, Id sourceNodeId, Id targetNodeId);
Id addNode(const int type, const std::string& serializedName);
void addSymbol(const int id, int definitionKind);
void addFile(const int id, const std::string& filePath, const std::string& modificationTime, bool complete);
Id addLocalSymbol(const std::string& name);
Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
bool addOccurrence(Id elementId, Id sourceLocationId);
Id addComponentAccess(Id nodeId, int type);
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
Id addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed);
void removeElement(Id id);
void removeElements(const std::vector<Id>& ids);
void removeElementsWithLocationInFiles(const std::vector<Id>& fileIds, std::function<void(int)> updateStatusCallback);
void removeErrorsInFiles(const std::vector<FilePath>& 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<StorageEdge> getEdgesBySourceId(Id sourceId) const;
std::vector<StorageEdge> getEdgesBySourceIds(const std::vector<Id>& sourceIds) const;
std::vector<StorageEdge> getEdgesByTargetId(Id targetId) const;
std::vector<StorageEdge> getEdgesByTargetIds(const std::vector<Id>& targetIds) const;
std::vector<StorageEdge> getEdgesBySourceOrTargetId(Id id) const;
std::vector<StorageEdge> getEdgesByType(int type) const;
std::vector<StorageEdge> getEdgesBySourceType(Id sourceId, int type) const;
std::vector<StorageEdge> getEdgesBySourcesType(const std::vector<Id>& sourceIds, int type) const;
std::vector<StorageEdge> getEdgesByTargetType(Id targetId, int type) const;
std::vector<StorageEdge> getEdgesByTargetsType(const std::vector<Id>& targetIds, int type) const;
StorageNode getNodeById(Id id) const;
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
StorageFile getFileByPath(const std::string& filePath) const;
std::vector<StorageFile> getFilesByPaths(const std::vector<FilePath>& filePaths) const;
std::shared_ptr<TextAccess> getFileContentByPath(const std::string& filePath) const;
std::shared_ptr<TextAccess> getFileContentById(Id fileId) const;
void setFileComplete(bool complete, Id fileId);
void setNodeType(int type, Id nodeId);
std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
std::vector<StorageOccurrence> getOccurrencesForLocationId(Id locationId) const;
std::vector<StorageOccurrence> getOccurrencesForLocationIds(const std::vector<Id>& locationIds) const;
std::vector<StorageOccurrence> getOccurrencesForElementIds(const std::vector<Id>& elementIds) const;
StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const;
std::vector<StorageComponentAccess> getComponentAccessesByNodeIds(const std::vector<Id>& memberEdgeIds) const;
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
template <typename ResultType>
std::vector<ResultType> getAll() const
{
return doGetAll<ResultType>("");
}
template <typename ResultType>
ResultType getFirstById(const Id id) const
{
if (id != 0)
{
return doGetFirst<ResultType>("WHERE id == " + std::to_string(id));
}
return ResultType();
}
template <typename ResultType>
std::vector<ResultType> getAllByIds(const std::vector<Id>& ids) const
{
if (ids.size())
{
return doGetAll<ResultType>("WHERE id IN (" + utility::join(utility::toStrings(ids), ',') + ")");
}
return std::vector<ResultType>();
}
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<std::pair<int, SqliteDatabaseIndex>> getIndices() const;
virtual void clearTables();
virtual void setupTables();
virtual void setupPrecompiledStatements();
template <typename ResultType>
std::vector<ResultType> doGetAll(const std::string& query) const;
template <typename ResultType>
ResultType doGetFirst(const std::string& query) const
{
std::vector<ResultType> results = doGetAll<ResultType>(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<StorageEdge> SqliteIndexStorage::doGetAll<StorageEdge>(const std::string& query) const;
template <>
std::vector<StorageNode> SqliteIndexStorage::doGetAll<StorageNode>(const std::string& query) const;
template <>
std::vector<StorageSymbol> SqliteIndexStorage::doGetAll<StorageSymbol>(const std::string& query) const;
template <>
std::vector<StorageFile> SqliteIndexStorage::doGetAll<StorageFile>(const std::string& query) const;
template <>
std::vector<StorageLocalSymbol> SqliteIndexStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
template <>
std::vector<StorageSourceLocation> SqliteIndexStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
template <>
std::vector<StorageOccurrence> SqliteIndexStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
template <>
std::vector<StorageComponentAccess> SqliteIndexStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
template <>
std::vector<StorageCommentLocation> SqliteIndexStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
template <>
std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::string& query) const;
#endif // SQLITE_INDEX_STORAGE_H