4f5f65d59e4ad4455bff9021e2bb72ab9bfdb872
[ccsdk/apps.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.apps.ms.neng.persistence.repository;
22
23 import java.util.List;
24 import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
25 import org.springframework.data.jpa.repository.Query;
26 import org.springframework.data.repository.CrudRepository;
27 import org.springframework.data.repository.query.Param;
28
29 /**
30  * Repository for the GeneratedName entity.
31  */
32 public interface GeneratedNameRespository extends CrudRepository<GeneratedName, Integer> {
33     
34     /*
35      * Finds an entity by element type, name and the 'isReleased' flag.
36      */
37     public GeneratedName findByElementTypeAndNameAndIsReleased(String elementType, String name, String isReleased);
38
39     /*
40      * Finds entities for a given external system ID.
41      */
42     public List<GeneratedName> findByExternalId(String externalId);
43
44     /*
45      * Finds the maximum sequence number used for a given prefix and suffix.
46      */
47     @Query("select max(sequenceNumber) from GeneratedName where prefix=:prefix "
48                     + "and ((suffix is null and :suffix is null) or suffix=:suffix)")
49     public String findMaxByPrefixAndSuffix(@Param("prefix") String prefix, @Param("suffix") String suffix);
50
51     /*
52      * Finds the maximum sequence number used that is greater than the given sequence number,
53      * for a given prefix and suffix. 
54      */
55     @Query("select max(sequenceNumber) from GeneratedName g where g.sequenceNumber > :seqNum "
56                     + "and g.prefix=:prefix and ((:suffix is null and g.suffix is null) or g.suffix=:suffix) "
57                     + "and g.isReleased='Y'")
58     public Long findNextReleasedSeq(@Param("seqNum") Long seqNum, @Param("prefix") String prefix,
59                     @Param("suffix") String suffix);
60
61     /*
62      * Finds the entity for given type and name, that is NOT already released. 
63      */
64     @Query("select g from GeneratedName g where g.elementType=:elementType "
65                     + "and g.name=:name and (g.isReleased is null or g.isReleased ='N')")
66     public GeneratedName findUnReleased(@Param("elementType") String elementType, @Param("name") String name);
67 }