View Javadoc
1   package net.sumaris.core.dao.technical.extraction;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 - 2019 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import net.sumaris.core.dao.cache.CacheNames;
26  import net.sumaris.core.vo.technical.extraction.ExtractionProductColumnVO;
27  import net.sumaris.core.vo.technical.extraction.ExtractionProductFilterVO;
28  import net.sumaris.core.vo.technical.extraction.ExtractionProductVO;
29  import net.sumaris.core.vo.technical.extraction.ProductFetchOptions;
30  import org.springframework.cache.annotation.CacheEvict;
31  import org.springframework.cache.annotation.CachePut;
32  import org.springframework.cache.annotation.Cacheable;
33  import org.springframework.cache.annotation.Caching;
34  
35  import java.util.List;
36  import java.util.Optional;
37  
38  /**
39   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>*
40   */
41  public interface ExtractionProductDao {
42  
43  
44      @Cacheable(cacheNames = CacheNames.PRODUCTS_BY_FILTER)
45      List<ExtractionProductVO> findByFilter(ExtractionProductFilterVO filter, ProductFetchOptions fetchOptions);
46  
47      default List<ExtractionProductVO> findByFilter() {
48          return findByFilter(null, null);
49      }
50  
51      @Cacheable(cacheNames = CacheNames.PRODUCT_BY_LABEL, key = "#label")
52      ExtractionProductVO getByLabel(String label, ProductFetchOptions fetchOptions);
53  
54      default ExtractionProductVO getByLabel(String label) {
55          return getByLabel(label, null);
56      }
57  
58      //@Cacheable(cacheNames = CacheNames.PRODUCT_BY_LABEL, key = "#label")
59      Optional<ExtractionProductVO> get(int id, ProductFetchOptions fetchOptions);
60  
61      default Optional<ExtractionProductVO> get(int id) {
62          return get(id, null);
63      }
64  
65      List<ExtractionProductColumnVO> getColumnsByIdAndTableLabel(int id, String tableLabel);
66  
67      @Caching(
68          evict = {
69              @CacheEvict(cacheNames = CacheNames.PRODUCT_BY_LABEL, key = "#source.label", condition = "#source != null && #source.id != null"),
70              @CacheEvict(cacheNames = CacheNames.PRODUCTS, allEntries = true),
71              @CacheEvict(cacheNames = CacheNames.PRODUCTS_BY_FILTER, allEntries = true),
72          },
73          put = {
74              @CachePut(cacheNames= CacheNames.PRODUCT_BY_LABEL, key="#source.label", condition = "#source != null && #source.label != null")
75          }
76      )
77      ExtractionProductVO/../../../net/sumaris/core/vo/technical/extraction/ExtractionProductVO.html#ExtractionProductVO">ExtractionProductVO save(ExtractionProductVO source);
78  
79      @Caching(evict = {
80              @CacheEvict(cacheNames = CacheNames.PRODUCT_BY_LABEL, allEntries = true),
81              @CacheEvict(cacheNames = CacheNames.PRODUCTS, allEntries = true),
82              @CacheEvict(cacheNames = CacheNames.PRODUCTS_BY_FILTER, allEntries = true)
83      })
84      void delete(int id);
85  
86  }