Aharoni, Pavel (pa0916) | 8c70f07 | 2018-11-18 00:07:12 +0200 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 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 | package org.onap.osam.job.repository.job;
|
| 21 |
|
| 22 | import org.onap.osam.job.dao.job.JobStatus;
|
| 23 | import org.onap.osam.job.dao.job.OsamJob;
|
| 24 | import org.springframework.data.jpa.repository.Modifying;
|
| 25 | import org.springframework.data.jpa.repository.Query;
|
| 26 | import org.springframework.data.repository.CrudRepository;
|
| 27 | import org.springframework.data.repository.query.Param;
|
| 28 | import org.springframework.transaction.annotation.Transactional;
|
| 29 |
|
| 30 | import java.util.Date;
|
| 31 | import java.util.List;
|
| 32 | import java.util.Optional;
|
| 33 | import java.util.UUID;
|
| 34 |
|
| 35 | public interface OsamJobRepository extends CrudRepository<OsamJob, Long> {
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 | Optional<OsamJob> findByUuid(UUID uuid);
|
| 40 |
|
| 41 | List<OsamJob> findAllByUuid(Iterable<UUID> uuids);
|
| 42 |
|
| 43 | //TODO Pavel add intervalCondition to the query
|
| 44 | //String intervalCondition = (topic==JobStatus.CREATING) ? "" : (" and MODIFIED_DATE <= '" + nowMinusInterval()+"'");
|
| 45 | //@Query("select o from OsamJob o where o.status = :status and o.takenBy is null and o.deletedAt is null order by o.modifiedDate asc")
|
| 46 | //List<OsamJob> queryFirst1ByStatusAndTakenByIsNullAndDeleteAtIsNullOrderByModifiedDateAsc(@Param("status") JobStatus status);
|
| 47 | List<OsamJob> queryFirst1ByStatusAndTakenByIsNullAndDeletedAtIsNullOrderByModifiedDateAsc(@Param("status") JobStatus status);
|
| 48 |
|
| 49 | //Updates
|
| 50 |
|
| 51 | @Transactional
|
| 52 | @Modifying
|
| 53 | @Query("update OsamJob job set job.takenBy = :takenBy where job.uuid = :uuid and job.age = :age and job.takenBy is null")
|
| 54 | Integer updateOsamCoreJobsAge(@Param("takenBy") String takenBy, @Param("uuid") UUID uuid, @Param("age") Integer age);
|
| 55 |
|
| 56 | @Transactional
|
| 57 | @Modifying
|
| 58 | @Query("update OsamJob job set job.deletedAt = :now where job.uuid = :uuid and job.status in(:pending, :stopped) and job.takenBy is null")
|
| 59 | Integer updateOsamCoreJobToBeDeleted(@Param("now") Date date, @Param("uuid") UUID uuid, @Param("pending") String pending, @Param("stopped") String stopped);
|
| 60 |
|
| 61 | @Transactional
|
| 62 | @Modifying
|
| 63 | @Query("update OsamJob job set job.status = concat(':prefix_',job.status), job.takenBy = null where job.uuid = :uuid and job.status not like ':prefix_%'")
|
| 64 | Integer muteOsamCoreJob(@Param("uuid") UUID uuid, @Param("")String prefix);
|
| 65 |
|
| 66 | }
|