blob: e4f615b7d63c3f73dcf0a881f918ae43efe824e1 (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// 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
@Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
@SuppressWarnings("removal") // TODO: Remove on Vespa 8
public void put(DocumentPut documentPut, DocumentProtocol.Priority priority) {
access.documents.put(documentPut.getId(), documentPut.getDocument());
}
@Override
public Document get(DocumentId id, Duration timeout) {
return access.documents.get(id);
}
@Override
@Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
@SuppressWarnings("removal") // TODO: Remove on Vespa 8
public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority priority, 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
@Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
@SuppressWarnings("removal") // TODO: Remove on Vespa 8
public boolean remove(DocumentRemove documentRemove, DocumentProtocol.Priority priority) {
return remove(documentRemove);
}
@Override
public boolean update(DocumentUpdate update) {
Document document = access.documents.get(update.getId());
if (document == null) {
return false;
}
update.applyTo(document);
return true;
}
@Override
@Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
@SuppressWarnings("removal") // TODO: Remove on Vespa 8
public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) {
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;
}
}
|