31f395aa864c5b8cd08def86f1baec31005cfbaf
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceorder / repositories / ExecutionTaskRepository.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 package org.onap.nbi.apis.serviceorder.repositories;
17
18 import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
19 import org.springframework.data.jpa.repository.Modifying;
20 import org.springframework.data.jpa.repository.Query;
21 import org.springframework.data.repository.CrudRepository;
22 import org.springframework.data.repository.query.Param;
23 import org.springframework.transaction.annotation.Propagation;
24 import org.springframework.transaction.annotation.Transactional;
25 import java.util.List;
26
27 public interface ExecutionTaskRepository extends CrudRepository<ExecutionTask, Long> {
28
29     @Query("SELECT t FROM ExecutionTask t WHERE TRIM(t.reliedTasks) LIKE '' ")
30     List<ExecutionTask> findByReliedTasksIsEmpty();
31
32     @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
33     @Modifying
34     @Query("UPDATE ExecutionTask t SET t.reliedTasks = REPLACE(t.reliedTasks, :internalId, '') WHERE t.reliedTasks "
35             + "LIKE CONCAT('%', :internalId, '%')")
36     void updateReliedTaskAfterDelete(@Param("internalId") Long internalId);
37
38     @Query("SELECT t FROM ExecutionTask t WHERE t.reliedTasks LIKE CONCAT('%', :internalId, '%')")
39     List<ExecutionTask> findTasksReliedToAnOrderItemId(@Param("internalId") Long internalId);
40 }