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 #include "sqlite_local_kvdb_snapshot.h"
17 #include "sqlite_local_kvdb_connection.h"
18
19 namespace DistributedDB {
SQLiteLocalKvDBSnapshot(IKvDBConnection * connect)20 SQLiteLocalKvDBSnapshot::SQLiteLocalKvDBSnapshot(IKvDBConnection *connect)
21 : connect_(connect)
22 {}
23
~SQLiteLocalKvDBSnapshot()24 SQLiteLocalKvDBSnapshot::~SQLiteLocalKvDBSnapshot()
25 {
26 connect_ = nullptr;
27 }
28
Get(const Key & key,Value & value) const29 int SQLiteLocalKvDBSnapshot::Get(const Key &key, Value &value) const
30 {
31 if (connect_ == nullptr) {
32 return -E_INVALID_DB;
33 }
34 IOption option;
35 return connect_->Get(option, key, value);
36 }
37
GetEntries(const Key & keyPrefix,std::vector<Entry> & entries) const38 int SQLiteLocalKvDBSnapshot::GetEntries(const Key &keyPrefix, std::vector<Entry> &entries) const
39 {
40 if (connect_ == nullptr) {
41 return -E_INVALID_DB;
42 }
43 IOption option;
44 return connect_->GetEntries(option, keyPrefix, entries);
45 }
46
Close()47 void SQLiteLocalKvDBSnapshot::Close()
48 {
49 if (connect_ != nullptr) {
50 connect_->Close();
51 connect_ = nullptr;
52 }
53 }
54 } // namespace DistributedDB
55