blob: 3f253f2ccfcda89d40f0a9e916b9f9a2eb067529 [file] [log] [blame]
Madan Jampani08822c42014-11-04 17:17:46 -08001package org.onlab.onos.store.service;
2
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -08003import com.google.common.base.MoreObjects;
4
Madan Jampani08822c42014-11-04 17:17:46 -08005
6/**
7 * Database read result.
8 */
9public class ReadResult {
10
11 private final String tableName;
12 private final String key;
13 private final VersionedValue value;
Madan Jampani12390c12014-11-12 00:35:56 -080014 private final ReadStatus status;
Madan Jampani08822c42014-11-04 17:17:46 -080015
Madan Jampani12390c12014-11-12 00:35:56 -080016 public ReadResult(ReadStatus status, String tableName, String key, VersionedValue value) {
17 this.status = status;
Madan Jampani08822c42014-11-04 17:17:46 -080018 this.tableName = tableName;
19 this.key = key;
20 this.value = value;
21 }
Madan Jampani12390c12014-11-12 00:35:56 -080022
23 /**
24 * Returns the status of the read operation.
25 */
26 public ReadStatus status() {
27 return status;
28 }
Madan Jampani08822c42014-11-04 17:17:46 -080029
30 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080031 * Returns database table name.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080032 * @return table name
Madan Jampani08822c42014-11-04 17:17:46 -080033 */
34 public String tableName() {
35 return tableName;
36 }
37
38 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080039 * Returns database table key.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080040 * @return key
Madan Jampani08822c42014-11-04 17:17:46 -080041 */
42 public String key() {
43 return key;
44 }
45
46 /**
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080047 * Returns true if database table contained value for the key.
48 *
49 * @return true if database table contained value for the key
50 */
51 public boolean valueExists() {
52 return value != null;
53 }
54
55 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080056 * Returns value associated with the key.
Madan Jampani08822c42014-11-04 17:17:46 -080057 * @return non-null value if the table contains one, null otherwise.
58 */
59 public VersionedValue value() {
60 return value;
61 }
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080062
63 @Override
64 public String toString() {
65 return MoreObjects.toStringHelper(getClass())
66 .add("tableName", tableName)
67 .add("key", key)
68 .add("value", value)
69 .toString();
70 }
Madan Jampani08822c42014-11-04 17:17:46 -080071}