@param string $ownedEntityFqn
@param string $srcOrTestSubFolder
@param string $projectRootNamespace

@return string
@throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
545608
public function getReciprocatedHasName(
        string $ownedEntityFqn,
        string $srcOrTestSubFolder,
        string $projectRootNamespace
    ): string {
        $parsedFqn = $this->parseFullyQualifiedName(
            $ownedEntityFqn,
            $srcOrTestSubFolder,
            $projectRootNamespace
        );

        $subDirectories = $parsedFqn[2];

        return $this->getSingularNamespacedName($ownedEntityFqn, $subDirectories);
    }
111758
private function makeEntityQuery(
      $options,
      $selectors,
      $etypeDirty,
      $subquery = false
  ) {
    $fullQueryCoverage = true;
    $sort = $options['sort'] ?? 'cdate';
    $etype = '_'.SQLite3::escapeString($etypeDirty);
    $queryParts = $this->iterateSelectorsForQuery($selectors, function ($value) use ($options, $etypeDirty, &$fullQueryCoverage) {
      $subquery = $this->makeEntityQuery(
          $options,
          [$value],
          $etypeDirty,
          true
      );
      $fullQueryCoverage = $fullQueryCoverage && $subquery['fullCoverage'];
      return $subquery['query'];
    }, function (&$curQuery, $key, $value, $typeIsOr, $typeIsNot) use ($etype, &$fullQueryCoverage) {
      $clauseNot = $key[0] === '!';
      // Any options having to do with data only return if the
      // entity has the specified variables.
      foreach ($value as $curValue) {
        switch ($key) {
          case 'guid':
          case '!guid':
            foreach ($curValue as $curGuid) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid"='.(int) $curGuid;
            }
            break;
          case 'tag':
          case '!tag':
            foreach ($curValue as $curTag) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."tags" LIKE \'%,'.
                  str_replace(
                      ['%', '_', ':'],
                      [':%', ':_', '::'],
                      SQLite3::escapeString($curTag)
                  ).',%\' ESCAPE \':\'';
            }
            break;
          case 'isset':
          case '!isset':
            foreach ($curValue as $curVar) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= 'ie."guid" '.
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'IN (SELECT "guid" FROM "'.
                  $this->prefix.'data'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curVar).
                  '\' AND "value"!=\'N;\')';
            }
            break;
          case 'ref':
          case '!ref':
            $guids = [];
            if (is_array($curValue[1])) {
              if (key_exists('guid', $curValue[1])) {
                $guids[] = (int) $curValue[1]['guid'];
              } else {
                foreach ($curValue[1] as $curEntity) {
                  if (is_object($curEntity)) {
                    $guids[] = (int) $curEntity->guid;
                  } elseif (is_array($curEntity)) {
                    $guids[] = (int) $curEntity['guid'];
                  } else {
                    $guids[] = (int) $curEntity;
                  }
                }
              }
            } elseif (is_object($curValue[1])) {
              $guids[] = (int) $curValue[1]->guid;
            } else {
              $guids[] = (int) $curValue[1];
            }
            foreach ($guids as $curQguid) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'references'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND "reference"='.
                  SQLite3::escapeString((int) $curQguid).')';
            }
            break;
          case 'strict':
          case '!strict':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              if (is_callable([$curValue[1], 'toReference'])) {
                $svalue = serialize($curValue[1]->toReference());
              } else {
                $svalue = serialize($curValue[1]);
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.$this->prefix.'data'.
                  $etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "value"=\''.
                  SQLite3::escapeString(
                      (
                        strpos($svalue, "\0") !== false
                        ? '~'.addcslashes($svalue, chr(0).'\\')
                        : $svalue
                      )
                  ).'\')';
            }
            break;
          case 'like':
          case '!like':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
            }
            break;
          case 'ilike':
          case '!ilike':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND lower("string") LIKE lower(\''.
                  SQLite3::escapeString($curValue[1]).
                  '\') ESCAPE \'\\\')';
            }
            break;
          case 'pmatch':
          case '!pmatch':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
            }
            break;
          case 'ipmatch':
          case '!ipmatch':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND lower("string") REGEXP lower(\''.
                  SQLite3::escapeString($curValue[1]).'\'))';
            }
            break;
          case 'match':
          case '!match':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', ie."cdate")';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', ie."mdate")';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.
                  '" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" IS NOT NULL AND '.
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', "string"))';
            }
            break;
          case 'gt':
          case '!gt':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate">'.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate">'.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" > '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" > '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'gte':
          case '!gte':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate">='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate">='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" >= '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" >= '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'lt':
          case '!lt':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"<'.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"<'.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" < '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" < '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'lte':
          case '!lte':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"<='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"<='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" <= '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" <= '.
                  ((float) $curValue[1]).')))';
            }
            break;
          // Cases after this point contains special values where
          // it can be solved by the query, but if those values
          // don't match, just check the variable exists.
          case 'equal':
          case '!equal':
          case 'data':
          case '!data':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[1] === true || $curValue[1] === false) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_true"='.
                  ($curValue[1] ? '1' : '0').')';
              break;
            } elseif ($curValue[1] === 1) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_one"=1)';
              break;
            } elseif ($curValue[1] === 0) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_zero"=1)';
              break;
            } elseif ($curValue[1] === -1) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_negone"=1)';
              break;
            } elseif ($curValue[1] === []) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_emptyarray"=1)';
              break;
            }
            // Fall through.
          case 'array':
          case '!array':
            if (!($typeIsNot xor $clauseNot)) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= 'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'data'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\')';
            }
            $fullQueryCoverage = false;
            break;
        }
      }
    });

    switch ($sort) {
      case 'guid':
        $sort = '"guid"';
        break;
      case 'mdate':
        $sort = '"mdate"';
        break;
      case 'cdate':
      default:
        $sort = '"cdate"';
        break;
    }
    if (isset($options['reverse']) && $options['reverse']) {
      $sort .= ' DESC';
    }

    if ($queryParts) {
      if ($subquery) {
        $query = "((".implode(') AND (', $queryParts)."))";
      } else {
        $limit = "";
        if ($fullQueryCoverage && key_exists('limit', $options)) {
          $limit = " LIMIT ".((int) $options['limit']);
        }
        $offset = "";
        if ($fullQueryCoverage && key_exists('offset', $options)) {
          $offset = " OFFSET ".((int) $options['offset']);
        }
        $query =
            "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
              "d.\"name\", d.\"value\" ".
            "FROM \"{$this->prefix}entities{$etype}\" e ".
            "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
            "INNER JOIN (".
              "SELECT \"guid\" ".
              "FROM \"{$this->prefix}entities{$etype}\" ie ".
              "WHERE (".
                implode(') AND (', $queryParts).
              ") ".
              "ORDER BY ie.{$sort}{$limit}{$offset}".
            ") f USING (\"guid\") ".
            "ORDER BY {$sort};";
      }
    } else {
      if ($subquery) {
        $query = '';
      } else {
        $limit = "";
        if (key_exists('limit', $options)) {
          $limit = " LIMIT ".((int) $options['limit']);
        }
        $offset = "";
        if (key_exists('offset', $options)) {
          $offset = " OFFSET ".((int) $options['offset']);
        }
        if ($limit || $offset) {
          $query =
              "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
                "d.\"name\", d.\"value\" ".
              "FROM \"{$this->prefix}entities{$etype}\" e ".
              "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
              "INNER JOIN (".
                "SELECT \"guid\" ".
                "FROM \"{$this->prefix}entities{$etype}\" ie ".
                "ORDER BY ie.{$sort}{$limit}{$offset}".
              ") f USING (\"guid\") ".
              "ORDER BY {$sort};";
        } else {
          $query =
              "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
                "d.\"name\", d.\"value\" ".
              "FROM \"{$this->prefix}entities{$etype}\" e ".
              "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
              "ORDER BY {$sort};";
        }
      }
    }

    return [
      'fullCoverage' => $fullQueryCoverage,
      'limitOffsetCoverage' => $fullQueryCoverage,
      'query' => $query
    ];
  }
1172673
public function generateEntity(
        string $entityFqn,
        bool $generateSpecificEntitySaver = false
    ): string {
        try {
            $this->action->setEntityFqn($entityFqn);
            $this->action->setGenerateSaver($generateSpecificEntitySaver);
            $this->action->run();

            return $this->action->getCreatedEntityFilePath();
        } catch (\Exception $e) {
            throw new DoctrineStaticMetaException(
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
                $e->getCode(),
                $e
            );
        }
    }
951279
@Override
  public final FctBcFctSimpleEntities
    lazyGetFctBcFctSimpleEntities() throws Exception {
    String beanName = this.factoryAppBeans.getFctBcFctSimpleEntitiesName();
    FctBcFctSimpleEntities fctBcFctSimpleEntities =
      (FctBcFctSimpleEntities) this.factoryAppBeans.getBeansMap().get(beanName);
    if (fctBcFctSimpleEntities == null) {
      fctBcFctSimpleEntities = new FctBcFctSimpleEntities();
      fctBcFctSimpleEntities
        .setSrvDatabase(this.factoryAppBeans.lazyGetSrvDatabase());
      this.factoryAppBeans.getBeansMap().put(beanName, fctBcFctSimpleEntities);
      this.factoryAppBeans.lazyGetLogger().info(null, AFactoryAppBeans.class,
        beanName + " has been created.");
    }
    return fctBcFctSimpleEntities;
  }
58113
public function getHasPluralInterfaceFqnForEntity(
        string $entityFqn
    ): string {
        $interfaceNamespace = $this->getInterfacesNamespaceForEntity($entityFqn);

        return $interfaceNamespace . '\\Has' . ucfirst($entityFqn::getDoctrineStaticMeta()->getPlural()) . 'Interface';
    }
1128755
public function getProjectNamespaceRootFromEntityFqn(string $entityFqn): string
    {
        return $this->tidy(
            \substr(
                $entityFqn,
                0,
                \strrpos(
                    $entityFqn,
                    '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME . '\\'
                )
            )
        );
    }
84816
public function generate(
        $vendor,
        $namespace,
        $entity,
        $skeletonsPath = null,
        $targetPath    = null,
        array $excludedSkeletons
    )
    {
        $skeletonsPath = $skeletonsPath ?: $this->skeletonsPath;
        $targetPath    = $targetPath ?: $this->targetPath;
        $finder        = new Finder();
        $inflector     = new Inflector(array(
            'MajoraVendor'    => $vendor,
            'MajoraNamespace' => $namespace,
            'MajoraEntity'    => $entity,
        ));
        $modifiersStack = array();

        // create file tree
        $finder->in($skeletonsPath);
        array_map(
            function($excludedSkeleton) use ($finder) {
                $finder->notPath($excludedSkeleton);
            },
            $excludedSkeletons
        );
        foreach ($finder as $templateFile) {

            $generatedFile = new SplFileInfo(
                $generatedFilePath = $this->generatePath(
                    $templateFile,
                    realpath($skeletonsPath),
                    realpath($targetPath),
                    $inflector
                ),
                '',
                ''
            );

            // directory ---------------------------------------------------------
            if ($templateFile->isDir()) {
                $this->generateDir($generatedFilePath);

                continue;
            }

            // file --------------------------------------------------------------
            $fileContent = $inflector->translate($templateFile->getContents());

            // always read template file metadata
            $metadata    = $this->getMetadata($fileContent);

            $forceGeneration = !empty($metadata['force_generation']);
            unset($metadata['force_generation']);

            $modifyContent = count($metadata);

            $alreadyGenerated = $this->filesystem->exists($generatedFilePath);

            // contents needs to be updated ?
            if ($alreadyGenerated && $modifyContent) {
                $fileContent = $generatedFile->getContents();
            }

            // stack content modifiers
            $modifiersStack[] = array(
                array($this, 'modify'),
                array($generatedFile, $templateFile, $metadata, $inflector)
            );

            // have to touch existing file ?
            if ($alreadyGenerated && !$forceGeneration) {
                continue;
            }

            $this->filesystem->dumpFile($generatedFilePath, $fileContent);

            $this->logger->info(sprintf('file %s: %s',
                $forceGeneration ? 'forced' : 'created',
                $generatedFilePath
            ));
        }

        // unstack all modifiers
        foreach ($modifiersStack as $modifierCallback) {
            call_user_func_array($modifierCallback[0], $modifierCallback[1]);
        }
    }
881455
private function prepEntity(TokenEntity $tokenEntity, ProfileEntity $profileEntity) {
        if(!$tokenEntity->issuer_url && $profileEntity->issuer_url) {
            $tokenEntity->issuer_url = $profileEntity->issuer_url;
            //$tokenEntity->issuer_url = EnvService::getUrl(API, 'v1/auth');
        }
        /*$userId = ArrayHelper::getValue($tokenEntity, 'subject.id');
        if($userId) {
            if(!$tokenEntity->subject_url) {
                $tokenEntity->subject_url = EnvService::getUrl(API, 'v1/user/' . $userId);
            }
        }*/
    }
463209
public function setFieldsToEntity(string $entityFqn, array $fieldFqns): self
    {
        foreach ($fieldFqns as $fieldFqn) {
            $this->fieldSetter->setEntityHasField($entityFqn, $fieldFqn);
        }

        return $this;
    }
1186994
@Override
   public void newEmbeddedRelationship(
            final Project project,
            final JavaResource resource,
            final String fieldName,
            final String fieldType) throws FileNotFoundException
   {
      JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
      JavaClassSource entityClass = getJavaClassFrom(resource);
      JavaClassSource fieldEntityClass;
      if (areTypesSame(fieldType, entityClass.getCanonicalName()))
      {
         fieldEntityClass = entityClass;
      }
      else
      {
         fieldEntityClass = findEntity(project, fieldType);
         entityClass.addImport(fieldEntityClass);
      }

      addFieldTo(entityClass, fieldEntityClass.getName(), fieldName,
               Embedded.class.getName());
      java.saveJavaSource(entityClass);
   }
408568
public function getInterfacesNamespaceForEntity(
        string $entityFqn
    ): string {
        $interfacesNamespace = $this->getProjectNamespaceRootFromEntityFqn($entityFqn)
                               . AbstractGenerator::ENTITY_RELATIONS_NAMESPACE
                               . '\\' . $this->getEntitySubNamespace($entityFqn)
                               . '\\Interfaces';

        return $this->tidy($interfacesNamespace);
    }
765729
public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
    {
        $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
        if ($existingWorkspace !== null) {
            $this->throwStatus(409, 'Workspace already exists', '');
        }

        if ($ownerAccountIdentifier !== null) {
            $owner = $this->userService->getUser($ownerAccountIdentifier);
            if ($owner === null) {
                $this->throwStatus(422, 'Requested owner account does not exist', '');
            }
        } else {
            $owner = null;
        }

        $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
        $this->workspaceRepository->add($workspace);
        $this->throwStatus(201, 'Workspace created', '');
    }
569375
public function getEntityNamespace()
    {
        $namespace = '';
        if (($bundleNamespace = $this->parseComment('bundleNamespace')) || ($bundleNamespace = $this->getConfig()->get(Formatter::CFG_BUNDLE_NAMESPACE))) {
            $namespace = $bundleNamespace.'\\';
        }
        if ($entityNamespace = $this->getConfig()->get(Formatter::CFG_ENTITY_NAMESPACE)) {
            $namespace .= $entityNamespace;
        } else {
            $namespace .= 'Entity';
        }

        return $namespace;
    }
105452
private void addRuntimeNameProperty() throws RepositoryException {
		
		String statement = 
				"/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + 
				"//*[@className='ro.nextreports.server.domain.Report']" + 
				"//*[fn:name()='parametersValues']";
		  
		QueryResult queryResult = getTemplate().query(statement);

		NodeIterator nodes = queryResult.getNodes();
		
		LOG.info("RuntimeHistory : Found " + nodes.getSize() + " parameterValues nodes");
		while (nodes.hasNext()) {			
			Node node = nodes.nextNode();
			NodeIterator childrenIt = node.getNodes();
			while (childrenIt.hasNext()) {
				Node child = childrenIt.nextNode();				
				child.setProperty("runtimeName", child.getName());
			}
		}	
		getTemplate().save();		
	}
232779
protected function getProjectRootPath(): string
    {
        try {
            return Config::getProjectRootDirectory();
        } catch (\Exception $e) {
            throw new DoctrineStaticMetaException(
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
                $e->getCode(),
                $e
            );
        }
    }
311413
@Override
    public JsonEntityBean getRootEntity(String groupType) {

        EntityEnum type = EntityEnum.getEntityEnum(groupType);

        String rootKey;
        if (EntityEnum.GROUP.equals(type)) {
            rootKey = "local.0";
        } else if (EntityEnum.CATEGORY.equals(type)) {
            IEntityGroup categoryGroup =
                    GroupService.getDistinguishedGroup(IPortletDefinition.DISTINGUISHED_GROUP);
            return new JsonEntityBean(categoryGroup, EntityEnum.CATEGORY);
        } else {
            throw new IllegalArgumentException(
                    "Unable to determine a root entity for group type '" + groupType + "'");
        }

        JsonEntityBean bean = getEntity(groupType, rootKey, false);

        return bean;
    }
1145472
public function buildWithSubQuery(VictoireQueryInterface $containerEntity, QueryBuilder $itemsQueryBuilder, EntityManager $em)
    {
        //get the query of the container entity
        $query = $containerEntity->getQuery();
        if (method_exists($containerEntity, 'additionnalQueryPart')) {
            $query = $containerEntity->additionnalQueryPart();
        }

        if ($query !== '' && $query !== null) {
            $subQuery = $em->createQueryBuilder()
                                ->select('item.id')
                                ->from($itemsQueryBuilder->getRootEntities()[0], 'item');

            $itemsQueryBuilder->andWhere(
                sprintf('main_item.id IN (%s %s)', $subQuery->getQuery()->getDql(), $query)
            );
        }

        //Add ORDER BY if set
        if ($orderBy = json_decode($containerEntity->getOrderBy(), true)) {
            foreach ($orderBy as $addOrderBy) {
                $reflectionClass = new \ReflectionClass($itemsQueryBuilder->getRootEntities()[0]);
                $reflectionProperty = $reflectionClass->getProperty($addOrderBy['by']);

                //If ordering field is an association, treat it as a boolean
                if ($this->isAssociationField($reflectionProperty)) {
                    $itemsQueryBuilder->addSelect('CASE WHEN main_item.'.$addOrderBy['by'].' IS NULL THEN 0 ELSE 1 END AS HIDDEN caseOrder');
                    $itemsQueryBuilder->addOrderBy('caseOrder', $addOrderBy['order']);
                } else {
                    $itemsQueryBuilder->addOrderBy('main_item.'.$addOrderBy['by'], $addOrderBy['order']);
                }
            }
        }

        $currentView = $this->currentView;

        // If the current page is a BEP, we parse all its properties and inject them as query parameters
        if ($currentView() && $currentView() instanceof BusinessPage && null !== $currentEntity = $currentView()->getBusinessEntity()) {

            // NEW
            $metadatas = $em->getClassMetadata(get_class($currentEntity));
            foreach ($metadatas->fieldMappings as $fieldName => $field) {
                if (strpos($query, ':'.$fieldName) !== false) {
                    $itemsQueryBuilder->setParameter($fieldName, $metadatas->getFieldValue($currentEntity, $fieldName));
                }
            }
            foreach ($metadatas->associationMappings as $fieldName => $field) {
                if (strpos($query, ':'.$fieldName) !== false) {
                    $itemsQueryBuilder->setParameter($fieldName, $metadatas->getFieldValue($currentEntity, $fieldName)->getId());
                }
            }

            if (strpos($query, ':currentEntity') !== false) {
                $itemsQueryBuilder->setParameter('currentEntity', $currentEntity->getId());
            }
        } elseif ($currentView() instanceof BusinessTemplate && strpos($query, ':currentEntity') !== false) {
            $itemsQueryBuilder->setParameter('currentEntity', $containerEntity->getEntity()->getId());
        }

        if (strpos($query, ':currentUser') !== false && is_object($this->getCurrentUser())) {
            $itemsQueryBuilder->setParameter('currentUser', $this->getCurrentUser()->getId());
        }

        return $itemsQueryBuilder;
    }