blob: b1ec06fabb586e2edec7d1b8ba0ce25400d28e7c [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 HIGUCHIcea3ba12014-11-05 18:18:08 -08003import static com.google.common.base.Preconditions.checkNotNull;
4
Yuta HIGUCHI4ee9ddb2014-11-05 18:28:57 -08005import java.util.Objects;
6
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -08007import com.google.common.base.MoreObjects;
8
Madan Jampani08822c42014-11-04 17:17:46 -08009/**
10 * Database read request.
11 */
12public class ReadRequest {
13
14 private final String tableName;
15 private final String key;
16
Yuta HIGUCHIcea3ba12014-11-05 18:18:08 -080017 /**
18 * Creates a read request,
19 * which will retrieve the specified key from the table.
20 *
21 * @param tableName name of the table
22 * @param key key in the table
23 * @return ReadRequest
24 */
25 public static ReadRequest get(String tableName, String key) {
26 return new ReadRequest(tableName, key);
27 }
28
Madan Jampani08822c42014-11-04 17:17:46 -080029 public ReadRequest(String tableName, String key) {
Yuta HIGUCHIcea3ba12014-11-05 18:18:08 -080030 this.tableName = checkNotNull(tableName);
31 this.key = checkNotNull(key);
Madan Jampani08822c42014-11-04 17:17:46 -080032 }
33
34 /**
35 * Return the name of the table.
36 * @return table name.
37 */
38 public String tableName() {
39 return tableName;
40 }
41
42 /**
43 * Returns the key.
44 * @return key.
45 */
46 public String key() {
47 return key;
48 }
49
50 @Override
51 public String toString() {
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080052 return MoreObjects.toStringHelper(getClass())
53 .add("tableName", tableName)
54 .add("key", key)
55 .toString();
Madan Jampani08822c42014-11-04 17:17:46 -080056 }
Yuta HIGUCHI4ee9ddb2014-11-05 18:28:57 -080057
58 @Override
59 public int hashCode() {
60 return Objects.hash(key, tableName);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj == null) {
69 return false;
70 }
71 if (getClass() != obj.getClass()) {
72 return false;
73 }
74 ReadRequest other = (ReadRequest) obj;
75 return Objects.equals(this.key, other.key) &&
76 Objects.equals(this.tableName, other.tableName);
77 }
Brian O'Connorabafb502014-12-02 22:26:20 -080078}