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 MULTI_VER_DATABASE_OPER_H
17  #define MULTI_VER_DATABASE_OPER_H
18  
19  #ifndef OMIT_MULTI_VER
20  #include "database_oper.h"
21  #include "multi_ver_natural_store.h"
22  
23  namespace DistributedDB {
24  class MultiVerDatabaseOper : public DatabaseOper {
25  public:
26      MultiVerDatabaseOper(MultiVerNaturalStore *multiVerNaturalStore, IKvDBMultiVerDataStorage *multiVerData,
27          IKvDBCommitStorage *commitHistory, MultiVerKvDataStorage *multiVerKvStorage);
~MultiVerDatabaseOper()28      ~MultiVerDatabaseOper() override {};
29  
30      int Rekey(const CipherPassword &passwd) override;
31  
32      int Import(const std::string &filePath, const CipherPassword &passwd) override;
33  
34      int Export(const std::string &filePath, const CipherPassword &passwd) const override;
35  
36  protected:
37      bool RekeyPreHandle(const CipherPassword &passwd, int &errCode) override;
38  
39      int BackupDb(const CipherPassword &passwd) const override;
40  
41      int CloseStorages() override;
42  
43      int RekeyPostHandle(const CipherPassword &passwd) override;
44  
45      int ExportAllDatabases(const std::string &currentDir, const CipherPassword &passwd,
46          const std::string &dbDir) const override;
47  
48      int BackupCurrentDatabase(const ImportFileInfo &info) const override;
49  
50      int ImportUnpackedDatabase(const ImportFileInfo &info, const CipherPassword &srcPasswd) const override;
51  
52      int ImportPostHandle() const override;
53  
54  private:
55      int ImportDatabase(const std::string &dir, const CipherPassword &passwd) const;
56  
57      MultiVerNaturalStore *multiVerNaturalStore_;
58      IKvDBMultiVerDataStorage *multiVerData_;
59      IKvDBCommitStorage *commitHistory_;
60      MultiVerKvDataStorage *multiVerKvStorage_;
61  };
62  } // namespace DistributedDB
63  #endif // MULTI_VER_DATABASE_OPER_H
64  #endif