• 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 OHOS_CLOUD_SYNC_SERVICE_RDB_DATA_HANDLER_H
17 #define OHOS_CLOUD_SYNC_SERVICE_RDB_DATA_HANDLER_H
18 
19 #include "abs_rdb_predicates.h"
20 #include "rdb_helper.h"
21 #include "result_set.h"
22 #include "values_bucket.h"
23 
24 #include "data_handler.h"
25 
26 namespace OHOS {
27 namespace FileManagement {
28 namespace CloudSync {
29 class RdbDataHandler : public DataHandler {
30 protected:
31     /* init */
RdbDataHandler(int32_t userId,const std::string & bundleName,const std::string & table,std::shared_ptr<NativeRdb::RdbStore> rdb)32     RdbDataHandler(int32_t userId, const std::string &bundleName, const std::string &table,
33         std::shared_ptr<NativeRdb::RdbStore> rdb)
34         : DataHandler(userId, bundleName, table),
35           rdb_(rdb),
36           tableName_(table) {}
37     virtual ~RdbDataHandler() = default;
38 
39     virtual int32_t BeginTransaction();
40     virtual int32_t RollBack();
41     virtual int32_t Commit();
42 
43     /* insert, delete, update, query */
44     virtual int32_t BatchInsert(int64_t &outRowId,
45                                 const std::string &table,
46                                 const std::vector<NativeRdb::ValuesBucket> &initialBatchValues);
47     virtual int32_t Insert(int64_t &outRowId, const NativeRdb::ValuesBucket &initialValues);
48     virtual int32_t Update(int &changedRows, const NativeRdb::ValuesBucket &values,
49         const std::string &whereClause, const std::vector<std::string> &whereArgs);
50     virtual int32_t Delete(int &deletedRows, const std::string &whereClause,
51         const std::vector<std::string> &whereArgs);
52     virtual std::shared_ptr<NativeRdb::ResultSet> Query(const NativeRdb::AbsRdbPredicates &predicates,
53         const std::vector<std::string> &columns);
54 
55     /* insert, delete, update with tableName */
56     virtual int32_t Insert(int64_t &outRowId, const std::string &tableName,
57         const NativeRdb::ValuesBucket &initialValues);
58     virtual int32_t Update(int &changedRows, const std::string &tableName,
59         const NativeRdb::ValuesBucket &values, const std::string &whereClause,
60         const std::vector<std::string> &whereArgs);
61     virtual int32_t Delete(int &deletedRows, const std::string &tableName,
62         const std::string &whereClause, const std::vector<std::string> &whereArgs);
63 
64     /* raw */
65     virtual int32_t ExecuteSql(const std::string &sql,
66         const std::vector<NativeRdb::ValueObject> &bindArgs = std::vector<NativeRdb::ValueObject>());
67 
68 private:
69     std::shared_ptr<NativeRdb::RdbStore> rdb_;
70     std::string tableName_;
71 };
72 } // namespace CloudSync
73 } // namespace FileManagement
74 } // namespace OHOS
75 #endif // OHOS_CLOUD_SYNC_SERVICE_RDB_DATA_HANDLER_H