1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "persistenceprovider.h"
#include "catchresult.h"
#include <future>
namespace storage::spi {
PersistenceProvider::~PersistenceProvider() = default;
Result
PersistenceProvider::put(const Bucket& bucket, Timestamp timestamp, DocumentSP doc, Context& context) {
auto catcher = std::make_unique<CatchResult>();
auto future = catcher->future_result();
putAsync(bucket, timestamp, std::move(doc), context, std::move(catcher));
return *future.get();
}
void
PersistenceProvider::putAsync(const Bucket &bucket, Timestamp timestamp, DocumentSP doc, Context &context,
OperationComplete::UP onComplete)
{
Result result = put(bucket, timestamp, std::move(doc), context);
onComplete->onComplete(std::make_unique<Result>(result));
}
RemoveResult
PersistenceProvider::remove(const Bucket& bucket, Timestamp timestamp, const DocumentId & docId, Context& context) {
auto catcher = std::make_unique<CatchResult>();
auto future = catcher->future_result();
removeAsync(bucket, timestamp, docId, context, std::move(catcher));
return dynamic_cast<const RemoveResult &>(*future.get());
}
void
PersistenceProvider::removeAsync(const Bucket &bucket, Timestamp timestamp, const DocumentId & docId, Context &context,
OperationComplete::UP onComplete)
{
RemoveResult result = remove(bucket, timestamp, docId, context);
onComplete->onComplete(std::make_unique<RemoveResult>(result));
}
RemoveResult
PersistenceProvider::removeIfFound(const Bucket& bucket, Timestamp timestamp, const DocumentId & docId, Context& context) {
auto catcher = std::make_unique<CatchResult>();
auto future = catcher->future_result();
removeIfFoundAsync(bucket, timestamp, docId, context, std::move(catcher));
return dynamic_cast<const RemoveResult &>(*future.get());
}
void
PersistenceProvider::removeIfFoundAsync(const Bucket &bucket, Timestamp timestamp, const DocumentId & docId, Context &context,
OperationComplete::UP onComplete)
{
RemoveResult result = removeIfFound(bucket, timestamp, docId, context);
onComplete->onComplete(std::make_unique<RemoveResult>(result));
}
UpdateResult
PersistenceProvider::update(const Bucket& bucket, Timestamp timestamp, DocumentUpdateSP upd, Context& context) {
auto catcher = std::make_unique<CatchResult>();
auto future = catcher->future_result();
updateAsync(bucket, timestamp, std::move(upd), context, std::move(catcher));
return dynamic_cast<const UpdateResult &>(*future.get());
}
void
PersistenceProvider::updateAsync(const Bucket &bucket, Timestamp timestamp, DocumentUpdateSP upd, Context &context,
OperationComplete::UP onComplete)
{
UpdateResult result = update(bucket, timestamp, std::move(upd), context);
onComplete->onComplete(std::make_unique<UpdateResult>(result));
}
}
|