Collection.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::CommonStorage
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "Collection.h"
24 
25 #include <IceUtil/UUID.h>
26 #include <mongo/client/dbclient.h>
27 
28 
29 namespace memoryx
30 {
31  // Collection implementation
32  Collection::Collection(const CommonStoragePtr& dbConn, const std::string& collNS) :
33  dbConn(dbConn)
34  {
35  ns = collNS;
36  iceId.name = IceUtil::generateUUID();
37  }
38 
40  {
41  return iceId;
42  }
43 
44  // inherited from Collection
45  Ice::Int Collection::count(const ::Ice::Current& c)
46  {
47  std::unique_lock lock(dbConnectionMutex);
48  return dbConn->count(ns);
49  }
50 
51  DBStorableData Collection::findByMongoId(const std::string& id, const ::Ice::Current& c)
52  {
53  std::unique_lock lock(dbConnectionMutex);
54  return dbConn->findByMongoId(ns, id);
55  }
56 
57  DBStorableDataList Collection::findByFieldValue(
58  const std::string& fieldName, const std::string& fieldValue,
59  const Ice::Current& c)
60  {
61  std::unique_lock lock(dbConnectionMutex);
62  return dbConn->findByFieldValue(ns, fieldName, fieldValue);
63  }
64 
66  const std::string& fieldName, const std::string& fieldValue,
67  const Ice::Current& c)
68  {
69  std::unique_lock lock(dbConnectionMutex);
70  return dbConn->findOneByFieldValue(ns, fieldName, fieldValue);
71  }
72 
74  const std::string& fieldName, const NameList& fieldValueList,
75  const Ice::Current& c)
76  {
77  std::unique_lock lock(dbConnectionMutex);
78  return dbConn->findByFieldValueList(ns, fieldName, fieldValueList);
79  }
80 
81 
82  DBStorableData Collection::findOneByQuery(const std::string& query,
83  const Ice::Current& c)
84  {
85  std::unique_lock lock(dbConnectionMutex);
86  return dbConn->findOneByQuery(ns, query);
87  }
88 
89  DBStorableDataList Collection::findByQuery(const std::string& query, const ::Ice::Current& c)
90  {
91  std::unique_lock lock(dbConnectionMutex);
92  return dbConn->findByQuery(ns, query);
93  }
94 
95  DBStorableDataList Collection::findByConstraintQuery(const std::string& query, const std::string& where, const Ice::Current&)
96  {
97  std::unique_lock lock(dbConnectionMutex);
98  return dbConn->findByQuery(ns, query, where);
99  }
100 
101  DBStorableDataList Collection::findAll(const Ice::Current& c)
102  {
103  std::unique_lock lock(dbConnectionMutex);
104  return dbConn->findAll(ns);
105  }
106 
107  DBStorableData Collection::findAllUniqueByFieldName(const std::string& fieldName, const ::Ice::Current&)
108  {
109  std::unique_lock lock(dbConnectionMutex);
110  return dbConn->findAllUniqueByFieldName(ns, fieldName);
111  }
112 
113  EntityIdList Collection::findAllIds(const Ice::Current& c)
114  {
115  std::unique_lock lock(dbConnectionMutex);
116  return dbConn->findAllIds(ns);
117  }
118 
119  NameList Collection::findAllFieldValues(const std::string& fieldName, const ::Ice::Current&)
120  {
121  std::unique_lock lock(dbConnectionMutex);
122  return dbConn->findAllFieldValues(ns, fieldName);
123  }
124 
125  std::string Collection::insert(const DBStorableData& obj, const ::Ice::Current& c)
126  {
127  std::unique_lock lock(dbConnectionMutex);
128  return dbConn->insert(ns, obj);
129  }
130 
131  std::vector<std::string> Collection::insertList(const DBStorableDataList& objectList, const Ice::Current&)
132  {
133  std::unique_lock lock(dbConnectionMutex);
134  return dbConn->insertList(ns, objectList);
135  }
136 
137  bool Collection::update(const DBStorableData& obj, const ::Ice::Current& c)
138  {
139  std::unique_lock lock(dbConnectionMutex);
140  return dbConn->update(ns, obj, "_id");
141  }
142 
143  bool Collection::updateWithUserKey(const DBStorableData& obj, const std::string& keyField, const ::Ice::Current& c)
144  {
145  std::unique_lock lock(dbConnectionMutex);
146  return dbConn->update(ns, obj, keyField);
147  }
148 
149  bool Collection::updateByQuery(const std::string& query, const DBStorableData& obj, const ::Ice::Current& c)
150  {
151  return dbConn->updateByQuery(ns, query, mongo::fromjson(obj.JSON));
152  }
153 
154  std::string Collection::save(const DBStorableData& obj,
155  const Ice::Current& c)
156  {
157  std::unique_lock lock(dbConnectionMutex);
158  return dbConn->insert(ns, obj, true);
159  }
160 
161  bool Collection::saveWithUserKey(const DBStorableData& obj,
162  const std::string& keyField, const Ice::Current& c)
163  {
164  std::unique_lock lock(dbConnectionMutex);
165  return dbConn->update(ns, obj, keyField, true);
166  }
167 
168  bool Collection::removeByMongoId(const std::string& id, const ::Ice::Current& c)
169  {
170  std::unique_lock lock(dbConnectionMutex);
171  return dbConn->removeByMongoId(ns, id);
172  }
173 
174  bool Collection::removeByFieldValue(const std::string& fieldName,
175  const std::string& fieldValue, const Ice::Current& c)
176  {
177  std::unique_lock lock(dbConnectionMutex);
178  return dbConn->removeByFieldValue(ns, fieldName, fieldValue);
179  }
180 
181  bool Collection::removeByQuery(const std::string& query, const ::Ice::Current& c)
182  {
183  std::unique_lock lock(dbConnectionMutex);
184  return dbConn->removeByQuery(ns, query);
185  }
186 
187  bool Collection::clear(const ::Ice::Current& c)
188  {
189  std::unique_lock lock(dbConnectionMutex);
190  return dbConn->clearCollection(ns);
191  }
192 
193  bool Collection::ensureIndex(const std::string& fieldName, bool unique, const ::Ice::Current& c)
194  {
195  std::unique_lock lock(dbConnectionMutex);
196  return dbConn->ensureIndex(ns, fieldName, unique);
197  }
198 
199  std::string Collection::getNS(const ::Ice::Current& c)
200  {
201  return ns;
202  }
203 }
memoryx::Collection::findByQuery
DBStorableDataList findByQuery(const std::string &query, const ::Ice::Current &c) override
Definition: Collection.cpp:89
memoryx::Collection::getNS
std::string getNS(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:199
memoryx::Collection::getIceId
Ice::Identity getIceId() const
Definition: Collection.cpp:39
memoryx::Collection::findByConstraintQuery
DBStorableDataList findByConstraintQuery(const std::string &query, const std::string &where, const Ice::Current &) override
Definition: Collection.cpp:95
memoryx::Collection::removeByMongoId
bool removeByMongoId(const std::string &id, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:168
memoryx::Collection::findAllFieldValues
NameList findAllFieldValues(const std::string &fieldName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:119
memoryx::Collection::removeByFieldValue
bool removeByFieldValue(const std::string &fieldName, const std::string &fieldValue, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:174
memoryx::Collection::update
bool update(const DBStorableData &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:137
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::Collection::findOneByFieldValue
DBStorableData findOneByFieldValue(const std::string &fieldName, const ::std::string &fieldValue, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:65
Collection.h
memoryx::Collection::insertList
std::vector< std::string > insertList(const DBStorableDataList &objectList, const Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:131
memoryx::Collection::saveWithUserKey
bool saveWithUserKey(const DBStorableData &obj, const std::string &keyField, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:161
memoryx::Collection::findAllIds
EntityIdList findAllIds(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:113
memoryx::Collection::findAll
DBStorableDataList findAll(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:101
memoryx::Collection::Collection
Collection(const CommonStoragePtr &dbConn, const std::string &collNS)
Definition: Collection.cpp:32
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
memoryx::Collection::ensureIndex
bool ensureIndex(const std::string &fieldName, bool unique, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:193
memoryx::Collection::removeByQuery
bool removeByQuery(const std::string &query, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:181
memoryx::Collection::updateWithUserKey
bool updateWithUserKey(const DBStorableData &obj, const std::string &keyField, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:143
memoryx::Collection::save
std::string save(const DBStorableData &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:154
memoryx::Collection::findByFieldValueList
DBStorableDataList findByFieldValueList(const std::string &fieldName, const NameList &fieldValueList, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:73
memoryx::Collection::insert
std::string insert(const DBStorableData &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:125
memoryx::Collection::findOneByQuery
DBStorableData findOneByQuery(const std::string &query, const ::Ice::Current &c) override
Definition: Collection.cpp:82
memoryx::Collection::count
Ice::Int count(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:45
memoryx::Collection::clear
bool clear(const ::Ice::Current &c) override
Definition: Collection.cpp:187
IceUtil::Handle< CommonStorage >
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::Collection::updateByQuery
bool updateByQuery(const std::string &query, const DBStorableData &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:149
memoryx::Collection::findByFieldValue
DBStorableDataList findByFieldValue(const std::string &fieldName, const ::std::string &fieldValue, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:57
memoryx::Collection::findByMongoId
DBStorableData findByMongoId(const std::string &id, const ::Ice::Current &c) override
Definition: Collection.cpp:51
memoryx::Collection::findAllUniqueByFieldName
DBStorableData findAllUniqueByFieldName(const std::string &fieldName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: Collection.cpp:107