@@ -1478,37 +1478,53 @@ std::vector<const StatisticsSample*> Database::select(
14781478 std::shared_ptr<const eprosima::statistics_backend::database::Entity> source_entity;
14791479 std::shared_ptr<const eprosima::statistics_backend::database::Entity> target_entity;
14801480
1481- EntityKind last_iteration_kind_source = EntityKind::INVALID;
1482- EntityKind last_iteration_kind_target = EntityKind::INVALID;
1483-
14841481 for (auto kinds : StatisticsBackend::get_data_supported_entity_kinds (data_type))
14851482 {
14861483 try
14871484 {
1488- // In case the kind is the same as the last iteration and the entity was already found
1489- // do not look for it again
1490- if (!source_entity || last_iteration_kind_source != kinds.first )
1485+ // In case the entity already exists, it does not need to seach for it but to compare its kind.
1486+ // If the kind is the same as the one is needed, continue looking for the target.
1487+ // If it is not, this pair of kinds is not correct and continue to the other.
1488+ if (!source_entity)
14911489 {
14921490 source_entity = get_entity (entity_id_source, kinds.first );
14931491 }
1494- if (!target_entity || last_iteration_kind_target != kinds.second )
1492+ else
1493+ {
1494+ if (source_entity->kind != kinds.first )
1495+ {
1496+ continue ;
1497+ }
1498+ }
1499+
1500+ if (!target_entity)
14951501 {
14961502 target_entity = get_entity (entity_id_target, kinds.second );
14971503 }
1504+ else
1505+ {
1506+ if (target_entity->kind != kinds.second )
1507+ {
1508+ continue ;
1509+ }
1510+ }
14981511 }
14991512 catch (const std::exception& e)
15001513 {
1501- // It has not found the entity, check next kinds possibility
1514+ // It has not found the entity, check next possible kinds
15021515 continue ;
15031516 }
15041517
1505- // In case it has found it , follow with that entity
1518+ // In case both entities have been found , follow with them
15061519 break ;
15071520 }
15081521
1522+ // There is no way to set both to not null unless it is a pair with both types.
1523+ // Every time source entity is found in correct kind look for target, if found correct, if not target is null.
1524+ // Target does not look for an entity unless source has been found AND in the correct entity.
15091525 if (!source_entity || !target_entity)
15101526 {
1511- throw BadParameter (" Entity not found in required EntityKind for this DataKind" );
1527+ throw BadParameter (" Entity not found in required EntityKind for the given DataKind" );
15121528 }
15131529
15141530 std::shared_lock<std::shared_timed_mutex> lock (mutex_);
@@ -1702,17 +1718,17 @@ std::vector<const StatisticsSample*> Database::select(
17021718 }
17031719 catch (const std::exception& e)
17041720 {
1705- // It has not found the entity, check next kinds possibility
1721+ // It has not found the entity, check next possible kind
17061722 continue ;
17071723 }
17081724
1709- // In case it has found it , follow with that entity
1725+ // In case it has found the entity , follow with it
17101726 break ;
17111727 }
17121728
17131729 if (!entity)
17141730 {
1715- throw BadParameter (" Entity not found in required EntityKind for this DataKind" );
1731+ throw BadParameter (" Entity not found in required EntityKind for the given DataKind" );
17161732 }
17171733
17181734 std::shared_lock<std::shared_timed_mutex> lock (mutex_);
0 commit comments