Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | package org.onosproject.ovsdb.rfc.operations; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.ovsdb.rfc.notation.Condition; |
| 23 | import org.onosproject.ovsdb.rfc.schema.TableSchema; |
| 24 | |
| 25 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 26 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 27 | |
| 28 | /** |
| 29 | * select operation.Refer to RFC 7047 Section 5.2. |
| 30 | */ |
| 31 | public final class Select implements Operation { |
| 32 | |
| 33 | @JsonIgnore |
| 34 | private final TableSchema tableSchema; |
| 35 | private final String op; |
| 36 | private final List<Condition> where; |
| 37 | private final List<String> columns; |
| 38 | |
| 39 | /** |
| 40 | * Constructs a Select object. |
| 41 | * @param schema TableSchema entity |
| 42 | * @param where the List of Condition entity |
| 43 | * @param columns the List of column name |
| 44 | */ |
| 45 | public Select(TableSchema schema, List<Condition> where, List<String> columns) { |
| 46 | checkNotNull(schema, "TableSchema cannot be null"); |
| 47 | checkNotNull(where, "where cannot be null"); |
| 48 | checkNotNull(columns, "columns cannot be null"); |
| 49 | this.tableSchema = schema; |
| 50 | this.op = Operations.SELECT.op(); |
| 51 | this.where = where; |
| 52 | this.columns = columns; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the columns member of select operation. |
| 57 | * @return the columns member of select operation |
| 58 | */ |
| 59 | public List<String> getColumns() { |
| 60 | return columns; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the where member of select operation. |
| 65 | * @return the where member of select operation |
| 66 | */ |
| 67 | public List<Condition> getWhere() { |
| 68 | return where; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String getOp() { |
| 73 | return op; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public TableSchema getTableSchema() { |
| 78 | return tableSchema; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * For the use of serialization. |
| 83 | * @return the table member of update operation |
| 84 | */ |
| 85 | @JsonProperty |
| 86 | public String getTable() { |
| 87 | return tableSchema.name(); |
| 88 | } |
| 89 | } |