blob: a26e044c899e509edf1028689950c4f003cd2f41 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.service;
Madan Jampani08822c42014-11-04 17:17:46 -080017
Yuta HIGUCHI841c0b62014-11-13 20:27:14 -080018import java.util.Map;
19
Madan Jampani37c2e702014-11-04 18:11:10 -080020/**
21 * Service interface for a strongly consistent and durable
22 * key value data store.
23 */
Madan Jampani08822c42014-11-04 17:17:46 -080024public interface DatabaseService {
25
26 /**
Madan Jampani12390c12014-11-12 00:35:56 -080027 * Reads the specified key.
28 * @param tableName name of the table associated with this operation.
Thomas Vachuska22925672014-11-11 17:57:53 -080029 * @param key key to read.
30 * @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 -080031 */
Madan Jampani12390c12014-11-12 00:35:56 -080032 VersionedValue get(String tableName, String key);
Madan Jampani23af4fc2014-11-12 00:54:18 -080033
Madan Jampani08822c42014-11-04 17:17:46 -080034 /**
Yuta HIGUCHI841c0b62014-11-13 20:27:14 -080035 * Reads the whole table.
36 *
37 * @param tableName name of the table associated with this operation.
38 * @return the whole table
39 */
40 Map<String, VersionedValue> getAll(String tableName);
41
42 /**
Madan Jampani12390c12014-11-12 00:35:56 -080043 * Associate the key with a value.
44 * @param tableName table name in which this key/value resides.
45 * @param key key with which the specified value is to be associated
46 * @param value value to be associated with the specified key
47 * @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 -080048 */
Madan Jampani12390c12014-11-12 00:35:56 -080049 VersionedValue put(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -080050
Madan Jampani08822c42014-11-04 17:17:46 -080051 /**
Madan Jampani12390c12014-11-12 00:35:56 -080052 * If the specified key is not already associated with a value, associate it with the given value.
53 * @param tableName table name in which this key/value resides.
54 * @param key key with which the specified value is to be associated
55 * @param value value to be associated with the specified key
56 * @return true if put was successful, false if there is already a value associated with this key
Madan Jampani08822c42014-11-04 17:17:46 -080057 */
Madan Jampani12390c12014-11-12 00:35:56 -080058 boolean putIfAbsent(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -080059
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080060 /**
Madan Jampani12390c12014-11-12 00:35:56 -080061 * Sets the key to the specified value if the version in the database (for that key)
62 * matches the specified version.
63 * @param tableName name of table associated with this operation.
64 * @param key key
65 * @param value value
66 * @param version version that should present in the database for the put to be successful.
67 * @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 -080068 */
Madan Jampani12390c12014-11-12 00:35:56 -080069 boolean putIfVersionMatches(String tableName, String key, byte[] value, long version);
Madan Jampani23af4fc2014-11-12 00:54:18 -080070
Madan Jampani08822c42014-11-04 17:17:46 -080071 /**
Madan Jampani12390c12014-11-12 00:35:56 -080072 * Replaces the entry for a key only if currently mapped to a given value.
73 * @param tableName name of table associated with this operation.
74 * @param key with which the specified value is associated
75 * @param oldValue value expected to be associated with the specified key
76 * @param newValue value to be associated with the specified key
77 * @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 -080078 */
Madan Jampani12390c12014-11-12 00:35:56 -080079 boolean putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue);
Madan Jampani23af4fc2014-11-12 00:54:18 -080080
Madan Jampani12390c12014-11-12 00:35:56 -080081 /**
82 * Removes the key (and associated value).
83 * @param tableName name of table associated with this operation.
84 * @param key key to remove
85 * @return value previously associated with the key. This call returns null if the key does not exist.
86 */
87 VersionedValue remove(String tableName, String key);
Madan Jampani23af4fc2014-11-12 00:54:18 -080088
Madan Jampani12390c12014-11-12 00:35:56 -080089 /**
90 * Removes the key (and associated value) if the version in the database matches specified version.
91 * @param tableName name of table associated with this operation.
92 * @param key key to remove
93 * @param version version that should present in the database for the remove to be successful.
94 * @return true if remove was successful, false if there version in database is different from what is specified.
95 */
96 boolean removeIfVersionMatches(String tableName, String key, long version);
Madan Jampani23af4fc2014-11-12 00:54:18 -080097
Madan Jampani12390c12014-11-12 00:35:56 -080098 /**
99 * Removes the key (and associated value) if the value in the database matches specified value.
100 * @param tableName name of table associated with this operation.
101 * @param key key to remove
102 * @param value value that should present in the database for the remove to be successful.
103 * @return true if remove was successful, false if there value in database is different from what is specified.
104 */
105 boolean removeIfValueMatches(String tableName, String key, byte[] value);
Madan Jampani23af4fc2014-11-12 00:54:18 -0800106
Madan Jampani12390c12014-11-12 00:35:56 -0800107 /**
108 * Performs a batch read operation and returns the results.
109 * @param batchRequest batch request.
110 * @return result of the batch operation.
111 */
112 BatchReadResult batchRead(BatchReadRequest batchRequest);
Madan Jampani23af4fc2014-11-12 00:54:18 -0800113
Madan Jampani12390c12014-11-12 00:35:56 -0800114 /**
115 * Performs a batch write operation and returns the results.
116 * This method provides transactional semantics. Either all writes succeed or none do.
117 * Even a single write failure would cause the entire batch to be aborted.
118 * In the case of unsuccessful operation, the batch result can be inspected to determine
119 * which operation(s) caused the batch to fail.
120 * @param batchRequest batch request.
121 * @return result of the batch operation.
122 */
123 BatchWriteResult batchWrite(BatchWriteRequest batchRequest);
Madan Jampani23af4fc2014-11-12 00:54:18 -0800124}