blob: 1863496eb808ff13273ac64a6866948b43407efe [file] [log] [blame]
Madan Jampani25461112015-02-17 14:17:29 -08001/*
2 * Copyright 2015 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 */
16
Madan Jampani94c23532015-02-05 17:40:01 -080017package org.onosproject.store.consistent.impl;
18
19import java.util.Collection;
20import java.util.List;
21import java.util.Map.Entry;
22import java.util.Set;
23
Madan Jampani393e0f02015-02-12 07:35:39 +053024import org.onosproject.store.service.UpdateOperation;
25import org.onosproject.store.service.Versioned;
26
Madan Jampani94c23532015-02-05 17:40:01 -080027import net.kuujo.copycat.state.Command;
28import net.kuujo.copycat.state.Initializer;
29import net.kuujo.copycat.state.Query;
30import net.kuujo.copycat.state.StateContext;
31
32/**
33 * Database state.
34 *
35 */
36public interface DatabaseState<K, V> {
37
38 /**
39 * Initializes the database state.
40 *
41 * @param context The map state context.
42 */
43 @Initializer
44 public void init(StateContext<DatabaseState<K, V>> context);
45
46 @Query
47 int size(String tableName);
48
49 @Query
50 boolean isEmpty(String tableName);
51
52 @Query
53 boolean containsKey(String tableName, K key);
54
55 @Query
56 boolean containsValue(String tableName, V value);
57
58 @Query
59 Versioned<V> get(String tableName, K key);
60
61 @Command
62 Versioned<V> put(String tableName, K key, V value);
63
64 @Command
65 Versioned<V> remove(String tableName, K key);
66
67 @Command
68 void clear(String tableName);
69
70 @Query
71 Set<K> keySet(String tableName);
72
73 @Query
74 Collection<Versioned<V>> values(String tableName);
75
76 @Query
77 Set<Entry<K, Versioned<V>>> entrySet(String tableName);
78
79 @Command
80 Versioned<V> putIfAbsent(String tableName, K key, V value);
81
82 @Command
83 boolean remove(String tableName, K key, V value);
84
85 @Command
86 boolean remove(String tableName, K key, long version);
87
88 @Command
89 boolean replace(String tableName, K key, V oldValue, V newValue);
90
91 @Command
92 boolean replace(String tableName, K key, long oldVersion, V newValue);
93
94 @Command
95 boolean batchUpdate(List<UpdateOperation<K, V>> updates);
96}