data: bookmark refactoring
* implemented handling of aggregations in bookmarks * split index Storage and bookmark storage * each sqlite database has its own version now * added bookmark tests * fixed creating bookmark tables when project can be loaded but bookmark db does not exist * fixed font size for bookmarkview tooltips * using bookmark cache now * using default category name when none specified by the user * raising bookmark windows when they should be shown * clearing a bookmark or category in the editor will now update the star icon accordingly * non-persistent bookmarks use ids of nodes and edges now (instead of names) * git ignore .srctrlbm files
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
*.coatidb
|
||||
*.srctrldb
|
||||
*.srctrlbm
|
||||
*.suo
|
||||
*.vcxproj.user
|
||||
*.sqlite
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
/* General settings */
|
||||
* {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* Bookmark browser header */
|
||||
|
||||
#header_background {
|
||||
|
||||
@@ -169,10 +169,15 @@ void Application::createAndLoadProject(const FilePath& projectSettingsFilePath)
|
||||
MessageStatus("Failed to load project: " + projectSettingsFilePath.str(), true).dispatch();
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Failed to load project, exception thrown: " << e.what());
|
||||
MessageStatus("Failed to load project, exception was thrown: " + projectSettingsFilePath.str(), true).dispatch();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Failed to load project, exception thrown.");
|
||||
MessageStatus("Failed to load project, exception was thrown: " + projectSettingsFilePath.str(), true).dispatch();
|
||||
LOG_ERROR_STREAM(<< "Failed to load project, unknown exception thrown.");
|
||||
MessageStatus("Failed to load project, unknown exception was thrown: " + projectSettingsFilePath.str(), true).dispatch();
|
||||
}
|
||||
|
||||
if (m_hasGUI)
|
||||
|
||||
@@ -199,8 +199,12 @@ add_files(
|
||||
data/IntermediateStorage.h
|
||||
data/PersistentStorage.cpp
|
||||
data/PersistentStorage.h
|
||||
data/SqliteIndex.cpp
|
||||
data/SqliteIndex.h
|
||||
data/SqliteBookmarkStorage.cpp
|
||||
data/SqliteBookmarkStorage.h
|
||||
data/SqliteDatabaseIndex.cpp
|
||||
data/SqliteDatabaseIndex.h
|
||||
data/SqliteIndexStorage.cpp
|
||||
data/SqliteIndexStorage.h
|
||||
data/SqliteStorage.cpp
|
||||
data/SqliteStorage.h
|
||||
data/Storage.cpp
|
||||
@@ -335,7 +339,7 @@ add_files(
|
||||
utility/messaging/type/MessageCreateBookmarkCategory.h
|
||||
utility/messaging/type/MessageDeactivateEdge.h
|
||||
utility/messaging/type/MessageDeleteBookmark.h
|
||||
utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h
|
||||
utility/messaging/type/MessageDeleteBookmarkCategory.h
|
||||
utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h
|
||||
utility/messaging/type/MessageDispatchWhenLicenseValid.h
|
||||
utility/messaging/type/MessageDisplayBookmarkCreator.h
|
||||
|
||||
@@ -33,8 +33,8 @@ void ComponentManager::setup(ViewLayout* viewLayout)
|
||||
m_componentFactory->getViewFactory()->createCompositeView(viewLayout, CompositeView::DIRECTION_HORIZONTAL, "Search");
|
||||
m_compositeViews.push_back(compositeView);
|
||||
|
||||
// std::shared_ptr<Component> bookmarkComponent = m_componentFactory->createBookmarkComponent(compositeView.get());
|
||||
// m_components.push_back(bookmarkComponent);
|
||||
std::shared_ptr<Component> bookmarkComponent = m_componentFactory->createBookmarkComponent(compositeView.get());
|
||||
m_components.push_back(bookmarkComponent);
|
||||
|
||||
std::shared_ptr<Component> undoRedoComponent = m_componentFactory->createUndoRedoComponent(compositeView.get());
|
||||
m_components.push_back(undoRedoComponent);
|
||||
|
||||
@@ -7,26 +7,22 @@
|
||||
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
#include "utility/Cache.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
|
||||
const std::string BookmarkController::m_edgeSeperatorToken = "=>";
|
||||
const std::string BookmarkController::s_edgeSeperatorToken = "=>";
|
||||
const std::string BookmarkController::s_defaultCategoryName = "Default Bookmark Category";
|
||||
|
||||
BookmarkController::BookmarkController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_activeTokens()
|
||||
, m_activeTokenNames()
|
||||
, m_activeTokenDisplayNames()
|
||||
, m_activeTokenTypes()
|
||||
, m_activeEdges()
|
||||
, m_activeEdgeNames()
|
||||
, m_activeEdgeDisplayNames()
|
||||
, m_activeEdgeTypes()
|
||||
, m_activeTokenExists(false)
|
||||
, m_bookmarkCache(storageAccess)
|
||||
, m_hasBookmarkForActiveToken(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -38,89 +34,28 @@ void BookmarkController::clear()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getAllBookmarks() const
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Retrieving all bookmarks");
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks;
|
||||
|
||||
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < nodeBookmarks.size(); i++)
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<NodeBookmark>(nodeBookmarks[i]));
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < edgeBookmarks.size(); i++)
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<EdgeBookmark>(edgeBookmarks[i]));
|
||||
}
|
||||
|
||||
// std::vector<Bookmark> bookmarks = m_storageAccess->getAllBookmarks();
|
||||
|
||||
// check whether bookmarks are still valid (so, no referenced tokens have been removed)
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < bookmarks[i]->getTokenNames().size(); j++)
|
||||
{
|
||||
std::string name = bookmarks[i]->getTokenNames()[j];
|
||||
int type = bookmarks[i]->getTokenTypes()[j];
|
||||
|
||||
bool exists = false;
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
|
||||
{
|
||||
TempEdge tmpEdge = getEdge(name, type);
|
||||
|
||||
exists = m_storageAccess->checkEdgeExists(tmpEdge.edgeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
exists = m_storageAccess->checkNodeExistsByName(name);
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds = bookmarks[i]->getTokenIds();
|
||||
|
||||
bookmarks[i]->setValid(exists);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Retrieving bookmarks with filter '" << std::to_string(filter) << "' and order '" << std::to_string(order) << "'");
|
||||
LOG_INFO_STREAM(<< "Retrieving bookmarks with filter \"" << std::to_string(filter) << "\" and order \"" << std::to_string(order) << "\"");
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
|
||||
|
||||
int bookmarkCount = bookmarks.size();
|
||||
bookmarks = getFilteredBookmarks(bookmarks, filter);
|
||||
|
||||
bookmarkCount = bookmarks.size();
|
||||
bookmarks = getOrderedBookmarks(bookmarks, order);
|
||||
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getActiveTokenNames() const
|
||||
{
|
||||
return m_activeTokenNames;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getActiveTokenDisplayNames() const
|
||||
{
|
||||
if (m_activeEdgeDisplayNames.size() > 0)
|
||||
if (m_activeEdgeIds.size() > 0)
|
||||
{
|
||||
return m_activeEdgeDisplayNames;
|
||||
return getActiveEdgeDisplayNames();
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_activeTokenDisplayNames;
|
||||
return getActiveNodeDisplayNames();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,82 +64,112 @@ std::vector<BookmarkCategory> BookmarkController::getAllBookmarkCategories() con
|
||||
return m_storageAccess->getAllBookmarkCategories();
|
||||
}
|
||||
|
||||
bool BookmarkController::activeTokenExists() const
|
||||
bool BookmarkController::hasBookmarkForActiveToken() const
|
||||
{
|
||||
return m_activeTokenExists;
|
||||
return m_hasBookmarkForActiveToken;
|
||||
}
|
||||
|
||||
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
|
||||
{
|
||||
if (m_activeEdgeNames.size() > 0)
|
||||
if (!m_activeEdgeIds.empty())
|
||||
{
|
||||
std::vector<EdgeBookmark> bookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
for (std::shared_ptr<EdgeBookmark> edgeBookmark: getAllEdgeBookmarks())
|
||||
{
|
||||
if (bookmarks[i].getTokenNames() == m_activeEdgeNames)
|
||||
if (!m_activeNodeIds.empty() && edgeBookmark->getActiveNodeId() == m_activeNodeIds.front() && utility::isPermutation(edgeBookmark->getEdgeIds(), m_activeEdgeIds))
|
||||
{
|
||||
return std::make_shared<EdgeBookmark>(bookmarks[i]);
|
||||
return std::make_shared<EdgeBookmark>(*(edgeBookmark.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<NodeBookmark> bookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
for (std::shared_ptr<NodeBookmark> nodeBookmark: getAllNodeBookmarks())
|
||||
{
|
||||
if (bookmarks[i].getTokenNames() == m_activeTokenNames)
|
||||
if (utility::isPermutation(nodeBookmark->getNodeIds(), m_activeNodeIds))
|
||||
{
|
||||
return std::make_shared<NodeBookmark>(bookmarks[i]);
|
||||
return std::make_shared<NodeBookmark>(*(nodeBookmark.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return std::shared_ptr<Bookmark>();
|
||||
}
|
||||
|
||||
BookmarkController::BookmarkCache::BookmarkCache(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
{
|
||||
}
|
||||
|
||||
void BookmarkController::BookmarkCache::clear()
|
||||
{
|
||||
m_nodeBookmarksValid = false;
|
||||
m_edgeBookmarksValid = false;
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> BookmarkController::BookmarkCache::getAllNodeBookmarks()
|
||||
{
|
||||
if (!m_nodeBookmarksValid)
|
||||
{
|
||||
m_nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
m_nodeBookmarksValid = true;
|
||||
}
|
||||
return m_nodeBookmarks;
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> BookmarkController::BookmarkCache::getAllEdgeBookmarks()
|
||||
{
|
||||
if (!m_edgeBookmarksValid)
|
||||
{
|
||||
m_edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
m_edgeBookmarksValid = true;
|
||||
}
|
||||
return m_edgeBookmarks;
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageActivateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to activate Bookmark");
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(message->bookmark.get()) != NULL)
|
||||
if (std::shared_ptr<EdgeBookmark> bookmark = std::dynamic_pointer_cast<EdgeBookmark>(message->bookmark))
|
||||
{
|
||||
EdgeBookmark* bookmark = dynamic_cast<EdgeBookmark*>(message->bookmark.get());
|
||||
|
||||
NodeBookmark baseBookmark = bookmark->getBaseBookmark();
|
||||
|
||||
MessageActivateNodes activateNodes;
|
||||
|
||||
for (unsigned int i = 0; i < baseBookmark.getTokenNames().size(); i++)
|
||||
{
|
||||
NameHierarchy nh = NameHierarchy::deserialize(baseBookmark.getTokenNames()[i]);
|
||||
activateNodes.addNode(0, nh);
|
||||
}
|
||||
|
||||
activateNodes.addNode(bookmark->getActiveNodeId(), NameHierarchy());
|
||||
activateNodes.dispatch();
|
||||
|
||||
NameHierarchy source;
|
||||
NameHierarchy target;
|
||||
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
|
||||
if (!bookmark->getEdgeIds().empty())
|
||||
{
|
||||
int tokenType = bookmark->getTokenTypes()[i];
|
||||
TempEdge tmpEdge = getEdge(bookmark->getTokenNames()[i], tokenType);
|
||||
const Id firstEdgeId = bookmark->getEdgeIds().front();
|
||||
const StorageEdge storageEdge = m_storageAccess->getEdgeById(firstEdgeId);
|
||||
|
||||
MessageActivateEdge activateEdge(tmpEdge.edgeId, Edge::intToType(tokenType), tmpEdge.source, tmpEdge.target);
|
||||
activateEdge.dispatch();
|
||||
const NameHierarchy sourceName = m_storageAccess->getNameHierarchyForNodeId(storageEdge.sourceNodeId);
|
||||
const NameHierarchy targetName = m_storageAccess->getNameHierarchyForNodeId(storageEdge.targetNodeId);
|
||||
|
||||
if (bookmark->getEdgeIds().size() == 1)
|
||||
{
|
||||
MessageActivateEdge(firstEdgeId, Edge::intToType(storageEdge.type), sourceName, targetName).dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageActivateEdge activateEdge(0, Edge::EdgeType::EDGE_AGGREGATION, sourceName, targetName);
|
||||
for (const Id aggregatedEdgeId: bookmark->getEdgeIds())
|
||||
{
|
||||
activateEdge.aggregationIds.push_back(aggregatedEdgeId);
|
||||
}
|
||||
activateEdge.dispatch();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Failed to activate bookmark, did not find edges to activate");
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (std::shared_ptr<NodeBookmark> bookmark = std::dynamic_pointer_cast<NodeBookmark>(message->bookmark))
|
||||
{
|
||||
NodeBookmark* bookmark = dynamic_cast<NodeBookmark*>(message->bookmark.get());
|
||||
|
||||
MessageActivateNodes activateNodes;
|
||||
|
||||
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
|
||||
for (Id nodeId: bookmark->getNodeIds())
|
||||
{
|
||||
NameHierarchy nh = NameHierarchy::deserialize(bookmark->getTokenNames()[i]);
|
||||
activateNodes.addNode(0, nh);
|
||||
activateNodes.addNode(nodeId, NameHierarchy());
|
||||
}
|
||||
|
||||
activateNodes.dispatch();
|
||||
@@ -215,73 +180,37 @@ void BookmarkController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new active token");
|
||||
|
||||
if (message->isEdge)
|
||||
m_activeEdgeIds.clear();
|
||||
|
||||
if (message->isEdge || message->isAggregation)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new Edge");
|
||||
m_activeEdgeIds = message->tokenIds;
|
||||
|
||||
std::vector<std::string> tokenNames;
|
||||
std::vector<std::string> tokenDisplayNames;
|
||||
std::vector<int> tokenTypes;
|
||||
|
||||
for (unsigned int i = 0; i < message->tokenIds.size(); i++)
|
||||
if (getBookmarkForActiveToken())
|
||||
{
|
||||
StorageEdge edge = m_storageAccess->getEdgeById(message->tokenIds[i]);
|
||||
|
||||
int typeId = edge.type;
|
||||
|
||||
tokenTypes.push_back(typeId);
|
||||
|
||||
NameHierarchy sourceHierarchy = m_storageAccess->getNameHierarchyForNodeId(edge.sourceNodeId);
|
||||
NameHierarchy targetHierarchy = m_storageAccess->getNameHierarchyForNodeId(edge.targetNodeId);
|
||||
|
||||
std::string sourceNode = NameHierarchy::serialize(sourceHierarchy);
|
||||
std::string targetNode = NameHierarchy::serialize(targetHierarchy);
|
||||
|
||||
std::string tokenName = sourceNode + m_edgeSeperatorToken + targetNode;
|
||||
|
||||
tokenNames.push_back(tokenName);
|
||||
|
||||
tokenDisplayNames.push_back(sourceHierarchy.getRawName() + m_edgeSeperatorToken + targetHierarchy.getRawName());
|
||||
}
|
||||
|
||||
m_activeEdges = message->tokenIds;
|
||||
m_activeEdgeNames = tokenNames;
|
||||
m_activeEdgeTypes = tokenTypes;
|
||||
m_activeEdgeDisplayNames = tokenDisplayNames;
|
||||
|
||||
if (m_storageAccess->checkEdgeBookmarkExistsByTokens(tokenNames))
|
||||
{
|
||||
m_activeTokenExists = true;
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeTokenExists = false;
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if(!message->isEdge)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Registering new Node");
|
||||
|
||||
m_activeTokens = message->tokenIds;
|
||||
m_activeTokenNames = getTokenNames(m_activeTokens);
|
||||
m_activeTokenTypes = getTokenTypes(m_activeTokens);
|
||||
m_activeTokenDisplayNames = getTokenDisplayNames(m_activeTokens);
|
||||
m_activeNodeIds = message->tokenIds;
|
||||
|
||||
m_activeEdges.clear();
|
||||
m_activeEdgeNames.clear();
|
||||
m_activeEdgeTypes.clear();
|
||||
m_activeEdgeDisplayNames.clear();
|
||||
|
||||
if (m_storageAccess->checkNodeBookmarkExistsByTokens(m_activeTokenNames))
|
||||
if (getBookmarkForActiveToken())
|
||||
{
|
||||
m_activeTokenExists = true;
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeTokenExists = false;
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
}
|
||||
@@ -291,157 +220,116 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to create new bookmark");
|
||||
|
||||
if (m_activeTokens.size() > 0)
|
||||
BookmarkCategory category(0, message->categoryName.empty() ? s_defaultCategoryName : message->categoryName);
|
||||
|
||||
if (!m_activeEdgeIds.empty())
|
||||
{
|
||||
if (m_activeEdges.size() > 0)
|
||||
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.empty())
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.size() <= 0)
|
||||
std::vector<std::string> activeEdgeDisplayNames = getActiveEdgeDisplayNames();
|
||||
if (!activeEdgeDisplayNames.empty())
|
||||
{
|
||||
displayName = getDisplayName(m_activeTokens[0]);
|
||||
displayName = activeEdgeDisplayNames.front();
|
||||
}
|
||||
}
|
||||
|
||||
EdgeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
|
||||
EdgeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
|
||||
bookmark.setEdgeIds(m_activeEdgeIds);
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
bookmark.setTokenTypes(m_activeTokenTypes);
|
||||
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
|
||||
bookmark.setCategory(category);
|
||||
|
||||
bookmark.setEdgeTokenIds(m_activeEdges);
|
||||
bookmark.setEdgeTokenNames(m_activeEdgeNames);
|
||||
bookmark.setEdgeTokenTypes(m_activeEdgeTypes);
|
||||
|
||||
Id id = m_storageAccess->addEdgeBookmark(bookmark);
|
||||
|
||||
bookmark.setId(id);
|
||||
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
if (!m_activeNodeIds.empty())
|
||||
{
|
||||
bookmark.setActiveNodeId(m_activeNodeIds.front());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Node Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.size() <= 0)
|
||||
{
|
||||
displayName = getDisplayName(m_activeTokens[0]);
|
||||
}
|
||||
|
||||
NodeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
|
||||
|
||||
bookmark.setTokenTypes(m_activeTokenTypes);
|
||||
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
|
||||
bookmark.setCategory(category);
|
||||
|
||||
Id id = m_storageAccess->addNodeBookmark(bookmark);
|
||||
|
||||
bookmark.setId(id);
|
||||
|
||||
m_activeTokenExists = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
LOG_ERROR("Cannot create bookmark for edge if no active node exists");
|
||||
}
|
||||
|
||||
const Id id = m_storageAccess->addEdgeBookmark(bookmark);
|
||||
bookmark.setId(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Creating Node Bookmark");
|
||||
|
||||
std::string displayName = message->displayName;
|
||||
if (displayName.empty())
|
||||
{
|
||||
std::vector<std::string> activeNodeDisplayNames = getActiveNodeDisplayNames();
|
||||
if (!activeNodeDisplayNames.empty())
|
||||
{
|
||||
displayName = activeNodeDisplayNames.front();
|
||||
}
|
||||
}
|
||||
|
||||
NodeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
|
||||
bookmark.setNodeIds(m_activeNodeIds);
|
||||
const Id id = m_storageAccess->addNodeBookmark(bookmark);
|
||||
bookmark.setId(id);
|
||||
}
|
||||
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
m_hasBookmarkForActiveToken = true;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageCreateBookmarkCategory* message)
|
||||
{
|
||||
std::string categoryName = message->name;
|
||||
LOG_INFO_STREAM(<< "Attempting to create new Bookmark category '" << categoryName << "'");
|
||||
|
||||
if (m_storageAccess->checkBookmarkCategoryExists(message->name) == false)
|
||||
{
|
||||
BookmarkCategory category;
|
||||
category.setName(message->name);
|
||||
|
||||
m_storageAccess->addBookmarkCategory(category);
|
||||
}
|
||||
const std::string& categoryName = message->name.empty() ? s_defaultCategoryName : message->name;
|
||||
LOG_INFO_STREAM(<< "Attempting to create new Bookmark category \"" << categoryName << "\"");
|
||||
m_storageAccess->addBookmarkCategory(categoryName);
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to delete Bookmark " << std::to_string(message->bookmarkId));
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(message->bookmarkId);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(message->bookmarkId);
|
||||
}
|
||||
m_storageAccess->removeBookmark(message->bookmarkId);
|
||||
|
||||
cleanBookmarkCategories();
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
if (!getBookmarkForActiveToken())
|
||||
{
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message)
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmarkCategory* message)
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = m_storageAccess->getAllBookmarkCategories();
|
||||
m_storageAccess->removeBookmarkCategory(message->categoryId);
|
||||
|
||||
for (unsigned int i = 0; i < categories.size(); i++)
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
if (!getBookmarkForActiveToken())
|
||||
{
|
||||
if (categories[i].getId() == message->categoryId)
|
||||
{
|
||||
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
|
||||
for (unsigned int j = 0; j < nodeBookmarks.size(); j++)
|
||||
{
|
||||
if (nodeBookmarks[j].getCategory().getName() == categories[i].getName())
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(nodeBookmarks[j].getId());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
|
||||
for (unsigned int j = 0; j < edgeBookmarks.size(); j++)
|
||||
{
|
||||
if (edgeBookmarks[j].getCategory().getName() == categories[i].getName())
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(edgeBookmarks[j].getId());
|
||||
}
|
||||
}
|
||||
|
||||
cleanBookmarkCategories();
|
||||
getView<BookmarkView>()->update();
|
||||
|
||||
return;
|
||||
}
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
}
|
||||
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageDeleteBookmarkForActiveTokens* message)
|
||||
{
|
||||
std::shared_ptr<Bookmark> bookmark = getBookmarkForActiveToken();
|
||||
|
||||
if (bookmark != NULL)
|
||||
if (std::shared_ptr<Bookmark> bookmark = getBookmarkForActiveToken())
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Deleting bookmark " << bookmark->getDisplayName());
|
||||
LOG_INFO_STREAM(<< "Deleting bookmark " << bookmark->getName());
|
||||
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmark.get()) != NULL)
|
||||
{
|
||||
m_storageAccess->removeEdgeBookmark(bookmark->getId());
|
||||
}
|
||||
else if(dynamic_cast<NodeBookmark*>(bookmark.get()) != NULL)
|
||||
{
|
||||
m_storageAccess->removeNodeBookmark(bookmark->getId());
|
||||
}
|
||||
m_storageAccess->removeBookmark(bookmark->getId());
|
||||
|
||||
cleanBookmarkCategories();
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
m_activeTokenExists = false;
|
||||
m_hasBookmarkForActiveToken = false;
|
||||
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
@@ -455,127 +343,88 @@ void BookmarkController::handleMessage(MessageEditBookmark* message)
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Attempting to update Bookmark " << std::to_string(message->bookmarkId));
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
EdgeBookmark bookmark = m_storageAccess->getEdgeBookmarkById(message->bookmarkId);
|
||||
const std::string& categoryName = message->categoryName.empty() ? s_defaultCategoryName : message->categoryName;
|
||||
m_storageAccess->updateBookmark(message->bookmarkId, message->displayName, message->comment, categoryName);
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
m_storageAccess->editEdgeBookmark(bookmark);
|
||||
}
|
||||
else
|
||||
{
|
||||
NodeBookmark bookmark = m_storageAccess->getNodeBookmarkById(message->bookmarkId);
|
||||
|
||||
bookmark.setDisplayName(message->displayName);
|
||||
bookmark.setComment(message->comment);
|
||||
BookmarkCategory category;
|
||||
category.setName(message->categoryName);
|
||||
bookmark.setCategory(category);
|
||||
|
||||
m_storageAccess->editNodeBookmark(bookmark);
|
||||
}
|
||||
cleanBookmarkCategories();
|
||||
m_bookmarkCache.clear();
|
||||
|
||||
getView<BookmarkView>()->update();
|
||||
}
|
||||
|
||||
void BookmarkController::handleMessage(MessageFinishedParsing* message)
|
||||
{
|
||||
m_bookmarkCache.clear();
|
||||
getView<BookmarkView>()->enableDisplayBookmarks(true);
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getTokenNames(const std::vector<Id>& ids) const
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getAllBookmarks() const
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
LOG_INFO_STREAM(<< "Retrieving all bookmarks");
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks;
|
||||
|
||||
for (std::shared_ptr<NodeBookmark> nodeBookmark: getAllNodeBookmarks())
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeId(ids[i]);
|
||||
names.push_back(NameHierarchy::serialize(nameHierarchy));
|
||||
bookmarks.push_back(nodeBookmark);
|
||||
}
|
||||
for (std::shared_ptr<EdgeBookmark> edgeBookmark: getAllEdgeBookmarks())
|
||||
{
|
||||
bookmarks.push_back(edgeBookmark);
|
||||
}
|
||||
|
||||
return names;
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getTokenDisplayNames(const std::vector<Id>& ids) const
|
||||
std::vector<std::shared_ptr<NodeBookmark>> BookmarkController::getAllNodeBookmarks() const
|
||||
{
|
||||
std::vector<std::shared_ptr<NodeBookmark>> bookmarks;
|
||||
for (const NodeBookmark& nodeBookmark: m_bookmarkCache.getAllNodeBookmarks())
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<NodeBookmark>(nodeBookmark));
|
||||
}
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<EdgeBookmark>> BookmarkController::getAllEdgeBookmarks() const
|
||||
{
|
||||
std::vector<std::shared_ptr<EdgeBookmark>> bookmarks;
|
||||
for (const EdgeBookmark& edgeBookmark: m_bookmarkCache.getAllEdgeBookmarks())
|
||||
{
|
||||
bookmarks.push_back(std::make_shared<EdgeBookmark>(edgeBookmark));
|
||||
}
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
std::vector<std::string> BookmarkController::getActiveNodeDisplayNames() const
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
for (const NameHierarchy& nameHierarchy: m_storageAccess->getNameHierarchiesForNodeIds(m_activeNodeIds))
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeId(ids[i]);
|
||||
names.push_back(nameHierarchy.getRawName());
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
std::vector<int> BookmarkController::getTokenTypes(const std::vector<Id>& ids) const
|
||||
std::vector<std::string> BookmarkController::getActiveEdgeDisplayNames() const
|
||||
{
|
||||
std::vector<int> types;
|
||||
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
std::vector<std::string> activeEdgeDisplayNames;
|
||||
for (Id activeEdgeId: m_activeEdgeIds)
|
||||
{
|
||||
int type = m_storageAccess->getNodeTypeForNodeWithId(ids[i]);
|
||||
types.push_back(type);
|
||||
const StorageEdge activeEdge = m_storageAccess->getEdgeById(activeEdgeId);
|
||||
const std::string sourceDisplayName = getNodeDisplayName(activeEdge.sourceNodeId);
|
||||
const std::string targetDisplayName = getNodeDisplayName(activeEdge.targetNodeId);
|
||||
activeEdgeDisplayNames.push_back(sourceDisplayName + s_edgeSeperatorToken + targetDisplayName);
|
||||
}
|
||||
|
||||
return types;
|
||||
return activeEdgeDisplayNames;
|
||||
}
|
||||
|
||||
std::string BookmarkController::getDisplayName(Id id) const
|
||||
std::string BookmarkController::getNodeDisplayName(const Id nodeId) const
|
||||
{
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeId(id);
|
||||
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeId(nodeId);
|
||||
return nameHierarchy.getRawName();
|
||||
}
|
||||
|
||||
BookmarkController::TempEdge BookmarkController::getEdge(const std::string& tokenName, const int tokenType) const
|
||||
{
|
||||
std::pair<std::string, std::string> edgeTokens = seperateEdgeToken(tokenName);
|
||||
|
||||
NameHierarchy source = NameHierarchy::deserialize(edgeTokens.first);
|
||||
NameHierarchy target = NameHierarchy::deserialize(edgeTokens.second);
|
||||
|
||||
Id edgeId = m_storageAccess->getIdForEdge(Edge::intToType(tokenType), source, target);
|
||||
|
||||
TempEdge result;
|
||||
|
||||
result.edgeId = edgeId;
|
||||
result.source = source;
|
||||
result.target = target;
|
||||
result.type = tokenType;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> BookmarkController::seperateEdgeToken(const std::string& token) const
|
||||
{
|
||||
std::pair<std::string, std::string> result;
|
||||
|
||||
if (token.find(m_edgeSeperatorToken) != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> st = utility::splitToVector(token, m_edgeSeperatorToken);
|
||||
|
||||
if (st.size() != 2)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Invalid edge token found: " << token);
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.first = st[0];
|
||||
result.second = st[1];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> result;
|
||||
@@ -586,27 +435,23 @@ std::vector<std::shared_ptr<Bookmark>> BookmarkController::getFilteredBookmarks(
|
||||
}
|
||||
else if (filter == MessageDisplayBookmarks::BookmarkFilter::NODES)
|
||||
{
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
for (std::shared_ptr<Bookmark> bookmark: bookmarks)
|
||||
{
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) == NULL)
|
||||
if (std::dynamic_pointer_cast<NodeBookmark>(bookmark))
|
||||
{
|
||||
result.push_back(bookmarks[i]);
|
||||
result.push_back(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else if (filter == MessageDisplayBookmarks::BookmarkFilter::EDGES)
|
||||
{
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
for (std::shared_ptr<Bookmark> bookmark: bookmarks)
|
||||
{
|
||||
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
|
||||
if (std::dynamic_pointer_cast<EdgeBookmark>(bookmark))
|
||||
{
|
||||
result.push_back(bookmarks[i]);
|
||||
result.push_back(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -668,11 +513,8 @@ void BookmarkController::cleanBookmarkCategories()
|
||||
{
|
||||
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
|
||||
|
||||
std::vector<BookmarkCategory> categories = getAllBookmarkCategories();
|
||||
|
||||
for (unsigned int i = 0; i < categories.size(); i++)
|
||||
for (const BookmarkCategory& category: getAllBookmarkCategories())
|
||||
{
|
||||
BookmarkCategory category = categories[i];
|
||||
bool used = false;
|
||||
|
||||
for (unsigned int j = 0; j < bookmarks.size(); j++)
|
||||
@@ -698,8 +540,8 @@ bool BookmarkController::bookmarkDateCompare(const std::shared_ptr<Bookmark> a,
|
||||
|
||||
bool BookmarkController::bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b)
|
||||
{
|
||||
std::string aName = a->getDisplayName();
|
||||
std::string bName = b->getDisplayName();
|
||||
std::string aName = a->getName();
|
||||
std::string bName = b->getName();
|
||||
|
||||
aName = utility::toLowerCase(aName);
|
||||
bName = utility::toLowerCase(bName);
|
||||
@@ -720,4 +562,4 @@ bool BookmarkController::bookmarkNameCompare(const std::shared_ptr<Bookmark> a,
|
||||
}
|
||||
|
||||
return aName.length() < bName.length();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@
|
||||
#define BOOKMARK_CONTROLLER_H
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateBookmark.h"
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageCreateBookmark.h"
|
||||
#include "utility/messaging/type/MessageCreateBookmarkCategory.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmark.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategory.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageEditBookmark.h"
|
||||
@@ -27,7 +31,7 @@ class BookmarkController
|
||||
, public MessageListener<MessageCreateBookmark>
|
||||
, public MessageListener<MessageCreateBookmarkCategory>
|
||||
, public MessageListener<MessageDeleteBookmark>
|
||||
, public MessageListener<MessageDeleteBookmarkCategoryWithBookmarks>
|
||||
, public MessageListener<MessageDeleteBookmarkCategory>
|
||||
, public MessageListener<MessageDeleteBookmarkForActiveTokens>
|
||||
, public MessageListener<MessageEditBookmark>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
@@ -38,23 +42,30 @@ public:
|
||||
|
||||
virtual void clear();
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> getAllBookmarks() const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const;
|
||||
|
||||
std::vector<std::string> getActiveTokenNames() const;
|
||||
std::vector<std::string> getActiveTokenDisplayNames() const;
|
||||
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
bool activeTokenExists() const;
|
||||
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const; // or null if no bookmark for that token exists
|
||||
bool hasBookmarkForActiveToken() const;
|
||||
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const;
|
||||
|
||||
private:
|
||||
struct TempEdge
|
||||
class BookmarkCache
|
||||
{
|
||||
public:
|
||||
Id edgeId;
|
||||
NameHierarchy source;
|
||||
NameHierarchy target;
|
||||
int type;
|
||||
BookmarkCache(StorageAccess* storageAccess);
|
||||
|
||||
void clear();
|
||||
|
||||
std::vector<NodeBookmark> getAllNodeBookmarks();
|
||||
std::vector<EdgeBookmark> getAllEdgeBookmarks();
|
||||
|
||||
private:
|
||||
StorageAccess* m_storageAccess;
|
||||
std::vector<NodeBookmark> m_nodeBookmarks;
|
||||
std::vector<EdgeBookmark> m_edgeBookmarks;
|
||||
bool m_nodeBookmarksValid;
|
||||
bool m_edgeBookmarksValid;
|
||||
};
|
||||
|
||||
virtual void handleMessage(MessageActivateBookmark* message);
|
||||
@@ -62,18 +73,18 @@ private:
|
||||
virtual void handleMessage(MessageCreateBookmark* message);
|
||||
virtual void handleMessage(MessageCreateBookmarkCategory* message);
|
||||
virtual void handleMessage(MessageDeleteBookmark* message);
|
||||
virtual void handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message);
|
||||
virtual void handleMessage(MessageDeleteBookmarkCategory* message);
|
||||
virtual void handleMessage(MessageDeleteBookmarkForActiveTokens* message);
|
||||
virtual void handleMessage(MessageEditBookmark* message);
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
|
||||
std::vector<std::string> getTokenNames(const std::vector<Id>& ids) const;
|
||||
std::vector<std::string> getTokenDisplayNames(const std::vector<Id>& ids) const;
|
||||
std::vector<int> getTokenTypes(const std::vector<Id>& ids) const;
|
||||
std::string getDisplayName(Id id) const;
|
||||
TempEdge getEdge(const std::string& tokenName, const int tokenType) const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getAllBookmarks() const;
|
||||
std::vector<std::shared_ptr<NodeBookmark>> getAllNodeBookmarks() const;
|
||||
std::vector<std::shared_ptr<EdgeBookmark>> getAllEdgeBookmarks() const;
|
||||
|
||||
std::pair<std::string, std::string> seperateEdgeToken(const std::string& token) const;
|
||||
std::vector<std::string> getActiveNodeDisplayNames() const;
|
||||
std::vector<std::string> getActiveEdgeDisplayNames() const;
|
||||
std::string getNodeDisplayName(const Id id) const;
|
||||
|
||||
std::vector<std::shared_ptr<Bookmark>> getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const;
|
||||
std::vector<std::shared_ptr<Bookmark>> getOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkOrder& order) const;
|
||||
@@ -85,20 +96,15 @@ private:
|
||||
static bool bookmarkDateCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
|
||||
static bool bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
|
||||
|
||||
static const std::string m_edgeSeperatorToken;
|
||||
static const std::string s_edgeSeperatorToken;
|
||||
static const std::string s_defaultCategoryName;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
std::vector<Id> m_activeTokens;
|
||||
std::vector<std::string> m_activeTokenNames;
|
||||
std::vector<std::string> m_activeTokenDisplayNames;
|
||||
std::vector<int> m_activeTokenTypes;
|
||||
mutable BookmarkCache m_bookmarkCache;
|
||||
|
||||
std::vector<Id> m_activeEdges;
|
||||
std::vector<std::string> m_activeEdgeNames;
|
||||
std::vector<std::string> m_activeEdgeDisplayNames;
|
||||
std::vector<int> m_activeEdgeTypes;
|
||||
|
||||
bool m_activeTokenExists;
|
||||
std::vector<Id> m_activeNodeIds;
|
||||
std::vector<Id> m_activeEdgeIds;
|
||||
bool m_hasBookmarkForActiveToken;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_CONTROLLER_H
|
||||
|
||||
@@ -48,7 +48,7 @@ void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
|
||||
{
|
||||
std::vector<std::string> names = getController()->getActiveTokenDisplayNames();
|
||||
|
||||
if (getController()->activeTokenExists())
|
||||
if (getController()->hasBookmarkForActiveToken())
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
|
||||
|
||||
@@ -80,6 +80,6 @@ void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
|
||||
void BookmarkView::handleMessage(MessageDisplayBookmarkEditor* message)
|
||||
{
|
||||
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
|
||||
|
||||
|
||||
displayBookmarkEditor(message->bookmark, categories);
|
||||
}
|
||||
}
|
||||
|
||||
+270
-174
@@ -24,8 +24,9 @@
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
PersistentStorage::PersistentStorage(const FilePath& dbPath)
|
||||
: m_sqliteStorage(dbPath)
|
||||
PersistentStorage::PersistentStorage(const FilePath& dbPath, const FilePath& bookmarkPath)
|
||||
: m_sqliteIndexStorage(dbPath)
|
||||
, m_sqliteBookmarkStorage(bookmarkPath)
|
||||
{
|
||||
m_commandIndex.addNode(0, SearchMatch::getCommandName(SearchMatch::COMMAND_ALL));
|
||||
m_commandIndex.addNode(0, SearchMatch::getCommandName(SearchMatch::COMMAND_ERROR));
|
||||
@@ -39,18 +40,18 @@ PersistentStorage::~PersistentStorage()
|
||||
|
||||
Id PersistentStorage::addNode(int type, const std::string& serializedName)
|
||||
{
|
||||
const StorageNode storedNode = m_sqliteStorage.getNodeBySerializedName(serializedName);
|
||||
const StorageNode storedNode = m_sqliteIndexStorage.getNodeBySerializedName(serializedName);
|
||||
Id id = storedNode.id;
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
id = m_sqliteStorage.addNode(type, serializedName);
|
||||
id = m_sqliteIndexStorage.addNode(type, serializedName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (storedNode.type < type)
|
||||
{
|
||||
m_sqliteStorage.setNodeType(type, id);
|
||||
m_sqliteIndexStorage.setNodeType(type, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,41 +60,41 @@ Id PersistentStorage::addNode(int type, const std::string& serializedName)
|
||||
|
||||
void PersistentStorage::addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete)
|
||||
{
|
||||
StorageFile file = m_sqliteStorage.getFirstById<StorageFile>(id);
|
||||
StorageFile file = m_sqliteIndexStorage.getFirstById<StorageFile>(id);
|
||||
if (file.id == 0)
|
||||
{
|
||||
m_sqliteStorage.addFile(id, filePath, modificationTime, complete);
|
||||
m_sqliteIndexStorage.addFile(id, filePath, modificationTime, complete);
|
||||
}
|
||||
else if (!file.complete && complete)
|
||||
{
|
||||
m_sqliteStorage.setFileComplete(complete, id);
|
||||
m_sqliteIndexStorage.setFileComplete(complete, id);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addSymbol(const Id id, int definitionKind)
|
||||
{
|
||||
if (m_sqliteStorage.getFirstById<StorageSymbol>(id).id == 0)
|
||||
if (m_sqliteIndexStorage.getFirstById<StorageSymbol>(id).id == 0)
|
||||
{
|
||||
m_sqliteStorage.addSymbol(id, definitionKind);
|
||||
m_sqliteIndexStorage.addSymbol(id, definitionKind);
|
||||
}
|
||||
}
|
||||
|
||||
Id PersistentStorage::addEdge(int type, Id sourceId, Id targetId)
|
||||
{
|
||||
Id edgeId = m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
Id edgeId = m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
if (edgeId == 0)
|
||||
{
|
||||
edgeId = m_sqliteStorage.addEdge(type, sourceId, targetId);
|
||||
edgeId = m_sqliteIndexStorage.addEdge(type, sourceId, targetId);
|
||||
}
|
||||
return edgeId;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addLocalSymbol(const std::string& name)
|
||||
{
|
||||
Id localSymbolId = m_sqliteStorage.getLocalSymbolByName(name).id;
|
||||
Id localSymbolId = m_sqliteIndexStorage.getLocalSymbolByName(name).id;
|
||||
if (localSymbolId == 0)
|
||||
{
|
||||
localSymbolId = m_sqliteStorage.addLocalSymbol(name);
|
||||
localSymbolId = m_sqliteIndexStorage.addLocalSymbol(name);
|
||||
}
|
||||
return localSymbolId;
|
||||
}
|
||||
@@ -101,10 +102,10 @@ Id PersistentStorage::addLocalSymbol(const std::string& name)
|
||||
Id PersistentStorage::addSourceLocation(
|
||||
Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type)
|
||||
{
|
||||
Id sourceLocationId = m_sqliteStorage.getSourceLocationByAll(fileNodeId, startLine, startCol, endLine, endCol, type).id;
|
||||
Id sourceLocationId = m_sqliteIndexStorage.getSourceLocationByAll(fileNodeId, startLine, startCol, endLine, endCol, type).id;
|
||||
if (sourceLocationId == 0)
|
||||
{
|
||||
sourceLocationId = m_sqliteStorage.addSourceLocation(
|
||||
sourceLocationId = m_sqliteIndexStorage.addSourceLocation(
|
||||
fileNodeId,
|
||||
startLine,
|
||||
startCol,
|
||||
@@ -118,20 +119,20 @@ Id PersistentStorage::addSourceLocation(
|
||||
|
||||
void PersistentStorage::addOccurrence(Id elementId, Id sourceLocationId)
|
||||
{
|
||||
m_sqliteStorage.addOccurrence(elementId, sourceLocationId);
|
||||
m_sqliteIndexStorage.addOccurrence(elementId, sourceLocationId);
|
||||
}
|
||||
|
||||
void PersistentStorage::addComponentAccess(Id nodeId , int type)
|
||||
{
|
||||
if (m_sqliteStorage.getComponentAccessByNodeId(nodeId).nodeId == 0)
|
||||
if (m_sqliteIndexStorage.getComponentAccessByNodeId(nodeId).nodeId == 0)
|
||||
{
|
||||
m_sqliteStorage.addComponentAccess(nodeId, type);
|
||||
m_sqliteIndexStorage.addComponentAccess(nodeId, type);
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol)
|
||||
{
|
||||
m_sqliteStorage.addCommentLocation(
|
||||
m_sqliteIndexStorage.addCommentLocation(
|
||||
fileNodeId,
|
||||
startLine,
|
||||
startCol,
|
||||
@@ -143,7 +144,7 @@ void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint s
|
||||
void PersistentStorage::addError(
|
||||
const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed)
|
||||
{
|
||||
m_sqliteStorage.addError(
|
||||
m_sqliteIndexStorage.addError(
|
||||
message,
|
||||
filePath,
|
||||
startLine,
|
||||
@@ -155,87 +156,172 @@ void PersistentStorage::addError(
|
||||
|
||||
Id PersistentStorage::addNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
return m_sqliteStorage.addNodeBookmark(bookmark);
|
||||
const Id categoryId = addBookmarkCategory(bookmark.getCategory().getName());
|
||||
const Id id = m_sqliteBookmarkStorage.addBookmark(bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId);
|
||||
|
||||
for (const Id& nodeId: bookmark.getNodeIds())
|
||||
{
|
||||
m_sqliteBookmarkStorage.addBookmarkedNode(id, m_sqliteIndexStorage.getNodeById(nodeId).serializedName);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
return m_sqliteStorage.addEdgeBookmark(bookmark);
|
||||
const Id categoryId = addBookmarkCategory(bookmark.getCategory().getName());
|
||||
const Id id = m_sqliteBookmarkStorage.addBookmark(bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId);
|
||||
for (const Id& edgeId: bookmark.getEdgeIds())
|
||||
{
|
||||
const StorageEdge storageEdge = m_sqliteIndexStorage.getEdgeById(edgeId);
|
||||
|
||||
bool sourceNodeActive = storageEdge.sourceNodeId == bookmark.getActiveNodeId();
|
||||
m_sqliteBookmarkStorage.addBookmarkedEdge(
|
||||
id,
|
||||
m_sqliteIndexStorage.getNodeById(storageEdge.sourceNodeId).serializedName, // todo: optimization for multiple edges in same bookmark: use a local cache here
|
||||
m_sqliteIndexStorage.getNodeById(storageEdge.targetNodeId).serializedName,
|
||||
storageEdge.type,
|
||||
sourceNodeActive
|
||||
);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
Id PersistentStorage::addBookmarkCategory(const BookmarkCategory& category)
|
||||
Id PersistentStorage::addBookmarkCategory(const std::string& name)
|
||||
{
|
||||
return m_sqliteStorage.addBookmarkCategory(category.getName());
|
||||
if (name.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id id = m_sqliteBookmarkStorage.getBookmarkCategoryByName(name).id;
|
||||
if (id == 0)
|
||||
{
|
||||
id = m_sqliteBookmarkStorage.addBookmarkCategory(name);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> PersistentStorage::getAllNodeBookmarks() const
|
||||
void PersistentStorage::updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const std::string& categoryName)
|
||||
{
|
||||
return m_sqliteStorage.getAllNodeBookmarks();
|
||||
const Id categoryId = addBookmarkCategory(categoryName); // only creates category if id didn't exist before;
|
||||
m_sqliteBookmarkStorage.updateBookmark(bookmarkId, name, comment, categoryId);
|
||||
}
|
||||
|
||||
NodeBookmark PersistentStorage::getNodeBookmarkById(const Id bookmarkId) const
|
||||
void PersistentStorage::removeBookmark(const Id id)
|
||||
{
|
||||
return m_sqliteStorage.getNodeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
return m_sqliteStorage.checkNodeBookmarkExistsByNames(tokenNames);
|
||||
}
|
||||
|
||||
void PersistentStorage::removeNodeBookmark(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeNodeBookmark(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::editNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
m_sqliteStorage.editNodeBookmark(bookmark);
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> PersistentStorage::getAllEdgeBookmarks() const
|
||||
{
|
||||
return m_sqliteStorage.getAllEdgeBookmarks();
|
||||
}
|
||||
|
||||
EdgeBookmark PersistentStorage::getEdgeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
return m_sqliteStorage.getEdgeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
return m_sqliteStorage.checkEdgeBookmarkExistsByNames(tokenNames);
|
||||
}
|
||||
|
||||
void PersistentStorage::removeEdgeBookmark(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeEdgeBookmark(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::editEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
m_sqliteStorage.editEdgeBookmark(bookmark);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkBookmarkCategoryExists(const std::string& name) const
|
||||
{
|
||||
return m_sqliteStorage.checkBookmarkCategoryExists(name);
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> PersistentStorage::getAllBookmarkCategories() const
|
||||
{
|
||||
return m_sqliteStorage.getAllBookmarkCategories();
|
||||
m_sqliteBookmarkStorage.removeBookmark(id);
|
||||
}
|
||||
|
||||
void PersistentStorage::removeBookmarkCategory(Id id)
|
||||
{
|
||||
m_sqliteStorage.removeBookmarkCategory(id);
|
||||
m_sqliteBookmarkStorage.removeBookmarkCategory(id);
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> PersistentStorage::getAllNodeBookmarks() const
|
||||
{
|
||||
std::unordered_map<Id, StorageBookmarkCategory> bookmarkCategories;
|
||||
for (const StorageBookmarkCategory& bookmarkCategory: m_sqliteBookmarkStorage.getAllBookmarkCategories())
|
||||
{
|
||||
bookmarkCategories[bookmarkCategory.id] = bookmarkCategory;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, std::vector<Id>> bookmarkIdToBookmarkedNodeIds;
|
||||
for (const StorageBookmarkedNode& bookmarkedNode: m_sqliteBookmarkStorage.getAllBookmarkedNodes())
|
||||
{
|
||||
bookmarkIdToBookmarkedNodeIds[bookmarkedNode.bookmarkId].push_back(m_sqliteIndexStorage.getNodeBySerializedName(bookmarkedNode.serializedNodeName).id);
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> nodeBookmarks;
|
||||
|
||||
for (const StorageBookmark& storageBookmark: m_sqliteBookmarkStorage.getAllBookmarks())
|
||||
{
|
||||
auto itCategories = bookmarkCategories.find(storageBookmark.categoryId);
|
||||
auto itNodeIds = bookmarkIdToBookmarkedNodeIds.find(storageBookmark.id);
|
||||
if (itCategories != bookmarkCategories.end() && itNodeIds != bookmarkIdToBookmarkedNodeIds.end())
|
||||
{
|
||||
NodeBookmark bookmark(
|
||||
storageBookmark.id,
|
||||
storageBookmark.name,
|
||||
storageBookmark.comment,
|
||||
storageBookmark.timestamp,
|
||||
BookmarkCategory(itCategories->second.id, itCategories->second.name)
|
||||
);
|
||||
bookmark.setNodeIds(itNodeIds->second);
|
||||
bookmark.setIsValid();
|
||||
nodeBookmarks.push_back(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeBookmarks;
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> PersistentStorage::getAllEdgeBookmarks() const
|
||||
{
|
||||
std::unordered_map<Id, StorageBookmarkCategory> bookmarkCategories;
|
||||
for (const StorageBookmarkCategory& bookmarkCategory: m_sqliteBookmarkStorage.getAllBookmarkCategories())
|
||||
{
|
||||
bookmarkCategories[bookmarkCategory.id] = bookmarkCategory;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, std::vector<StorageBookmarkedEdge>> bookmarkIdToBookmarkedEdges;
|
||||
for (const StorageBookmarkedEdge& bookmarkedEdge: m_sqliteBookmarkStorage.getAllBookmarkedEdges())
|
||||
{
|
||||
bookmarkIdToBookmarkedEdges[bookmarkedEdge.bookmarkId].push_back(bookmarkedEdge);
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> edgeBookmarks;
|
||||
|
||||
Cache<std::string, Id> nodeIdCache([&](std::string serializedNodeName){ return m_sqliteIndexStorage.getNodeBySerializedName(serializedNodeName).id; });
|
||||
for (const StorageBookmark& storageBookmark: m_sqliteBookmarkStorage.getAllBookmarks())
|
||||
{
|
||||
auto itCategories = bookmarkCategories.find(storageBookmark.categoryId);
|
||||
auto itBookmarkedEdges = bookmarkIdToBookmarkedEdges.find(storageBookmark.id);
|
||||
if (itCategories != bookmarkCategories.end() && itBookmarkedEdges != bookmarkIdToBookmarkedEdges.end())
|
||||
{
|
||||
EdgeBookmark bookmark(
|
||||
storageBookmark.id,
|
||||
storageBookmark.name,
|
||||
storageBookmark.comment,
|
||||
storageBookmark.timestamp,
|
||||
BookmarkCategory(itCategories->second.id, itCategories->second.name)
|
||||
);
|
||||
|
||||
Id activeNodeId = 0;
|
||||
for (const StorageBookmarkedEdge& bookmarkedEdge: itBookmarkedEdges->second)
|
||||
{
|
||||
const Id sourceNodeId = nodeIdCache.getValue(bookmarkedEdge.serializedSourceNodeName);
|
||||
const Id targetNodeId = nodeIdCache.getValue(bookmarkedEdge.serializedTargetNodeName);
|
||||
const Id edgeId = m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceNodeId, targetNodeId, bookmarkedEdge.edgeType).id;
|
||||
bookmark.addEdgeId(edgeId);
|
||||
|
||||
if (activeNodeId == 0)
|
||||
{
|
||||
activeNodeId = bookmarkedEdge.sourceNodeActive ? sourceNodeId : targetNodeId;
|
||||
}
|
||||
}
|
||||
bookmark.setActiveNodeId(activeNodeId);
|
||||
bookmark.setIsValid();
|
||||
edgeBookmarks.push_back(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
return edgeBookmarks;
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> PersistentStorage::getAllBookmarkCategories() const
|
||||
{
|
||||
std::vector<BookmarkCategory> categories;
|
||||
for (const StorageBookmarkCategory storageBookmarkCategoriy: m_sqliteBookmarkStorage.getAllBookmarkCategories())
|
||||
{
|
||||
categories.push_back(BookmarkCategory(storageBookmarkCategoriy.id, storageBookmarkCategoriy.name));
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
|
||||
void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageNode& node: m_sqliteStorage.getAll<StorageNode>())
|
||||
for (StorageNode& node: m_sqliteIndexStorage.getAll<StorageNode>())
|
||||
{
|
||||
callback(node.id, node);
|
||||
}
|
||||
@@ -243,7 +329,7 @@ void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const St
|
||||
|
||||
void PersistentStorage::forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageFile& file: m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageFile& file: m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
callback(file);
|
||||
}
|
||||
@@ -251,7 +337,7 @@ void PersistentStorage::forEachFile(std::function<void(const StorageFile& /*data
|
||||
|
||||
void PersistentStorage::forEachSymbol(std::function<void(const StorageSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageSymbol& symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
for (StorageSymbol& symbol: m_sqliteIndexStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
callback(symbol);
|
||||
}
|
||||
@@ -259,7 +345,7 @@ void PersistentStorage::forEachSymbol(std::function<void(const StorageSymbol& /*
|
||||
|
||||
void PersistentStorage::forEachEdge(std::function<void(const Id /*id*/, const StorageEdge& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageEdge& edge: m_sqliteStorage.getAll<StorageEdge>())
|
||||
for (StorageEdge& edge: m_sqliteIndexStorage.getAll<StorageEdge>())
|
||||
{
|
||||
callback(edge.id, edge);
|
||||
}
|
||||
@@ -268,7 +354,7 @@ void PersistentStorage::forEachEdge(std::function<void(const Id /*id*/, const St
|
||||
void PersistentStorage::forEachLocalSymbol(std::function<void(
|
||||
const Id /*id*/, const StorageLocalSymbol& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageLocalSymbol& localSymbol: m_sqliteStorage.getAll<StorageLocalSymbol>())
|
||||
for (StorageLocalSymbol& localSymbol: m_sqliteIndexStorage.getAll<StorageLocalSymbol>())
|
||||
{
|
||||
callback(localSymbol.id, localSymbol);
|
||||
}
|
||||
@@ -276,7 +362,7 @@ void PersistentStorage::forEachLocalSymbol(std::function<void(
|
||||
|
||||
void PersistentStorage::forEachSourceLocation(std::function<void(const Id /*id*/, const StorageSourceLocation& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageSourceLocation& sourceLocation: m_sqliteStorage.getAll<StorageSourceLocation>())
|
||||
for (StorageSourceLocation& sourceLocation: m_sqliteIndexStorage.getAll<StorageSourceLocation>())
|
||||
{
|
||||
callback(sourceLocation.id, sourceLocation);
|
||||
}
|
||||
@@ -284,7 +370,7 @@ void PersistentStorage::forEachSourceLocation(std::function<void(const Id /*id*/
|
||||
|
||||
void PersistentStorage::forEachOccurrence(std::function<void(const StorageOccurrence& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageOccurrence& occurrence: m_sqliteStorage.getAll<StorageOccurrence>())
|
||||
for (StorageOccurrence& occurrence: m_sqliteIndexStorage.getAll<StorageOccurrence>())
|
||||
{
|
||||
callback(occurrence);
|
||||
}
|
||||
@@ -292,7 +378,7 @@ void PersistentStorage::forEachOccurrence(std::function<void(const StorageOccurr
|
||||
|
||||
void PersistentStorage::forEachComponentAccess(std::function<void(const StorageComponentAccess& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageComponentAccess& componentAccess: m_sqliteStorage.getAll<StorageComponentAccess>())
|
||||
for (StorageComponentAccess& componentAccess: m_sqliteIndexStorage.getAll<StorageComponentAccess>())
|
||||
{
|
||||
callback(componentAccess);
|
||||
}
|
||||
@@ -300,7 +386,7 @@ void PersistentStorage::forEachComponentAccess(std::function<void(const StorageC
|
||||
|
||||
void PersistentStorage::forEachCommentLocation(std::function<void(const StorageCommentLocation& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageCommentLocation& commentLocation: m_sqliteStorage.getAll<StorageCommentLocation>())
|
||||
for (StorageCommentLocation& commentLocation: m_sqliteIndexStorage.getAll<StorageCommentLocation>())
|
||||
{
|
||||
callback(commentLocation);
|
||||
}
|
||||
@@ -308,7 +394,7 @@ void PersistentStorage::forEachCommentLocation(std::function<void(const StorageC
|
||||
|
||||
void PersistentStorage::forEachError(std::function<void(const StorageError& /*data*/)> callback) const
|
||||
{
|
||||
for (StorageError& error: m_sqliteStorage.getAll<StorageError>())
|
||||
for (StorageError& error: m_sqliteIndexStorage.getAll<StorageError>())
|
||||
{
|
||||
callback(error);
|
||||
}
|
||||
@@ -318,12 +404,12 @@ void PersistentStorage::startInjection()
|
||||
{
|
||||
m_preInjectionErrorCount = getErrors().size();
|
||||
|
||||
m_sqliteStorage.beginTransaction();
|
||||
m_sqliteIndexStorage.beginTransaction();
|
||||
}
|
||||
|
||||
void PersistentStorage::finishInjection()
|
||||
{
|
||||
m_sqliteStorage.commitTransaction();
|
||||
m_sqliteIndexStorage.commitTransaction();
|
||||
|
||||
auto errors = getErrors();
|
||||
|
||||
@@ -333,44 +419,51 @@ void PersistentStorage::finishInjection()
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::setMode(const SqliteStorage::StorageModeType mode)
|
||||
void PersistentStorage::setMode(const SqliteIndexStorage::StorageModeType mode)
|
||||
{
|
||||
m_sqliteStorage.setMode(mode);
|
||||
m_sqliteIndexStorage.setMode(mode);
|
||||
}
|
||||
|
||||
FilePath PersistentStorage::getDbFilePath() const
|
||||
{
|
||||
return m_sqliteStorage.getDbFilePath();
|
||||
return m_sqliteIndexStorage.getDbFilePath();
|
||||
}
|
||||
|
||||
bool PersistentStorage::isEmpty() const
|
||||
{
|
||||
return m_sqliteStorage.isEmpty();
|
||||
return m_sqliteIndexStorage.isEmpty();
|
||||
}
|
||||
|
||||
bool PersistentStorage::isIncompatible() const
|
||||
{
|
||||
return m_sqliteStorage.isIncompatible();
|
||||
return m_sqliteIndexStorage.isIncompatible();
|
||||
}
|
||||
|
||||
std::string PersistentStorage::getProjectSettingsText() const
|
||||
{
|
||||
return m_sqliteStorage.getProjectSettingsText();
|
||||
return m_sqliteIndexStorage.getProjectSettingsText();
|
||||
}
|
||||
|
||||
void PersistentStorage::setProjectSettingsText(std::string text)
|
||||
{
|
||||
m_sqliteStorage.setProjectSettingsText(text);
|
||||
m_sqliteIndexStorage.setProjectSettingsText(text);
|
||||
}
|
||||
|
||||
void PersistentStorage::setup()
|
||||
{
|
||||
m_sqliteStorage.setup();
|
||||
if (m_sqliteIndexStorage.isEmpty())
|
||||
{
|
||||
m_sqliteIndexStorage.setup();
|
||||
}
|
||||
if (m_sqliteBookmarkStorage.isEmpty())
|
||||
{
|
||||
m_sqliteBookmarkStorage.setup();
|
||||
}
|
||||
}
|
||||
|
||||
void PersistentStorage::clear()
|
||||
{
|
||||
m_sqliteStorage.clear();
|
||||
m_sqliteIndexStorage.clear();
|
||||
|
||||
clearCaches();
|
||||
}
|
||||
@@ -415,10 +508,10 @@ void PersistentStorage::clearFileElements(const std::vector<FilePath>& filePaths
|
||||
|
||||
if (!fileNodeIds.empty())
|
||||
{
|
||||
m_sqliteStorage.removeElementsWithLocationInFiles(fileNodeIds, updateStatusCallback);
|
||||
m_sqliteStorage.removeElements(fileNodeIds);
|
||||
m_sqliteIndexStorage.removeElementsWithLocationInFiles(fileNodeIds, updateStatusCallback);
|
||||
m_sqliteIndexStorage.removeElements(fileNodeIds);
|
||||
|
||||
m_sqliteStorage.removeErrorsInFiles(filePaths);
|
||||
m_sqliteIndexStorage.removeErrorsInFiles(filePaths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +521,7 @@ std::vector<FileInfo> PersistentStorage::getInfoOnAllFiles() const
|
||||
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getAll<StorageFile>();
|
||||
std::vector<StorageFile> storageFiles = m_sqliteIndexStorage.getAll<StorageFile>();
|
||||
for (size_t i = 0; i < storageFiles.size(); i++)
|
||||
{
|
||||
boost::posix_time::ptime modificationTime = boost::posix_time::not_a_date_time;
|
||||
@@ -460,18 +553,21 @@ void PersistentStorage::optimizeMemory()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
m_sqliteStorage.optimizeMemory();
|
||||
m_sqliteStorage.setVersion();
|
||||
m_sqliteIndexStorage.setVersion();
|
||||
m_sqliteIndexStorage.optimizeMemory();
|
||||
|
||||
m_sqliteBookmarkStorage.setVersion();
|
||||
m_sqliteBookmarkStorage.optimizeMemory();
|
||||
}
|
||||
|
||||
Id PersistentStorage::getNodeIdForFileNode(const FilePath& filePath) const
|
||||
{
|
||||
return m_sqliteStorage.getFileByPath(filePath.str()).id;
|
||||
return m_sqliteIndexStorage.getFileByPath(filePath.str()).id;
|
||||
}
|
||||
|
||||
Id PersistentStorage::getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const
|
||||
{
|
||||
return m_sqliteStorage.getNodeBySerializedName(NameHierarchy::serialize(nameHierarchy)).id;
|
||||
return m_sqliteIndexStorage.getNodeBySerializedName(NameHierarchy::serialize(nameHierarchy)).id;
|
||||
}
|
||||
|
||||
std::vector<Id> PersistentStorage::getNodeIdsForNameHierarchies(const std::vector<NameHierarchy> nameHierarchies) const
|
||||
@@ -492,13 +588,13 @@ NameHierarchy PersistentStorage::getNameHierarchyForNodeId(Id nodeId) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return NameHierarchy::deserialize(m_sqliteStorage.getFirstById<StorageNode>(nodeId).serializedName);
|
||||
return NameHierarchy::deserialize(m_sqliteIndexStorage.getFirstById<StorageNode>(nodeId).serializedName);
|
||||
}
|
||||
|
||||
std::vector<NameHierarchy> PersistentStorage::getNameHierarchiesForNodeIds(const std::vector<Id> nodeIds) const
|
||||
{
|
||||
std::vector<NameHierarchy> nameHierarchies;
|
||||
for (const StorageNode& storageNode : m_sqliteStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
for (const StorageNode& storageNode : m_sqliteIndexStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
{
|
||||
nameHierarchies.push_back(NameHierarchy::deserialize(storageNode.serializedName));
|
||||
}
|
||||
@@ -507,12 +603,12 @@ std::vector<NameHierarchy> PersistentStorage::getNameHierarchiesForNodeIds(const
|
||||
|
||||
Node::NodeType PersistentStorage::getNodeTypeForNodeWithId(Id nodeId) const
|
||||
{
|
||||
return Node::intToType(m_sqliteStorage.getFirstById<StorageNode>(nodeId).type);
|
||||
return Node::intToType(m_sqliteIndexStorage.getFirstById<StorageNode>(nodeId).type);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkNodeExistsByName(const std::string& serializedName) const
|
||||
{
|
||||
return m_sqliteStorage.checkNodeExistsByName(serializedName);
|
||||
return m_sqliteIndexStorage.checkNodeExistsByName(serializedName);
|
||||
}
|
||||
|
||||
Id PersistentStorage::getIdForEdge(
|
||||
@@ -521,17 +617,17 @@ Id PersistentStorage::getIdForEdge(
|
||||
{
|
||||
Id sourceId = getNodeIdForNameHierarchy(fromNameHierarchy);
|
||||
Id targetId = getNodeIdForNameHierarchy(toNameHierarchy);
|
||||
return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
return m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
|
||||
}
|
||||
|
||||
StorageEdge PersistentStorage::getEdgeById(Id edgeId) const
|
||||
{
|
||||
return m_sqliteStorage.getEdgeById(edgeId);
|
||||
return m_sqliteIndexStorage.getEdgeById(edgeId);
|
||||
}
|
||||
|
||||
bool PersistentStorage::checkEdgeExists(Id edgeId) const
|
||||
{
|
||||
return m_sqliteStorage.checkEdgeExists(edgeId);
|
||||
return m_sqliteIndexStorage.checkEdgeExists(edgeId);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationCollection> PersistentStorage::getFullTextSearchLocations(
|
||||
@@ -687,12 +783,12 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(const
|
||||
elementIds.insert(elementIds.end(), result.elementIds.begin(), result.elementIds.end());
|
||||
}
|
||||
|
||||
for (StorageNode& node : m_sqliteStorage.getAllByIds<StorageNode>(elementIds))
|
||||
for (StorageNode& node : m_sqliteIndexStorage.getAllByIds<StorageNode>(elementIds))
|
||||
{
|
||||
storageNodeMap[node.id] = node;
|
||||
}
|
||||
|
||||
for (StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(elementIds))
|
||||
for (StorageSymbol& symbol : m_sqliteIndexStorage.getAllByIds<StorageSymbol>(elementIds))
|
||||
{
|
||||
storageSymbolMap[symbol.id] = symbol;
|
||||
}
|
||||
@@ -813,7 +909,7 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
|
||||
// fetch StorageNodes for node ids
|
||||
std::map<Id, StorageNode> storageNodeMap;
|
||||
for (StorageNode& node : m_sqliteStorage.getAllByIds<StorageNode>(elementIds))
|
||||
for (StorageNode& node : m_sqliteIndexStorage.getAllByIds<StorageNode>(elementIds))
|
||||
{
|
||||
storageNodeMap.emplace(node.id, node);
|
||||
}
|
||||
@@ -854,7 +950,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
std::shared_ptr<Graph> graph = std::make_shared<Graph>();
|
||||
|
||||
std::unordered_set<Id> explicitlyDefinedSymbolIds;
|
||||
for (StorageSymbol symbol: m_sqliteStorage.getAll<StorageSymbol>())
|
||||
for (StorageSymbol symbol: m_sqliteIndexStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
if (intToDefinitionKind(symbol.definitionKind) == DEFINITION_EXPLICIT)
|
||||
{
|
||||
@@ -863,7 +959,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
for (StorageNode node: m_sqliteStorage.getAll<StorageNode>())
|
||||
for (StorageNode node: m_sqliteIndexStorage.getAll<StorageNode>())
|
||||
{
|
||||
if (explicitlyDefinedSymbolIds.find(node.id) != explicitlyDefinedSymbolIds.end() &&
|
||||
(
|
||||
@@ -879,7 +975,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForAll() const
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageFile file: m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageFile file: m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
tokenIds.push_back(file.id);
|
||||
}
|
||||
@@ -908,7 +1004,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
if (tokenIds.size() == 1)
|
||||
{
|
||||
const Id elementId = tokenIds[0];
|
||||
StorageNode node = m_sqliteStorage.getFirstById<StorageNode>(elementId);
|
||||
StorageNode node = m_sqliteIndexStorage.getFirstById<StorageNode>(elementId);
|
||||
|
||||
if (node.id > 0)
|
||||
{
|
||||
@@ -924,7 +1020,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getEdgesBySourceOrTargetId(elementId);
|
||||
std::vector<StorageEdge> edges = m_sqliteIndexStorage.getEdgesBySourceOrTargetId(elementId);
|
||||
for (const StorageEdge& edge : edges)
|
||||
{
|
||||
Edge::EdgeType edgeType = Edge::intToType(edge.type);
|
||||
@@ -947,7 +1043,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
addAggregations = true;
|
||||
}
|
||||
}
|
||||
else if (m_sqliteStorage.isEdge(elementId))
|
||||
else if (m_sqliteIndexStorage.isEdge(elementId))
|
||||
{
|
||||
edgeIds.push_back(elementId);
|
||||
}
|
||||
@@ -956,7 +1052,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
if (ids.size() >= 1 || isNamespace)
|
||||
{
|
||||
std::set<Id> symbolIds;
|
||||
for (const StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(ids))
|
||||
for (const StorageSymbol& symbol : m_sqliteIndexStorage.getAllByIds<StorageSymbol>(ids))
|
||||
{
|
||||
if (symbol.id > 0 && (!isNamespace || intToDefinitionKind(symbol.definitionKind) != DEFINITION_IMPLICIT))
|
||||
{
|
||||
@@ -964,7 +1060,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
}
|
||||
symbolIds.insert(symbol.id);
|
||||
}
|
||||
for (const StorageNode& node : m_sqliteStorage.getAllByIds<StorageNode>(ids))
|
||||
for (const StorageNode& node : m_sqliteIndexStorage.getAllByIds<StorageNode>(ids))
|
||||
{
|
||||
if (symbolIds.find(node.id) == symbolIds.end())
|
||||
{
|
||||
@@ -976,7 +1072,7 @@ std::shared_ptr<Graph> PersistentStorage::getGraphForActiveTokenIds(const std::v
|
||||
{
|
||||
if (nodeIds.size() != ids.size())
|
||||
{
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getAllByIds<StorageEdge>(ids);
|
||||
std::vector<StorageEdge> edges = m_sqliteIndexStorage.getAllByIds<StorageEdge>(ids);
|
||||
for (const StorageEdge& edge : edges)
|
||||
{
|
||||
if (edge.id > 0)
|
||||
@@ -1017,18 +1113,18 @@ std::vector<Id> PersistentStorage::getActiveTokenIdsForId(Id tokenId, Id* declar
|
||||
{
|
||||
std::vector<Id> activeTokenIds;
|
||||
|
||||
if (!(m_sqliteStorage.isEdge(tokenId) || m_sqliteStorage.isNode(tokenId)))
|
||||
if (!(m_sqliteIndexStorage.isEdge(tokenId) || m_sqliteIndexStorage.isNode(tokenId)))
|
||||
{
|
||||
return activeTokenIds;
|
||||
}
|
||||
|
||||
activeTokenIds.push_back(tokenId);
|
||||
|
||||
if (m_sqliteStorage.isNode(tokenId))
|
||||
if (m_sqliteIndexStorage.isNode(tokenId))
|
||||
{
|
||||
*declarationId = tokenId;
|
||||
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteStorage.getEdgesByTargetId(tokenId);
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetId(tokenId);
|
||||
for (size_t i = 0; i < incomingEdges.size(); i++)
|
||||
{
|
||||
activeTokenIds.push_back(incomingEdges[i].id);
|
||||
@@ -1046,18 +1142,18 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
std::set<Id> nodeIds;
|
||||
std::set<Id> implicitNodeIds;
|
||||
|
||||
for (const StorageOccurrence& occurrence: m_sqliteStorage.getOccurrencesForLocationIds(locationIds))
|
||||
for (const StorageOccurrence& occurrence: m_sqliteIndexStorage.getOccurrencesForLocationIds(locationIds))
|
||||
{
|
||||
const Id elementId = occurrence.elementId;
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getFirstById<StorageEdge>(elementId);
|
||||
StorageEdge edge = m_sqliteIndexStorage.getFirstById<StorageEdge>(elementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
{
|
||||
edgeIds.insert(edge.targetNodeId);
|
||||
}
|
||||
else if(m_sqliteStorage.isNode(elementId))
|
||||
else if(m_sqliteIndexStorage.isNode(elementId))
|
||||
{
|
||||
StorageSymbol symbol = m_sqliteStorage.getFirstById<StorageSymbol>(elementId);
|
||||
StorageSymbol symbol = m_sqliteIndexStorage.getFirstById<StorageSymbol>(elementId);
|
||||
if (symbol.id != 0) // here we test if location is a symbol
|
||||
{
|
||||
if (intToDefinitionKind(symbol.definitionKind) == DEFINITION_IMPLICIT)
|
||||
@@ -1111,22 +1207,22 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
|
||||
for (const StorageFile& file : m_sqliteStorage.getAllByIds<StorageFile>(fileIds))
|
||||
for (const StorageFile& file : m_sqliteIndexStorage.getAllByIds<StorageFile>(fileIds))
|
||||
{
|
||||
collection->addSourceLocationFile(m_sqliteStorage.getSourceLocationsForFile(file.filePath));
|
||||
collection->addSourceLocationFile(m_sqliteIndexStorage.getSourceLocationsForFile(file.filePath));
|
||||
}
|
||||
|
||||
if (nonFileIds.size())
|
||||
{
|
||||
std::vector<Id> locationIds;
|
||||
std::unordered_map<Id, Id> locationIdToElementIdMap;
|
||||
for (const StorageOccurrence& occurrence: m_sqliteStorage.getOccurrencesForElementIds(nonFileIds))
|
||||
for (const StorageOccurrence& occurrence: m_sqliteIndexStorage.getOccurrencesForElementIds(nonFileIds))
|
||||
{
|
||||
locationIds.push_back(occurrence.sourceLocationId);
|
||||
locationIdToElementIdMap[occurrence.sourceLocationId] = occurrence.elementId;
|
||||
}
|
||||
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it != locationIdToElementIdMap.end())
|
||||
@@ -1156,10 +1252,10 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
|
||||
for (StorageSourceLocation location: m_sqliteStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
for (StorageSourceLocation location: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
std::vector<Id> elementIds;
|
||||
for (const StorageOccurrence& occurrence: m_sqliteStorage.getOccurrencesForLocationId(location.id))
|
||||
for (const StorageOccurrence& occurrence: m_sqliteIndexStorage.getOccurrencesForLocationId(location.id))
|
||||
{
|
||||
elementIds.push_back(occurrence.elementId);
|
||||
}
|
||||
@@ -1183,7 +1279,7 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForFile
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return m_sqliteStorage.getSourceLocationsForFile(filePath);
|
||||
return m_sqliteIndexStorage.getSourceLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForLinesInFile(
|
||||
@@ -1201,7 +1297,7 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile
|
||||
|
||||
std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(filePath, false, false);
|
||||
|
||||
std::vector<StorageCommentLocation> storageLocations = m_sqliteStorage.getCommentLocationsInFile(filePath);
|
||||
std::vector<StorageCommentLocation> storageLocations = m_sqliteIndexStorage.getCommentLocationsInFile(filePath);
|
||||
for (size_t i = 0; i < storageLocations.size(); i++)
|
||||
{
|
||||
file->addSourceLocation(
|
||||
@@ -1220,19 +1316,19 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile
|
||||
|
||||
std::shared_ptr<TextAccess> PersistentStorage::getFileContent(const FilePath& filePath) const
|
||||
{
|
||||
return m_sqliteStorage.getFileContentByPath(filePath.str());
|
||||
return m_sqliteIndexStorage.getFileContentByPath(filePath.str());
|
||||
}
|
||||
|
||||
FileInfo PersistentStorage::getFileInfoForFilePath(const FilePath& filePath) const
|
||||
{
|
||||
return FileInfo(filePath, m_sqliteStorage.getFileByPath(filePath.str()).modificationTime);
|
||||
return FileInfo(filePath, m_sqliteIndexStorage.getFileByPath(filePath.str()).modificationTime);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> PersistentStorage::getFileInfosForFilePaths(const std::vector<FilePath>& filePaths) const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
std::vector<StorageFile> storageFiles = m_sqliteStorage.getFilesByPaths(filePaths);
|
||||
std::vector<StorageFile> storageFiles = m_sqliteIndexStorage.getFilesByPaths(filePaths);
|
||||
for (const StorageFile& file : storageFiles)
|
||||
{
|
||||
fileInfos.push_back(FileInfo(FilePath(file.filePath), file.modificationTime));
|
||||
@@ -1247,12 +1343,12 @@ StorageStats PersistentStorage::getStorageStats() const
|
||||
|
||||
StorageStats stats;
|
||||
|
||||
stats.nodeCount = m_sqliteStorage.getNodeCount();
|
||||
stats.edgeCount = m_sqliteStorage.getEdgeCount();
|
||||
stats.nodeCount = m_sqliteIndexStorage.getNodeCount();
|
||||
stats.edgeCount = m_sqliteIndexStorage.getEdgeCount();
|
||||
|
||||
stats.fileCount = m_sqliteStorage.getFileCount();
|
||||
stats.completedFileCount = m_sqliteStorage.getCompletedFileCount();
|
||||
stats.fileLOCCount = m_sqliteStorage.getFileLineSum();
|
||||
stats.fileCount = m_sqliteIndexStorage.getFileCount();
|
||||
stats.completedFileCount = m_sqliteIndexStorage.getCompletedFileCount();
|
||||
stats.fileLOCCount = m_sqliteIndexStorage.getFileLineSum();
|
||||
|
||||
return stats;
|
||||
}
|
||||
@@ -1277,7 +1373,7 @@ ErrorCountInfo PersistentStorage::getErrorCount() const
|
||||
|
||||
std::vector<ErrorInfo> PersistentStorage::getErrors() const
|
||||
{
|
||||
std::vector<ErrorInfo> errors = m_sqliteStorage.getAll<StorageError>();
|
||||
std::vector<ErrorInfo> errors = m_sqliteIndexStorage.getAll<StorageError>();
|
||||
std::vector<ErrorInfo> filteredErrors;
|
||||
|
||||
for (const ErrorInfo& error : errors)
|
||||
@@ -1296,7 +1392,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getErrorSourceLocat
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<SourceLocationCollection> errorCollection = std::make_shared<SourceLocationCollection>();
|
||||
for (const ErrorInfo& error : m_sqliteStorage.getAll<StorageError>())
|
||||
for (const ErrorInfo& error : m_sqliteIndexStorage.getAll<StorageError>())
|
||||
{
|
||||
if (m_errorFilter.filter(error))
|
||||
{
|
||||
@@ -1380,7 +1476,7 @@ FilePath PersistentStorage::getFileNodePath(Id fileId) const
|
||||
std::unordered_map<Id, std::set<Id>> PersistentStorage::getFileIdToIncludingFileIdMap() const
|
||||
{
|
||||
std::unordered_map<Id, std::set<Id>> fileIdToIncludingFileIdMap;
|
||||
for (const StorageEdge& includeEdge : m_sqliteStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_INCLUDE)))
|
||||
for (const StorageEdge& includeEdge : m_sqliteIndexStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_INCLUDE)))
|
||||
{
|
||||
fileIdToIncludingFileIdMap[includeEdge.targetNodeId].insert(includeEdge.sourceNodeId);
|
||||
}
|
||||
@@ -1394,7 +1490,7 @@ std::unordered_map<Id, std::set<Id>> PersistentStorage::getFileIdToImportingFile
|
||||
std::vector<Id> importedElementIds;
|
||||
std::map<Id, std::set<Id>> elementIdToImportingFileIds;
|
||||
|
||||
for (const StorageEdge& importEdge : m_sqliteStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_IMPORT)))
|
||||
for (const StorageEdge& importEdge : m_sqliteIndexStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_IMPORT)))
|
||||
{
|
||||
importedElementIds.push_back(importEdge.targetNodeId);
|
||||
elementIdToImportingFileIds[importEdge.targetNodeId].insert(importEdge.sourceNodeId);
|
||||
@@ -1404,13 +1500,13 @@ std::unordered_map<Id, std::set<Id>> PersistentStorage::getFileIdToImportingFile
|
||||
{
|
||||
std::vector<Id> importedSourceLocationIds;
|
||||
std::unordered_map<Id, Id> importedSourceLocationToElementIds;
|
||||
for (const StorageOccurrence& occurrence: m_sqliteStorage.getOccurrencesForElementIds(importedElementIds))
|
||||
for (const StorageOccurrence& occurrence: m_sqliteIndexStorage.getOccurrencesForElementIds(importedElementIds))
|
||||
{
|
||||
importedSourceLocationIds.push_back(occurrence.sourceLocationId);
|
||||
importedSourceLocationToElementIds[occurrence.sourceLocationId] = occurrence.elementId;
|
||||
}
|
||||
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteStorage.getAllByIds<StorageSourceLocation>(importedSourceLocationIds))
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(importedSourceLocationIds))
|
||||
{
|
||||
auto it = importedSourceLocationToElementIds.find(sourceLocation.id);
|
||||
if (it != importedSourceLocationToElementIds.end())
|
||||
@@ -1553,18 +1649,18 @@ void PersistentStorage::addNodesToGraph(const std::vector<Id>& nodeIds, Graph* g
|
||||
}
|
||||
|
||||
std::unordered_map<Id, StorageSymbol> symbolMap;
|
||||
for (const StorageSymbol& symbol : m_sqliteStorage.getAllByIds<StorageSymbol>(nodeIds))
|
||||
for (const StorageSymbol& symbol : m_sqliteIndexStorage.getAllByIds<StorageSymbol>(nodeIds))
|
||||
{
|
||||
symbolMap[symbol.id] = symbol;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, StorageFile> fileMap;
|
||||
for (const StorageFile& file : m_sqliteStorage.getAllByIds<StorageFile>(nodeIds))
|
||||
for (const StorageFile& file : m_sqliteIndexStorage.getAllByIds<StorageFile>(nodeIds))
|
||||
{
|
||||
fileMap[file.id] = file;
|
||||
}
|
||||
|
||||
for (const StorageNode& storageNode : m_sqliteStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
for (const StorageNode& storageNode : m_sqliteIndexStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
{
|
||||
const Node::NodeType type = Node::intToType(storageNode.type);
|
||||
if (type == Node::NODE_FILE)
|
||||
@@ -1637,7 +1733,7 @@ void PersistentStorage::addEdgesToGraph(const std::vector<Id>& edgeIds, Graph* g
|
||||
return;
|
||||
}
|
||||
|
||||
for (const StorageEdge& storageEdge : m_sqliteStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
for (const StorageEdge& storageEdge : m_sqliteIndexStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
{
|
||||
Node* sourceNode = graph->getNodeById(storageEdge.sourceNodeId);
|
||||
Node* targetNode = graph->getNodeById(storageEdge.targetNodeId);
|
||||
@@ -1662,7 +1758,7 @@ void PersistentStorage::addNodesWithChildrenAndEdgesToGraph(
|
||||
std::vector<Id> nodeIdsFull = nodeIds;
|
||||
if (edgeIds.size() > 0)
|
||||
{
|
||||
for (const StorageEdge& storageEdge : m_sqliteStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
for (const StorageEdge& storageEdge : m_sqliteIndexStorage.getAllByIds<StorageEdge>(edgeIds))
|
||||
{
|
||||
nodeIdsFull.push_back(storageEdge.sourceNodeId);
|
||||
nodeIdsFull.push_back(storageEdge.targetNodeId);
|
||||
@@ -1732,7 +1828,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
connectedNodeIds[isSource ? edge.targetNodeId : edge.sourceNodeId].push_back(edgeInfo);
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> outgoingEdges = m_sqliteStorage.getEdgesBySourceIds(childNodeIds);
|
||||
std::vector<StorageEdge> outgoingEdges = m_sqliteIndexStorage.getEdgesBySourceIds(childNodeIds);
|
||||
for (const StorageEdge& outEdge : outgoingEdges)
|
||||
{
|
||||
EdgeInfo edgeInfo;
|
||||
@@ -1741,7 +1837,7 @@ void PersistentStorage::addAggregationEdgesToGraph(
|
||||
connectedNodeIds[outEdge.targetNodeId].push_back(edgeInfo);
|
||||
}
|
||||
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteStorage.getEdgesByTargetIds(childNodeIds);
|
||||
std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetIds(childNodeIds);
|
||||
for (const StorageEdge& inEdge : incomingEdges)
|
||||
{
|
||||
EdgeInfo edgeInfo;
|
||||
@@ -1814,7 +1910,7 @@ void PersistentStorage::addComponentAccessToGraph(Graph* graph) const
|
||||
}
|
||||
);
|
||||
|
||||
std::vector<StorageComponentAccess> accesses = m_sqliteStorage.getComponentAccessesByNodeIds(nodeIds);
|
||||
std::vector<StorageComponentAccess> accesses = m_sqliteIndexStorage.getComponentAccessesByNodeIds(nodeIds);
|
||||
for (const StorageComponentAccess& access : accesses)
|
||||
{
|
||||
if (access.nodeId != 0)
|
||||
@@ -1832,18 +1928,18 @@ void PersistentStorage::buildSearchIndex()
|
||||
FilePath dbPath = getDbFilePath();
|
||||
|
||||
std::unordered_map<Id, StorageSymbol> symbolMap;
|
||||
for (StorageSymbol symbol : m_sqliteStorage.getAll<StorageSymbol>())
|
||||
for (StorageSymbol symbol : m_sqliteIndexStorage.getAll<StorageSymbol>())
|
||||
{
|
||||
symbolMap[symbol.id] = symbol;
|
||||
}
|
||||
|
||||
std::unordered_map<Id, StorageFile> fileMap;
|
||||
for (StorageFile file : m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageFile file : m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
fileMap[file.id] = file;
|
||||
}
|
||||
|
||||
for (StorageNode node : m_sqliteStorage.getAll<StorageNode>())
|
||||
for (StorageNode node : m_sqliteIndexStorage.getAll<StorageNode>())
|
||||
{
|
||||
if (Node::intToType(node.type) == Node::NODE_FILE)
|
||||
{
|
||||
@@ -1879,7 +1975,7 @@ void PersistentStorage::buildFilePathMaps()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
for (StorageFile file: m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageFile file: m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
m_fileNodeIds.emplace(file.filePath, file.id);
|
||||
m_fileNodePaths.emplace(file.id, file.filePath);
|
||||
@@ -1890,9 +1986,9 @@ void PersistentStorage::buildFullTextSearchIndex() const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
for (StorageFile file : m_sqliteStorage.getAll<StorageFile>())
|
||||
for (StorageFile file : m_sqliteIndexStorage.getAll<StorageFile>())
|
||||
{
|
||||
m_fullTextSearchIndex.addFile(file.id, m_sqliteStorage.getFileContentById(file.id)->getText());
|
||||
m_fullTextSearchIndex.addFile(file.id, m_sqliteIndexStorage.getFileContentById(file.id)->getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1900,14 +1996,14 @@ void PersistentStorage::buildHierarchyCache()
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<StorageEdge> memberEdges = m_sqliteStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
std::vector<StorageEdge> memberEdges = m_sqliteIndexStorage.getEdgesByType(Edge::typeToInt(Edge::EDGE_MEMBER));
|
||||
|
||||
Cache<Id, Node::NodeType> nodeTypeCache([this](Id id){
|
||||
return Node::intToType(m_sqliteStorage.getFirstById<StorageNode>(id).type);
|
||||
return Node::intToType(m_sqliteIndexStorage.getFirstById<StorageNode>(id).type);
|
||||
});
|
||||
|
||||
Cache<Id, bool> indexedNodeCache([this](Id id){
|
||||
StorageSymbol symbol = m_sqliteStorage.getFirstById<StorageSymbol>(id);
|
||||
StorageSymbol symbol = m_sqliteIndexStorage.getFirstById<StorageSymbol>(id);
|
||||
if (symbol.id > 0)
|
||||
{
|
||||
return intToDefinitionKind(symbol.definitionKind) != DEFINITION_NONE;
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/search/SearchIndex.h"
|
||||
#include "data/HierarchyCache.h"
|
||||
#include "data/SqliteStorage.h"
|
||||
#include "data/SqliteIndexStorage.h"
|
||||
#include "data/SqliteBookmarkStorage.h"
|
||||
#include "data/Storage.h"
|
||||
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
@@ -23,7 +24,7 @@ class PersistentStorage
|
||||
, public StorageAccess
|
||||
{
|
||||
public:
|
||||
PersistentStorage(const FilePath& dbPath);
|
||||
PersistentStorage(const FilePath& dbPath, const FilePath& bookmarkPath);
|
||||
virtual ~PersistentStorage();
|
||||
|
||||
virtual Id addNode(int type, const std::string& serializedName);
|
||||
@@ -38,23 +39,18 @@ public:
|
||||
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category);
|
||||
virtual Id addBookmarkCategory(const std::string& categoryName);
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeNodeBookmark(Id id);
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
void updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const std::string& categoryName);
|
||||
|
||||
virtual void removeBookmark(const Id id);
|
||||
virtual void removeBookmarkCategory(const Id id);
|
||||
|
||||
std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeEdgeBookmark(Id id);
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
virtual void removeBookmarkCategory(Id id);
|
||||
|
||||
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
|
||||
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
|
||||
@@ -70,7 +66,7 @@ public:
|
||||
virtual void startInjection();
|
||||
virtual void finishInjection();
|
||||
|
||||
void setMode(const SqliteStorage::StorageModeType mode);
|
||||
void setMode(const SqliteIndexStorage::StorageModeType mode);
|
||||
|
||||
FilePath getDbFilePath() const;
|
||||
|
||||
@@ -188,7 +184,8 @@ private:
|
||||
|
||||
mutable FullTextSearchIndex m_fullTextSearchIndex;
|
||||
|
||||
SqliteStorage m_sqliteStorage;
|
||||
SqliteIndexStorage m_sqliteIndexStorage;
|
||||
SqliteBookmarkStorage m_sqliteBookmarkStorage;
|
||||
|
||||
mutable std::map <FilePath, Id> m_fileNodeIds;
|
||||
mutable std::map <Id, FilePath> m_fileNodePaths;
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
#include "SqliteBookmarkStorage.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
const size_t SqliteBookmarkStorage::s_storageVersion = 1;
|
||||
|
||||
SqliteBookmarkStorage::SqliteBookmarkStorage(const FilePath& dbFilePath)
|
||||
: SqliteStorage(dbFilePath)
|
||||
{
|
||||
}
|
||||
|
||||
SqliteBookmarkStorage::~SqliteBookmarkStorage()
|
||||
{
|
||||
}
|
||||
|
||||
Id SqliteBookmarkStorage::addBookmarkCategory(const std::string& name)
|
||||
{
|
||||
std::string statement = "INSERT INTO bookmark_category(id, name) "
|
||||
"VALUES (NULL, ?);";
|
||||
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, name.c_str());
|
||||
|
||||
executeStatement(stmt);
|
||||
const Id id = m_database.lastRowId();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteBookmarkStorage::addBookmark(const std::string& name, const std::string& comment, const std::string& timestamp, const Id categoryId)
|
||||
{
|
||||
std::string statement = "INSERT INTO bookmark(id, name, comment, timestamp, category_id) "
|
||||
"VALUES (NULL, ?, ?, ?, " + std::to_string(categoryId) + ");";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, name.c_str());
|
||||
stmt.bind(2, comment.c_str());
|
||||
stmt.bind(3, timestamp.c_str());
|
||||
executeStatement(stmt);
|
||||
|
||||
const Id id = m_database.lastRowId();
|
||||
return id;
|
||||
}
|
||||
catch (CppSQLite3Exception e)
|
||||
{
|
||||
LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id SqliteBookmarkStorage::addBookmarkedNode(const Id bookmarkId, const std::string& nodeName)
|
||||
{
|
||||
executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(bookmarkId) + ");");
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
std::string statement = "INSERT INTO bookmarked_node(id, serialized_node_name) "
|
||||
"VALUES (" + std::to_string(id) + ", ?);";
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, nodeName.c_str());
|
||||
executeStatement(stmt);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Id SqliteBookmarkStorage::addBookmarkedEdge(const Id bookmarkId, const std::string& sourceNodeName, const std::string& targetNodeName, const int edgeType, const bool sourceNodeActive)
|
||||
{
|
||||
executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(bookmarkId) + ");");
|
||||
Id id = m_database.lastRowId();
|
||||
|
||||
std::string statement = "INSERT INTO bookmarked_edge(id, serialized_source_node_name, serialized_target_node_name, edge_type, source_node_active) "
|
||||
"VALUES (" + std::to_string(id) + ", ?, ?, " + std::to_string(edgeType) + ", " + std::to_string(sourceNodeActive) + ");";
|
||||
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
|
||||
stmt.bind(1, sourceNodeName.c_str());
|
||||
stmt.bind(2, targetNodeName.c_str());
|
||||
executeStatement(stmt);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
std::vector<StorageBookmark> SqliteBookmarkStorage::getAllBookmarks() const
|
||||
{
|
||||
return doGetAll<StorageBookmark>("");
|
||||
}
|
||||
|
||||
void SqliteBookmarkStorage::removeBookmark(const Id id)
|
||||
{
|
||||
executeStatement(
|
||||
"DELETE FROM bookmark WHERE id = (" + std::to_string(id) + ");"
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<StorageBookmarkedNode> SqliteBookmarkStorage::getAllBookmarkedNodes() const
|
||||
{
|
||||
return doGetAll<StorageBookmarkedNode>("");
|
||||
}
|
||||
|
||||
std::vector<StorageBookmarkedEdge> SqliteBookmarkStorage::getAllBookmarkedEdges() const
|
||||
{
|
||||
return doGetAll<StorageBookmarkedEdge>("");
|
||||
}
|
||||
|
||||
void SqliteBookmarkStorage::updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const Id categoryId)
|
||||
{
|
||||
executeStatement("UPDATE bookmark SET name = '" + name + "' WHERE id == " + std::to_string(bookmarkId) + ";");
|
||||
executeStatement("UPDATE bookmark SET comment = '" + comment + "' WHERE id == " + std::to_string(bookmarkId) + ";");
|
||||
executeStatement("UPDATE bookmark SET category_id = " + std::to_string(categoryId) + " WHERE id == " + std::to_string(bookmarkId) + ";");
|
||||
}
|
||||
|
||||
std::vector<StorageBookmarkCategory> SqliteBookmarkStorage::getAllBookmarkCategories() const
|
||||
{
|
||||
return doGetAll<StorageBookmarkCategory>("");
|
||||
}
|
||||
|
||||
StorageBookmarkCategory SqliteBookmarkStorage::getBookmarkCategoryByName(const std::string& name) const
|
||||
{
|
||||
return doGetFirst<StorageBookmarkCategory>("WHERE name == '" + name + "'");
|
||||
}
|
||||
|
||||
void SqliteBookmarkStorage::removeBookmarkCategory(Id id)
|
||||
{
|
||||
executeStatement(
|
||||
"DELETE FROM bookmark_category WHERE id = (" + std::to_string(id) + ");"
|
||||
);
|
||||
}
|
||||
|
||||
size_t SqliteBookmarkStorage::getStaticStorageVersion() const
|
||||
{
|
||||
return s_storageVersion;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int, SqliteDatabaseIndex>> SqliteBookmarkStorage::getIndices() const
|
||||
{
|
||||
return std::vector<std::pair<int, SqliteDatabaseIndex>>();
|
||||
}
|
||||
|
||||
void SqliteBookmarkStorage::clearTables()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.bookmarked_edge;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.bookmarked_node;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.bookmarked_element;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.bookmark;");
|
||||
m_database.execDML("DROP TABLE IF EXISTS main.bookmark_category;");
|
||||
}
|
||||
catch (CppSQLite3Exception& e)
|
||||
{
|
||||
LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
void SqliteBookmarkStorage::setupTables()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmark_category("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"PRIMARY KEY(id)"
|
||||
");"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmark("
|
||||
"id INTEGER NOT NULL, "
|
||||
"name TEXT, "
|
||||
"comment TEXT, "
|
||||
"timestamp TEXT, "
|
||||
"category_id INTEGER, "
|
||||
"FOREIGN KEY(category_id) REFERENCES bookmark_category(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(id)"
|
||||
");"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarked_element("
|
||||
"id INTEGER NOT NULL, "
|
||||
"bookmark_id INTEGER NOT NULL, "
|
||||
"FOREIGN KEY(bookmark_id) REFERENCES bookmark(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(id)"
|
||||
");"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarked_node("
|
||||
"id INTEGER NOT NULL, "
|
||||
"serialized_node_name TEXT, "
|
||||
"FOREIGN KEY(id) REFERENCES bookmarked_element(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(id)"
|
||||
");"
|
||||
);
|
||||
|
||||
m_database.execDML(
|
||||
"CREATE TABLE IF NOT EXISTS bookmarked_edge("
|
||||
"id INTEGER NOT NULL, "
|
||||
"serialized_source_node_name TEXT, "
|
||||
"serialized_target_node_name TEXT, "
|
||||
"edge_type INTEGER, "
|
||||
"source_node_active INTEGER, "
|
||||
"FOREIGN KEY(id) REFERENCES bookmarked_element(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(id)"
|
||||
");"
|
||||
);
|
||||
}
|
||||
catch (CppSQLite3Exception& e)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Failed to create tables: " << std::to_string(e.errorCode()) << ": " << e.errorMessage());
|
||||
throw e;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Failed to create tables: " << e.what());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageBookmarkCategory> SqliteBookmarkStorage::doGetAll<StorageBookmarkCategory>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, name FROM bookmark_category " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageBookmarkCategory> categories;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const std::string name = q.getStringField(1, "");
|
||||
|
||||
if (id != 0 && name != "")
|
||||
{
|
||||
categories.push_back(StorageBookmarkCategory(id, name));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageBookmark> SqliteBookmarkStorage::doGetAll<StorageBookmark>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT id, name, comment, timestamp, category_id FROM bookmark " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageBookmark> bookmarks;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const std::string name = q.getStringField(1, "");
|
||||
const std::string comment = q.getStringField(2, "");
|
||||
const std::string timestamp = q.getStringField(3, "");
|
||||
const Id categoryId = q.getIntField(4, 0);
|
||||
|
||||
if (id != 0 && name != "" && timestamp != "")
|
||||
{
|
||||
bookmarks.push_back(StorageBookmark(id, name, comment, timestamp, categoryId));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return bookmarks;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageBookmarkedNode> SqliteBookmarkStorage::doGetAll<StorageBookmarkedNode>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT "
|
||||
"bookmarked_node.id, bookmarked_element.bookmark_id, bookmarked_node.serialized_node_name "
|
||||
"FROM bookmarked_node "
|
||||
"INNER JOIN "
|
||||
"bookmarked_element ON bookmarked_node.id = bookmarked_element.id " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageBookmarkedNode> bookmarkedNodes;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const Id bookmarkId = q.getIntField(1, 0);
|
||||
const std::string serializedNodeName = q.getStringField(2, "");
|
||||
|
||||
if (id != 0 && bookmarkId != 0 && serializedNodeName != "")
|
||||
{
|
||||
bookmarkedNodes.push_back(StorageBookmarkedNode(id, bookmarkId, serializedNodeName));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return bookmarkedNodes;
|
||||
}
|
||||
|
||||
template <>
|
||||
std::vector<StorageBookmarkedEdge> SqliteBookmarkStorage::doGetAll<StorageBookmarkedEdge>(const std::string& query) const
|
||||
{
|
||||
CppSQLite3Query q = executeQuery(
|
||||
"SELECT "
|
||||
"bookmarked_edge.id, bookmarked_element.bookmark_id, bookmarked_edge.serialized_source_node_name, bookmarked_edge.serialized_target_node_name, bookmarked_edge.edge_type, bookmarked_edge.source_node_active "
|
||||
"FROM bookmarked_edge "
|
||||
"INNER JOIN "
|
||||
"bookmarked_element ON bookmarked_edge.id = bookmarked_element.id " + query + ";"
|
||||
);
|
||||
|
||||
std::vector<StorageBookmarkedEdge> bookmarkedEdges;
|
||||
while (!q.eof())
|
||||
{
|
||||
const Id id = q.getIntField(0, 0);
|
||||
const Id bookmarkId = q.getIntField(1, 0);
|
||||
const std::string serializedSourceNodeName = q.getStringField(2, "");
|
||||
const std::string serializedTargetNodeName = q.getStringField(3, "");
|
||||
const int edgeType = q.getIntField(4, -1);
|
||||
const int sourceNodeActive = q.getIntField(5, -1);
|
||||
|
||||
if (id != 0 && bookmarkId != 0 && serializedSourceNodeName != "" && serializedTargetNodeName != "" && edgeType != -1 && sourceNodeActive != -1)
|
||||
{
|
||||
bookmarkedEdges.push_back(StorageBookmarkedEdge(id, bookmarkId, serializedSourceNodeName, serializedTargetNodeName, edgeType, sourceNodeActive));
|
||||
}
|
||||
|
||||
q.nextRow();
|
||||
}
|
||||
return bookmarkedEdges;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef SQLITE_BOOKMARK_STORAGE_H
|
||||
#define SQLITE_BOOKMARK_STORAGE_H
|
||||
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/SqliteStorage.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class SqliteBookmarkStorage
|
||||
: public SqliteStorage
|
||||
{
|
||||
public:
|
||||
SqliteBookmarkStorage(const FilePath& dbFilePath);
|
||||
virtual ~SqliteBookmarkStorage();
|
||||
|
||||
Id addBookmarkCategory(const std::string& name);
|
||||
Id addBookmark(const std::string& name, const std::string& comment, const std::string& timestamp, const Id categoryId);
|
||||
Id addBookmarkedNode(const Id bookmarkId, const std::string& nodeName);
|
||||
Id addBookmarkedEdge(const Id bookmarkId, const std::string& sourceNodeName, const std::string& targetNodeName, const int edgeType, const bool sourceNodeActive);
|
||||
|
||||
void removeBookmarkCategory(Id id);
|
||||
void removeBookmark(const Id id);
|
||||
|
||||
std::vector<StorageBookmark> getAllBookmarks() const;
|
||||
std::vector<StorageBookmarkedNode> getAllBookmarkedNodes() const;
|
||||
std::vector<StorageBookmarkedEdge> getAllBookmarkedEdges() const;
|
||||
|
||||
void updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const Id categoryId);
|
||||
|
||||
std::vector<StorageBookmarkCategory> getAllBookmarkCategories() const;
|
||||
StorageBookmarkCategory getBookmarkCategoryByName(const std::string& name) const;
|
||||
|
||||
private:
|
||||
static const size_t s_storageVersion;
|
||||
|
||||
virtual size_t getStaticStorageVersion() const;
|
||||
virtual std::vector<std::pair<int, SqliteDatabaseIndex>> getIndices() const;
|
||||
virtual void clearTables();
|
||||
virtual void setupTables();
|
||||
|
||||
//void updateBookmarkMetaData(const BookmarkMetaData& metaData);
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
std::vector<StorageBookmarkCategory> SqliteBookmarkStorage::doGetAll<StorageBookmarkCategory>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageBookmark> SqliteBookmarkStorage::doGetAll<StorageBookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageBookmarkedNode> SqliteBookmarkStorage::doGetAll<StorageBookmarkedNode>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageBookmarkedEdge> SqliteBookmarkStorage::doGetAll<StorageBookmarkedEdge>(const std::string& query) const;
|
||||
|
||||
#endif // SQLITE_BOOKMARK_STORAGE_H
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "data/SqliteDatabaseIndex.h"
|
||||
|
||||
SqliteDatabaseIndex::SqliteDatabaseIndex(const std::string& indexName, const std::string& indexTarget)
|
||||
: m_indexName(indexName)
|
||||
, m_indexTarget(indexTarget)
|
||||
{
|
||||
}
|
||||
|
||||
SqliteDatabaseIndex::~SqliteDatabaseIndex()
|
||||
{
|
||||
}
|
||||
|
||||
void SqliteDatabaseIndex::createOnDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"CREATE INDEX IF NOT EXISTS " + m_indexName + " ON " + m_indexTarget + ";"
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteDatabaseIndex::removeFromDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"DROP INDEX IF EXISTS main." + m_indexName + ";"
|
||||
).c_str());
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef SQLITE_DATABASE_INDEX_H
|
||||
#define SQLITE_DATABASE_INDEX_H
|
||||
|
||||
#include <string>
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
class SqliteDatabaseIndex
|
||||
{
|
||||
public:
|
||||
SqliteDatabaseIndex(const std::string& indexName, const std::string& indexTarget);
|
||||
~SqliteDatabaseIndex();
|
||||
|
||||
void createOnDatabase(CppSQLite3DB& database);
|
||||
void removeFromDatabase(CppSQLite3DB& database);
|
||||
|
||||
private:
|
||||
std::string m_indexName;
|
||||
std::string m_indexTarget;
|
||||
};
|
||||
|
||||
#endif // SQLITE_DATABASE_INDEX_H
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "data/SqliteIndex.h"
|
||||
|
||||
SqliteIndex::SqliteIndex(const std::string& indexName, const std::string& indexTarget)
|
||||
: m_indexName(indexName)
|
||||
, m_indexTarget(indexTarget)
|
||||
{
|
||||
}
|
||||
|
||||
SqliteIndex::~SqliteIndex()
|
||||
{
|
||||
}
|
||||
|
||||
void SqliteIndex::createOnDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"CREATE INDEX IF NOT EXISTS " + m_indexName + " ON " + m_indexTarget + ";"
|
||||
).c_str());
|
||||
}
|
||||
|
||||
void SqliteIndex::removeFromDatabase(CppSQLite3DB& database)
|
||||
{
|
||||
database.execDML((
|
||||
"DROP INDEX IF EXISTS main." + m_indexName + ";"
|
||||
).c_str());
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef SQLITE_INDEX_H
|
||||
#define SQLITE_INDEX_H
|
||||
|
||||
#include <string>
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
class SqliteIndex
|
||||
{
|
||||
public:
|
||||
SqliteIndex(const std::string& indexName, const std::string& indexTarget);
|
||||
~SqliteIndex();
|
||||
|
||||
void createOnDatabase(CppSQLite3DB& database);
|
||||
void removeFromDatabase(CppSQLite3DB& database);
|
||||
|
||||
private:
|
||||
std::string m_indexName;
|
||||
std::string m_indexTarget;
|
||||
};
|
||||
|
||||
#endif // SQLITE_INDEX_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
||||
#ifndef SQLITE_INDEX_STORAGE_H
|
||||
#define SQLITE_INDEX_STORAGE_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "data/SqliteDatabaseIndex.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/SqliteStorage.h"
|
||||
|
||||
class TextAccess;
|
||||
class Version;
|
||||
struct ParseLocation;
|
||||
|
||||
class SqliteIndexStorage
|
||||
: public SqliteStorage
|
||||
{
|
||||
public:
|
||||
SqliteIndexStorage(const FilePath& dbFilePath);
|
||||
virtual ~SqliteIndexStorage();
|
||||
|
||||
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;
|
||||
|
||||
bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
StorageNode getNodeById(Id id) const;
|
||||
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
|
||||
bool checkNodeExistsByName(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);
|
||||
|
||||
StorageSourceLocation getSourceLocationByAll(const Id fileNodeId, const uint startLine, const uint startCol, const uint endLine, const uint endCol, const int type) const;
|
||||
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 size_t getStaticStorageVersion() const;
|
||||
virtual std::vector<std::pair<int, SqliteDatabaseIndex>> getIndices() const;
|
||||
virtual void clearTables();
|
||||
virtual void setupTables();
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
+32
-1783
File diff suppressed because it is too large
Load Diff
+15
-191
@@ -1,27 +1,11 @@
|
||||
#ifndef SQLITE_STORAGE_H
|
||||
#define SQLITE_STORAGE_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "data/SqliteIndex.h"
|
||||
#include "data/SqliteDatabaseIndex.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
class TextAccess;
|
||||
class Version;
|
||||
struct ParseLocation;
|
||||
#include "utility/Version.h"
|
||||
|
||||
class SqliteStorage
|
||||
{
|
||||
@@ -35,7 +19,7 @@ public:
|
||||
};
|
||||
|
||||
SqliteStorage(const FilePath& dbFilePath);
|
||||
~SqliteStorage();
|
||||
virtual ~SqliteStorage();
|
||||
|
||||
void setup();
|
||||
void clear();
|
||||
@@ -52,140 +36,16 @@ public:
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isIncompatible() const;
|
||||
std::string getProjectSettingsText() const;
|
||||
void setProjectSettingsText(std::string text);
|
||||
|
||||
void setVersion();
|
||||
|
||||
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);
|
||||
Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
Id addBookmarkCategory(const std::string& name);
|
||||
|
||||
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;
|
||||
|
||||
bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
StorageNode getNodeById(Id id) const;
|
||||
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
|
||||
bool checkNodeExistsByName(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);
|
||||
|
||||
StorageSourceLocation getSourceLocationByAll(const Id fileNodeId, const uint startLine, const uint startCol, const uint endLine, const uint endCol, const int type) const;
|
||||
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>("");
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
bool checkNodeBookmarkExistsByNames(const std::vector<std::string>& names) const;
|
||||
void removeNodeBookmark(Id id);
|
||||
void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
|
||||
std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
bool checkEdgeBookmarkExistsByNames(const std::vector<std::string>& names) const;
|
||||
void removeEdgeBookmark(Id id);
|
||||
void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
BookmarkCategory getBookmarkCategoryByName(const std::string& name) const;
|
||||
BookmarkCategory getOrCreateBookmarkCategoryByName(const std::string& name);
|
||||
bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
void removeBookmarkCategory(Id id);
|
||||
|
||||
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 STORAGE_VERSION;
|
||||
|
||||
void clearTables();
|
||||
void setupTables();
|
||||
protected:
|
||||
void setupMetaTable();
|
||||
void clearMetaTable();
|
||||
|
||||
void executeStatement(const std::string& statement) const;
|
||||
void executeStatement(CppSQLite3Statement& statement) const;
|
||||
int executeScalar(const std::string& statement) const;
|
||||
int executeStatementScalar(const std::string& statement) const;
|
||||
CppSQLite3Query executeQuery(const std::string& statement) const;
|
||||
CppSQLite3Query executeQuery(CppSQLite3Statement& statement) const;
|
||||
|
||||
@@ -200,54 +60,18 @@ private:
|
||||
Version getApplicationVersion() const;
|
||||
void setApplicationVersion();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
mutable CppSQLite3DB m_database;
|
||||
FilePath m_dbFilePath;
|
||||
|
||||
StorageModeType m_mode;
|
||||
std::vector<std::pair<int, SqliteIndex>> m_indices;
|
||||
|
||||
private:
|
||||
virtual size_t getStaticStorageVersion() const = 0;
|
||||
virtual std::vector<std::pair<int, SqliteDatabaseIndex>> getIndices() const = 0;
|
||||
virtual void clearTables() = 0;
|
||||
virtual void setupTables() = 0;
|
||||
|
||||
std::vector<std::pair<int, SqliteDatabaseIndex>> m_indices;
|
||||
};
|
||||
|
||||
template <>
|
||||
std::vector<StorageEdge> SqliteStorage::doGetAll<StorageEdge>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageNode> SqliteStorage::doGetAll<StorageNode>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageSymbol> SqliteStorage::doGetAll<StorageSymbol>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageFile> SqliteStorage::doGetAll<StorageFile>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageLocalSymbol> SqliteStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageSourceLocation> SqliteStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<NodeBookmark> SqliteStorage::doGetAll<NodeBookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageOccurrence> SqliteStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageComponentAccess> SqliteStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageCommentLocation> SqliteStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<Bookmark> SqliteStorage::doGetAll<Bookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<EdgeBookmark> SqliteStorage::doGetAll<EdgeBookmark>(const std::string& query) const;
|
||||
template <>
|
||||
std::vector<BookmarkCategory> SqliteStorage::doGetAll<BookmarkCategory>(const std::string& query) const;
|
||||
|
||||
#endif // SQLITE_STORAGE_H
|
||||
|
||||
@@ -234,4 +234,116 @@ struct StorageError
|
||||
bool indexed;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct StorageBookmarkCategory
|
||||
{
|
||||
StorageBookmarkCategory()
|
||||
: id(0)
|
||||
, name("")
|
||||
{}
|
||||
|
||||
StorageBookmarkCategory(
|
||||
Id id,
|
||||
const std::string& name
|
||||
)
|
||||
: id(id)
|
||||
, name(name)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct StorageBookmark
|
||||
{
|
||||
StorageBookmark()
|
||||
: id(0)
|
||||
, name("")
|
||||
, comment("")
|
||||
, timestamp("")
|
||||
, categoryId(0)
|
||||
{}
|
||||
|
||||
StorageBookmark(
|
||||
Id id,
|
||||
const std::string& name,
|
||||
const std::string& comment,
|
||||
const std::string& timestamp,
|
||||
const Id categoryId
|
||||
)
|
||||
: id(id)
|
||||
, name(name)
|
||||
, comment(comment)
|
||||
, timestamp(timestamp)
|
||||
, categoryId(categoryId)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
std::string name;
|
||||
std::string comment;
|
||||
std::string timestamp;
|
||||
Id categoryId;
|
||||
};
|
||||
|
||||
struct StorageBookmarkedNode
|
||||
{
|
||||
StorageBookmarkedNode()
|
||||
: id(0)
|
||||
, bookmarkId(0)
|
||||
, serializedNodeName("")
|
||||
{}
|
||||
|
||||
StorageBookmarkedNode(
|
||||
Id id,
|
||||
Id bookmarkId,
|
||||
const std::string& serializedNodeName
|
||||
)
|
||||
: id(id)
|
||||
, bookmarkId(bookmarkId)
|
||||
, serializedNodeName(serializedNodeName)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
Id bookmarkId;
|
||||
std::string serializedNodeName;
|
||||
};
|
||||
|
||||
struct StorageBookmarkedEdge
|
||||
{
|
||||
StorageBookmarkedEdge()
|
||||
: id(0)
|
||||
, bookmarkId(0)
|
||||
, serializedSourceNodeName("")
|
||||
, serializedTargetNodeName("")
|
||||
, edgeType(0)
|
||||
, sourceNodeActive(false)
|
||||
{}
|
||||
|
||||
StorageBookmarkedEdge(
|
||||
Id id,
|
||||
Id bookmarkId,
|
||||
const std::string& serializedSourceNodeName,
|
||||
const std::string& serializedTargetNodeName,
|
||||
int edgeType,
|
||||
bool sourceNodeActive
|
||||
)
|
||||
: id(id)
|
||||
, bookmarkId(bookmarkId)
|
||||
, serializedSourceNodeName(serializedSourceNodeName)
|
||||
, serializedTargetNodeName(serializedTargetNodeName)
|
||||
, edgeType(edgeType)
|
||||
, sourceNodeActive(sourceNodeActive)
|
||||
{}
|
||||
|
||||
Id id;
|
||||
Id bookmarkId;
|
||||
std::string serializedSourceNodeName;
|
||||
std::string serializedTargetNodeName;
|
||||
int edgeType;
|
||||
bool sourceNodeActive;
|
||||
};
|
||||
|
||||
#endif // STORAGE_TYPES_H
|
||||
|
||||
@@ -25,7 +25,7 @@ void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
if (!m_filePaths.empty())
|
||||
{
|
||||
m_storage->setMode(SqliteStorage::STORAGE_MODE_CLEAR);
|
||||
m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_CLEAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ TaskFinishParsing::~TaskFinishParsing()
|
||||
|
||||
void TaskFinishParsing::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
m_storage->setMode(SqliteStorage::STORAGE_MODE_READ);
|
||||
m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_READ);
|
||||
}
|
||||
|
||||
Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
@@ -80,25 +80,19 @@ public:
|
||||
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark) = 0;
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark) = 0;
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category) = 0;
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark) = 0; // todo: remove these from storage access
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark) = 0; // todo: remove these from storage access
|
||||
virtual Id addBookmarkCategory(const std::string& categoryName) = 0; // todo: remove these from storage access
|
||||
|
||||
virtual void updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const std::string& categoryName) = 0; // todo: remove these from storage access
|
||||
|
||||
virtual void removeBookmark(const Id id) = 0; // todo: remove these from storage access
|
||||
virtual void removeBookmarkCategory(const Id id) = 0; // todo: remove these from storage access
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const = 0;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const = 0;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
|
||||
virtual void removeNodeBookmark(Id id) = 0;
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark) = 0;
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const = 0;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const = 0;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
|
||||
virtual void removeEdgeBookmark(Id id) = 0;
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark) = 0;
|
||||
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const = 0;
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const = 0;
|
||||
virtual void removeBookmarkCategory(Id id) = 0;
|
||||
|
||||
protected:
|
||||
ErrorFilter m_errorFilter;
|
||||
|
||||
@@ -349,16 +349,40 @@ Id StorageAccessProxy::addEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::addBookmarkCategory(const BookmarkCategory& category)
|
||||
Id StorageAccessProxy::addBookmarkCategory(const std::string& categoryName)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->addBookmarkCategory(category);
|
||||
return m_subject->addBookmarkCategory(categoryName);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const std::string& categoryName)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->updateBookmark(bookmarkId, name, comment, categoryName);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeBookmark(const Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeBookmark(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeBookmarkCategory(const Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeBookmarkCategory(id);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<NodeBookmark> StorageAccessProxy::getAllNodeBookmarks() const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -369,42 +393,6 @@ std::vector<NodeBookmark> StorageAccessProxy::getAllNodeBookmarks() const
|
||||
return std::vector<NodeBookmark>();
|
||||
}
|
||||
|
||||
NodeBookmark StorageAccessProxy::getNodeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNodeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
return NodeBookmark();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkNodeBookmarkExistsByTokens(tokenNames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeNodeBookmark(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeNodeBookmark(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::editNodeBookmark(const NodeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->editNodeBookmark(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<EdgeBookmark> StorageAccessProxy::getAllEdgeBookmarks() const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -415,42 +403,6 @@ std::vector<EdgeBookmark> StorageAccessProxy::getAllEdgeBookmarks() const
|
||||
return std::vector<EdgeBookmark>();
|
||||
}
|
||||
|
||||
EdgeBookmark StorageAccessProxy::getEdgeBookmarkById(const Id bookmarkId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getEdgeBookmarkById(bookmarkId);
|
||||
}
|
||||
|
||||
return EdgeBookmark();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkEdgeBookmarkExistsByTokens(tokenNames);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeEdgeBookmark(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeEdgeBookmark(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::editEdgeBookmark(const EdgeBookmark& bookmark)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->editEdgeBookmark(bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BookmarkCategory> StorageAccessProxy::getAllBookmarkCategories() const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -461,24 +413,6 @@ std::vector<BookmarkCategory> StorageAccessProxy::getAllBookmarkCategories() con
|
||||
return std::vector<BookmarkCategory>();
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::checkBookmarkCategoryExists(const std::string& name) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->checkBookmarkCategoryExists(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::removeBookmarkCategory(Id id)
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
m_subject->removeBookmarkCategory(id);
|
||||
}
|
||||
}
|
||||
|
||||
void StorageAccessProxy::setErrorFilter(const ErrorFilter& filter)
|
||||
{
|
||||
StorageAccess::setErrorFilter(filter);
|
||||
|
||||
@@ -71,23 +71,17 @@ public:
|
||||
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
virtual Id addBookmarkCategory(const BookmarkCategory& category);
|
||||
virtual Id addBookmarkCategory(const std::string& categoryName);
|
||||
|
||||
virtual void updateBookmark(const Id bookmarkId, const std::string& name, const std::string& comment, const std::string& categoryName);
|
||||
|
||||
virtual void removeBookmark(const Id id);
|
||||
virtual void removeBookmarkCategory(const Id id);
|
||||
|
||||
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
|
||||
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeNodeBookmark(Id id);
|
||||
virtual void editNodeBookmark(const NodeBookmark& bookmark);
|
||||
|
||||
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
|
||||
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
|
||||
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
|
||||
virtual void removeEdgeBookmark(Id id);
|
||||
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
|
||||
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
|
||||
virtual void removeBookmarkCategory(Id id);
|
||||
|
||||
protected:
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
@@ -1,28 +1,12 @@
|
||||
#include "Bookmark.h"
|
||||
|
||||
Bookmark::Bookmark()
|
||||
: m_id(-1)
|
||||
, m_tokenTypes()
|
||||
, m_tokenIds()
|
||||
, m_tokenNames()
|
||||
, m_comment("")
|
||||
, m_displayName("")
|
||||
, m_valid(false)
|
||||
, m_timeStamp()
|
||||
, m_category()
|
||||
{
|
||||
}
|
||||
|
||||
Bookmark::Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: m_id(-1)
|
||||
, m_tokenTypes()
|
||||
, m_tokenIds(tokens)
|
||||
, m_tokenNames(tokenNames)
|
||||
Bookmark::Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
|
||||
: m_id(id)
|
||||
, m_name(name)
|
||||
, m_comment(comment)
|
||||
, m_displayName(displayName)
|
||||
, m_valid(false)
|
||||
, m_timeStamp(timeStamp)
|
||||
, m_category()
|
||||
, m_category(category)
|
||||
, m_isValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,34 +24,14 @@ void Bookmark::setId(const Id id)
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
std::vector<int> Bookmark::getTokenTypes() const
|
||||
std::string Bookmark::getName() const
|
||||
{
|
||||
return m_tokenTypes;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenTypes(const std::vector<int>& types)
|
||||
void Bookmark::setName(const std::string& name)
|
||||
{
|
||||
m_tokenTypes = types;
|
||||
}
|
||||
|
||||
std::vector<Id> Bookmark::getTokenIds() const
|
||||
{
|
||||
return m_tokenIds;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenIds(const std::vector<Id>& ids)
|
||||
{
|
||||
m_tokenIds = ids;
|
||||
}
|
||||
|
||||
std::vector<std::string> Bookmark::getTokenNames() const
|
||||
{
|
||||
return m_tokenNames;
|
||||
}
|
||||
|
||||
void Bookmark::setTokenNames(const std::vector<std::string>& names)
|
||||
{
|
||||
m_tokenNames = names;
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
std::string Bookmark::getComment() const
|
||||
@@ -80,31 +44,16 @@ void Bookmark::setComment(const std::string& comment)
|
||||
m_comment = comment;
|
||||
}
|
||||
|
||||
std::string Bookmark::getDisplayName() const
|
||||
{
|
||||
return m_displayName;
|
||||
}
|
||||
|
||||
void Bookmark::setDisplayName(const std::string& name)
|
||||
{
|
||||
m_displayName = name;
|
||||
}
|
||||
|
||||
bool Bookmark::isValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
void Bookmark::setValid(const bool valid)
|
||||
{
|
||||
m_valid = valid;
|
||||
}
|
||||
|
||||
TimePoint Bookmark::getTimeStamp() const
|
||||
{
|
||||
return m_timeStamp;
|
||||
}
|
||||
|
||||
void Bookmark::setTimeStamp(const TimePoint& timeStamp)
|
||||
{
|
||||
m_timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
BookmarkCategory Bookmark::getCategory() const
|
||||
{
|
||||
return m_category;
|
||||
@@ -113,4 +62,15 @@ BookmarkCategory Bookmark::getCategory() const
|
||||
void Bookmark::setCategory(const BookmarkCategory& category)
|
||||
{
|
||||
m_category = category;
|
||||
}
|
||||
}
|
||||
|
||||
bool Bookmark::isValid() const
|
||||
{
|
||||
return m_isValid;
|
||||
}
|
||||
|
||||
void Bookmark::setIsValid(const bool isValid)
|
||||
{
|
||||
m_isValid = isValid;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,49 +12,34 @@
|
||||
class Bookmark
|
||||
{
|
||||
public:
|
||||
Bookmark();
|
||||
Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
Bookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
|
||||
virtual ~Bookmark();
|
||||
|
||||
Id getId() const;
|
||||
void setId(const Id id);
|
||||
|
||||
std::vector<int> getTokenTypes() const;
|
||||
void setTokenTypes(const std::vector<int>& types);
|
||||
|
||||
std::vector<Id> getTokenIds() const;
|
||||
void setTokenIds(const std::vector<Id>& ids);
|
||||
|
||||
std::vector<std::string> getTokenNames() const;
|
||||
void setTokenNames(const std::vector<std::string>& names);
|
||||
std::string getName() const;
|
||||
void setName(const std::string& name);
|
||||
|
||||
std::string getComment() const;
|
||||
void setComment(const std::string& comment);
|
||||
|
||||
std::string getDisplayName() const;
|
||||
void setDisplayName(const std::string& name);
|
||||
|
||||
bool isValid() const;
|
||||
void setValid(const bool valid);
|
||||
|
||||
TimePoint getTimeStamp() const;
|
||||
void setTimeStamp(const TimePoint& timeStamp);
|
||||
|
||||
BookmarkCategory getCategory() const;
|
||||
void setCategory(const BookmarkCategory& category);
|
||||
|
||||
bool isValid() const;
|
||||
void setIsValid(const bool isValid = true);
|
||||
|
||||
private:
|
||||
Id m_id;
|
||||
std::vector<int> m_tokenTypes;
|
||||
std::vector<Id> m_tokenIds;
|
||||
std::vector<std::string> m_tokenNames;
|
||||
std::string m_name;
|
||||
std::string m_comment;
|
||||
std::string m_displayName;
|
||||
|
||||
bool m_valid;
|
||||
|
||||
TimePoint m_timeStamp;
|
||||
|
||||
BookmarkCategory m_category;
|
||||
bool m_isValid;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_H
|
||||
#endif // BOOKMARK_H
|
||||
|
||||
@@ -6,6 +6,12 @@ BookmarkCategory::BookmarkCategory()
|
||||
{
|
||||
}
|
||||
|
||||
BookmarkCategory::BookmarkCategory(const Id id, const std::string& name)
|
||||
: m_id(id)
|
||||
, m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
BookmarkCategory::~BookmarkCategory()
|
||||
{
|
||||
}
|
||||
@@ -28,4 +34,4 @@ std::string BookmarkCategory::getName() const
|
||||
void BookmarkCategory::setName(const std::string& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ class BookmarkCategory
|
||||
{
|
||||
public:
|
||||
BookmarkCategory();
|
||||
BookmarkCategory(const Id id, const std::string& name);
|
||||
~BookmarkCategory();
|
||||
|
||||
Id getId() const;
|
||||
@@ -22,4 +23,4 @@ private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
#endif // BOOKMARK_CATEGORY_H
|
||||
#endif // BOOKMARK_CATEGORY_H
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
#include "EdgeBookmark.h"
|
||||
|
||||
EdgeBookmark::EdgeBookmark()
|
||||
: Bookmark()
|
||||
{
|
||||
}
|
||||
|
||||
EdgeBookmark::EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
|
||||
EdgeBookmark::EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
|
||||
: Bookmark(id, name, comment, timeStamp, category)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,42 +9,27 @@ EdgeBookmark::~EdgeBookmark()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<int> EdgeBookmark::getEdgeTokenTypes() const
|
||||
void EdgeBookmark::addEdgeId(const Id edgeId)
|
||||
{
|
||||
return m_edgeTokenTypes;
|
||||
m_edgeIds.push_back(edgeId);
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenTypes(const std::vector<int>& tokenTypes)
|
||||
void EdgeBookmark::setEdgeIds(const std::vector<Id>& edgesIds)
|
||||
{
|
||||
m_edgeTokenTypes = tokenTypes;
|
||||
m_edgeIds = edgesIds;
|
||||
}
|
||||
|
||||
std::vector<Id> EdgeBookmark::getEdgeTokenIds() const
|
||||
std::vector<Id> EdgeBookmark::getEdgeIds() const
|
||||
{
|
||||
return m_edgeTokenIds;
|
||||
return m_edgeIds;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenIds(const std::vector<Id>& tokenIds)
|
||||
void EdgeBookmark::setActiveNodeId(const Id activeNodeId)
|
||||
{
|
||||
m_edgeTokenIds = tokenIds;
|
||||
m_activeNodeId = activeNodeId;
|
||||
}
|
||||
|
||||
std::vector<std::string> EdgeBookmark::getEdgeTokenNames() const
|
||||
Id EdgeBookmark::getActiveNodeId() const
|
||||
{
|
||||
return m_edgeTokenNames;
|
||||
return m_activeNodeId;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setEdgeTokenNames(const std::vector<std::string>& tokenNames)
|
||||
{
|
||||
m_edgeTokenNames = tokenNames;
|
||||
}
|
||||
|
||||
NodeBookmark EdgeBookmark::getBaseBookmark() const
|
||||
{
|
||||
return m_baseBookmark;
|
||||
}
|
||||
|
||||
void EdgeBookmark::setBaseBookmark(const NodeBookmark& baseBookmark)
|
||||
{
|
||||
m_baseBookmark = baseBookmark;
|
||||
}
|
||||
@@ -2,34 +2,25 @@
|
||||
#define EDGE_BOOKMARK_H
|
||||
|
||||
#include "Bookmark.h"
|
||||
#include "NodeBookmark.h"
|
||||
#include "data/graph/Edge.h"
|
||||
|
||||
class EdgeBookmark
|
||||
: public Bookmark
|
||||
{
|
||||
public:
|
||||
EdgeBookmark();
|
||||
EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
EdgeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
|
||||
virtual ~EdgeBookmark();
|
||||
|
||||
std::vector<int> getEdgeTokenTypes() const;
|
||||
void setEdgeTokenTypes(const std::vector<int>& tokenTypes);
|
||||
void addEdgeId(const Id edgeId);
|
||||
void setEdgeIds(const std::vector<Id>& edgesIds);
|
||||
std::vector<Id> getEdgeIds() const;
|
||||
|
||||
std::vector<Id> getEdgeTokenIds() const;
|
||||
void setEdgeTokenIds(const std::vector<Id>& tokenIds);
|
||||
|
||||
std::vector<std::string> getEdgeTokenNames() const;
|
||||
void setEdgeTokenNames(const std::vector<std::string>& tokenNames);
|
||||
|
||||
NodeBookmark getBaseBookmark() const;
|
||||
void setBaseBookmark(const NodeBookmark& baseBookmark);
|
||||
void setActiveNodeId(const Id activeNodeId);
|
||||
Id getActiveNodeId() const;
|
||||
|
||||
private:
|
||||
std::vector<int> m_edgeTokenTypes;
|
||||
std::vector<Id> m_edgeTokenIds;
|
||||
std::vector<std::string> m_edgeTokenNames;
|
||||
|
||||
NodeBookmark m_baseBookmark;
|
||||
std::vector<Id> m_edgeIds;
|
||||
Id m_activeNodeId;
|
||||
};
|
||||
|
||||
#endif // EDGE_BOOKMARK_H
|
||||
#endif // EDGE_BOOKMARK_H
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
#include "NodeBookmark.h"
|
||||
|
||||
NodeBookmark::NodeBookmark()
|
||||
: Bookmark()
|
||||
{
|
||||
}
|
||||
|
||||
NodeBookmark::NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
|
||||
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
|
||||
NodeBookmark::NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category)
|
||||
: Bookmark(id, name, comment, timeStamp, category)
|
||||
{
|
||||
}
|
||||
|
||||
NodeBookmark::~NodeBookmark()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void NodeBookmark::addNodeId(const Id nodeId)
|
||||
{
|
||||
m_nodeIds.push_back(nodeId);
|
||||
}
|
||||
|
||||
void NodeBookmark::setNodeIds(const std::vector<Id>& nodeIds)
|
||||
{
|
||||
m_nodeIds = nodeIds;
|
||||
}
|
||||
|
||||
std::vector<Id> NodeBookmark::getNodeIds() const
|
||||
{
|
||||
return m_nodeIds;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,15 @@ class NodeBookmark
|
||||
: public Bookmark
|
||||
{
|
||||
public:
|
||||
NodeBookmark();
|
||||
NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
|
||||
NodeBookmark(const Id id, const std::string& name, const std::string& comment, const TimePoint& timeStamp, const BookmarkCategory& category);
|
||||
virtual ~NodeBookmark();
|
||||
|
||||
void addNodeId(const Id nodeId);
|
||||
void setNodeIds(const std::vector<Id>& nodeIds);
|
||||
std::vector<Id> getNodeIds() const;
|
||||
|
||||
private:
|
||||
std::vector<Id> m_nodeIds;
|
||||
};
|
||||
|
||||
#endif // NODE_BOOKMARK_H
|
||||
|
||||
@@ -36,7 +36,7 @@ void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
|
||||
if (sourceFileCount > 0)
|
||||
{
|
||||
m_storage->setMode(SqliteStorage::STORAGE_MODE_WRITE);
|
||||
m_storage->setMode(SqliteIndexStorage::STORAGE_MODE_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -193,10 +193,12 @@ void Project::load()
|
||||
}
|
||||
|
||||
const FilePath projectSettingsPath = m_settings->getFilePath();
|
||||
|
||||
const std::string dbExtension = (projectSettingsPath.extension() == ".coatiproject" ? "coatidb" : "srctrldb");
|
||||
const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension(dbExtension);
|
||||
const FilePath bookmarkPath = FilePath(projectSettingsPath).replaceExtension("srctrlbm");
|
||||
|
||||
m_storage = std::make_shared<PersistentStorage>(dbPath);
|
||||
m_storage = std::make_shared<PersistentStorage>(dbPath, bookmarkPath);
|
||||
|
||||
bool canLoad = false;
|
||||
|
||||
@@ -212,7 +214,6 @@ void Project::load()
|
||||
else if (m_storage->isEmpty())
|
||||
{
|
||||
m_state = PROJECT_STATE_EMPTY;
|
||||
m_storage->setup();
|
||||
}
|
||||
else if (m_storage->isIncompatible())
|
||||
{
|
||||
@@ -230,6 +231,8 @@ void Project::load()
|
||||
canLoad = true;
|
||||
}
|
||||
|
||||
m_storage->setup();
|
||||
|
||||
m_sourceGroups = SourceGroupFactory::getInstance()->createSourceGroups(m_settings->getAllSourceGroupSettings());
|
||||
if (!m_sourceGroups.empty())
|
||||
{
|
||||
|
||||
@@ -8,9 +8,8 @@ class MessageDeleteBookmark
|
||||
: public Message<MessageDeleteBookmark>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmark(const Id bookmarkId, const bool isEdge)
|
||||
MessageDeleteBookmark(const Id bookmarkId)
|
||||
: bookmarkId(bookmarkId)
|
||||
, isEdge(isEdge)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,7 +23,6 @@ public:
|
||||
}
|
||||
|
||||
const Id bookmarkId;
|
||||
const bool isEdge;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_H
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_H
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef MESSAGE_DELETE_BOOKMARK_CATEGORY_H
|
||||
#define MESSAGE_DELETE_BOOKMARK_CATEGORY_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageDeleteBookmarkCategory
|
||||
: public Message<MessageDeleteBookmarkCategory>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmarkCategory(const Id id)
|
||||
: categoryId(id)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageDeleteBookmarkCategory()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDeleteBookmarkCategory";
|
||||
}
|
||||
|
||||
const Id categoryId;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_CATEGORY_H
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
#define MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageDeleteBookmarkCategoryWithBookmarks
|
||||
: public Message<MessageDeleteBookmarkCategoryWithBookmarks>
|
||||
{
|
||||
public:
|
||||
MessageDeleteBookmarkCategoryWithBookmarks(const Id id)
|
||||
: categoryId(id)
|
||||
{
|
||||
}
|
||||
|
||||
~MessageDeleteBookmarkCategoryWithBookmarks()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageDeleteBookmarkCategoryWithBookmarks";
|
||||
}
|
||||
|
||||
const Id categoryId;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_DELETE_BOOKMARK_CATEGORY_WITH_BOOKMARKS_H
|
||||
@@ -92,27 +92,30 @@ QtBookmark::~QtBookmark()
|
||||
|
||||
void QtBookmark::setBookmark(const std::shared_ptr<Bookmark> bookmark)
|
||||
{
|
||||
m_bookmark = bookmark;
|
||||
|
||||
m_activateButton->setText(bookmark->getDisplayName().c_str());
|
||||
|
||||
if (m_bookmark->isValid() == false)
|
||||
if (bookmark)
|
||||
{
|
||||
m_activateButton->setEnabled(false);
|
||||
m_editButton->setEnabled(false);
|
||||
}
|
||||
m_bookmark = bookmark;
|
||||
|
||||
if (m_bookmark->getComment().length() > 0)
|
||||
{
|
||||
m_comment->setText(m_bookmark->getComment().c_str());
|
||||
m_toggleCommentButton->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_toggleCommentButton->hide();
|
||||
}
|
||||
m_activateButton->setText(m_bookmark->getName().c_str());
|
||||
|
||||
m_dateLabel->setText(getDateString().c_str());
|
||||
if (m_bookmark->isValid() == false)
|
||||
{
|
||||
m_activateButton->setEnabled(false);
|
||||
m_editButton->setEnabled(false);
|
||||
}
|
||||
|
||||
if (m_bookmark->getComment().length() > 0)
|
||||
{
|
||||
m_comment->setText(m_bookmark->getComment().c_str());
|
||||
m_toggleCommentButton->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_toggleCommentButton->hide();
|
||||
}
|
||||
|
||||
m_dateLabel->setText(getDateString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Id QtBookmark::getBookmarkId() const
|
||||
@@ -169,7 +172,7 @@ void QtBookmark::resizeEvent(QResizeEvent* event)
|
||||
return;
|
||||
}
|
||||
|
||||
m_activateButton->setText(m_bookmark->getDisplayName().c_str());
|
||||
m_activateButton->setText(m_bookmark->getName().c_str());
|
||||
QTimer::singleShot(10, this, SLOT(elideButtonText()));
|
||||
}
|
||||
|
||||
@@ -218,21 +221,21 @@ void QtBookmark::deleteClicked()
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes)
|
||||
{
|
||||
MessageDeleteBookmark(m_bookmark->getId(), (dynamic_cast<EdgeBookmark*>(m_bookmark.get()) != NULL)).dispatch();
|
||||
MessageDeleteBookmark(m_bookmark->getId()).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmark::elideButtonText()
|
||||
{
|
||||
m_activateButton->setText(m_activateButton->fontMetrics().elidedText(
|
||||
m_bookmark->getDisplayName().c_str(), Qt::ElideMiddle, m_activateButton->width() - 16));
|
||||
m_bookmark->getName().c_str(), Qt::ElideMiddle, m_activateButton->width() - 16));
|
||||
}
|
||||
|
||||
void QtBookmark::handleMessage(MessageEditBookmark* message)
|
||||
{
|
||||
if (m_bookmark->getId() == message->bookmarkId)
|
||||
{
|
||||
m_bookmark->setDisplayName(message->displayName);
|
||||
m_bookmark->setName(message->displayName);
|
||||
m_bookmark->setComment(message->comment);
|
||||
|
||||
m_activateButton->setText(message->displayName.c_str());
|
||||
|
||||
@@ -186,19 +186,21 @@ void QtBookmarkBar::doDisplayBookmarkCreator(const std::vector<std::string>& nam
|
||||
bookmarkCreator->setDisplayName(displayName);
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doDisplayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(NULL, true, bookmark->getId());
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
bookmarkCreator->setDisplayName(bookmark->getDisplayName());
|
||||
bookmarkCreator->setDisplayName(bookmark->getName());
|
||||
bookmarkCreator->setComment(bookmark->getComment());
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
|
||||
bookmarkCreator->setIsEdge((dynamic_cast<EdgeBookmark*>(bookmark.get()) != NULL));
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doDisplayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
@@ -211,6 +213,7 @@ void QtBookmarkBar::doDisplayBookmarks(const std::vector<std::shared_ptr<Bookmar
|
||||
|
||||
m_bookmarkBrowser->setBookmarks(bookmarks);
|
||||
m_bookmarkBrowser->show();
|
||||
m_bookmarkBrowser->raise();
|
||||
}
|
||||
|
||||
void QtBookmarkBar::doSetCreateButtonState(const BookmarkView::CreateButtonState& state)
|
||||
@@ -248,4 +251,4 @@ void QtBookmarkBar::doSetCreateButtonState(const BookmarkView::CreateButtonState
|
||||
void QtBookmarkBar::doEnableDisplayButton(bool enable)
|
||||
{
|
||||
m_showBookmarksButton->setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkCategory.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/utility/utilityQt.h"
|
||||
@@ -142,6 +142,6 @@ void QtBookmarkCategory::deleteClicked()
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes
|
||||
{
|
||||
MessageDeleteBookmarkCategoryWithBookmarks(m_id).dispatch();
|
||||
MessageDeleteBookmarkCategory(m_id).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,17 +126,17 @@ void QtBookmarkBrowser::setBookmarks(const std::vector<std::shared_ptr<Bookmark>
|
||||
{
|
||||
m_bookmarkTree->clear();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarks.size(); i++)
|
||||
for (std::shared_ptr<Bookmark> bookmark: bookmarks)
|
||||
{
|
||||
QtBookmark* bookmark = new QtBookmark();
|
||||
bookmark->setBookmark(bookmarks[i]);
|
||||
QtBookmark* qtBookmark = new QtBookmark();
|
||||
qtBookmark->setBookmark(bookmark);
|
||||
|
||||
QTreeWidgetItem* top = findOrCreateTreeCategory(bookmarks[i]->getCategory());
|
||||
QTreeWidgetItem* top = findOrCreateTreeCategory(bookmark->getCategory());
|
||||
QTreeWidgetItem* treeWidgetItem = new QTreeWidgetItem(top);
|
||||
m_bookmarkTree->setItemWidget(treeWidgetItem, 0, bookmark);
|
||||
m_bookmarkTree->setItemWidget(treeWidgetItem, 0, qtBookmark);
|
||||
top->addChild(treeWidgetItem);
|
||||
|
||||
bookmark->setTreeWidgetItem(top);
|
||||
qtBookmark->setTreeWidgetItem(top);
|
||||
|
||||
top->setExpanded(true);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ add_files(
|
||||
SettingsMigratorTestSuite.h
|
||||
SearchIndexTestSuite.h
|
||||
SourceLocationCollectionTestSuite.h
|
||||
SqliteStorageTestSuite.h
|
||||
SqliteBookmarkStorageTestSuite.h
|
||||
SqliteIndexStorageTestSuite.h
|
||||
StorageTestSuite.h
|
||||
TaskSchedulerTestSuite.h
|
||||
TextAccessTestSuite.h
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/SqliteBookmarkStorage.h"
|
||||
|
||||
class SqliteBookmarkStorageTestSuite: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_add_bookmarks()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
for (unsigned int i = 0; i < bookmarkCount; i++)
|
||||
{
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
}
|
||||
|
||||
result = storage.getAllBookmarks().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, bookmarkCount);
|
||||
}
|
||||
|
||||
void test_add_bookmarked_node()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
|
||||
for (unsigned int i = 0; i < bookmarkCount; i++)
|
||||
{
|
||||
storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
}
|
||||
|
||||
result = storage.getAllBookmarkedNodes().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, bookmarkCount);
|
||||
}
|
||||
|
||||
void test_remove_bookmark_also_removes_bookmarked_node()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
int bookmarkCount = 4;
|
||||
int result = -1;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
const Id bookmarkedNodeId = storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
|
||||
storage.removeBookmark(bookmarkId);
|
||||
|
||||
result = storage.getAllBookmarkedNodes().size();
|
||||
}
|
||||
|
||||
boost::filesystem::remove(databasePath);
|
||||
|
||||
TS_ASSERT_EQUALS(result, 0);
|
||||
}
|
||||
|
||||
void test_edit_nodeBookmark()
|
||||
{
|
||||
std::string databasePath = "data/SQLiteTestSuite/bookmarkTest.sqlite";
|
||||
|
||||
const std::string updatedName = "updated name";
|
||||
const std::string updatedComment = "updated comment";
|
||||
|
||||
StorageBookmark storageBookmark;
|
||||
{
|
||||
boost::filesystem::remove(databasePath);
|
||||
SqliteBookmarkStorage storage(databasePath);
|
||||
storage.setup();
|
||||
|
||||
const Id categoryId = storage.addBookmarkCategory("test category");
|
||||
const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimePoint::now().toString(), categoryId);
|
||||
const Id bookmarkedNodeId = storage.addBookmarkedNode(bookmarkId, "test name");
|
||||
|
||||
storage.updateBookmark(bookmarkId, updatedName, updatedComment, categoryId);
|
||||
|
||||
storageBookmark = storage.getAllBookmarks().front();
|
||||
}
|
||||
|
||||
TS_ASSERT_EQUALS(updatedName, storageBookmark.name);
|
||||
TS_ASSERT_EQUALS(updatedComment, storageBookmark.comment);
|
||||
}
|
||||
};
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
#include "sqlite/CppSQLite3.h"
|
||||
#include "data/SqliteStorage.h"
|
||||
#include "data/SqliteIndexStorage.h"
|
||||
|
||||
class SqliteStorageTestSuite: public CxxTest::TestSuite
|
||||
class SqliteIndexStorageTestSuite: public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_storage_adds_node_successfully()
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
|
||||
int nodeCount = -1;
|
||||
{
|
||||
SqliteStorage storage(databasePath);
|
||||
SqliteIndexStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
storage.addNode(0, "a");
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
|
||||
int nodeCount = -1;
|
||||
{
|
||||
SqliteStorage storage(databasePath);
|
||||
SqliteIndexStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int nodeId = storage.addNode(0, "a");
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
|
||||
int edgeCount = -1;
|
||||
{
|
||||
SqliteStorage storage(databasePath);
|
||||
SqliteIndexStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addNode(0, "a");
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
std::string databasePath = "data/SQLiteTestSuite/test.sqlite";
|
||||
int edgeCount = -1;
|
||||
{
|
||||
SqliteStorage storage(databasePath);
|
||||
SqliteIndexStorage storage(databasePath);
|
||||
storage.setup();
|
||||
storage.beginTransaction();
|
||||
int sourceNodeId = storage.addNode(0, "a");
|
||||
@@ -232,7 +232,7 @@ private:
|
||||
{
|
||||
public:
|
||||
TestStorage()
|
||||
: PersistentStorage("data/test.sqlite")
|
||||
: PersistentStorage("data/test.sqlite", "data/testBookmarks.sqlite")
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---------
|
||||
Debugging
|
||||
---------
|
||||
To debug unit tests remove the post-build event, set the execution directory for 'Coati_test' to '.../Coati/bin/test' and run 'Coati_test' as startup project
|
||||
|
||||
|
||||
Post build event (if you manage to delete it without saving it somewhere):
|
||||
|
||||
setlocal
|
||||
cd $(ProjectDir)../../bin/test/
|
||||
$(OutDir)$(TargetName)$(TargetExt)
|
||||
if %errorlevel% neq 0 goto :cmEnd
|
||||
:cmEnd
|
||||
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
|
||||
:cmErrorLevel
|
||||
exit /b %1
|
||||
:cmDone
|
||||
if %errorlevel% neq 0 goto :VCEnd
|
||||
Reference in New Issue
Block a user