Epic-231:versioning, and backup the configuration
[sdnc/oam.git] / configbackuprestore / vnfconfigbackupservice / src / main / java / com / onap / sdnc / vnfbackupservice / dao / VnfBackupServiceRepo.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : SDNC-FEATURES
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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 com.onap.sdnc.vnfbackupservice.dao;
21
22 import java.sql.Timestamp;
23 import java.util.List;
24
25 import javax.transaction.Transactional;
26
27 import org.springframework.data.jpa.repository.JpaRepository;
28 import org.springframework.data.jpa.repository.Modifying;
29 import org.springframework.data.jpa.repository.Query;
30 import org.springframework.data.repository.query.Param;
31 import org.springframework.stereotype.Repository;
32
33
34 import com.onap.sdnc.vnfbackupservice.model.VnfConfigDetailsDB;
35
36 @Repository
37 public interface VnfBackupServiceRepo extends JpaRepository<VnfConfigDetailsDB, Long> {
38
39         @Query(value = "Select * from vnfconfigdetails where vnfid = :vnfid", nativeQuery = true)
40         List<VnfConfigDetailsDB> getVnfDetails(@Param("vnfid") String vnfid);
41         
42         @Query(value = "Select * from vnfconfigdetails where vnfid = :vnfid ORDER BY vnfversion DESC LIMIT 1", nativeQuery = true)
43         VnfConfigDetailsDB getVnfDetail(@Param("vnfid") String vnfid);
44
45         @Modifying
46         @Query(value = "insert into vnfconfigdetails (configinfo,creationdate,lastupdated,status,vnfid,vnfname,vnfversion) VALUES (:configinfo,:creationdate,:lastupdated,:status,:vnfid,:vnfname,:vnfversion)", nativeQuery = true)
47         @Transactional
48         void saveVnfDetails(@Param("configinfo") String configinfo, @Param("creationdate") Timestamp creationDate,
49                         @Param("lastupdated") Timestamp lastupdated, @Param("status") int status, @Param("vnfid") String vnfid,
50                         @Param("vnfname") String vnfname,@Param("vnfversion") String vnfversion);
51
52         @Query(value = "Select configinfo && vnfversion from vnfconfigdetails where vnfid = :vnfid", nativeQuery = true)
53         List<VnfConfigDetailsDB> getVnfDetailhavingAllVersion(@Param("vnfid") String vnfid);
54
55         @Query(value = "Select backuptime from vnfschedulertime where id=1", nativeQuery = true)
56         String getvnfschedulertime();
57
58         @Modifying
59         @Query(value = "insert into vnfschedulertime(id, backuptime) VALUES (:id, :backuptime)", nativeQuery = true)
60         @Transactional
61         void insertSchedulerTime(@Param("id") int id, @Param("backuptime") String backuptime);
62
63         @Modifying
64         @Query(value = "UPDATE vnfschedulertime SET backuptime =:formatDateTime WHERE id = 1", nativeQuery = true)
65         @Transactional
66         void updateSchedulerTime(@Param("formatDateTime") String formatDateTime);
67         
68 }