data: saving file contents to sqlite db

This commit is contained in:
Eberhard Graether
2015-09-30 02:12:49 +02:00
parent 4782efddcb
commit de1af6ce7d
12 changed files with 76 additions and 17 deletions
+1 -1
View File
@@ -360,7 +360,7 @@ void QtCodeFile::clickedMaximizeButton()
}
else
{
MessageShowFile(m_filePath.str(), 0, 0).dispatch();
MessageShowFile(m_filePath, 0, 0).dispatch();
}
m_minimizeButton->setEnabled(true);
@@ -114,10 +114,10 @@ void CodeController::handleMessage(MessageShowFile* message)
params.startLineNumber = message->startLineNumber;
params.endLineNumber = message->endLineNumber;
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(message->filePath);
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(message->filePath);
params.code = textAccess->getText();
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath);
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath.str());
getView()->showCodeFile(params);
}
@@ -221,7 +221,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const
{
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(file->getFilePath().str());
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(file->getFilePath());
std::deque<SnippetMerger::Range> ranges;
+23 -3
View File
@@ -3,6 +3,7 @@
#include "data/graph/Node.h"
#include "data/location/TokenLocation.h"
#include "utility/logging/logging.h"
#include "utility/text/TextAccess.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
@@ -80,12 +81,16 @@ Id SqliteStorage::addNode(int type, Id nameId)
Id SqliteStorage::addFile(Id nameId, const std::string& filePath, const std::string& modificationTime)
{
Id id = addNode(Node::NODE_FILE, nameId);
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(filePath);
m_database.execDML((
"INSERT INTO file(id, path, modification_time) VALUES("
+ std::to_string(id) + ", '" + filePath + "', '" + modificationTime + "');"
CppSQLite3Statement stmt = m_database.compileStatement((
"INSERT INTO file(id, path, modification_time, content) VALUES("
+ std::to_string(id) + ", '" + filePath + "', '" + modificationTime + "', ?);"
).c_str());
stmt.bind(1, content->getText().c_str());
stmt.execDML();
return id;
}
@@ -449,6 +454,20 @@ std::vector<StorageFile> SqliteStorage::getAllFiles() const
return getAllFiles("SELECT file.id, node.name_id, file.path, file.modification_time FROM file INNER JOIN node ON file.id = node.id;");
}
std::shared_ptr<TextAccess> SqliteStorage::getFileContentByPath(const std::string& filePath) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT content FROM file WHERE path = '" + filePath + "';"
).c_str());
if (!q.eof())
{
return TextAccess::createFromString(q.getStringField(0, ""));
}
return TextAccess::createFromFile(filePath);
}
void SqliteStorage::setNodeType(int type, Id nodeId)
{
m_database.execDML((
@@ -721,6 +740,7 @@ void SqliteStorage::setupTables()
"id INTEGER NOT NULL, "
"path TEXT, "
"modification_time TEXT, "
"content TEXT, "
"PRIMARY KEY(id), "
"FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE);"
);
+3
View File
@@ -14,6 +14,8 @@
#include "data/location/TokenLocationCollection.h"
#include "data/StorageTypes.h"
class TextAccess;
class SqliteStorage
{
public:
@@ -71,6 +73,7 @@ public:
StorageFile getFileByName(const std::string& fileName) const;
StorageFile getFileByPath(const std::string& filePath) const;
std::vector<StorageFile> getAllFiles() const;
std::shared_ptr<TextAccess> getFileContentByPath(const std::string& filePath) const;
void setNodeType(int type, Id nodeId);
+6 -1
View File
@@ -1149,6 +1149,11 @@ std::shared_ptr<TokenLocationFile> Storage::getTokenLocationOfParentScope(const
return file;
}
std::shared_ptr<TextAccess> Storage::getFileContent(const FilePath& filePath) const
{
return m_sqliteStorage.getFileContentByPath(filePath.str());
}
const SearchIndex& Storage::getSearchIndex() const
{
return m_tokenIndex;
@@ -1293,7 +1298,7 @@ Id Storage::addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, Parse
return edgeId;
}
Id Storage::getFileNodeId(const FilePath& filePath)
Id Storage::getFileNodeId(const FilePath& filePath) const
{
std::map<FilePath, Id>::const_iterator it = m_fileNodeIds.find(filePath);
+4 -3
View File
@@ -152,9 +152,10 @@ public:
) const;
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
const SearchIndex& getSearchIndex() const;
private:
@@ -166,7 +167,7 @@ private:
Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type);
Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, ParseLocation location);
Id getFileNodeId(const FilePath& filePath);
Id getFileNodeId(const FilePath& filePath) const;
Id getLastVisibleParentNodeId(const Id nodeId) const;
std::vector<Id> getAllChildNodeIds(const Id nodeId) const;
@@ -191,7 +192,7 @@ private:
SearchIndex m_tokenIndex;
SqliteStorage m_sqliteStorage;
std::map <FilePath, Id> m_fileNodeIds;
mutable std::map <FilePath, Id> m_fileNodeIds;
HierarchyCache m_hierarchyCache;
TokenLocationCollection m_errorLocationCollection;
+3
View File
@@ -13,6 +13,7 @@
struct FileInfo;
class Graph;
class TextAccess;
class TokenLocation;
class TokenLocationCollection;
class TokenLocationFile;
@@ -51,6 +52,8 @@ public:
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const = 0;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const = 0;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
};
#endif // STORAGE_ACCESS_H
@@ -224,3 +224,13 @@ std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationOfParentS
return std::make_shared<TokenLocationFile>("");
}
std::shared_ptr<TextAccess> StorageAccessProxy::getFileContent(const FilePath& filePath) const
{
if (hasSubject())
{
return m_subject->getFileContent(filePath);
}
return nullptr;
}
+2 -1
View File
@@ -42,9 +42,10 @@ public:
) const;
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(const TokenLocation* child) const;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
private:
StorageAccess* m_subject;
};
+13 -2
View File
@@ -18,6 +18,11 @@ std::shared_ptr<ConfigManager> ConfigManager::createAndLoad(const std::shared_pt
return configManager;
}
void ConfigManager::clear()
{
m_values.clear();
}
bool ConfigManager::getValue(const std::string& key, std::string& value) const
{
std::multimap<std::string, std::string>::const_iterator it = m_values.find(key);
@@ -246,13 +251,19 @@ bool ConfigManager::createXmlDocument(bool saveAsFile, const std::string filepat
for(std::multimap<std::string,std::string>::iterator it = m_values.begin(); it != m_values.end(); ++it)
{
if (!it->first.size() || !it->second.size())
{
continue;
}
std::vector<std::string> tokens = utility::splitToVector(it->first, "/");
TiXmlElement* element = doc.RootElement();
TiXmlElement* child;
while(tokens.size() > 1)
while (tokens.size() > 1)
{
child = element->FirstChildElement(tokens.front().c_str());
if(!child)
if (!child)
{
child = new TiXmlElement(tokens.front().c_str());
element->LinkEndChild(child);
+3
View File
@@ -15,6 +15,8 @@ public:
static std::shared_ptr<ConfigManager> createEmpty();
static std::shared_ptr<ConfigManager> createAndLoad(const std::shared_ptr<TextAccess> textAccess);
void clear();
bool getValue(const std::string& key, std::string& value) const;
bool getValue(const std::string& key, int& value) const;
bool getValue(const std::string& key, float& value) const;
@@ -46,6 +48,7 @@ private:
void parseSubtree(TiXmlNode* parentElement, const std::string& currentPath);
bool createXmlDocument(bool saveAsFile, std::string filepath, std::string& output);
std::multimap<std::string, std::string> m_values;
};
@@ -1,13 +1,15 @@
#ifndef MESSAGE_SHOW_FILE_H
#define MESSAGE_SHOW_FILE_H
#include "utility/file/FilePath.h"
#include "utility/messaging/Message.h"
#include "utility/types.h"
class MessageShowFile: public Message<MessageShowFile>
class MessageShowFile
: public Message<MessageShowFile>
{
public:
MessageShowFile(const std::string& filePath, uint startLineNumber, uint endLineNumber)
MessageShowFile(const FilePath& filePath, uint startLineNumber, uint endLineNumber)
: filePath(filePath)
, startLineNumber(startLineNumber)
, endLineNumber(endLineNumber)
@@ -19,7 +21,7 @@ public:
return "MessageShowFile";
}
const std::string filePath;
const FilePath filePath;
const uint startLineNumber;
const uint endLineNumber;
};