27#include <Ice/ObjectAdapter.h>
28#include <IceUtil/UUID.h>
32#include <ArmarXCore/interface/serialization/JSONSerialization.h>
58 memoryx::NameList result;
70 result.push_back((*it)->getNS());
86 const ::Ice::Current&
c)
93 const std::string newName = coll->getNS();
101 if (newName == (*it)->getNS())
111 ARMARX_INFO_S << coll->getNS() <<
" collection added to list";
115 ARMARX_INFO_S << coll->getNS() <<
" collection already in list";
128 const ::Ice::Current&
c)
138 const ::Ice::Current&
c)
161 DBStorableData dbEntity;
171 const EntityBasePtr& entity,
172 const Ice::Current&
c)
180 const EntityBasePtr& entity)
195 const Ice::Current&
c)
204 EntityIdList entityIds(entityList.size(),
"");
206 for (
size_t i = 0; i < entityList.size(); i++)
212 catch (
const memoryx::InvalidEntityException& e)
223 const EntityBasePtr& entity,
224 const Ice::Current&
c)
232 const EntityBasePtr& entity)
238 return oldEntity->getId();
256 DBStorableDataList dbEntities;
257 dbEntities.reserve(entityList.size());
259 for (
size_t i = 0; i < entityList.size(); i++)
263 dbEntities.push_back(
dbSerializer->serializeIceObject(entityList[i]));
271 const EntityBasePtr& update,
272 const ::Ice::Current&
c)
280 const EntityBasePtr& update)
282 update->setId(entityId);
283 DBStorableData dbEntity;
335 if (entityId.empty() || entityId.size() != 24)
351 ? (*it)->findByMongoId(entityId)
352 : (*it)->findOneByFieldValue(
"_id", entityId);
354 if (!dbEntity.JSON.empty())
369 const Ice::Current&
c)
const
382 CollectionInterfacePrx coll = *it;
389 const DBStorableData dbEntity = coll->findOneByFieldValue(
"name", entityName);
391 if (!dbEntity.JSON.empty())
402 const ::Ice::Current&
c)
const
412 if (entityId.empty())
415 return EntityBasePtr();
429 ? (*it)->findByMongoId(entityId)
430 : (*it)->findOneByFieldValue(
"_id", entityId);
432 if (!dbEntity.JSON.empty())
438 return EntityBasePtr();
443 const ::Ice::Current&
c)
const
461 const DBStorableData dbEntity = (*it)->findOneByFieldValue(
"name", name);
463 if (!dbEntity.JSON.empty())
469 return EntityBasePtr();
474 const ::std::string& attrValue,
475 const ::Ice::Current&
c)
const
477 EntityBaseList result;
478 const std::string fieldName =
"attrs." + attrName +
".value.value";
481 for (CollectionPrxList::const_iterator itColl =
readCollections.begin();
490 const DBStorableDataList dbEntities = (*itColl)->findByFieldValue(fieldName, attrValue);
492 for (DBStorableDataList::const_iterator itEntity = dbEntities.begin();
493 itEntity != dbEntities.end();
500 result.push_back(entity);
510 const NameList& attrValueList,
511 const ::Ice::Current&
c)
const
513 EntityBaseList result;
514 const std::string fieldName =
"attrs." + attrName +
".value.value";
517 for (CollectionPrxList::const_iterator itColl =
readCollections.begin();
526 const DBStorableDataList dbEntities =
527 (*itColl)->findByFieldValueList(fieldName, attrValueList);
529 for (DBStorableDataList::const_iterator itEntity = dbEntities.begin();
530 itEntity != dbEntities.end();
537 result.push_back(entity);
560 result += (*it)->count();
613 const EntityIdList collIds = (*it)->findAllIds();
614 result.insert(result.end(), collIds.begin(), collIds.end());
622 EntityBaseList result;
632 for (
const auto& dbEntity : col->findAll())
638 result.push_back(std::move(entity));
653 result.insert({entity->getId(), std::move(entity)});
663 EntityBasePtr entity;
667 entity = EntityBasePtr::dynamicCast(
dbSerializer->deserializeIceObject(dbEntity));
669 catch (
const armarx::JSONException& ex)
671 entity = EntityBasePtr();
679 const Ice::Current&
c)
const
689 EntityMemorySegmentInterfacePrx::uncheckedCast(
c.adapter->createProxy(
getIceId()));
691 std::string memName = mem->getMemoryName();
693 MemoryInterfacePrx::checkedCast(
c.adapter->getCommunicator()->stringToProxy(memName));
700 const Ice::Current&
c)
const
710 EntityMemorySegmentInterfacePrx::uncheckedCast(
c.adapter->createProxy(
getIceId()));
712 std::string memName = mem->getMemoryName();
714 MemoryInterfacePrx::checkedCast(
c.adapter->getCommunicator()->stringToProxy(memName));
721 const EntityAttributeBasePtr& attribute,
722 const Ice::Current&
c)
727 throw EntityNotFoundException();
729 entity->putAttribute(attribute);
730 DBStorableData dbEntity;
742 const EntityAttributeList& attributeMap,
743 const Ice::Current&
c)
748 throw EntityNotFoundException();
750 for (
auto attribute : attributeMap)
752 entity->putAttribute(attribute);
755 DBStorableData dbEntity;
775 EntityRefList result;
787 CollectionInterfacePrx prx = *it;
788 const DBStorableDataList
data = prx->findByQuery(query);
790 for (
const DBStorableData& e :
data)
796 auto proxy = EntityMemorySegmentInterfacePrx::uncheckedCast(
799 std::string memName = mem->getMemoryName();
800 auto memoryProxy = MemoryInterfacePrx::checkedCast(
801 c.adapter->getCommunicator()->stringToProxy(memName));
804 result.push_back(ref);
The EntityRef class is used to store references to Entities as values in other Entity instances.
void setSegmentName(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) override
void setParentMemory(const MemoryInterfacePtr &memory, const Ice::Current &) override
PersistentEntitySegment(CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds=true)
virtual EntityBasePtr getEntityByIdThreadUnsafe(const ::std::string &entityId) const
EntityRefList findRefsByQuery(const std::string &query, const Ice::Current &c) override
retrieves Entity Refs that match the query.
virtual EntityIdList getAllEntityIdsThreadUnsafe() const
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
clear removes all elements from the current memoryx::PersistentEntitySegment::writeCollection
~PersistentEntitySegment() override
MemoryInterfacePtr parentMemory
void addReadCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
virtual std::string upsertEntityByNameThreadUnsafe(const std::string &entityName, const EntityBasePtr &entity)
std::string addEntity(const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
addEntity add new entity and return the newly generated entity ID
virtual std::string addEntityThreadUnsafe(const EntityBasePtr &entity)
CollectionPrxList readCollections
virtual std::string upsertEntityThreadUnsafe(const std::string &entityId, const EntityBasePtr &entity)
bool hasEntityById(const std::string &entityId, const Ice::Current &=Ice::emptyCurrent) const override
void print(const ::Ice::Current &=Ice::emptyCurrent) const override
virtual EntityIdList upsertEntityListThreadUnsafe(const EntityBaseList &entityList)
std::string getSegmentName(const ::Ice::Current &=Ice::emptyCurrent) const override
MongoSerializerPtr dbSerializer
EntityBasePtr getEntityById(const ::std::string &entityId, const ::Ice::Current &=Ice::emptyCurrent) const override
void setEntityAttribute(const std::string &entityId, const EntityAttributeBasePtr &attribute, const Ice::Current &) override
std::string getObjectTypeId(const ::Ice::Current &=Ice::emptyCurrent) const override
std::string upsertEntityByName(const std::string &entityName, const EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
NameList getReadCollectionsNS(const ::Ice::Current &=Ice::emptyCurrent) const override
EntityIdList upsertEntityList(const EntityBaseList &entityList, const Ice::Current &=Ice::emptyCurrent) override
bool hasEntityByIdThreadUnsafe(const std::string &entityId) const
void removeAllEntities(const ::Ice::Current &c=Ice::emptyCurrent) override
removeAllEntities collects all entities managed by this memory segment and removes them from the segm...
void setSingleRWCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
EntityIdList getAllEntityIds(const ::Ice::Current &=Ice::emptyCurrent) const override
void clearReadCollections(const ::Ice::Current &=Ice::emptyCurrent) override
virtual EntityBasePtr getEntityByNameThreadUnsafe(const ::std::string &name) const
std::string upsertEntity(const std::string &entityId, const EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
virtual EntityIdList addEntityListThreadUnsafe(const EntityBaseList &entityList)
virtual void updateEntityThreadUnsafe(const ::std::string &entityId, const EntityBasePtr &update)
virtual void removeEntityThreadUnsafe(const ::std::string &entityId)
bool hasEntityByName(const std::string &entityName, const Ice::Current &=Ice::emptyCurrent) const override
EntityBaseList getEntitiesByAttrValue(const ::std::string &attrName, const ::std::string &attrValue, const ::Ice::Current &=Ice::emptyCurrent) const override
::Ice::Identity getIceId(const ::Ice::Current &=Ice::emptyCurrent) const override
std::string getWriteCollectionNS(const ::Ice::Current &=Ice::emptyCurrent) const override
EntityBasePtr deserializeEntity(const DBStorableData &dbEntity) const
EntityBaseList getAllEntities(const ::Ice::Current &=Ice::emptyCurrent) const override
getAllEntities returns a list of all entities managed by this memory segment
bool hasEntityByNameThreadUnsafe(const std::string &entityName) const
void removeEntity(const ::std::string &entityId, const ::Ice::Current &=Ice::emptyCurrent) override
removeEntity removes an entity with the ID entityId
void setWriteCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
EntityIdList addEntityList(const EntityBaseList &entityList, const Ice::Current &=Ice::emptyCurrent) override
addEntityList adds all entities contained in \entityList to this segment and returns a list of create...
EntityRefBasePtr getEntityRefByName(const std::string &name, const Ice::Current &c) const override
void setEntityAttributes(const std::string &entityId, const EntityAttributeList &attributeMap, const Ice::Current &) override
EntityBaseList getEntitiesByAttrValueList(const ::std::string &attrName, const NameList &attrValueList, const ::Ice::Current &=Ice::emptyCurrent) const override
IdEntityMap getIdEntityMap(const ::Ice::Current &=Ice::emptyCurrent) const override
std::recursive_mutex dbSerializerMutex
Ice::Int size(const ::Ice::Current &=Ice::emptyCurrent) const override
size counts the number of memoryx::Entity instances contained available reachable throuhg memoryx::Pe...
EntityRefBasePtr getEntityRefById(const std::string &id, const Ice::Current &) const override
CollectionInterfacePrx writeCollection
void updateEntity(const ::std::string &entityId, const EntityBasePtr &update, const ::Ice::Current &=Ice::emptyCurrent) override
EntityBasePtr getEntityByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
std::unique_ptr< ScopedSharedLock > ScopedSharedLockPtr
ScopedSharedLockPtr getReadLock(const Ice::Current &c) const
ScopedUniqueLockPtr getWriteLock(const Ice::Current &c) const
std::unique_ptr< ScopedSharedLock > ScopedUniqueLockPtr
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
IceInternal::Handle< EntityRef > EntityRefPtr
IceInternal::Handle< SegmentedMemory > SegmentedMemoryPtr