blob: 62ad3a34a741273b1da67dec16fd18a7b0800421 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.local;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentId;
import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.documentapi.Response;
import com.yahoo.documentapi.SyncSession;
import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;
import java.time.Duration;
/**
* @author bratseth
*/
public class LocalSyncSession implements SyncSession {
private LocalDocumentAccess access;
public LocalSyncSession(LocalDocumentAccess access) {
this.access = access;
}
@Override
public void put(DocumentPut documentPut) {
if (documentPut.getCondition().isPresent()) {
throw new UnsupportedOperationException("test-and-set is not supported.");
}
access.documents.put(documentPut.getId(), documentPut.getDocument());
}
@Override
public Document get(DocumentId id, Duration timeout) {
return access.documents.get(id);
}
@Override
public boolean remove(DocumentRemove documentRemove) {
if (documentRemove.getCondition().isPresent()) {
throw new UnsupportedOperationException("test-and-set is not supported.");
}
access.documents.remove(documentRemove.getId());
return true;
}
@Override
public boolean update(DocumentUpdate update) {
Document document = access.documents.get(update.getId());
if (document == null) {
return false;
}
update.applyTo(document);
return true;
}
@Override
public Response getNext() {
throw new UnsupportedOperationException("Queue not supported.");
}
@Override
public Response getNext(int timeout) {
throw new UnsupportedOperationException("Queue not supported.");
}
@Override
public void destroy() {
access = null;
}
}
|