alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame^] | 1 | /* |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.service; |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Database read result. |
| 23 | */ |
| 24 | public class ReadResult { |
| 25 | |
| 26 | private final String tableName; |
| 27 | private final String key; |
| 28 | private final VersionedValue value; |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 29 | private final ReadStatus status; |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 30 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 31 | public ReadResult(ReadStatus status, String tableName, String key, VersionedValue value) { |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 32 | this.status = status; |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 33 | this.tableName = tableName; |
| 34 | this.key = key; |
| 35 | this.value = value; |
| 36 | } |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 37 | |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 38 | /** |
| 39 | * Returns the status of the read operation. |
Madan Jampani | 9b37d57 | 2014-11-12 11:53:24 -0800 | [diff] [blame] | 40 | * @return read operation status |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 41 | */ |
| 42 | public ReadStatus status() { |
Madan Jampani | 23af4fc | 2014-11-12 00:54:18 -0800 | [diff] [blame] | 43 | return status; |
Madan Jampani | 12390c1 | 2014-11-12 00:35:56 -0800 | [diff] [blame] | 44 | } |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
Madan Jampani | 9b19a82 | 2014-11-04 21:37:13 -0800 | [diff] [blame] | 47 | * Returns database table name. |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 48 | * @return table name |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 49 | */ |
| 50 | public String tableName() { |
| 51 | return tableName; |
| 52 | } |
| 53 | |
| 54 | /** |
Madan Jampani | 9b19a82 | 2014-11-04 21:37:13 -0800 | [diff] [blame] | 55 | * Returns database table key. |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 56 | * @return key |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 57 | */ |
| 58 | public String key() { |
| 59 | return key; |
| 60 | } |
| 61 | |
| 62 | /** |
Yuta HIGUCHI | 361664e | 2014-11-06 17:28:47 -0800 | [diff] [blame] | 63 | * 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 Jampani | 9b19a82 | 2014-11-04 21:37:13 -0800 | [diff] [blame] | 72 | * Returns value associated with the key. |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 73 | * @return non-null value if the table contains one, null otherwise. |
| 74 | */ |
| 75 | public VersionedValue value() { |
| 76 | return value; |
| 77 | } |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return MoreObjects.toStringHelper(getClass()) |
Madan Jampani | f5d263b | 2014-11-13 10:04:40 -0800 | [diff] [blame] | 82 | .add("status", status) |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 83 | .add("tableName", tableName) |
| 84 | .add("key", key) |
| 85 | .add("value", value) |
| 86 | .toString(); |
| 87 | } |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 88 | } |