package com.mousetech.gourmetj.persistence.dao; import java.util.List; import javax.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; 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 * * @author timh * @since Dec 28, 2021 */ @Repository public interface ShopcatRepository extends JpaRepository { 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 findDistinctCategoryNative(); @Transactional @Query(value = "UPDATE Shopcat set shopcategory = :newCatname WHERE shopcategory = :oldCatname") @Modifying public int UpdateShopcats(String oldCatname, String newCatname); public Shopcat findShopcatByIngkey(String ingkey); public void deleteByIngkey(String key); public List findAllByOrderByShopcategoryAsc(); @Query(value = "SELECT s.ingkey FROM Shopcat s WHERE s.shopcategory = :shopcat ORDER BY s.ingkey") public List findByIngkeySorted(String shopcat); @Transactional @Query(value = "UPDATE Shopcat set shopcategory = :newCat WHERE ingkey IN :selectedIngkey") @Modifying public void updateShopcatFor(String newCat, List selectedIngkey); @Transactional @Query(value = "DELETE Shopcat WHERE ingkey IN :selectedIngkey") @Modifying public void deleteShopcatFor(List selectedIngkey); }