2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.ccsdk.apps.ms.neng.persistence.repository;
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;
30 * Repository for the GeneratedName entity.
32 public interface GeneratedNameRespository extends CrudRepository<GeneratedName, Integer> {
35 * Finds an entity by element type, name and the 'isReleased' flag.
37 public GeneratedName findByElementTypeAndNameAndIsReleased(String elementType, String name, String isReleased);
40 * Finds entities for a given external system ID.
42 public List<GeneratedName> findByExternalId(String externalId);
45 * Finds entities for a given external system ID and element type, ignoring any special characters in names.
47 @Query(value = "select * from Generated_Name g where g.external_Id=:externalId and "
48 + "REPLACE(REPLACE(REPLACE(element_type,'NAME',''),'-',''),'_','')=:elementType",
50 public GeneratedName findByExternalIdAndRelaxedElementType(@Param("externalId")String externalId,
51 @Param("elementType")String elementType);
54 * Finds the maximum sequence number used for a given prefix and suffix.
56 @Query("select max(sequenceNumber) from GeneratedName where prefix=:prefix "
57 + "and ((suffix is null and :suffix is null) or suffix=:suffix)")
58 public String findMaxByPrefixAndSuffix(@Param("prefix") String prefix, @Param("suffix") String suffix);
61 * Finds the maximum sequence number used that is greater than the given sequence number,
62 * for a given prefix and suffix.
64 @Query("select max(sequenceNumber) from GeneratedName g where g.sequenceNumber > :seqNum "
65 + "and g.prefix=:prefix and ((:suffix is null and g.suffix is null) or g.suffix=:suffix) "
66 + "and g.isReleased='Y'")
67 public Long findNextReleasedSeq(@Param("seqNum") Long seqNum, @Param("prefix") String prefix,
68 @Param("suffix") String suffix);
71 * Finds the entity for given type and name, that is NOT already released.
73 @Query("select g from GeneratedName g where g.elementType=:elementType "
74 + "and g.name=:name and (g.isReleased is null or g.isReleased ='N')")
75 public GeneratedName findUnReleased(@Param("elementType") String elementType, @Param("name") String name);