blob: 6685dde74bbd94402dc2b96411e954e0bc87691d [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;
Madan Jampani94c23532015-02-05 17:40:01 -080020import java.util.Map.Entry;
21import java.util.Set;
22
Madan Jampanibff6d8f2015-03-31 16:53:47 -070023import org.onosproject.store.service.Transaction;
Madan Jampani393e0f02015-02-12 07:35:39 +053024import org.onosproject.store.service.Versioned;
25
Madan Jampani94c23532015-02-05 17:40:01 -080026import net.kuujo.copycat.state.Command;
27import net.kuujo.copycat.state.Initializer;
28import net.kuujo.copycat.state.Query;
29import net.kuujo.copycat.state.StateContext;
30
31/**
32 * Database state.
33 *
34 */
35public interface DatabaseState<K, V> {
36
37 /**
38 * Initializes the database state.
39 *
40 * @param context The map state context.
41 */
42 @Initializer
43 public void init(StateContext<DatabaseState<K, V>> context);
44
45 @Query
Madan Jampania89f8f92015-04-01 14:39:54 -070046 Set<String> tableNames();
47
48 @Query
Madan Jampani94c23532015-02-05 17:40:01 -080049 int size(String tableName);
50
51 @Query
52 boolean isEmpty(String tableName);
53
54 @Query
55 boolean containsKey(String tableName, K key);
56
57 @Query
58 boolean containsValue(String tableName, V value);
59
60 @Query
61 Versioned<V> get(String tableName, K key);
62
63 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070064 Result<Versioned<V>> put(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080065
66 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070067 Result<Versioned<V>> remove(String tableName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080068
69 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070070 Result<Void> clear(String tableName);
Madan Jampani94c23532015-02-05 17:40:01 -080071
72 @Query
73 Set<K> keySet(String tableName);
74
75 @Query
76 Collection<Versioned<V>> values(String tableName);
77
78 @Query
79 Set<Entry<K, Versioned<V>>> entrySet(String tableName);
80
81 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070082 Result<Versioned<V>> putIfAbsent(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080083
84 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070085 Result<Boolean> remove(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080086
87 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070088 Result<Boolean> remove(String tableName, K key, long version);
Madan Jampani94c23532015-02-05 17:40:01 -080089
90 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070091 Result<Boolean> replace(String tableName, K key, V oldValue, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -080092
93 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070094 Result<Boolean> replace(String tableName, K key, long oldVersion, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -080095
96 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070097 boolean prepareAndCommit(Transaction transaction);
98
99 @Command
100 boolean prepare(Transaction transaction);
101
102 @Command
103 boolean commit(Transaction transaction);
104
105 @Command
106 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800107}