Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
'OCP\\AppFramework\\ORM\\Attribute\\JoinColumn' => $baseDir . '/lib/public/AppFramework/ORM/Attribute/JoinColumn.php',
'OCP\\AppFramework\\ORM\\Attribute\\ManyToOne' => $baseDir . '/lib/public/AppFramework/ORM/Attribute/ManyToOne.php',
'OCP\\AppFramework\\ORM\\Attribute\\OneToOne' => $baseDir . '/lib/public/AppFramework/ORM/Attribute/OneToOne.php',
'OCP\\AppFramework\\ORM\\IEntityDeleteStatementBuilder' => $baseDir . '/lib/public/AppFramework/ORM/IEntityDeleteStatementBuilder.php',
'OCP\\AppFramework\\ORM\\IEntityExpressionBuilder' => $baseDir . '/lib/public/AppFramework/ORM/IEntityExpressionBuilder.php',
'OCP\\AppFramework\\ORM\\IEntityQueryBuilder' => $baseDir . '/lib/public/AppFramework/ORM/IEntityQueryBuilder.php',
'OCP\\AppFramework\\ORM\\ISelectEntityQueryBuilder' => $baseDir . '/lib/public/AppFramework/ORM/ISelectEntityQueryBuilder.php',
'OCP\\AppFramework\\ORM\\Repository' => $baseDir . '/lib/public/AppFramework/ORM/Repository.php',
'OCP\\AppFramework\\PublicShareController' => $baseDir . '/lib/public/AppFramework/PublicShareController.php',
'OCP\\AppFramework\\QueryException' => $baseDir . '/lib/public/AppFramework/QueryException.php',
Expand Down Expand Up @@ -1286,8 +1290,11 @@
'OC\\AppFramework\\OCS\\BaseResponse' => $baseDir . '/lib/private/AppFramework/OCS/BaseResponse.php',
'OC\\AppFramework\\OCS\\V1Response' => $baseDir . '/lib/private/AppFramework/OCS/V1Response.php',
'OC\\AppFramework\\OCS\\V2Response' => $baseDir . '/lib/private/AppFramework/OCS/V2Response.php',
'OC\\AppFramework\\ORM\\EntityDeleteStatementBuilder' => $baseDir . '/lib/private/AppFramework/ORM/EntityDeleteStatementBuilder.php',
'OC\\AppFramework\\ORM\\EntityExpressionBuilder' => $baseDir . '/lib/private/AppFramework/ORM/EntityExpressionBuilder.php',
'OC\\AppFramework\\ORM\\EntityInfo' => $baseDir . '/lib/private/AppFramework/ORM/EntityInfo.php',
'OC\\AppFramework\\ORM\\EntityManager' => $baseDir . '/lib/private/AppFramework/ORM/EntityManager.php',
'OC\\AppFramework\\ORM\\EntityQueryBuilder' => $baseDir . '/lib/private/AppFramework/ORM/EntityQueryBuilder.php',
'OC\\AppFramework\\ORM\\PropertyAttributes' => $baseDir . '/lib/private/AppFramework/ORM/PropertyAttributes.php',
'OC\\AppFramework\\Routing\\RouteActionHandler' => $baseDir . '/lib/private/AppFramework/Routing/RouteActionHandler.php',
'OC\\AppFramework\\Routing\\RouteParser' => $baseDir . '/lib/private/AppFramework/Routing/RouteParser.php',
Expand Down
7 changes: 7 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\AppFramework\\ORM\\Attribute\\JoinColumn' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/Attribute/JoinColumn.php',
'OCP\\AppFramework\\ORM\\Attribute\\ManyToOne' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/Attribute/ManyToOne.php',
'OCP\\AppFramework\\ORM\\Attribute\\OneToOne' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/Attribute/OneToOne.php',
'OCP\\AppFramework\\ORM\\IEntityDeleteStatementBuilder' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/IEntityDeleteStatementBuilder.php',
'OCP\\AppFramework\\ORM\\IEntityExpressionBuilder' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/IEntityExpressionBuilder.php',
'OCP\\AppFramework\\ORM\\IEntityQueryBuilder' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/IEntityQueryBuilder.php',
'OCP\\AppFramework\\ORM\\ISelectEntityQueryBuilder' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/ISelectEntityQueryBuilder.php',
'OCP\\AppFramework\\ORM\\Repository' => __DIR__ . '/../../..' . '/lib/public/AppFramework/ORM/Repository.php',
'OCP\\AppFramework\\PublicShareController' => __DIR__ . '/../../..' . '/lib/public/AppFramework/PublicShareController.php',
'OCP\\AppFramework\\QueryException' => __DIR__ . '/../../..' . '/lib/public/AppFramework/QueryException.php',
Expand Down Expand Up @@ -1327,8 +1331,11 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\AppFramework\\OCS\\BaseResponse' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/BaseResponse.php',
'OC\\AppFramework\\OCS\\V1Response' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/V1Response.php',
'OC\\AppFramework\\OCS\\V2Response' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/V2Response.php',
'OC\\AppFramework\\ORM\\EntityDeleteStatementBuilder' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/EntityDeleteStatementBuilder.php',
'OC\\AppFramework\\ORM\\EntityExpressionBuilder' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/EntityExpressionBuilder.php',
'OC\\AppFramework\\ORM\\EntityInfo' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/EntityInfo.php',
'OC\\AppFramework\\ORM\\EntityManager' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/EntityManager.php',
'OC\\AppFramework\\ORM\\EntityQueryBuilder' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/EntityQueryBuilder.php',
'OC\\AppFramework\\ORM\\PropertyAttributes' => __DIR__ . '/../../..' . '/lib/private/AppFramework/ORM/PropertyAttributes.php',
'OC\\AppFramework\\Routing\\RouteActionHandler' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteActionHandler.php',
'OC\\AppFramework\\Routing\\RouteParser' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteParser.php',
Expand Down
61 changes: 61 additions & 0 deletions lib/private/AppFramework/ORM/EntityDeleteStatementBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

// SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OC\AppFramework\ORM;

use OCP\AppFramework\ORM\IEntityDeleteStatementBuilder;
use OCP\AppFramework\ORM\IEntityExpressionBuilder;
use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IQueryBuilder;

final readonly class EntityDeleteStatementBuilder implements IEntityDeleteStatementBuilder {
private EntityExpressionBuilder $expressionBuilder;

public function __construct(
private IQueryBuilder $qb,
EntityManager $entityManager,
EntityInfo $entityInfo,
) {
// Bulk deletes aren't run against a table alias (see Repository::deleteBy()), so
// columns are referenced unprefixed here, unlike the `e.` used for joined selects.
$this->expressionBuilder = new EntityExpressionBuilder($this->qb, $entityManager, $entityInfo, '');
}

#[\Override]
public function expr(): IEntityExpressionBuilder {
return $this->expressionBuilder;
}

#[\Override]
public function where(string|ICompositeExpression ...$predicates): static {
$this->qb->where(...$predicates);
return $this;
}

#[\Override]
public function andWhere(string|ICompositeExpression ...$predicates): static {
$this->qb->andWhere(...$predicates);
return $this;
}

#[\Override]
public function orWhere(string|ICompositeExpression ...$predicates): static {
$this->qb->orWhere(...$predicates);
return $this;
}

#[\Override]
public function setMaxResults(int $maxResults): static {
$this->qb->setMaxResults($maxResults);
return $this;
}

#[\Override]
public function executeStatement(): int {
return $this->qb->executeStatement();
}
}
120 changes: 120 additions & 0 deletions lib/private/AppFramework/ORM/EntityExpressionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

declare(strict_types=1);

// SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OC\AppFramework\ORM;

use OCP\AppFramework\ORM\IEntityExpressionBuilder;
use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;

final readonly class EntityExpressionBuilder implements IEntityExpressionBuilder {
private IExpressionBuilder $expr;

/**
* @param EntityInfo<object> $entityInfo
* @param string $columnPrefix Prepended to every resolved column, e.g. the `e.` table
* alias used for joined selects; pass '' for unaliased
* queries such as a bulk delete.
*/
public function __construct(
private IQueryBuilder $qb,
private EntityManager $entityManager,
private EntityInfo $entityInfo,
private string $columnPrefix = 'e.',
) {
$this->expr = $this->qb->expr();
}

#[\Override]
public function andX(string|ICompositeExpression ...$x): ICompositeExpression {
return $this->expr->andX(...$x);
}

#[\Override]
public function orX(string|ICompositeExpression ...$x): ICompositeExpression {
return $this->expr->orX(...$x);
}

#[\Override]
public function eq(string $property, mixed $value): string {
return $this->expr->eq($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function neq(string $property, mixed $value): string {
return $this->expr->neq($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function lt(string $property, mixed $value): string {
return $this->expr->lt($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function lte(string $property, mixed $value): string {
return $this->expr->lte($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function gt(string $property, mixed $value): string {
return $this->expr->gt($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function gte(string $property, mixed $value): string {
return $this->expr->gte($this->column($property), $this->parameter($property, $value));
}

#[\Override]
public function like(string $property, string $pattern): string {
return $this->expr->like($this->column($property), $this->parameter($property, $pattern));
}

#[\Override]
public function notLike(string $property, string $pattern): string {
return $this->expr->notLike($this->column($property), $this->parameter($property, $pattern));
}

#[\Override]
public function in(string $property, array $values): string {
return $this->expr->in($this->column($property), $this->parameter($property, $values, true));
}

#[\Override]
public function notIn(string $property, array $values): string {
return $this->expr->notIn($this->column($property), $this->parameter($property, $values, true));
}

#[\Override]
public function isNull(string $property): string {
return $this->expr->isNull($this->column($property));
}

#[\Override]
public function isNotNull(string $property): string {
return $this->expr->isNotNull($this->column($property));
}

private function column(string $property): string {
return $this->columnPrefix . $this->resolveColumn($property);
}

private function parameter(string $property, mixed $value, bool $isArray = false): string {
$column = $this->resolveColumn($property);
/** @psalm-suppress MixedAssignment $value is caller-supplied, unwrapped of any \BackedEnum case. */
$value = $this->entityManager->toParameterValue($value);
$type = $this->entityManager->getParameterType($this->entityInfo->mappingColumnToTypes[$column], $isArray);

return (string)$this->qb->createNamedParameter($value, $type);
}

private function resolveColumn(string $property): string {
return $this->entityInfo->mappingPropertyToColumn[$property]
?? throw new \InvalidArgumentException($this->entityInfo->entityClass . ' has no property named ' . $property);
}
}
Loading
Loading