gourmetj-springboot/src/main/java/com/mousetech/gourmetj/persistence/dao/ShopcatRepository.java

58 lines
1.8 KiB
Java
Raw Normal View History

2022-01-03 14:06:42 +00:00
package com.mousetech.gourmetj.persistence.dao;
import java.util.List;
2022-01-13 23:46:28 +00:00
import javax.transaction.Transactional;
2022-01-03 14:06:42 +00:00
import org.springframework.data.jpa.repository.JpaRepository;
2022-01-13 23:46:28 +00:00
import org.springframework.data.jpa.repository.Modifying;
2022-01-03 14:06:42 +00:00
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.mousetech.gourmetj.persistence.model.Shopcat;
/**
* JpaRepository for Shopping Categories, which relate ManyToOne
* to Ingredient. Service method is @see RecipeService
2022-01-03 14:06:42 +00:00
*
* @author timh
* @since Dec 28, 2021
*/
@Repository
public interface ShopcatRepository
extends JpaRepository<Shopcat, Long> {
final static String SQL_FIND_CATEGORIES =
"SELECT DISTINCT shopcategory from shopcats"
+ " where shopcategory is not null and shopcategory <> ''"
+ " ORDER BY shopcategory ASC";
@Query(value = SQL_FIND_CATEGORIES, nativeQuery = true)
public List<String> findDistinctCategoryNative();
2022-01-04 15:17:43 +00:00
2022-01-13 23:46:28 +00:00
@Transactional
@Query(value = "UPDATE Shopcat set shopcategory = :newCatname WHERE shopcategory = :oldCatname")
@Modifying
public int UpdateShopcats(String oldCatname,
String newCatname);
2022-01-04 15:17:43 +00:00
public Shopcat findShopcatByIngkey(String ingkey);
public void deleteByIngkey(String key);
2022-01-13 23:46:28 +00:00
public List<Shopcat> findAllByOrderByShopcategoryAsc();
@Query(value = "SELECT s.ingkey FROM Shopcat s WHERE s.shopcategory = :shopcat ORDER BY s.ingkey")
public List<String> findByIngkeySorted(String shopcat);
@Transactional
@Query(value = "UPDATE Shopcat set shopcategory = :newCat WHERE ingkey IN :selectedIngkey")
@Modifying
public void updateShopcatFor(String newCat, List<String> selectedIngkey);
@Transactional
@Query(value = "DELETE Shopcat WHERE ingkey IN :selectedIngkey")
@Modifying public void deleteShopcatFor(List<String> selectedIngkey);
2022-01-03 14:06:42 +00:00
}