/
TargetTagRepository.java
53 lines (47 loc) · 1.74 KB
/
TargetTagRepository.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.jpa.repository;
import java.util.Optional;
import jakarta.persistence.EntityManager;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
/**
* {@link TargetTag} repository.
*
*/
@Transactional(readOnly = true)
public interface TargetTagRepository extends BaseEntityRepository<JpaTargetTag> {
/**
* find {@link TargetTag} by its name.
*
* @param tagName
* to filter on
* @return the {@link TargetTag} if found, otherwise null
*/
Optional<TargetTag> findByNameEquals(String tagName);
/**
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
* reasons (this is a "delete everything" query after all) we add the tenant
* manually to query even if this will by done by {@link EntityManager}
* anyhow. The DB should take care of optimizing this away.
*
* @param tenant
* to delete data from
*/
@Modifying
@Transactional
@Query("DELETE FROM JpaTargetTag t WHERE t.tenant = :tenant")
void deleteByTenant(@Param("tenant") String tenant);
}