blob: 868dda5f81e702052e716face878fc95182c4b93 [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) {
Madan Jampani23af4fc2014-11-12 00:54:18 -080017 this.status = status;
Madan Jampani08822c42014-11-04 17:17:46 -080018 this.tableName = tableName;
19 this.key = key;
20 this.value = value;
21 }
Madan Jampani23af4fc2014-11-12 00:54:18 -080022
Madan Jampani12390c12014-11-12 00:35:56 -080023 /**
24 * Returns the status of the read operation.
Madan Jampani9b37d572014-11-12 11:53:24 -080025 * @return read operation status
Madan Jampani12390c12014-11-12 00:35:56 -080026 */
27 public ReadStatus status() {
Madan Jampani23af4fc2014-11-12 00:54:18 -080028 return status;
Madan Jampani12390c12014-11-12 00:35:56 -080029 }
Madan Jampani08822c42014-11-04 17:17:46 -080030
31 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080032 * Returns database table name.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080033 * @return table name
Madan Jampani08822c42014-11-04 17:17:46 -080034 */
35 public String tableName() {
36 return tableName;
37 }
38
39 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080040 * Returns database table key.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080041 * @return key
Madan Jampani08822c42014-11-04 17:17:46 -080042 */
43 public String key() {
44 return key;
45 }
46
47 /**
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080048 * Returns true if database table contained value for the key.
49 *
50 * @return true if database table contained value for the key
51 */
52 public boolean valueExists() {
53 return value != null;
54 }
55
56 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080057 * Returns value associated with the key.
Madan Jampani08822c42014-11-04 17:17:46 -080058 * @return non-null value if the table contains one, null otherwise.
59 */
60 public VersionedValue value() {
61 return value;
62 }
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080063
64 @Override
65 public String toString() {
66 return MoreObjects.toStringHelper(getClass())
Madan Jampanif5d263b2014-11-13 10:04:40 -080067 .add("status", status)
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080068 .add("tableName", tableName)
69 .add("key", key)
70 .add("value", value)
71 .toString();
72 }
Madan Jampani08822c42014-11-04 17:17:46 -080073}