Projekt

Obecné

Profil

Stáhnout (1.46 KB) Statistiky
| Větev: | Tag: | Revize:
1
package cz.zcu.kiv.backendapi.catalog;
2

    
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.data.jpa.repository.Query;
5
import org.springframework.stereotype.Repository;
6

    
7
import java.util.List;
8
import java.util.Set;
9
import java.util.UUID;
10

    
11
/**
12
 * Catalog repository
13
 */
14
@Repository
15
public interface CatalogItemRepository extends JpaRepository<CatalogItem, UUID> {
16

    
17
    /**
18
     * Returns all catalog items containing specific values
19
     *
20
     * @param name    name - optional
21
     * @param country country - optional
22
     * @param type    type - optional
23
     * @return set of catalog items satisfying filter conditions
24
     */
25
    @Query("SELECT DISTINCT e FROM CatalogItem e " +
26
            "LEFT JOIN FETCH AlternativeName a ON e = a.catalogItem " +
27
            "LEFT JOIN FETCH Country c ON e = c.catalogItem " +
28
            "LEFT JOIN FETCH e.types t " +
29
            "WHERE (?1 = '' OR UPPER(e.name) LIKE UPPER(?1) OR UPPER(a.name) LIKE UPPER(?1)) " +
30
            "AND (?2 = '' OR UPPER(c.name) LIKE UPPER(?2)) " +
31
            "AND (?3 = '' OR UPPER(t.type) LIKE UPPER(?3))")
32
    Set<CatalogItem> filterCatalog(String name, String country, String type);
33

    
34
    /**
35
     * Selects catalog items with given name (alternative name)
36
     *
37
     * @param name name
38
     * @return list of catalog items with given name
39
     */
40
    @Query("SELECT DISTINCT a.catalogItem FROM AlternativeName a WHERE ?1 = a.name")
41
    List<CatalogItem> getItemsByName(String name);
42
}
(4-4/6)