blob: 9d0c8ee64aa8756ea15c1ea78deba4ddd5bec995 [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/**
Ray Milkeyb41100a2014-04-10 10:42:15 -07005 * Interface for a class to represent a Table in a Key-Value store.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07006 */
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 */
Ray Milkey7531a342014-04-11 15:08:12 -070013 public long getVersionNonexistant();
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070014
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
Ray Milkey269ffb92014-04-03 14:43:30 -070066 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070067 * @return version after update
68 * @throws ObjectDoesntExistException
69 * @throws WrongVersionException
70 */
71 public long update(byte[] key, byte[] value, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070072 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070073
74 /**
75 * Update an existing Key-Value entry in table, without checking version.
76 *
77 * @param key
78 * @param value
79 * @return version after update
80 * @throws ObjectDoesntExistException
81 */
82 public long update(byte[] key, byte[] value)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070083 throws ObjectDoesntExistException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070084
85 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070086 * Remove an existing Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070087 *
88 * @param key
Ray Milkey269ffb92014-04-03 14:43:30 -070089 * @param version expected version in the data store
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070090 * @return version of removed object
91 * @throws ObjectDoesntExistException
92 * @throws WrongVersionException
93 */
94 public long delete(byte[] key, long version)
Yuta HIGUCHI826b4a42014-03-24 13:10:33 -070095 throws ObjectDoesntExistException, WrongVersionException;
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070096
97 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070098 * Remove a Key-Value entry in table.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -070099 *
100 * @param key
Ray Milkey7531a342014-04-11 15:08:12 -0700101 * @return version of removed object or non existant version if it did not exist.
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700102 */
103 public long forceDelete(byte[] key);
104
105 /**
106 * Get all the entries in table.
Ray Milkey269ffb92014-04-03 14:43:30 -0700107 *
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -0700108 * @return entries in this table.
109 */
110 public Iterable<IKVEntry> getAllEntries();
Ray Milkey0f913a02014-04-07 20:58:17 -0700111}