• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef DATASHARESERVICE_RDB_DELEGATE_H
17 #define DATASHARESERVICE_RDB_DELEGATE_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "concurrent_map.h"
23 #include "db_delegate.h"
24 #include "rdb_errno.h"
25 #include "rdb_helper.h"
26 #include "rdb_store.h"
27 #include "uri_utils.h"
28 #include "rdb_utils.h"
29 
30 namespace OHOS::DataShare {
31 using namespace OHOS::NativeRdb;
32 class RdbDelegate final : public DBDelegate {
33 public:
34     explicit RdbDelegate(const std::string &dir, int version, bool registerFunction);
35     int64_t Insert(const std::string &tableName, const DataShareValuesBucket &valuesBucket) override;
36     int64_t Update(const std::string &tableName, const DataSharePredicates &predicate,
37         const DataShareValuesBucket &valuesBucket) override;
38     int64_t Delete(const std::string &tableName, const DataSharePredicates &predicate) override;
39     std::shared_ptr<DataShareResultSet> Query(const std::string &tableName, const DataSharePredicates &predicates,
40         const std::vector<std::string> &columns, int &errCode) override;
41     std::string Query(const std::string &sql, const std::vector<std::string> &selectionArgs) override;
42     std::shared_ptr<NativeRdb::ResultSet> QuerySql(const std::string &sql) override;
43 
44 private:
45     static std::atomic<int32_t> resultSetCount;
46     std::shared_ptr<RdbStore> store_;
47     int errCode_ = E_OK;
48 };
49 class DefaultOpenCallback : public RdbOpenCallback {
50 public:
OnCreate(RdbStore & rdbStore)51     int OnCreate(RdbStore &rdbStore) override
52     {
53         return E_OK;
54     }
OnUpgrade(RdbStore & rdbStore,int oldVersion,int newVersion)55     int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override
56     {
57         return E_OK;
58     }
59 };
60 } // namespace OHOS::DataShare
61 #endif // DATASHARESERVICE_RDB_DELEGATE_H
62