aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/SyncSession.java
blob: c254df3ba020246f2d25725f3247148856abd062 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;

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.messagebus.protocol.DocumentProtocol;

import java.time.Duration;

/**
 * <p>A session for synchronous access to a document repository. This class
 * provides simple document access where throughput is not a concern.</p>
 *
 * @author Simon Thoresen Hult
 * @author bjorncs
 */
public interface SyncSession extends Session {

    /**
     * <p>Puts a document. When this method returns, the document is safely
     * received. This enables setting condition compared to using Document.</p>
     *
     * @param documentPut The DocumentPut operation
     */
    void put(DocumentPut documentPut);

    /**
     * <p>Puts a document. When this method returns, the document is safely
     * received.</p>
     *
     * @param documentPut The DocumentPut operation
     * @param priority The priority with which to perform this operation.
     */
    default void put(DocumentPut documentPut, DocumentProtocol.Priority priority) {
        put(documentPut);
    }

    /**
     * <p>Gets a document.</p>
     *
     * @param id The id of the document to get.
     * @return The known document having this id, or null if there is no
     *         document having this id.
     * @throws UnsupportedOperationException Thrown if this access does not
     *                                       support retrieving.
     */
    default Document get(DocumentId id) { return get(id, null); }

    /**
     * Gets a document with an unspecified timeout
     *
     * @param id       The id of the document to get.
     * @param fieldSet A comma-separated list of fields to retrieve
     * @param priority The priority with which to perform this operation.
     * @return The known document having this id, or null if there is no
     *         document having this id.
     * @throws UnsupportedOperationException Thrown if this access does not
     *                                       support retrieving.
     */
    default Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority priority) {
        return get(id, fieldSet, priority, null);
    }

    /**
     * <p>Gets a document with timeout.</p>
     *
     * @param id The id of the document to get.
     * @param timeout Timeout. If timeout is null, an unspecified default will be used.
     * @return The known document having this id, or null if there is no
     *         document having this id.
     * @throws UnsupportedOperationException Thrown if this access does not support retrieving.
     * @throws DocumentAccessException on any messagebus error, including timeout ({@link com.yahoo.messagebus.ErrorCode#TIMEOUT}).
     */
    Document get(DocumentId id, Duration timeout);

    /**
     * <p>Gets a document with timeout. </p>
     *
     * @param id       The id of the document to get.
     * @param fieldSet A comma-separated list of fields to retrieve
     * @param priority The priority with which to perform this operation.
     * @param timeout Timeout. If timeout is null, an unspecified default will be used.
     * @return The known document having this id, or null if there is no
     *         document having this id.
     * @throws UnsupportedOperationException Thrown if this access does not support retrieving.
     * @throws DocumentAccessException on any messagebus error, including timeout ({@link com.yahoo.messagebus.ErrorCode#TIMEOUT}).
     */
    Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority priority, Duration timeout);

    /**
     * <p>Removes a document if it is present and condition is fulfilled.</p>
     * @param documentRemove document to delete
     * @return true If the document with this id was removed, false otherwise.
     */
    boolean remove(DocumentRemove documentRemove);

    /**
     * <p>Removes a document if it is present.</p>
     *
     * @param documentRemove Document remove operation
     * @param priority The priority with which to perform this operation.
     * @return true If the document with this id was removed, false otherwise.
     * @throws UnsupportedOperationException Thrown if this access does not
     *                                       support removal.
     */
    boolean remove(DocumentRemove documentRemove, DocumentProtocol.Priority priority);

    /**
     * <p>Updates a document.</p>
     *
     * @param update The updates to perform.
     * @return True, if the document was found and updated.
     * @throws UnsupportedOperationException Thrown if this access does not
     *                                       support update.
     */
    boolean update(DocumentUpdate update);

    /**
     * <p>Updates a document.</p>
     *
     * @param update   The updates to perform.
     * @param priority The priority with which to perform this operation.
     * @return True, if the document was found and updated.
     * @throws UnsupportedOperationException Thrown if this access does not
     *                                       support update.
     */
    boolean update(DocumentUpdate update, DocumentProtocol.Priority priority);

}