blob: 864b270b496eff866dcb81b4537662f81a46e08a [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07002
3
4/**
5 * Interface for a class to represent a Table in a Key-Value store
6 */
7public interface IKVTable {
8
9 /**
10 * Version number which represents that the object does not exist, or has
11 * never been read the DB before.
12 */
13 public long VERSION_NONEXISTENT();
14
15 /**
16 * Interface for a class to represent an entry in Table.
17 */
18 public static interface IKVEntry {
19
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070020 public byte[] getKey();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070021
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070022 public byte[] getValue();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070023
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070024 public long getVersion();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070025
26 }
27
28 /**
29 * @return ID to identify this table.
30 */
31 public IKVTableID getTableId();
32
33 /**
34 * Create a Key-Value entry on table.
35 *
36 * @param key
37 * @param value
38 * @return version of the created entry
39 * @throws ObjectExistsException
40 */
41 public long create(byte[] key, byte[] value) throws ObjectExistsException;
42
43 /**
44 * Create a Key-Value entry on table, without existence checking.
45 *
46 * @param key
47 * @param value
48 * @return version of the created entry
49 */
50 public long forceCreate(byte[] key, byte[] value);
51
52 /**
53 * Read a Key-Value entry from table.
54 *
55 * @param key
56 * @return Corresponding {@link IKVEntry}
57 * @throws ObjectDoesntExistException
58 */
59 public IKVEntry read(byte[] key) throws ObjectDoesntExistException;
60
61 /**
62 * Update an existing Key-Value entry in table.
63 *
64 * @param key
65 * @param value
66 * @param version
67 * expected version in the data store
68 * @return version after update
69 * @throws ObjectDoesntExistException
70 * @throws WrongVersionException
71 */
72 public long update(byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070073 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070074
75 /**
76 * Update an existing Key-Value entry in table, without checking version.
77 *
78 * @param key
79 * @param value
80 * @return version after update
81 * @throws ObjectDoesntExistException
82 */
83 public long update(byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070084 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070085
86 /**
87 * Remove an existing Key-Value entry in table
88 *
89 * @param key
90 * @param version
91 * expected version in the data store
92 * @return version of removed object
93 * @throws ObjectDoesntExistException
94 * @throws WrongVersionException
95 */
96 public long delete(byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070097 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070098
99 /**
100 * Remove a Key-Value entry in table
101 *
102 * @param key
103 * @return version of removed object or VERSION_NONEXISTENT, if it did not exist.
104 */
105 public long forceDelete(byte[] key);
106
107 /**
108 * Get all the entries in table.
109 * @return entries in this table.
110 */
111 public Iterable<IKVEntry> getAllEntries();
112}