2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.so.db.catalog.data.repository;
23 import java.util.List;
25 import org.onap.so.db.catalog.beans.Service;
26 import org.onap.so.db.catalog.data.projections.InlineService;
27 import org.springframework.data.jpa.repository.JpaRepository;
28 import org.springframework.data.jpa.repository.Query;
29 import org.springframework.data.repository.query.Param;
30 import org.springframework.data.rest.core.annotation.RepositoryRestResource;
32 @RepositoryRestResource(collectionResourceRel = "service", path = "service", excerptProjection = InlineService.class)
33 public interface ServiceRepository extends JpaRepository<Service, String> {
34 List<Service> findByModelName(String modelName);
36 Service findOneByModelName(String modelName);
39 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
43 @Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
44 Service findFirstByModelNameOrderByModelVersionDesc(String modelName);
47 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
51 @Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
52 Service findByModelNameOrderByModelVersionDesc(String modelName);
54 Service findOneByModelNameAndModelVersion(String modelName, String modelVersion);
56 Service findByModelNameAndModelVersion(String modelName, String modelVersion);
58 Service findByServiceType(String serviceType);
61 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
65 @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
66 Service findFirstOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
69 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
73 @Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
74 Service findOneByModelUUIDOrderByModelVersionDesc(String modelUUID);
76 Service findByModelVersionAndModelInvariantUUID(@Param("MODEL_VERSION") String modelVersion,
77 @Param("MODEL_INVARIANT_UUID") String modelInvariantUUID);
80 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
84 @Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
85 Service findFirstByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID);
87 List<Service> findByModelUUID(String modelUUID);
89 Service findOneByModelUUID(String modelUUID);
92 * This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
93 * @param modelInvariantId
96 @Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC;", nativeQuery = true)
97 List<Service> findByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantId);