|
5 | 5 | import org.springframework.data.repository.query.Param;
|
6 | 6 | import org.springframework.stereotype.Repository;
|
7 | 7 | import org.springframework.transaction.annotation.Transactional;
|
| 8 | +import com.almielka.restapicrud.domain.Company; |
8 | 9 |
|
9 | 10 | import java.util.Set;
|
10 | 11 |
|
|
18 | 19 | @Repository
|
19 | 20 | public interface ProductRepository extends CommonRepository<Product> {
|
20 | 21 |
|
| 22 | + /** |
| 23 | + * Retrieve {@link Product}s from the data store by {@code name} of {@link Company}, returning all products |
| 24 | + * whose Company name <i>containing</i> with the given name. |
| 25 | + * |
| 26 | + * @param name Value to search for |
| 27 | + * @return a Collection of matching products (or an empty Collection if none found) |
| 28 | + */ |
| 29 | + @Query(value = "SELECT * " + |
| 30 | + "FROM product p " + |
| 31 | + "INNER JOIN company c " + |
| 32 | + "ON p.company_id = c.id " + |
| 33 | + "WHERE c.name LIKE %:name%", |
| 34 | + nativeQuery = true) |
| 35 | + @Transactional(readOnly = true) |
| 36 | + Set<Product> findByCompanyNameContaining(@Param("name") String name); |
| 37 | + |
| 38 | + /** |
| 39 | + * Retrieve {@link Product}s from the data store by {@code name} of {@link Company}, returning all products |
| 40 | + * whose Company type <i>equals</i> with the given type. |
| 41 | + * |
| 42 | + * @param type Value to search for |
| 43 | + * @return a Collection of matching products (or an empty Collection if none found) |
| 44 | + */ |
| 45 | + @Query(value = "SELECT * " + |
| 46 | + "FROM product p " + |
| 47 | + "INNER JOIN company c " + |
| 48 | + "ON p.company_id = c.id " + |
| 49 | + "WHERE c.company_type = :type", |
| 50 | + nativeQuery = true) |
| 51 | + @Transactional(readOnly = true) |
| 52 | + Set<Product> findByCompanyType(@Param("type") String type); |
| 53 | + |
21 | 54 | @Query(value = "SELECT p, " +
|
22 | 55 | "COUNT(*)" +
|
23 | 56 | "FROM Product p " +
|
|
0 commit comments