blob: e298548ad0ca59129cadd966c54ab1c4fef5266f [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07002
3import java.util.Collection;
4import java.util.List;
5
Jonathan Hart6df90172014-04-03 10:13:11 -07006import net.onrc.onos.core.datastore.IKVTable.IKVEntry;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07007
8/**
9 * Interface for a client class used to access the Key-Value store
10 */
11public interface IKVClient {
12
13 public IKVTable getTable(final String tableName);
14
15 /**
16 * Drop table.
17 *
18 * Behavior of IKVTable instances accessing dropped table is undefined.
19 *
20 * @param table IKVTable to drop.
21 */
22 public void dropTable(IKVTable table);
23
24 /**
25 * Create a Key-Value entry on table.
26 *
27 * @param tableId
28 * @param key
29 * @param value
30 * @return version of the created entry
31 * @throws ObjectExistsException
32 */
33 public long create(IKVTableID tableId, byte[] key, byte[] value) throws ObjectExistsException;
34
35 /**
36 * Create a Key-Value entry on table, without existence checking.
37 *
38 * @param tableId
39 * @param key
40 * @param value
41 * @return version of the created entry
42 */
43 public long forceCreate(IKVTableID tableId, byte[] key, byte[] value);
44
45 /**
46 * Read a Key-Value entry from table.
47 *
48 * @param tableId
49 * @param key
50 * @return Corresponding {@link IKVEntry}
51 * @throws ObjectDoesntExistException
52 */
53 public IKVEntry read(IKVTableID tableId, byte[] key) throws ObjectDoesntExistException;
54
55 /**
56 * Update an existing Key-Value entry in table.
57 *
58 * @param tableId
59 * @param key
60 * @param value
61 * @param version
62 * expected version in the data store
63 * @return version after update
64 * @throws ObjectDoesntExistException
65 * @throws WrongVersionException
66 */
67 public long update(IKVTableID tableId, byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070068 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070069
70 /**
71 * Update an existing Key-Value entry in table, without checking version.
72 *
73 * FIXME remove this method and use forceCreate for this purpose?
74 * @param tableId
75 * @param key
76 * @param value
77 * @return version after update
78 * @throws ObjectDoesntExistException
79 */
80 @Deprecated
81 public long update(IKVTableID tableId, byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070082 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070083
84 // TODO Adding serialized value as parameter to this interface may
85 // give an option to improve performance on some backends.
86 /**
87 * Remove an existing Key-Value entry in table
88 *
89 * @param tableId
90 * @param key
91 * @param version
92 * expected version in the data store
93 * @return version of removed object
94 * @throws ObjectDoesntExistException
95 * @throws WrongVersionException
96 */
97 public long delete(IKVTableID tableId, byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070098 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070099
100 /**
101 * Remove a Key-Value entry in table
102 *
103 * @param tableId
104 * @param key
105 * @return version of removed object or -1, if it did not exist.
106 */
107 public long forceDelete(IKVTableID tableId, byte[] key);
108
109 /**
110 * Get all the entries in table.
111 * @param tableId
112 * @return entries in this table.
113 */
114 public Iterable<IKVEntry> getAllEntries(IKVTableID tableId);
115
116 /**
117 *
118 * @see #create(IKVTableID, byte[], byte[])
119 *
120 * @return IMultiOpEntry for this operation
121 *
122 */
123 public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value);
124
125 public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key,
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -0700126 byte[] value);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700127
128 public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key);
129
130 public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value,
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -0700131 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700132
133 public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value,
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -0700134 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700135
136 public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key);
137
138 /**
139 * Batch delete operation
140 * @param ops delete operations
141 * @return true if failed operation exists
142 */
143 public boolean multiDelete(final Collection<IMultiEntryOperation> ops);
144
145 /**
146 * Batch write operation
147 * @param ops write operations
148 * @return true if failed operation exists
149 */
150 public boolean multiWrite(final List<IMultiEntryOperation> ops);
151
152 /**
153 * Batch read operation
154 * @param ops read operations
155 * @return true if failed operation exists
156 */
157 public boolean multiRead(final Collection<IMultiEntryOperation> ops);
158
159 /**
160 * Version number which represents that the object does not exist, or has
161 * never been read the DB before.
162 */
163 public long VERSION_NONEXISTENT();
164
165}