blob: 0fa1cbd325612f6c9a8b0307d9c308cb3c6156fc [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/**
Ray Milkeyb41100a2014-04-10 10:42:15 -07009 * Interface for a client class used to access the Key-Value store.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070010 */
11public interface IKVClient {
12
13 public IKVTable getTable(final String tableName);
14
15 /**
16 * Drop table.
Ray Milkey269ffb92014-04-03 14:43:30 -070017 * <p/>
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070018 * 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
Ray Milkey269ffb92014-04-03 14:43:30 -070061 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070062 * @return version after update
63 * @throws ObjectDoesntExistException
64 * @throws WrongVersionException
65 */
66 public long update(IKVTableID tableId, byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070067 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070068
69 /**
70 * Update an existing Key-Value entry in table, without checking version.
Ray Milkey269ffb92014-04-03 14:43:30 -070071 * <p/>
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070072 * FIXME remove this method and use forceCreate for this purpose?
Ray Milkey269ffb92014-04-03 14:43:30 -070073 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070074 * @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.
Ray Milkey269ffb92014-04-03 14:43:30 -070086
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070087 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070088 * Remove an existing Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070089 *
90 * @param tableId
91 * @param key
Ray Milkey269ffb92014-04-03 14:43:30 -070092 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070093 * @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 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700101 * Remove a Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700102 *
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.
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700112 * @param tableId
113 * @return entries in this table.
114 */
115 public Iterable<IKVEntry> getAllEntries(IKVTableID tableId);
116
117 /**
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700118 * @return IMultiOpEntry for this operation
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 * @see #create(IKVTableID, byte[], byte[])
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700120 */
121 public IMultiEntryOperation createOp(IKVTableID tableId, byte[] key, byte[] value);
122
123 public IMultiEntryOperation forceCreateOp(IKVTableID tableId, byte[] key,
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 byte[] value);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700125
126 public IMultiEntryOperation readOp(IKVTableID tableId, byte[] key);
127
128 public IMultiEntryOperation updateOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700129 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700130
131 public IMultiEntryOperation deleteOp(IKVTableID tableId, byte[] key, byte[] value,
Ray Milkey269ffb92014-04-03 14:43:30 -0700132 long version);
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700133
134 public IMultiEntryOperation forceDeleteOp(IKVTableID tableId, byte[] key);
135
136 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700137 * Batch delete operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700139 * @param ops delete operations
140 * @return true if failed operation exists
141 */
142 public boolean multiDelete(final Collection<IMultiEntryOperation> ops);
143
144 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700145 * Batch write operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700147 * @param ops write operations
148 * @return true if failed operation exists
149 */
150 public boolean multiWrite(final List<IMultiEntryOperation> ops);
151
152 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700153 * Batch read operation.
Ray Milkey269ffb92014-04-03 14:43:30 -0700154 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700155 * @param ops read operations
156 * @return true if failed operation exists
157 */
158 public boolean multiRead(final Collection<IMultiEntryOperation> ops);
159
160 /**
161 * Version number which represents that the object does not exist, or has
162 * never been read the DB before.
163 */
164 public long VERSION_NONEXISTENT();
165
166}