blob: 2dec72d2fbf9ae68452c128146ded274af78de2c [file] [log] [blame]
Brian O'Connorabafb502014-12-02 22:26:20 -08001package org.onosproject.store.service;
Madan Jampani08822c42014-11-04 17:17:46 -08002
Yuta HIGUCHI841c0b62014-11-13 20:27:14 -08003import java.util.Map;
4
Madan Jampani37c2e702014-11-04 18:11:10 -08005/**
6 * Service interface for a strongly consistent and durable
7 * key value data store.
8 */
Madan Jampani08822c42014-11-04 17:17:46 -08009public interface DatabaseService {
10
11 /**
Madan Jampani12390c12014-11-12 00:35:56 -080012 * Reads the specified key.
13 * @param tableName name of the table associated with this operation.
Thomas Vachuska22925672014-11-11 17:57:53 -080014 * @param key key to read.
15 * @return value (and version) associated with this key. This calls returns null if the key does not exist.
Madan Jampani08822c42014-11-04 17:17:46 -080016 */
Madan Jampani12390c12014-11-12 00:35:56 -080017 VersionedValue get(String tableName, String key);
Madan Jampani23af4fc2014-11-12 00:54:18 -080018
Madan Jampani08822c42014-11-04 17:17:46 -080019 /**
Yuta HIGUCHI841c0b62014-11-13 20:27:14 -080020 * Reads the whole table.
21 *
22 * @param tableName name of the table associated with this operation.
23 * @return the whole table
24 */
25 Map<String, VersionedValue> getAll(String tableName);
26
27 /**
Madan Jampani12390c12014-11-12 00:35:56 -080028 * Associate the key with a value.
29 * @param tableName table name in which this key/value resides.
30 * @param key key with which the specified value is to be associated
31 * @param value value to be associated with the specified key
32 * @return the previous value associated with the specified key, or null if there was no mapping for the key.
Madan Jampani08822c42014-11-04 17:17:46 -080033 */
Madan Jampani12390c12014-11-12 00:35:56 -080034 VersionedValue put(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -080035
Madan Jampani08822c42014-11-04 17:17:46 -080036 /**
Madan Jampani12390c12014-11-12 00:35:56 -080037 * If the specified key is not already associated with a value, associate it with the given value.
38 * @param tableName table name in which this key/value resides.
39 * @param key key with which the specified value is to be associated
40 * @param value value to be associated with the specified key
41 * @return true if put was successful, false if there is already a value associated with this key
Madan Jampani08822c42014-11-04 17:17:46 -080042 */
Madan Jampani12390c12014-11-12 00:35:56 -080043 boolean putIfAbsent(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -080044
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080045 /**
Madan Jampani12390c12014-11-12 00:35:56 -080046 * Sets the key to the specified value if the version in the database (for that key)
47 * matches the specified version.
48 * @param tableName name of table associated with this operation.
49 * @param key key
50 * @param value value
51 * @param version version that should present in the database for the put to be successful.
52 * @return true if put was successful, false if there version in database is different from what is specified.
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080053 */
Madan Jampani12390c12014-11-12 00:35:56 -080054 boolean putIfVersionMatches(String tableName, String key, byte[] value, long version);
Madan Jampani23af4fc2014-11-12 00:54:18 -080055
Madan Jampani08822c42014-11-04 17:17:46 -080056 /**
Madan Jampani12390c12014-11-12 00:35:56 -080057 * Replaces the entry for a key only if currently mapped to a given value.
58 * @param tableName name of table associated with this operation.
59 * @param key with which the specified value is associated
60 * @param oldValue value expected to be associated with the specified key
61 * @param newValue value to be associated with the specified key
62 * @return true if put was successful, false if there version in database is different from what is specified.
Madan Jampani08822c42014-11-04 17:17:46 -080063 */
Madan Jampani12390c12014-11-12 00:35:56 -080064 boolean putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue);
Madan Jampani23af4fc2014-11-12 00:54:18 -080065
Madan Jampani12390c12014-11-12 00:35:56 -080066 /**
67 * Removes the key (and associated value).
68 * @param tableName name of table associated with this operation.
69 * @param key key to remove
70 * @return value previously associated with the key. This call returns null if the key does not exist.
71 */
72 VersionedValue remove(String tableName, String key);
Madan Jampani23af4fc2014-11-12 00:54:18 -080073
Madan Jampani12390c12014-11-12 00:35:56 -080074 /**
75 * Removes the key (and associated value) if the version in the database matches specified version.
76 * @param tableName name of table associated with this operation.
77 * @param key key to remove
78 * @param version version that should present in the database for the remove to be successful.
79 * @return true if remove was successful, false if there version in database is different from what is specified.
80 */
81 boolean removeIfVersionMatches(String tableName, String key, long version);
Madan Jampani23af4fc2014-11-12 00:54:18 -080082
Madan Jampani12390c12014-11-12 00:35:56 -080083 /**
84 * Removes the key (and associated value) if the value in the database matches specified value.
85 * @param tableName name of table associated with this operation.
86 * @param key key to remove
87 * @param value value that should present in the database for the remove to be successful.
88 * @return true if remove was successful, false if there value in database is different from what is specified.
89 */
90 boolean removeIfValueMatches(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -080091
Madan Jampani12390c12014-11-12 00:35:56 -080092 /**
93 * Performs a batch read operation and returns the results.
94 * @param batchRequest batch request.
95 * @return result of the batch operation.
96 */
97 BatchReadResult batchRead(BatchReadRequest batchRequest);
Madan Jampani23af4fc2014-11-12 00:54:18 -080098
Madan Jampani12390c12014-11-12 00:35:56 -080099 /**
100 * Performs a batch write operation and returns the results.
101 * This method provides transactional semantics. Either all writes succeed or none do.
102 * Even a single write failure would cause the entire batch to be aborted.
103 * In the case of unsuccessful operation, the batch result can be inspected to determine
104 * which operation(s) caused the batch to fail.
105 * @param batchRequest batch request.
106 * @return result of the batch operation.
107 */
108 BatchWriteResult batchWrite(BatchWriteRequest batchRequest);
Madan Jampani23af4fc2014-11-12 00:54:18 -0800109}