Skip to content

Commit efac54d

Browse files
committed
added mongodbstorage, refs #1
1 parent adcc2c1 commit efac54d

File tree

4 files changed

+544
-0
lines changed

4 files changed

+544
-0
lines changed

source/annotatorlib/include/AnnotatorLib/AnnotatorLibDatastructs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ enum class StorageType {
6868
*
6969
*/
7070
JSON,
71+
/**
72+
*
73+
*/
74+
MONGODB,
7175
};
7276

7377
/**
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright 2016-2017 Annotator Team
2+
#ifndef ANNOTATOR_ANNOTATORLIB_STORAGE_MONGODBSTORAGE_H
3+
#define ANNOTATOR_ANNOTATORLIB_STORAGE_MONGODBSTORAGE_H
4+
5+
/************************************************************
6+
MySQLStorage class header
7+
************************************************************/
8+
#include <AnnotatorLib/Storage/AbstractStorage.h>
9+
#include <AnnotatorLib/Storage/Pkg_Storage.h>
10+
#include <AnnotatorLib/annotatorlib_api.h>
11+
12+
#include <Poco/MongoDB/Connection.h>
13+
#include <Poco/MongoDB/Database.h>
14+
15+
namespace AnnotatorLib {
16+
namespace Storage {
17+
18+
/************************************************************/
19+
/**
20+
* @brief The MongoDBStorage class
21+
*/
22+
class ANNOTATORLIB_API MongoDBStorage : public AbstractStorage {
23+
public:
24+
virtual ~MongoDBStorage();
25+
26+
virtual bool open() override;
27+
28+
bool isOpen() override;
29+
30+
bool flush() override;
31+
32+
bool isSaved() override;
33+
34+
virtual bool close() override;
35+
36+
/**
37+
* @brief setPath
38+
* @param path
39+
* Path should be like:
40+
* "host=localhost;user=annotator;password=annotator;db=annotator";
41+
*/
42+
void setPath(std::string path) override;
43+
44+
StorageType getType() override;
45+
46+
/**
47+
* @brief addAnnotation
48+
* @param annotation
49+
* @param add_associated_objects
50+
* @return
51+
*/
52+
virtual bool addAnnotation(shared_ptr<Annotation> annotation,
53+
bool add_associated_objects = true) override;
54+
/**
55+
* @brief removeAnnotation
56+
* @param id
57+
* @param unregister
58+
* @return
59+
*/
60+
virtual shared_ptr<Annotation> removeAnnotation(
61+
unsigned long id, bool unregister = true) override;
62+
63+
/**
64+
* @brief updateAnnotation
65+
* Informs session that internals of the Annotation have changed.
66+
* @param annotation
67+
*/
68+
virtual void updateAnnotation(shared_ptr<Annotation> annotation) override;
69+
70+
/**
71+
* @brief addClass
72+
* Add a class to the session and to database if open.
73+
* @param c
74+
* @return
75+
*/
76+
virtual bool addClass(shared_ptr<Class> c) override;
77+
/**
78+
* @brief removeClass
79+
* removes class from database if open
80+
* @param c
81+
* @return
82+
*/
83+
virtual shared_ptr<Class> removeClass(Class* c) override;
84+
85+
virtual void updateClass(shared_ptr<Class> theClass) override;
86+
87+
/**
88+
* @brief addObject
89+
* @param object
90+
* @param add_associated_objects
91+
* @return
92+
*/
93+
virtual bool addObject(shared_ptr<Object> object,
94+
bool add_associated_objects = true) override;
95+
/**
96+
* @brief removeObject
97+
* @param id
98+
* @param remove_annotations
99+
* @return
100+
*/
101+
virtual shared_ptr<Object> removeObject(
102+
unsigned long id, bool remove_annotations = true) override;
103+
104+
virtual void updateObject(shared_ptr<Object> object) override;
105+
106+
protected:
107+
std::string path;
108+
Poco::MongoDB::Connection* connection = nullptr;
109+
std::string dbname;
110+
111+
bool _open = false;
112+
bool _save = true;
113+
114+
Poco::MongoDB::Database getDatabase();
115+
116+
void insertOrUpdateAnnotationAttributes(shared_ptr<Annotation> annotation);
117+
void insertOrUpdateObjectAttributes(shared_ptr<Object> object);
118+
};
119+
/************************************************************/
120+
/* External declarations (package visibility) */
121+
/************************************************************/
122+
123+
/* Inline functions */
124+
125+
} // of namespace Storage
126+
} // of namespace AnnotatorLib
127+
128+
/************************************************************
129+
End of MongoDBStorage class header
130+
************************************************************/
131+
132+
#endif

source/annotatorlib/source/AnnotatorLibDatastructs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ std::string StorageTypeToString(StorageType type) {
4747
return "sqlite";
4848
case StorageType::JSON:
4949
return "json";
50+
case StorageType::MONGODB:
51+
return "mongodb";
5052
case StorageType::UNKNOWN:
5153
return "unknown";
5254
default:
@@ -60,6 +62,7 @@ StorageType StorageTypeFromString(std::string str) {
6062
if (str == "mysql") return StorageType::MYSQL;
6163
if (str == "sqlite") return StorageType::SQLITE;
6264
if (str == "json") return StorageType::JSON;
65+
if (str == "mongodb") return StorageType::MONGODB;
6366
return StorageType::UNKNOWN;
6467
}
6568

0 commit comments

Comments
 (0)