blob: 529dd3e1fb4137941f50a280f9a7112ae32c4f0a [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 HIGUCHIcea3ba12014-11-05 18:18:08 -080018import static com.google.common.base.Preconditions.checkNotNull;
19
Yuta HIGUCHI4ee9ddb2014-11-05 18:28:57 -080020import java.util.Objects;
21
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080022import com.google.common.base.MoreObjects;
23
Madan Jampani08822c42014-11-04 17:17:46 -080024/**
25 * Database read request.
26 */
27public class ReadRequest {
28
29 private final String tableName;
30 private final String key;
31
Yuta HIGUCHIcea3ba12014-11-05 18:18:08 -080032 /**
33 * Creates a read request,
34 * which will retrieve the specified key from the table.
35 *
36 * @param tableName name of the table
37 * @param key key in the table
38 * @return ReadRequest
39 */
40 public static ReadRequest get(String tableName, String key) {
41 return new ReadRequest(tableName, key);
42 }
43
Madan Jampani08822c42014-11-04 17:17:46 -080044 public ReadRequest(String tableName, String key) {
Yuta HIGUCHIcea3ba12014-11-05 18:18:08 -080045 this.tableName = checkNotNull(tableName);
46 this.key = checkNotNull(key);
Madan Jampani08822c42014-11-04 17:17:46 -080047 }
48
49 /**
50 * Return the name of the table.
51 * @return table name.
52 */
53 public String tableName() {
54 return tableName;
55 }
56
57 /**
58 * Returns the key.
59 * @return key.
60 */
61 public String key() {
62 return key;
63 }
64
65 @Override
66 public String toString() {
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080067 return MoreObjects.toStringHelper(getClass())
68 .add("tableName", tableName)
69 .add("key", key)
70 .toString();
Madan Jampani08822c42014-11-04 17:17:46 -080071 }
Yuta HIGUCHI4ee9ddb2014-11-05 18:28:57 -080072
73 @Override
74 public int hashCode() {
75 return Objects.hash(key, tableName);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (obj == null) {
84 return false;
85 }
86 if (getClass() != obj.getClass()) {
87 return false;
88 }
89 ReadRequest other = (ReadRequest) obj;
90 return Objects.equals(this.key, other.key) &&
91 Objects.equals(this.tableName, other.tableName);
92 }
Brian O'Connorabafb502014-12-02 22:26:20 -080093}