• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package ohos.devtools.datasources.utils.monitorconfig.dao;
17 
18 import ohos.devtools.datasources.databases.databasepool.AbstractDataStore;
19 import ohos.devtools.datasources.utils.monitorconfig.entity.MonitorInfo;
20 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager;
21 import org.apache.logging.log4j.LogManager;
22 import org.apache.logging.log4j.Logger;
23 
24 import java.util.List;
25 
26 /**
27  * Dao layer of monitoring item configuration data
28  *
29  * @since 2021/5/19 16:39
30  */
31 public class MonitorConfigDao extends AbstractDataStore {
32     private static final Logger LOGGER = LogManager.getLogger(MonitorConfigDao.class);
33     private static volatile MonitorConfigDao singleton;
34 
MonitorConfigDao()35     private MonitorConfigDao() {
36     }
37 
38     /**
39      * Get an instance
40      *
41      * @return MonitorConfigDao
42      */
getInstance()43     public static MonitorConfigDao getInstance() {
44         if (singleton == null) {
45             synchronized (MonitorConfigDao.class) {
46                 if (singleton == null) {
47                     singleton = new MonitorConfigDao();
48                 }
49             }
50         }
51         return singleton;
52     }
53 
54     /**
55      * 插入界面返回的监控项采集项数据
56      *
57      * @param monitorInfo monitorInfo
58      * @return boolean
59      */
insertMonitorInfo(MonitorInfo monitorInfo)60     public boolean insertMonitorInfo(MonitorInfo monitorInfo) {
61         if (ProfilerLogManager.isInfoEnabled()) {
62             LOGGER.info("insertMonitorInfo");
63         }
64         boolean result = false;
65         result = insert(monitorInfo);
66         if (result) {
67             if (ProfilerLogManager.isInfoEnabled()) {
68                 LOGGER.info("local session Data written to the table successfully");
69             }
70         } else {
71             if (ProfilerLogManager.isInfoEnabled()) {
72                 LOGGER.info("local session Failed to write data to table");
73             }
74         }
75         return true;
76     }
77 
78     /**
79      * 插入界面返回的监控项采集项数据
80      *
81      * @param monitorInfo monitorInfo
82      * @return boolean
83      */
insertMonitorInfos(List<MonitorInfo> monitorInfo)84     public boolean insertMonitorInfos(List<MonitorInfo> monitorInfo) {
85         return insert(monitorInfo);
86     }
87 
88 }
89