source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/jpa/JpaComponentDao.java @ 4098

Last change on this file since 4098 was 4098, checked in by George.Georgovassilis@mpi.nl, 10 years ago

#360, #431, #432: JPA and unified component entities

  • Property svn:mime-type set to text/plain
File size: 2.6 KB
Line 
1package clarin.cmdi.componentregistry.persistence.jpa;
2
3import java.util.List;
4
5import org.springframework.data.jpa.repository.JpaRepository;
6import org.springframework.data.jpa.repository.Modifying;
7import org.springframework.data.jpa.repository.Query;
8import org.springframework.transaction.annotation.Transactional;
9
10import clarin.cmdi.componentregistry.model.BaseDescription;
11import clarin.cmdi.componentregistry.persistence.ComponentDao;
12
13/**
14 * Basic jpa persistence functions. The more complicated rest is performed by {@link ComponentDao}
15 * @author george.georgovassilis@mpi.nl
16 *
17 */
18public interface JpaComponentDao extends JpaRepository<BaseDescription, Long>{
19
20    @Query("select c from BaseDescription c where c.componentId = ?1")
21    BaseDescription findByComponentId(String componentId);
22   
23    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = false order by upper(c.name), c.id")
24    List<BaseDescription> findPublicItems();
25
26    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = false and c.componentId like ?1 order by upper(c.name) asc")
27    List<BaseDescription> findPublicItems(String idPrefix);
28
29    @Query("select c from BaseDescription c where c.ispublic = false and c.deleted = true and c.dbUserId = ?1 order by upper(c.name), c.id")
30    List<BaseDescription> findDeletedItemsForUser(Long userId);
31
32    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = true order by upper(c.name), c.id")
33    List<BaseDescription> findPublicDeletedItems();
34   
35    @Query("select c from BaseDescription c where c.dbUserId = ?1 AND c.deleted = false AND c.ispublic = false AND c.componentId like ?2 AND not exists (select 1 from Ownership o where o.componentId = c.componentId) order by upper(c.name), c.id")
36    List<BaseDescription> findItemsForUserThatAreNotInGroups(Long userId, String idPrefix);
37
38    @Modifying
39    @Query(nativeQuery=true, value="update basedescription set content = ?2 where component_id like ?1")
40    void updateContent(String componentId, String content);
41   
42    @Query(nativeQuery=true, value="select content from basedescription where component_id like ?1 and is_deleted = ?2")
43    String findContentByComponentId(String componentId, boolean deleted);
44
45    @Query(nativeQuery=true, value="select content from basedescription where component_id like ?1")
46    String findContentByComponentId(String componentId);
47   
48    @Query("select c.componentId from BaseDescription c where c.deleted = false and c.componentId like ?1 order by c.id asc")
49    List<String> findNonDeletedItemIds(String componentIdPrefix);
50
51}
Note: See TracBrowser for help on using the repository browser.