blob: ec403231f936b1a28b4b4fd7fc7f7265c2bb522e [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 HIGUCHI5e1cfe02014-11-04 21:22:45 -080018import com.google.common.base.MoreObjects;
19
Madan Jampani08822c42014-11-04 17:17:46 -080020
21/**
22 * Database read result.
23 */
24public class ReadResult {
25
26 private final String tableName;
27 private final String key;
28 private final VersionedValue value;
Madan Jampani12390c12014-11-12 00:35:56 -080029 private final ReadStatus status;
Madan Jampani08822c42014-11-04 17:17:46 -080030
Madan Jampani12390c12014-11-12 00:35:56 -080031 public ReadResult(ReadStatus status, String tableName, String key, VersionedValue value) {
Madan Jampani23af4fc2014-11-12 00:54:18 -080032 this.status = status;
Madan Jampani08822c42014-11-04 17:17:46 -080033 this.tableName = tableName;
34 this.key = key;
35 this.value = value;
36 }
Madan Jampani23af4fc2014-11-12 00:54:18 -080037
Madan Jampani12390c12014-11-12 00:35:56 -080038 /**
39 * Returns the status of the read operation.
Madan Jampani9b37d572014-11-12 11:53:24 -080040 * @return read operation status
Madan Jampani12390c12014-11-12 00:35:56 -080041 */
42 public ReadStatus status() {
Madan Jampani23af4fc2014-11-12 00:54:18 -080043 return status;
Madan Jampani12390c12014-11-12 00:35:56 -080044 }
Madan Jampani08822c42014-11-04 17:17:46 -080045
46 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080047 * Returns database table name.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080048 * @return table name
Madan Jampani08822c42014-11-04 17:17:46 -080049 */
50 public String tableName() {
51 return tableName;
52 }
53
54 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080055 * Returns database table key.
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080056 * @return key
Madan Jampani08822c42014-11-04 17:17:46 -080057 */
58 public String key() {
59 return key;
60 }
61
62 /**
Yuta HIGUCHI361664e2014-11-06 17:28:47 -080063 * Returns true if database table contained value for the key.
64 *
65 * @return true if database table contained value for the key
66 */
67 public boolean valueExists() {
68 return value != null;
69 }
70
71 /**
Madan Jampani9b19a822014-11-04 21:37:13 -080072 * Returns value associated with the key.
Madan Jampani08822c42014-11-04 17:17:46 -080073 * @return non-null value if the table contains one, null otherwise.
74 */
75 public VersionedValue value() {
76 return value;
77 }
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080078
79 @Override
80 public String toString() {
81 return MoreObjects.toStringHelper(getClass())
Madan Jampanif5d263b2014-11-13 10:04:40 -080082 .add("status", status)
Yuta HIGUCHI5e1cfe02014-11-04 21:22:45 -080083 .add("tableName", tableName)
84 .add("key", key)
85 .add("value", value)
86 .toString();
87 }
Madan Jampani08822c42014-11-04 17:17:46 -080088}