Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datastore; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 2 | |
| 3 | |
| 4 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 5 | * Interface for a class to represent a Table in a Key-Value store. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 6 | */ |
| 7 | public 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 Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 13 | public long getVersionNonexistant(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 14 | |
| 15 | /** |
| 16 | * Interface for a class to represent an entry in Table. |
| 17 | */ |
| 18 | public static interface IKVEntry { |
| 19 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 20 | public byte[] getKey(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 21 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 22 | public byte[] getValue(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 23 | |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 24 | public long getVersion(); |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 25 | |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 67 | * @return version after update |
| 68 | * @throws ObjectDoesntExistException |
| 69 | * @throws WrongVersionException |
| 70 | */ |
| 71 | public long update(byte[] key, byte[] value, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 72 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 73 | |
| 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 HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 83 | throws ObjectDoesntExistException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 86 | * Remove an existing Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 87 | * |
| 88 | * @param key |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | * @param version expected version in the data store |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 90 | * @return version of removed object |
| 91 | * @throws ObjectDoesntExistException |
| 92 | * @throws WrongVersionException |
| 93 | */ |
| 94 | public long delete(byte[] key, long version) |
Yuta HIGUCHI | 826b4a4 | 2014-03-24 13:10:33 -0700 | [diff] [blame] | 95 | throws ObjectDoesntExistException, WrongVersionException; |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 98 | * Remove a Key-Value entry in table. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 99 | * |
| 100 | * @param key |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 101 | * @return version of removed object or non existant version if it did not exist. |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 102 | */ |
| 103 | public long forceDelete(byte[] key); |
| 104 | |
| 105 | /** |
| 106 | * Get all the entries in table. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | * |
Yuta HIGUCHI | 66ca1bf | 2014-03-12 18:34:09 -0700 | [diff] [blame] | 108 | * @return entries in this table. |
| 109 | */ |
| 110 | public Iterable<IKVEntry> getAllEntries(); |
Ray Milkey | 0f913a0 | 2014-04-07 20:58:17 -0700 | [diff] [blame] | 111 | } |