• 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 #ifndef NATIVE_RDB_ABS_SHARED_RESULT_SET_H
17 #define NATIVE_RDB_ABS_SHARED_RESULT_SET_H
18 
19 #include <memory>
20 #include <string>
21 #include <thread>
22 #include <vector>
23 
24 #include "abs_result_set.h"
25 #include "message_parcel.h"
26 #include "parcel.h"
27 #include "shared_block.h"
28 #include "shared_result_set.h"
29 
30 namespace OHOS {
31 namespace NativeRdb {
32 class AbsSharedResultSet : public AbsResultSet, public SharedResultSet {
33 public:
34     AbsSharedResultSet();
35     AbsSharedResultSet(std::string name);
36     virtual ~AbsSharedResultSet();
37     int GetBlob(int columnIndex, std::vector<uint8_t> &blob) override;
38     int GetString(int columnIndex, std::string &value) override;
39     int GetInt(int columnIndex, int &value) override;
40     int GetLong(int columnIndex, int64_t &value) override;
41     int GetDouble(int columnIndex, double &value) override;
42     int IsColumnNull(int columnIndex, bool &isNull) override;
43     int GetColumnType(int columnIndex, ColumnType &columnType) override;
44     int GoToRow(int position) override;
45     int GetAllColumnNames(std::vector<std::string> &columnNames) override;
46     int GetRowCount(int &count) override;
47     AppDataFwk::SharedBlock *GetBlock() const override;
48     bool OnGo(int oldRowIndex, int newRowIndex) override;
49     void FillBlock(int startRowIndex, AppDataFwk::SharedBlock *block) override;
50     virtual void SetBlock(AppDataFwk::SharedBlock *block);
51     int Close() override;
52     bool HasBlock() const;
53 protected:
54     int CheckState(int columnIndex);
55     void ClearBlock();
56     void ClosedBlock();
57     virtual void Finalize();
58 
59     friend class ISharedResultSetStub;
60     bool Unmarshalling(MessageParcel &parcel);
61     bool Marshalling(MessageParcel &parcel);
62 private:
63     // The default position of the cursor
64     static const int INIT_POS = -1;
65     static const size_t DEFAULT_BLOCK_SIZE = 2 * 1024 * 1024;
66 
67     // The SharedBlock owned by this AbsSharedResultSet
68     AppDataFwk::SharedBlock *sharedBlock_  = nullptr;
69 };
70 } // namespace NativeRdb
71 } // namespace OHOS
72 
73 #endif