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_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H 17 #define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H 18 #include "rdb_predicates.h" 19 #include "store/general_value.h" 20 #include "store_types.h" 21 #include "query.h" 22 namespace OHOS::DistributedRdb { 23 class RdbQuery : public DistributedData::GenQuery { 24 public: 25 using Predicates = NativeRdb::RdbPredicates; 26 static constexpr uint64_t TYPE_ID = 0x20000001; 27 RdbQuery() = default; 28 explicit RdbQuery(bool isRemote); 29 30 ~RdbQuery() override = default; 31 32 bool IsEqual(uint64_t tid) override; 33 std::vector<std::string> GetTables() override; 34 std::vector<std::string> GetDevices() const; 35 DistributedDB::Query GetQuery() const; 36 DistributedDB::RemoteCondition GetRemoteCondition() const; 37 bool IsRemoteQuery(); 38 void SetDevices(const std::vector<std::string> &devices); 39 void SetSql(const std::string &sql, DistributedData::Values &&args); 40 void FromTable(const std::vector<std::string> &tables); 41 void MakeQuery(const PredicatesMemo &predicates); 42 43 private: 44 void EqualTo(const RdbPredicateOperation& operation); 45 void NotEqualTo(const RdbPredicateOperation& operation); 46 void And(const RdbPredicateOperation& operation); 47 void Or(const RdbPredicateOperation& operation); 48 void OrderBy(const RdbPredicateOperation& operation); 49 void Limit(const RdbPredicateOperation& operation); 50 using PredicateHandle = void (RdbQuery::*)(const RdbPredicateOperation &operation); 51 static constexpr inline PredicateHandle HANDLES[OPERATOR_MAX] = { 52 &RdbQuery::EqualTo, 53 &RdbQuery::NotEqualTo, 54 &RdbQuery::And, 55 &RdbQuery::Or, 56 &RdbQuery::OrderBy, 57 &RdbQuery::Limit, 58 }; 59 static constexpr inline uint32_t DECIMAL_BASE = 10; 60 61 DistributedDB::Query query_; 62 bool isRemote_ = false; 63 std::string sql_; 64 DistributedData::Values args_; 65 std::vector<std::string> devices_; 66 std::vector<std::string> tables_; 67 }; 68 } // namespace OHOS::DistributedRdb 69 #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H 70