Committed by
Gerrit Code Review
[ONOS-2563]Optimize RFC 7047's code.
Change-Id: I000f2b802420e4f47ce320f6ed021049bd2fd83e
Showing
23 changed files
with
272 additions
and
559 deletions
| ... | @@ -16,25 +16,25 @@ | ... | @@ -16,25 +16,25 @@ |
| 16 | package org.onosproject.ovsdb.rfc.error; | 16 | package org.onosproject.ovsdb.rfc.error; |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | - * AbnormalSchema exception is thrown when the received schema is invalid. | 19 | + * AbnormalJsonNodeException exception is thrown when the received JsonNode is invalid. |
| 20 | */ | 20 | */ |
| 21 | -public class AbnormalSchemaException extends RuntimeException { | 21 | +public class AbnormalJsonNodeException extends RuntimeException { |
| 22 | private static final long serialVersionUID = 8328377718334680368L; | 22 | private static final long serialVersionUID = 8328377718334680368L; |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | - * Constructs a AbnormalSchemaException object. | 25 | + * Constructs a AbnormalJsonNodeException object. |
| 26 | * @param message error message | 26 | * @param message error message |
| 27 | */ | 27 | */ |
| 28 | - public AbnormalSchemaException(String message) { | 28 | + public AbnormalJsonNodeException(String message) { |
| 29 | super(message); | 29 | super(message); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | /** | 32 | /** |
| 33 | - * Constructs a AbnormalSchemaException object. | 33 | + * Constructs a AbnormalJsonNodeException object. |
| 34 | * @param message error message | 34 | * @param message error message |
| 35 | * @param cause Throwable | 35 | * @param cause Throwable |
| 36 | */ | 36 | */ |
| 37 | - public AbnormalSchemaException(String message, Throwable cause) { | 37 | + public AbnormalJsonNodeException(String message, Throwable cause) { |
| 38 | super(message, cause); | 38 | super(message, cause); |
| 39 | } | 39 | } |
| 40 | 40 | ... | ... |
| 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.error; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * This exception is thrown when the argument is not supported. | ||
| 20 | - */ | ||
| 21 | -public class ArgumentException extends RuntimeException { | ||
| 22 | - private static final long serialVersionUID = 4950089877540156797L; | ||
| 23 | - | ||
| 24 | - /** | ||
| 25 | - * Constructs a ArgumentException object. | ||
| 26 | - * @param message error message | ||
| 27 | - */ | ||
| 28 | - public ArgumentException(String message) { | ||
| 29 | - super(message); | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Constructs a ArgumentException object. | ||
| 34 | - * @param message error message | ||
| 35 | - * @param cause Throwable | ||
| 36 | - */ | ||
| 37 | - public ArgumentException(String message, Throwable cause) { | ||
| 38 | - super(message, cause); | ||
| 39 | - } | ||
| 40 | -} |
ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/error/JsonParsingException.java
deleted
100644 → 0
| 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.error; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * The JsonParsingException is thrown when JSON could not be successfully | ||
| 20 | - * parsed. | ||
| 21 | - */ | ||
| 22 | -public class JsonParsingException extends RuntimeException { | ||
| 23 | - private static final long serialVersionUID = 1424752181911923235L; | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * Constructs a JsonParsingException object. | ||
| 27 | - * @param message error message | ||
| 28 | - */ | ||
| 29 | - public JsonParsingException(String message) { | ||
| 30 | - super(message); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - /** | ||
| 34 | - * Constructs a JsonParsingException object. | ||
| 35 | - * @param message error message | ||
| 36 | - * @param cause Throwable | ||
| 37 | - */ | ||
| 38 | - public JsonParsingException(String message, Throwable cause) { | ||
| 39 | - super(message, cause); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - /** | ||
| 43 | - * Constructs a JsonParsingException object. | ||
| 44 | - * @param cause Throwable | ||
| 45 | - */ | ||
| 46 | - public JsonParsingException(Throwable cause) { | ||
| 47 | - super(cause); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - /** | ||
| 51 | - * Constructs a JsonParsingException object. | ||
| 52 | - * @param message error message | ||
| 53 | - * @param cause Throwable | ||
| 54 | - * @param enableSuppression enable Suppression | ||
| 55 | - * @param writableStackTrace writable StackTrace | ||
| 56 | - */ | ||
| 57 | - public JsonParsingException(String message, Throwable cause, | ||
| 58 | - boolean enableSuppression, | ||
| 59 | - boolean writableStackTrace) { | ||
| 60 | - super(message, cause, enableSuppression, writableStackTrace); | ||
| 61 | - } | ||
| 62 | -} |
ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/error/TypedSchemaException.java
deleted
100644 → 0
| 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.error; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * This is a generic exception thrown by the Typed Schema utilities. | ||
| 20 | - */ | ||
| 21 | -public class TypedSchemaException extends RuntimeException { | ||
| 22 | - private static final long serialVersionUID = -1452257990783176715L; | ||
| 23 | - | ||
| 24 | - /** | ||
| 25 | - * Constructs a TypedSchemaException object. | ||
| 26 | - * @param message error message | ||
| 27 | - */ | ||
| 28 | - public TypedSchemaException(String message) { | ||
| 29 | - super(message); | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * Constructs a TypedSchemaException object. | ||
| 34 | - * @param message error message | ||
| 35 | - * @param cause Throwable | ||
| 36 | - */ | ||
| 37 | - public TypedSchemaException(String message, Throwable cause) { | ||
| 38 | - super(message, cause); | ||
| 39 | - } | ||
| 40 | -} |
ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/error/UnsupportedEncodingException.java
deleted
100644 → 0
| 1 | -package org.onosproject.ovsdb.rfc.error; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * This exception is thrown when the encoding does not meet UTF-8 in RFC7047. | ||
| 5 | - */ | ||
| 6 | -public class UnsupportedEncodingException extends RuntimeException { | ||
| 7 | - private static final long serialVersionUID = -4865311369828520666L; | ||
| 8 | - | ||
| 9 | - /** | ||
| 10 | - * Constructs a UnsupportedEncodingException object. | ||
| 11 | - * @param message error message | ||
| 12 | - */ | ||
| 13 | - public UnsupportedEncodingException(String message) { | ||
| 14 | - super(message); | ||
| 15 | - } | ||
| 16 | -} |
| ... | @@ -16,26 +16,26 @@ | ... | @@ -16,26 +16,26 @@ |
| 16 | package org.onosproject.ovsdb.rfc.error; | 16 | package org.onosproject.ovsdb.rfc.error; |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | - * This exception is thrown when a result does not meet any of the known formats | 19 | + * This exception is thrown when the caller invoke the unsupported method or |
| 20 | - * in RFC7047. | 20 | + * use the encoding is not supported. |
| 21 | */ | 21 | */ |
| 22 | -public class UnknownResultException extends RuntimeException { | 22 | +public class UnsupportedException extends RuntimeException { |
| 23 | private static final long serialVersionUID = 1377011546616825375L; | 23 | private static final long serialVersionUID = 1377011546616825375L; |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | - * Constructs a UnknownResultException object. | 26 | + * Constructs a UnsupportedException object. |
| 27 | * @param message error message | 27 | * @param message error message |
| 28 | */ | 28 | */ |
| 29 | - public UnknownResultException(String message) { | 29 | + public UnsupportedException(String message) { |
| 30 | super(message); | 30 | super(message); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | - * Constructs a UnknownResultException object. | 34 | + * Constructs a UnsupportedException object. |
| 35 | * @param message error message | 35 | * @param message error message |
| 36 | * @param cause Throwable | 36 | * @param cause Throwable |
| 37 | */ | 37 | */ |
| 38 | - public UnknownResultException(String message, Throwable cause) { | 38 | + public UnsupportedException(String message, Throwable cause) { |
| 39 | super(message, cause); | 39 | super(message, cause); |
| 40 | } | 40 | } |
| 41 | } | 41 | } | ... | ... |
| ... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ovsdb.rfc.error; | 16 | package org.onosproject.ovsdb.rfc.error; |
| 17 | 17 | ||
| 18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 19 | 18 | ||
| 20 | /** | 19 | /** |
| 21 | * This exception is used when the a table or row is accessed though a typed | 20 | * This exception is used when the a table or row is accessed though a typed |
| ... | @@ -47,15 +46,9 @@ public class VersionMismatchException extends RuntimeException { | ... | @@ -47,15 +46,9 @@ public class VersionMismatchException extends RuntimeException { |
| 47 | * @param fromVersion the initial version | 46 | * @param fromVersion the initial version |
| 48 | * @return message | 47 | * @return message |
| 49 | */ | 48 | */ |
| 50 | - public static String createFromMessage(String actualVersion, | 49 | + public static String createFromMessage(String actualVersion, String fromVersion) { |
| 51 | - String fromVersion) { | 50 | + String message = "The fromVersion should less than the actualVersion.\n fromVersion: " |
| 52 | - String message = toStringHelper("VersionMismatchException") | 51 | + + fromVersion + ".\n" + "actualVersion: " + actualVersion; |
| 53 | - .addValue("The fromVersion should less than the actualVersion.\n" | ||
| 54 | - + "fromVersion: " | ||
| 55 | - + fromVersion | ||
| 56 | - + ".\n" | ||
| 57 | - + "actualVersion: " + actualVersion) | ||
| 58 | - .toString(); | ||
| 59 | return message; | 52 | return message; |
| 60 | } | 53 | } |
| 61 | 54 | ||
| ... | @@ -66,13 +59,8 @@ public class VersionMismatchException extends RuntimeException { | ... | @@ -66,13 +59,8 @@ public class VersionMismatchException extends RuntimeException { |
| 66 | * @return message | 59 | * @return message |
| 67 | */ | 60 | */ |
| 68 | public static String createToMessage(String actualVersion, String toVersion) { | 61 | public static String createToMessage(String actualVersion, String toVersion) { |
| 69 | - String message = toStringHelper("VersionMismatchException") | 62 | + String message = "The toVersion should greater than the actualVersion.\n" |
| 70 | - .addValue("The toVersion should greater than the required version.\n" | 63 | + + "toVersion: " + toVersion + ".\n" + " actualVersion: " + actualVersion; |
| 71 | - + "toVersion: " | ||
| 72 | - + toVersion | ||
| 73 | - + ".\n" | ||
| 74 | - + "Actual Version: " + actualVersion) | ||
| 75 | - .toString(); | ||
| 76 | return message; | 64 | return message; |
| 77 | } | 65 | } |
| 78 | } | 66 | } | ... | ... |
| ... | @@ -32,18 +32,18 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ... | @@ -32,18 +32,18 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 32 | */ | 32 | */ |
| 33 | @JsonDeserialize(converter = UpdateNotificationConverter.class) | 33 | @JsonDeserialize(converter = UpdateNotificationConverter.class) |
| 34 | public final class UpdateNotification { | 34 | public final class UpdateNotification { |
| 35 | - private final Object context; | 35 | + private final Object jsonValue; |
| 36 | private final JsonNode tbUpdatesJsonNode; | 36 | private final JsonNode tbUpdatesJsonNode; |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * Constructs a UpdateNotification object. | 39 | * Constructs a UpdateNotification object. |
| 40 | - * @param context the "json-value" in "params" of the result JsonNode | 40 | + * @param jsonValue the "json-value" in "params" of the result JsonNode |
| 41 | * @param tbUpdatesJsonNode the "table-updates" in "params" of the result JsonNode | 41 | * @param tbUpdatesJsonNode the "table-updates" in "params" of the result JsonNode |
| 42 | */ | 42 | */ |
| 43 | - public UpdateNotification(Object context, JsonNode tbUpdatesJsonNode) { | 43 | + public UpdateNotification(Object jsonValue, JsonNode tbUpdatesJsonNode) { |
| 44 | - checkNotNull(context, "context cannot be null"); | 44 | + checkNotNull(jsonValue, "jsonValue cannot be null"); |
| 45 | checkNotNull(tbUpdatesJsonNode, "tablebUpdates JsonNode cannot be null"); | 45 | checkNotNull(tbUpdatesJsonNode, "tablebUpdates JsonNode cannot be null"); |
| 46 | - this.context = context; | 46 | + this.jsonValue = jsonValue; |
| 47 | this.tbUpdatesJsonNode = tbUpdatesJsonNode; | 47 | this.tbUpdatesJsonNode = tbUpdatesJsonNode; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| ... | @@ -51,8 +51,8 @@ public final class UpdateNotification { | ... | @@ -51,8 +51,8 @@ public final class UpdateNotification { |
| 51 | * Return context. | 51 | * Return context. |
| 52 | * @return context | 52 | * @return context |
| 53 | */ | 53 | */ |
| 54 | - public Object context() { | 54 | + public Object jsonValue() { |
| 55 | - return context; | 55 | + return jsonValue; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| ... | @@ -65,7 +65,7 @@ public final class UpdateNotification { | ... | @@ -65,7 +65,7 @@ public final class UpdateNotification { |
| 65 | 65 | ||
| 66 | @Override | 66 | @Override |
| 67 | public int hashCode() { | 67 | public int hashCode() { |
| 68 | - return Objects.hash(context, tbUpdatesJsonNode); | 68 | + return Objects.hash(jsonValue, tbUpdatesJsonNode); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @Override | 71 | @Override |
| ... | @@ -75,7 +75,7 @@ public final class UpdateNotification { | ... | @@ -75,7 +75,7 @@ public final class UpdateNotification { |
| 75 | } | 75 | } |
| 76 | if (obj instanceof UpdateNotification) { | 76 | if (obj instanceof UpdateNotification) { |
| 77 | final UpdateNotification other = (UpdateNotification) obj; | 77 | final UpdateNotification other = (UpdateNotification) obj; |
| 78 | - return Objects.equals(this.context, other.context) | 78 | + return Objects.equals(this.jsonValue, other.jsonValue) |
| 79 | && Objects.equals(this.tbUpdatesJsonNode, | 79 | && Objects.equals(this.tbUpdatesJsonNode, |
| 80 | other.tbUpdatesJsonNode); | 80 | other.tbUpdatesJsonNode); |
| 81 | } | 81 | } |
| ... | @@ -84,7 +84,7 @@ public final class UpdateNotification { | ... | @@ -84,7 +84,7 @@ public final class UpdateNotification { |
| 84 | 84 | ||
| 85 | @Override | 85 | @Override |
| 86 | public String toString() { | 86 | public String toString() { |
| 87 | - return toStringHelper(this).add("context", context) | 87 | + return toStringHelper(this).add("jsonValue", jsonValue) |
| 88 | .add("tbUpdatesJsonNode", tbUpdatesJsonNode).toString(); | 88 | .add("tbUpdatesJsonNode", tbUpdatesJsonNode).toString(); |
| 89 | } | 89 | } |
| 90 | } | 90 | } | ... | ... |
| ... | @@ -20,27 +20,22 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -20,27 +20,22 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | 20 | ||
| 21 | import java.util.Objects; | 21 | import java.util.Objects; |
| 22 | 22 | ||
| 23 | -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; | ||
| 24 | - | ||
| 25 | -import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 26 | - | ||
| 27 | /** | 23 | /** |
| 28 | * Column is the basic element of the OpenVswitch database. | 24 | * Column is the basic element of the OpenVswitch database. |
| 29 | */ | 25 | */ |
| 30 | public final class Column { | 26 | public final class Column { |
| 31 | - @JsonIgnore | 27 | + private final String columnName; |
| 32 | - private final ColumnSchema schema; | ||
| 33 | private final Object data; | 28 | private final Object data; |
| 34 | 29 | ||
| 35 | /** | 30 | /** |
| 36 | * Column constructor. | 31 | * Column constructor. |
| 37 | - * @param schema the column schema | 32 | + * @param columnName the column name |
| 38 | * @param obj the data of the column | 33 | * @param obj the data of the column |
| 39 | */ | 34 | */ |
| 40 | - public Column(ColumnSchema schema, Object obj) { | 35 | + public Column(String columnName, Object obj) { |
| 41 | - checkNotNull(schema, "schema cannot be null"); | 36 | + checkNotNull(columnName, "columnName cannot be null"); |
| 42 | checkNotNull(obj, "data cannot be null"); | 37 | checkNotNull(obj, "data cannot be null"); |
| 43 | - this.schema = schema; | 38 | + this.columnName = columnName; |
| 44 | this.data = obj; | 39 | this.data = obj; |
| 45 | } | 40 | } |
| 46 | 41 | ||
| ... | @@ -53,16 +48,16 @@ public final class Column { | ... | @@ -53,16 +48,16 @@ public final class Column { |
| 53 | } | 48 | } |
| 54 | 49 | ||
| 55 | /** | 50 | /** |
| 56 | - * Returns ColumnSchema. | 51 | + * Returns columnName. |
| 57 | - * @return ColumnSchema | 52 | + * @return columnName |
| 58 | */ | 53 | */ |
| 59 | - public ColumnSchema schema() { | 54 | + public String columnName() { |
| 60 | - return schema; | 55 | + return columnName; |
| 61 | } | 56 | } |
| 62 | 57 | ||
| 63 | @Override | 58 | @Override |
| 64 | public int hashCode() { | 59 | public int hashCode() { |
| 65 | - return Objects.hash(schema, data); | 60 | + return Objects.hash(columnName, data); |
| 66 | } | 61 | } |
| 67 | 62 | ||
| 68 | @Override | 63 | @Override |
| ... | @@ -72,7 +67,7 @@ public final class Column { | ... | @@ -72,7 +67,7 @@ public final class Column { |
| 72 | } | 67 | } |
| 73 | if (obj instanceof Column) { | 68 | if (obj instanceof Column) { |
| 74 | final Column other = (Column) obj; | 69 | final Column other = (Column) obj; |
| 75 | - return Objects.equals(this.schema, other.schema) | 70 | + return Objects.equals(this.columnName, other.columnName) |
| 76 | && Objects.equals(this.data, other.data); | 71 | && Objects.equals(this.data, other.data); |
| 77 | } | 72 | } |
| 78 | return false; | 73 | return false; |
| ... | @@ -80,7 +75,7 @@ public final class Column { | ... | @@ -80,7 +75,7 @@ public final class Column { |
| 80 | 75 | ||
| 81 | @Override | 76 | @Override |
| 82 | public String toString() { | 77 | public String toString() { |
| 83 | - return toStringHelper(this).add("schema", schema).add("data", data) | 78 | + return toStringHelper(this).add("columnName", columnName) |
| 84 | - .toString(); | 79 | + .add("data", data).toString(); |
| 85 | } | 80 | } |
| 86 | } | 81 | } | ... | ... |
| ... | @@ -19,22 +19,16 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -19,22 +19,16 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | 20 | ||
| 21 | import java.util.Collection; | 21 | import java.util.Collection; |
| 22 | -import java.util.List; | ||
| 23 | import java.util.Map; | 22 | import java.util.Map; |
| 24 | import java.util.Objects; | 23 | import java.util.Objects; |
| 25 | 24 | ||
| 26 | -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; | ||
| 27 | -import org.onosproject.ovsdb.rfc.schema.TableSchema; | ||
| 28 | - | ||
| 29 | -import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 30 | import com.google.common.collect.Maps; | 25 | import com.google.common.collect.Maps; |
| 31 | 26 | ||
| 32 | /** | 27 | /** |
| 33 | * Row is the basic element of the OpenVswitch's table. | 28 | * Row is the basic element of the OpenVswitch's table. |
| 34 | */ | 29 | */ |
| 35 | public final class Row { | 30 | public final class Row { |
| 36 | - @JsonIgnore | 31 | + private String tableName; |
| 37 | - private TableSchema tableSchema; | ||
| 38 | private Map<String, Column> columns; | 32 | private Map<String, Column> columns; |
| 39 | 33 | ||
| 40 | /** | 34 | /** |
| ... | @@ -46,52 +40,49 @@ public final class Row { | ... | @@ -46,52 +40,49 @@ public final class Row { |
| 46 | 40 | ||
| 47 | /** | 41 | /** |
| 48 | * Row constructor. | 42 | * Row constructor. |
| 49 | - * @param tableSchema TableSchema entity | 43 | + * @param tableName table name |
| 50 | */ | 44 | */ |
| 51 | - public Row(TableSchema tableSchema) { | 45 | + public Row(String tableName) { |
| 52 | - checkNotNull(tableSchema, "tableSchema cannot be null"); | 46 | + checkNotNull(tableName, "tableName cannot be null"); |
| 53 | - this.tableSchema = tableSchema; | 47 | + this.tableName = tableName; |
| 54 | this.columns = Maps.newHashMap(); | 48 | this.columns = Maps.newHashMap(); |
| 55 | } | 49 | } |
| 56 | 50 | ||
| 57 | /** | 51 | /** |
| 58 | * Row constructor. | 52 | * Row constructor. |
| 59 | - * @param tableSchema TableSchema entity | 53 | + * @param tableName table name |
| 60 | - * @param columns List of Column entity | 54 | + * @param columns Map of Column entity |
| 61 | */ | 55 | */ |
| 62 | - public Row(TableSchema tableSchema, List<Column> columns) { | 56 | + public Row(String tableName, Map<String, Column> columns) { |
| 63 | - checkNotNull(tableSchema, "tableSchema cannot be null"); | 57 | + checkNotNull(tableName, "table name cannot be null"); |
| 64 | checkNotNull(columns, "columns cannot be null"); | 58 | checkNotNull(columns, "columns cannot be null"); |
| 65 | - this.tableSchema = tableSchema; | 59 | + this.tableName = tableName; |
| 66 | - this.columns = Maps.newHashMap(); | 60 | + this.columns = columns; |
| 67 | - for (Column column : columns) { | ||
| 68 | - this.columns.put(column.schema().name(), column); | ||
| 69 | - } | ||
| 70 | } | 61 | } |
| 71 | 62 | ||
| 72 | /** | 63 | /** |
| 73 | - * Returns tableSchema. | 64 | + * Returns tableName. |
| 74 | - * @return tableSchema | 65 | + * @return tableName |
| 75 | */ | 66 | */ |
| 76 | - public TableSchema getTableSchema() { | 67 | + public String tableName() { |
| 77 | - return tableSchema; | 68 | + return tableName; |
| 78 | } | 69 | } |
| 79 | 70 | ||
| 80 | /** | 71 | /** |
| 81 | - * Set tableSchema value. | 72 | + * Set tableName value. |
| 82 | - * @param tableSchema TableSchema entity | 73 | + * @param tableName table name |
| 83 | */ | 74 | */ |
| 84 | - public void setTableSchema(TableSchema tableSchema) { | 75 | + public void setTableName(String tableName) { |
| 85 | - this.tableSchema = tableSchema; | 76 | + this.tableName = tableName; |
| 86 | } | 77 | } |
| 87 | 78 | ||
| 88 | /** | 79 | /** |
| 89 | * Returns Column by ColumnSchema. | 80 | * Returns Column by ColumnSchema. |
| 90 | - * @param schema ColumnSchema entity | 81 | + * @param columnName column name |
| 91 | * @return Column | 82 | * @return Column |
| 92 | */ | 83 | */ |
| 93 | - public Column getColumn(ColumnSchema schema) { | 84 | + public Column getColumn(String columnName) { |
| 94 | - return (Column) columns.get(schema.name()); | 85 | + return columns.get(columnName); |
| 95 | } | 86 | } |
| 96 | 87 | ||
| 97 | /** | 88 | /** |
| ... | @@ -113,7 +104,7 @@ public final class Row { | ... | @@ -113,7 +104,7 @@ public final class Row { |
| 113 | 104 | ||
| 114 | @Override | 105 | @Override |
| 115 | public int hashCode() { | 106 | public int hashCode() { |
| 116 | - return Objects.hash(tableSchema, columns); | 107 | + return Objects.hash(tableName, columns); |
| 117 | } | 108 | } |
| 118 | 109 | ||
| 119 | @Override | 110 | @Override |
| ... | @@ -123,7 +114,7 @@ public final class Row { | ... | @@ -123,7 +114,7 @@ public final class Row { |
| 123 | } | 114 | } |
| 124 | if (obj instanceof Row) { | 115 | if (obj instanceof Row) { |
| 125 | final Row other = (Row) obj; | 116 | final Row other = (Row) obj; |
| 126 | - return Objects.equals(this.tableSchema, other.tableSchema) | 117 | + return Objects.equals(this.tableName, other.tableName) |
| 127 | && Objects.equals(this.columns, other.columns); | 118 | && Objects.equals(this.columns, other.columns); |
| 128 | } | 119 | } |
| 129 | return false; | 120 | return false; |
| ... | @@ -131,6 +122,7 @@ public final class Row { | ... | @@ -131,6 +122,7 @@ public final class Row { |
| 131 | 122 | ||
| 132 | @Override | 123 | @Override |
| 133 | public String toString() { | 124 | public String toString() { |
| 134 | - return toStringHelper(this).add("tableSchema", tableSchema).add("columns", columns).toString(); | 125 | + return toStringHelper(this).add("tableName", tableName) |
| 126 | + .add("columns", columns).toString(); | ||
| 135 | } | 127 | } |
| 136 | } | 128 | } | ... | ... |
| ... | @@ -72,6 +72,6 @@ public final class Delete implements Operation { | ... | @@ -72,6 +72,6 @@ public final class Delete implements Operation { |
| 72 | */ | 72 | */ |
| 73 | @JsonProperty | 73 | @JsonProperty |
| 74 | public String getTable() { | 74 | public String getTable() { |
| 75 | - return (tableSchema == null) ? null : tableSchema.name(); | 75 | + return tableSchema.name(); |
| 76 | } | 76 | } |
| 77 | } | 77 | } | ... | ... |
| ... | @@ -22,7 +22,6 @@ import java.util.Map; | ... | @@ -22,7 +22,6 @@ import java.util.Map; |
| 22 | 22 | ||
| 23 | import org.onosproject.ovsdb.rfc.notation.Column; | 23 | import org.onosproject.ovsdb.rfc.notation.Column; |
| 24 | import org.onosproject.ovsdb.rfc.notation.Row; | 24 | import org.onosproject.ovsdb.rfc.notation.Row; |
| 25 | -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; | ||
| 26 | import org.onosproject.ovsdb.rfc.schema.TableSchema; | 25 | import org.onosproject.ovsdb.rfc.schema.TableSchema; |
| 27 | import org.onosproject.ovsdb.rfc.utils.TransValueUtil; | 26 | import org.onosproject.ovsdb.rfc.utils.TransValueUtil; |
| 28 | 27 | ||
| ... | @@ -67,10 +66,10 @@ public final class Insert implements Operation { | ... | @@ -67,10 +66,10 @@ public final class Insert implements Operation { |
| 67 | private void generateOperationRow(Row row) { | 66 | private void generateOperationRow(Row row) { |
| 68 | Collection<Column> columns = row.getColumns(); | 67 | Collection<Column> columns = row.getColumns(); |
| 69 | for (Column column : columns) { | 68 | for (Column column : columns) { |
| 70 | - ColumnSchema columnSchema = column.schema(); | 69 | + String columnName = column.columnName(); |
| 71 | Object value = column.data(); | 70 | Object value = column.data(); |
| 72 | - Object untypedValue = TransValueUtil.getFormatData(value); | 71 | + Object formatValue = TransValueUtil.getFormatData(value); |
| 73 | - this.row.put(columnSchema.name(), untypedValue); | 72 | + this.row.put(columnName, formatValue); |
| 74 | } | 73 | } |
| 75 | } | 74 | } |
| 76 | 75 | ||
| ... | @@ -106,6 +105,6 @@ public final class Insert implements Operation { | ... | @@ -106,6 +105,6 @@ public final class Insert implements Operation { |
| 106 | */ | 105 | */ |
| 107 | @JsonProperty | 106 | @JsonProperty |
| 108 | public String getTable() { | 107 | public String getTable() { |
| 109 | - return (tableSchema == null) ? null : tableSchema.name(); | 108 | + return tableSchema.name(); |
| 110 | } | 109 | } |
| 111 | } | 110 | } | ... | ... |
| ... | @@ -86,6 +86,6 @@ public final class Mutate implements Operation { | ... | @@ -86,6 +86,6 @@ public final class Mutate implements Operation { |
| 86 | */ | 86 | */ |
| 87 | @JsonProperty | 87 | @JsonProperty |
| 88 | public String getTable() { | 88 | public String getTable() { |
| 89 | - return (tableSchema == null) ? null : tableSchema.name(); | 89 | + return tableSchema.name(); |
| 90 | } | 90 | } |
| 91 | } | 91 | } | ... | ... |
| ... | @@ -84,6 +84,6 @@ public final class Select implements Operation { | ... | @@ -84,6 +84,6 @@ public final class Select implements Operation { |
| 84 | */ | 84 | */ |
| 85 | @JsonProperty | 85 | @JsonProperty |
| 86 | public String getTable() { | 86 | public String getTable() { |
| 87 | - return (tableSchema == null) ? null : tableSchema.name(); | 87 | + return tableSchema.name(); |
| 88 | } | 88 | } |
| 89 | } | 89 | } | ... | ... |
| ... | @@ -24,7 +24,6 @@ import java.util.Map; | ... | @@ -24,7 +24,6 @@ import java.util.Map; |
| 24 | import org.onosproject.ovsdb.rfc.notation.Column; | 24 | import org.onosproject.ovsdb.rfc.notation.Column; |
| 25 | import org.onosproject.ovsdb.rfc.notation.Condition; | 25 | import org.onosproject.ovsdb.rfc.notation.Condition; |
| 26 | import org.onosproject.ovsdb.rfc.notation.Row; | 26 | import org.onosproject.ovsdb.rfc.notation.Row; |
| 27 | -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; | ||
| 28 | import org.onosproject.ovsdb.rfc.schema.TableSchema; | 27 | import org.onosproject.ovsdb.rfc.schema.TableSchema; |
| 29 | import org.onosproject.ovsdb.rfc.utils.TransValueUtil; | 28 | import org.onosproject.ovsdb.rfc.utils.TransValueUtil; |
| 30 | 29 | ||
| ... | @@ -68,10 +67,10 @@ public final class Update implements Operation { | ... | @@ -68,10 +67,10 @@ public final class Update implements Operation { |
| 68 | private void generateOperationRow(Row row) { | 67 | private void generateOperationRow(Row row) { |
| 69 | Collection<Column> columns = row.getColumns(); | 68 | Collection<Column> columns = row.getColumns(); |
| 70 | for (Column column : columns) { | 69 | for (Column column : columns) { |
| 71 | - ColumnSchema columnSchema = column.schema(); | 70 | + String columnName = column.columnName(); |
| 72 | Object value = column.data(); | 71 | Object value = column.data(); |
| 73 | - Object untypedValue = TransValueUtil.getFormatData(value); | 72 | + Object formatValue = TransValueUtil.getFormatData(value); |
| 74 | - this.row.put(columnSchema.name(), untypedValue); | 73 | + this.row.put(columnName, formatValue); |
| 75 | } | 74 | } |
| 76 | } | 75 | } |
| 77 | 76 | ||
| ... | @@ -107,6 +106,6 @@ public final class Update implements Operation { | ... | @@ -107,6 +106,6 @@ public final class Update implements Operation { |
| 107 | */ | 106 | */ |
| 108 | @JsonProperty | 107 | @JsonProperty |
| 109 | public String getTable() { | 108 | public String getTable() { |
| 110 | - return (tableSchema == null) ? null : tableSchema.name(); | 109 | + return tableSchema.name(); |
| 111 | } | 110 | } |
| 112 | } | 111 | } | ... | ... |
| ... | @@ -17,8 +17,9 @@ package org.onosproject.ovsdb.rfc.schema.type; | ... | @@ -17,8 +17,9 @@ package org.onosproject.ovsdb.rfc.schema.type; |
| 17 | 17 | ||
| 18 | import java.util.Set; | 18 | import java.util.Set; |
| 19 | 19 | ||
| 20 | -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; | 20 | +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException; |
| 21 | import org.onosproject.ovsdb.rfc.schema.type.UuidBaseType.RefType; | 21 | import org.onosproject.ovsdb.rfc.schema.type.UuidBaseType.RefType; |
| 22 | +import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; | ||
| 22 | 23 | ||
| 23 | import com.fasterxml.jackson.databind.JsonNode; | 24 | import com.fasterxml.jackson.databind.JsonNode; |
| 24 | import com.google.common.collect.Sets; | 25 | import com.google.common.collect.Sets; |
| ... | @@ -29,27 +30,29 @@ import com.google.common.collect.Sets; | ... | @@ -29,27 +30,29 @@ import com.google.common.collect.Sets; |
| 29 | public final class BaseTypeFactory { | 30 | public final class BaseTypeFactory { |
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| 32 | - * Constructs a BaseTypeFactory object. | 33 | + * Constructs a BaseTypeFactory object. This class should not be |
| 33 | - * This class should not be instantiated. | 34 | + * instantiated. |
| 34 | */ | 35 | */ |
| 35 | private BaseTypeFactory() { | 36 | private BaseTypeFactory() { |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | /** | 39 | /** |
| 39 | * Create a BaseType from the JsonNode. | 40 | * Create a BaseType from the JsonNode. |
| 40 | - * @param json the BaseType JsonNode | 41 | + * @param baseTypeJson the BaseType JsonNode |
| 41 | * @param keyorval the key node or value node | 42 | * @param keyorval the key node or value node |
| 42 | * @return BaseType | 43 | * @return BaseType |
| 43 | */ | 44 | */ |
| 44 | - public static BaseType getBaseTypeFromJson(JsonNode json, String keyorval) { | 45 | + public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) { |
| 45 | - if (json.isValueNode()) { | 46 | + if (baseTypeJson.isValueNode()) { |
| 46 | - String type = json.asText().trim(); | 47 | + String type = baseTypeJson.asText().trim(); |
| 47 | return fromTypeStr(type); | 48 | return fromTypeStr(type); |
| 48 | } else { | 49 | } else { |
| 49 | - if (!json.has(keyorval)) { | 50 | + if (!baseTypeJson.has(keyorval)) { |
| 50 | - throw new TypedSchemaException("not a type"); | 51 | + String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found" |
| 52 | + + ObjectMapperUtil.convertToString(baseTypeJson); | ||
| 53 | + throw new AbnormalJsonNodeException(message); | ||
| 51 | } | 54 | } |
| 52 | - return fromJsonNode(json.get(keyorval)); | 55 | + return fromJsonNode(baseTypeJson.get(keyorval)); |
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| 55 | 58 | ... | ... |
| ... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.ovsdb.rfc.schema.type; | 16 | package org.onosproject.ovsdb.rfc.schema.type; |
| 17 | 17 | ||
| 18 | -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; | 18 | +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException; |
| 19 | import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; | 19 | import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; |
| 20 | 20 | ||
| 21 | import com.fasterxml.jackson.databind.JsonNode; | 21 | import com.fasterxml.jackson.databind.JsonNode; |
| ... | @@ -26,8 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -26,8 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode; |
| 26 | public final class ColumnTypeFactory { | 26 | public final class ColumnTypeFactory { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | - * Constructs a ColumnTypeFactory object. | 29 | + * Constructs a ColumnTypeFactory object. This class should not be |
| 30 | - * This class should not be instantiated. | 30 | + * instantiated. |
| 31 | */ | 31 | */ |
| 32 | private ColumnTypeFactory() { | 32 | private ColumnTypeFactory() { |
| 33 | } | 33 | } |
| ... | @@ -54,20 +54,22 @@ public final class ColumnTypeFactory { | ... | @@ -54,20 +54,22 @@ public final class ColumnTypeFactory { |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | - * JsonNode like "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type": | 57 | + * JsonNode like |
| 58 | + * "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type": | ||
| 58 | * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max": | 59 | * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max": |
| 59 | * "unlimited"}}. | 60 | * "unlimited"}}. |
| 60 | - * @param json the ColumnType JsonNode | 61 | + * @param columnTypeJson the ColumnType JsonNode |
| 61 | * @return ColumnType | 62 | * @return ColumnType |
| 62 | */ | 63 | */ |
| 63 | - public static ColumnType getColumnTypeFromJson(JsonNode json) { | 64 | + public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) { |
| 64 | - if (!json.isObject() || !json.has(Type.VALUE.type())) { | 65 | + if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) { |
| 65 | - return createAtomicColumnType(json); | 66 | + return createAtomicColumnType(columnTypeJson); |
| 66 | - } else if (!json.isValueNode() && json.has(Type.VALUE.type())) { | 67 | + } else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) { |
| 67 | - return createKeyValuedColumnType(json); | 68 | + return createKeyValuedColumnType(columnTypeJson); |
| 68 | } | 69 | } |
| 69 | - throw new TypedSchemaException("could not find the right column type :" | 70 | + String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType" |
| 70 | - + ObjectMapperUtil.convertToString(json)); | 71 | + + ObjectMapperUtil.convertToString(columnTypeJson); |
| 72 | + throw new AbnormalJsonNodeException(message); | ||
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | /** | 75 | /** |
| ... | @@ -76,12 +78,11 @@ public final class ColumnTypeFactory { | ... | @@ -76,12 +78,11 @@ public final class ColumnTypeFactory { |
| 76 | * @return AtomicColumnType entity | 78 | * @return AtomicColumnType entity |
| 77 | */ | 79 | */ |
| 78 | private static AtomicColumnType createAtomicColumnType(JsonNode json) { | 80 | private static AtomicColumnType createAtomicColumnType(JsonNode json) { |
| 79 | - BaseType baseType = BaseTypeFactory | 81 | + BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); |
| 80 | - .getBaseTypeFromJson(json, Type.KEY.type()); | ||
| 81 | int min = 1; | 82 | int min = 1; |
| 82 | int max = 1; | 83 | int max = 1; |
| 83 | JsonNode node = json.get("min"); | 84 | JsonNode node = json.get("min"); |
| 84 | - if (node != null) { | 85 | + if (node != null && node.isNumber()) { |
| 85 | min = node.asInt(); | 86 | min = node.asInt(); |
| 86 | } | 87 | } |
| 87 | node = json.get("max"); | 88 | node = json.get("max"); |
| ... | @@ -101,14 +102,12 @@ public final class ColumnTypeFactory { | ... | @@ -101,14 +102,12 @@ public final class ColumnTypeFactory { |
| 101 | * @return KeyValuedColumnType entity | 102 | * @return KeyValuedColumnType entity |
| 102 | */ | 103 | */ |
| 103 | private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) { | 104 | private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) { |
| 104 | - BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, | 105 | + BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); |
| 105 | - Type.KEY.type()); | 106 | + BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type()); |
| 106 | - BaseType valueType = BaseTypeFactory | ||
| 107 | - .getBaseTypeFromJson(json, Type.VALUE.type()); | ||
| 108 | int min = 1; | 107 | int min = 1; |
| 109 | int max = 1; | 108 | int max = 1; |
| 110 | JsonNode node = json.get("min"); | 109 | JsonNode node = json.get("min"); |
| 111 | - if (node != null) { | 110 | + if (node != null && node.isNumber()) { |
| 112 | min = node.asInt(); | 111 | min = node.asInt(); |
| 113 | } | 112 | } |
| 114 | node = json.get("max"); | 113 | node = json.get("max"); | ... | ... |
| ... | @@ -22,7 +22,6 @@ import java.util.Objects; | ... | @@ -22,7 +22,6 @@ import java.util.Objects; |
| 22 | 22 | ||
| 23 | import org.onosproject.ovsdb.rfc.error.ColumnSchemaNotFoundException; | 23 | import org.onosproject.ovsdb.rfc.error.ColumnSchemaNotFoundException; |
| 24 | import org.onosproject.ovsdb.rfc.error.TableSchemaNotFoundException; | 24 | import org.onosproject.ovsdb.rfc.error.TableSchemaNotFoundException; |
| 25 | -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; | ||
| 26 | import org.onosproject.ovsdb.rfc.error.VersionMismatchException; | 25 | import org.onosproject.ovsdb.rfc.error.VersionMismatchException; |
| 27 | import org.onosproject.ovsdb.rfc.notation.Column; | 26 | import org.onosproject.ovsdb.rfc.notation.Column; |
| 28 | import org.onosproject.ovsdb.rfc.notation.Row; | 27 | import org.onosproject.ovsdb.rfc.notation.Row; |
| ... | @@ -50,17 +49,17 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -50,17 +49,17 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 50 | * @param table table name | 49 | * @param table table name |
| 51 | * @param formVersion the initial version | 50 | * @param formVersion the initial version |
| 52 | */ | 51 | */ |
| 53 | - public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, | 52 | + public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, OvsdbTable table, |
| 54 | - OvsdbTable table, VersionNum formVersion) { | 53 | + VersionNum formVersion) { |
| 55 | checkNotNull(dbSchema, "database schema cannot be null"); | 54 | checkNotNull(dbSchema, "database schema cannot be null"); |
| 56 | checkNotNull(row, "row cannot be null"); | 55 | checkNotNull(row, "row cannot be null"); |
| 57 | checkNotNull(table, "table cannot be null"); | 56 | checkNotNull(table, "table cannot be null"); |
| 58 | checkNotNull(formVersion, "the initial version cannot be null"); | 57 | checkNotNull(formVersion, "the initial version cannot be null"); |
| 59 | this.dbSchema = dbSchema; | 58 | this.dbSchema = dbSchema; |
| 59 | + row.setTableName(table.tableName()); | ||
| 60 | this.row = row; | 60 | this.row = row; |
| 61 | TableDescription tableDesc = new TableDescription(table, formVersion); | 61 | TableDescription tableDesc = new TableDescription(table, formVersion); |
| 62 | this.tableDesc = tableDesc; | 62 | this.tableDesc = tableDesc; |
| 63 | - row.setTableSchema(dbSchema.getTableSchema(table.tableName())); | ||
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | /** | 65 | /** |
| ... | @@ -107,21 +106,20 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -107,21 +106,20 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 107 | * @param untilVersion The end of the version | 106 | * @param untilVersion The end of the version |
| 108 | * @throws VersionMismatchException this is a version mismatch exception | 107 | * @throws VersionMismatchException this is a version mismatch exception |
| 109 | */ | 108 | */ |
| 110 | - private void checkVersion(String schemaVersion, String fromVersion, | 109 | + private void checkVersion(String schemaVersion, String fromVersion, String untilVersion) { |
| 111 | - String untilVersion) { | ||
| 112 | VersionUtil.versionMatch(fromVersion); | 110 | VersionUtil.versionMatch(fromVersion); |
| 113 | VersionUtil.versionMatch(untilVersion); | 111 | VersionUtil.versionMatch(untilVersion); |
| 114 | if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { | 112 | if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { |
| 115 | if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) { | 113 | if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) { |
| 116 | - String message = VersionMismatchException | 114 | + String message = VersionMismatchException.createFromMessage(schemaVersion, |
| 117 | - .createFromMessage(schemaVersion, fromVersion); | 115 | + fromVersion); |
| 118 | throw new VersionMismatchException(message); | 116 | throw new VersionMismatchException(message); |
| 119 | } | 117 | } |
| 120 | } | 118 | } |
| 121 | if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { | 119 | if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { |
| 122 | if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) { | 120 | if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) { |
| 123 | - String message = VersionMismatchException | 121 | + String message = VersionMismatchException.createToMessage(schemaVersion, |
| 124 | - .createToMessage(schemaVersion, untilVersion); | 122 | + untilVersion); |
| 125 | throw new VersionMismatchException(message); | 123 | throw new VersionMismatchException(message); |
| 126 | } | 124 | } |
| 127 | } | 125 | } |
| ... | @@ -138,13 +136,23 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -138,13 +136,23 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 138 | 136 | ||
| 139 | /** | 137 | /** |
| 140 | * Returns ColumnSchema from TableSchema by column name. | 138 | * Returns ColumnSchema from TableSchema by column name. |
| 141 | - * @param tableSchema TableSchema entity | ||
| 142 | * @param columnName column name | 139 | * @param columnName column name |
| 143 | * @return ColumnSchema | 140 | * @return ColumnSchema |
| 144 | */ | 141 | */ |
| 145 | - private ColumnSchema getColumnSchema(TableSchema tableSchema, | 142 | + private ColumnSchema getColumnSchema(String columnName) { |
| 146 | - String columnName) { | 143 | + TableSchema tableSchema = getTableSchema(); |
| 147 | - return tableSchema.getColumnSchema(columnName); | 144 | + if (tableSchema == null) { |
| 145 | + String message = TableSchemaNotFoundException.createMessage(tableDesc.name(), | ||
| 146 | + dbSchema.name()); | ||
| 147 | + throw new TableSchemaNotFoundException(message); | ||
| 148 | + } | ||
| 149 | + ColumnSchema columnSchema = tableSchema.getColumnSchema(columnName); | ||
| 150 | + if (columnSchema == null) { | ||
| 151 | + String message = ColumnSchemaNotFoundException.createMessage(columnName, | ||
| 152 | + tableSchema.name()); | ||
| 153 | + throw new ColumnSchemaNotFoundException(message); | ||
| 154 | + } | ||
| 155 | + return columnSchema; | ||
| 148 | } | 156 | } |
| 149 | 157 | ||
| 150 | @Override | 158 | @Override |
| ... | @@ -154,26 +162,11 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -154,26 +162,11 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 154 | } | 162 | } |
| 155 | String columnName = columnDesc.name(); | 163 | String columnName = columnDesc.name(); |
| 156 | checkColumnSchemaVersion(columnDesc); | 164 | checkColumnSchemaVersion(columnDesc); |
| 157 | - if (columnName == null) { | 165 | + ColumnSchema columnSchema = getColumnSchema(columnName); |
| 158 | - throw new TypedSchemaException("Error processing GetColumn : " | ||
| 159 | - + tableDesc.name() + "." + columnDesc.method()); | ||
| 160 | - } | ||
| 161 | - TableSchema tableSchema = getTableSchema(); | ||
| 162 | - if (tableSchema == null) { | ||
| 163 | - String message = TableSchemaNotFoundException | ||
| 164 | - .createMessage(tableDesc.name(), dbSchema.name()); | ||
| 165 | - throw new TableSchemaNotFoundException(message); | ||
| 166 | - } | ||
| 167 | - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); | ||
| 168 | - if (columnSchema == null) { | ||
| 169 | - String message = ColumnSchemaNotFoundException | ||
| 170 | - .createMessage(columnName, tableSchema.name()); | ||
| 171 | - throw new ColumnSchemaNotFoundException(message); | ||
| 172 | - } | ||
| 173 | if (row == null) { | 166 | if (row == null) { |
| 174 | - return new Column(columnSchema, null); | 167 | + return null; |
| 175 | } | 168 | } |
| 176 | - return row.getColumn(columnSchema); | 169 | + return row.getColumn(columnSchema.name()); |
| 177 | } | 170 | } |
| 178 | 171 | ||
| 179 | @Override | 172 | @Override |
| ... | @@ -183,26 +176,11 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -183,26 +176,11 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 183 | } | 176 | } |
| 184 | String columnName = columnDesc.name(); | 177 | String columnName = columnDesc.name(); |
| 185 | checkColumnSchemaVersion(columnDesc); | 178 | checkColumnSchemaVersion(columnDesc); |
| 186 | - if (columnName == null) { | 179 | + ColumnSchema columnSchema = getColumnSchema(columnName); |
| 187 | - throw new TypedSchemaException("Error processing GetColumn : " | 180 | + if (row == null || row.getColumn(columnSchema.name()) == null) { |
| 188 | - + tableDesc.name() + "." + columnDesc.method()); | ||
| 189 | - } | ||
| 190 | - TableSchema tableSchema = getTableSchema(); | ||
| 191 | - if (tableSchema == null) { | ||
| 192 | - String message = TableSchemaNotFoundException | ||
| 193 | - .createMessage(tableDesc.name(), dbSchema.name()); | ||
| 194 | - throw new TableSchemaNotFoundException(message); | ||
| 195 | - } | ||
| 196 | - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); | ||
| 197 | - if (columnSchema == null) { | ||
| 198 | - String message = ColumnSchemaNotFoundException | ||
| 199 | - .createMessage(columnName, tableSchema.name()); | ||
| 200 | - throw new ColumnSchemaNotFoundException(message); | ||
| 201 | - } | ||
| 202 | - if (row == null || row.getColumn(columnSchema) == null) { | ||
| 203 | return null; | 181 | return null; |
| 204 | } | 182 | } |
| 205 | - return row.getColumn(columnSchema).data(); | 183 | + return row.getColumn(columnSchema.name()).data(); |
| 206 | } | 184 | } |
| 207 | 185 | ||
| 208 | @Override | 186 | @Override |
| ... | @@ -212,64 +190,44 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -212,64 +190,44 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 212 | } | 190 | } |
| 213 | String columnName = columnDesc.name(); | 191 | String columnName = columnDesc.name(); |
| 214 | checkColumnSchemaVersion(columnDesc); | 192 | checkColumnSchemaVersion(columnDesc); |
| 215 | - if (columnName == null) { | 193 | + ColumnSchema columnSchema = getColumnSchema(columnName); |
| 216 | - throw new TypedSchemaException("Unable to locate Column Name for " | 194 | + Column column = new Column(columnSchema.name(), obj); |
| 217 | - + tableDesc.name() + "." + columnDesc.method()); | ||
| 218 | - } | ||
| 219 | - TableSchema tableSchema = getTableSchema(); | ||
| 220 | - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); | ||
| 221 | - Column column = new Column(columnSchema, obj); | ||
| 222 | row.addColumn(columnName, column); | 195 | row.addColumn(columnName, column); |
| 223 | } | 196 | } |
| 224 | 197 | ||
| 225 | @Override | 198 | @Override |
| 226 | - public Object getTbSchema() { | 199 | + public UUID getTableUuid() { |
| 227 | - if (!isValid()) { | ||
| 228 | - return null; | ||
| 229 | - } | ||
| 230 | - if (dbSchema == null) { | ||
| 231 | - return null; | ||
| 232 | - } | ||
| 233 | - return getTableSchema(); | ||
| 234 | - } | ||
| 235 | - | ||
| 236 | - @Override | ||
| 237 | - public UUID getUuid() { | ||
| 238 | if (!isValid()) { | 200 | if (!isValid()) { |
| 239 | return null; | 201 | return null; |
| 240 | } | 202 | } |
| 241 | - ColumnDescription columnDesc = new ColumnDescription("_uuid", | 203 | + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuid"); |
| 242 | - "getTbUuid"); | ||
| 243 | return (UUID) getDataHandler(columnDesc); | 204 | return (UUID) getDataHandler(columnDesc); |
| 244 | } | 205 | } |
| 245 | 206 | ||
| 246 | @Override | 207 | @Override |
| 247 | - public Column getUuidColumn() { | 208 | + public Column getTableUuidColumn() { |
| 248 | if (!isValid()) { | 209 | if (!isValid()) { |
| 249 | return null; | 210 | return null; |
| 250 | } | 211 | } |
| 251 | - ColumnDescription columnDesc = new ColumnDescription("_uuid", | 212 | + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn"); |
| 252 | - "getTbUuidColumn"); | ||
| 253 | return (Column) getColumnHandler(columnDesc); | 213 | return (Column) getColumnHandler(columnDesc); |
| 254 | } | 214 | } |
| 255 | 215 | ||
| 256 | @Override | 216 | @Override |
| 257 | - public UUID getVersion() { | 217 | + public UUID getTableVersion() { |
| 258 | if (!isValid()) { | 218 | if (!isValid()) { |
| 259 | return null; | 219 | return null; |
| 260 | } | 220 | } |
| 261 | - ColumnDescription columnDesc = new ColumnDescription("_version", | 221 | + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersion"); |
| 262 | - "getTbVersion"); | ||
| 263 | return (UUID) getDataHandler(columnDesc); | 222 | return (UUID) getDataHandler(columnDesc); |
| 264 | } | 223 | } |
| 265 | 224 | ||
| 266 | @Override | 225 | @Override |
| 267 | - public Column getVersionColumn() { | 226 | + public Column getTableVersionColumn() { |
| 268 | if (!isValid()) { | 227 | if (!isValid()) { |
| 269 | return null; | 228 | return null; |
| 270 | } | 229 | } |
| 271 | - ColumnDescription columnDesc = new ColumnDescription("_version", | 230 | + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn"); |
| 272 | - "getTbVersionColumn"); | ||
| 273 | return (Column) getColumnHandler(columnDesc); | 231 | return (Column) getColumnHandler(columnDesc); |
| 274 | } | 232 | } |
| 275 | 233 | ||
| ... | @@ -319,9 +277,8 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { | ... | @@ -319,9 +277,8 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { |
| 319 | 277 | ||
| 320 | @Override | 278 | @Override |
| 321 | public String toString() { | 279 | public String toString() { |
| 322 | - TableSchema schema = (TableSchema) getTbSchema(); | 280 | + TableSchema schema = (TableSchema) getTableSchema(); |
| 323 | String tableName = schema.name(); | 281 | String tableName = schema.name(); |
| 324 | - return toStringHelper(this).add("tableName", tableName).add("row", row) | 282 | + return toStringHelper(this).add("tableName", tableName).add("row", row).toString(); |
| 325 | - .toString(); | ||
| 326 | } | 283 | } |
| 327 | } | 284 | } | ... | ... |
| ... | @@ -45,32 +45,26 @@ public interface OvsdbTableService { | ... | @@ -45,32 +45,26 @@ public interface OvsdbTableService { |
| 45 | public void setDataHandler(ColumnDescription columndesc, Object obj); | 45 | public void setDataHandler(ColumnDescription columndesc, Object obj); |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | - * Returns the TableSchema from row. | ||
| 49 | - * @return Object TableSchema | ||
| 50 | - */ | ||
| 51 | - public Object getTbSchema(); | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | * Returns UUID which column name is _uuid. | 48 | * Returns UUID which column name is _uuid. |
| 55 | * @return UUID | 49 | * @return UUID |
| 56 | */ | 50 | */ |
| 57 | - public UUID getUuid(); | 51 | + public UUID getTableUuid(); |
| 58 | 52 | ||
| 59 | /** | 53 | /** |
| 60 | * Returns UUID Column which column name is _uuid. | 54 | * Returns UUID Column which column name is _uuid. |
| 61 | * @return UUID Column | 55 | * @return UUID Column |
| 62 | */ | 56 | */ |
| 63 | - public Column getUuidColumn(); | 57 | + public Column getTableUuidColumn(); |
| 64 | 58 | ||
| 65 | /** | 59 | /** |
| 66 | * Returns UUID which column name is _version. | 60 | * Returns UUID which column name is _version. |
| 67 | * @return UUID | 61 | * @return UUID |
| 68 | */ | 62 | */ |
| 69 | - public UUID getVersion(); | 63 | + public UUID getTableVersion(); |
| 70 | 64 | ||
| 71 | /** | 65 | /** |
| 72 | * Returns UUID Column which column name is _version. | 66 | * Returns UUID Column which column name is _version. |
| 73 | * @return UUID Column | 67 | * @return UUID Column |
| 74 | */ | 68 | */ |
| 75 | - public Column getVersionColumn(); | 69 | + public Column getTableVersionColumn(); |
| 76 | } | 70 | } | ... | ... |
| ... | @@ -20,11 +20,9 @@ import java.util.HashMap; | ... | @@ -20,11 +20,9 @@ import java.util.HashMap; |
| 20 | import java.util.Iterator; | 20 | import java.util.Iterator; |
| 21 | import java.util.List; | 21 | import java.util.List; |
| 22 | import java.util.Map; | 22 | import java.util.Map; |
| 23 | -import java.util.Map.Entry; | ||
| 24 | 23 | ||
| 25 | -import org.onosproject.ovsdb.rfc.error.AbnormalSchemaException; | 24 | +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException; |
| 26 | -import org.onosproject.ovsdb.rfc.error.JsonParsingException; | 25 | +import org.onosproject.ovsdb.rfc.error.UnsupportedException; |
| 27 | -import org.onosproject.ovsdb.rfc.error.UnknownResultException; | ||
| 28 | import org.onosproject.ovsdb.rfc.jsonrpc.Callback; | 26 | import org.onosproject.ovsdb.rfc.jsonrpc.Callback; |
| 29 | import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse; | 27 | import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse; |
| 30 | import org.onosproject.ovsdb.rfc.message.OperationResult; | 28 | import org.onosproject.ovsdb.rfc.message.OperationResult; |
| ... | @@ -54,90 +52,77 @@ import com.google.common.collect.Maps; | ... | @@ -54,90 +52,77 @@ import com.google.common.collect.Maps; |
| 54 | */ | 52 | */ |
| 55 | public final class FromJsonUtil { | 53 | public final class FromJsonUtil { |
| 56 | 54 | ||
| 57 | - private static final Logger log = LoggerFactory | 55 | + private static final Logger log = LoggerFactory.getLogger(FromJsonUtil.class); |
| 58 | - .getLogger(FromJsonUtil.class); | ||
| 59 | 56 | ||
| 60 | /** | 57 | /** |
| 61 | * Constructs a FromJsonUtil object. Utility classes should not have a | 58 | * Constructs a FromJsonUtil object. Utility classes should not have a |
| 62 | - * public or default constructor, otherwise IDE will compile unsuccessfully. This | 59 | + * public or default constructor, otherwise IDE will compile unsuccessfully. |
| 63 | - * class should not be instantiated. | 60 | + * This class should not be instantiated. |
| 64 | */ | 61 | */ |
| 65 | private FromJsonUtil() { | 62 | private FromJsonUtil() { |
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | /** | 65 | /** |
| 69 | - * convert JsonNode into DatabaseSchema. | 66 | + * Verify whether the jsonNode is normal. |
| 70 | - * @param dbName database name | 67 | + * @param jsonNode JsonNode |
| 71 | - * @param json the JsonNode of get_schema result | 68 | + * @param nodeStr the node name of JsonNode |
| 72 | - * @return DatabaseSchema | ||
| 73 | - * @throws JsonParsingException this is a JsonNode parse exception | ||
| 74 | */ | 69 | */ |
| 75 | - public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode json) { | 70 | + private static void validateJsonNode(JsonNode jsonNode, String nodeStr) { |
| 76 | - if (!json.isObject() || !json.has("tables")) { | 71 | + if (!jsonNode.isObject() || !jsonNode.has(nodeStr)) { |
| 77 | - throw new JsonParsingException( | 72 | + String message = "Abnormal DatabaseSchema JsonNode, it should contain " + nodeStr |
| 78 | - "bad DatabaseSchema root, expected \"tables\" as child but was not found"); | 73 | + + " node but was not found"; |
| 74 | + throw new AbnormalJsonNodeException(message); | ||
| 79 | } | 75 | } |
| 80 | - if (!json.isObject() || !json.has("version")) { | ||
| 81 | - throw new JsonParsingException( | ||
| 82 | - "bad DatabaseSchema root, expected \"version\" as child but was not found"); | ||
| 83 | } | 76 | } |
| 84 | 77 | ||
| 85 | - String dbVersion = json.get("version").asText(); | 78 | + /** |
| 86 | - | 79 | + * convert JsonNode into DatabaseSchema. |
| 80 | + * @param dbName database name | ||
| 81 | + * @param dbJson the JsonNode of get_schema result | ||
| 82 | + * @return DatabaseSchema | ||
| 83 | + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception | ||
| 84 | + */ | ||
| 85 | + public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode dbJson) { | ||
| 86 | + validateJsonNode(dbJson, "tables"); | ||
| 87 | + validateJsonNode(dbJson, "version"); | ||
| 88 | + String dbVersion = dbJson.get("version").asText(); | ||
| 87 | Map<String, TableSchema> tables = new HashMap<>(); | 89 | Map<String, TableSchema> tables = new HashMap<>(); |
| 88 | - for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("tables") | 90 | + Iterator<Map.Entry<String, JsonNode>> tablesIter = dbJson.get("tables").fields(); |
| 89 | - .fields(); iter.hasNext();) { | 91 | + while (tablesIter.hasNext()) { |
| 90 | - Map.Entry<String, JsonNode> table = iter.next(); | 92 | + Map.Entry<String, JsonNode> table = tablesIter.next(); |
| 91 | - tables.put(table.getKey(), | 93 | + tables.put(table.getKey(), jsonNodeToTableSchema(table.getKey(), table.getValue())); |
| 92 | - jsonNodeToTableSchema(table.getKey(), table.getValue())); | ||
| 93 | } | 94 | } |
| 94 | - | ||
| 95 | return new DatabaseSchema(dbName, dbVersion, tables); | 95 | return new DatabaseSchema(dbName, dbVersion, tables); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | * convert JsonNode into TableSchema. | 99 | * convert JsonNode into TableSchema. |
| 100 | * @param tableName table name | 100 | * @param tableName table name |
| 101 | - * @param json table JsonNode | 101 | + * @param tableJson table JsonNode |
| 102 | * @return TableSchema | 102 | * @return TableSchema |
| 103 | - * @throws AbnormalSchemaException this is an abnormal schema exception | 103 | + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception |
| 104 | */ | 104 | */ |
| 105 | - private static TableSchema jsonNodeToTableSchema(String tableName, | 105 | + private static TableSchema jsonNodeToTableSchema(String tableName, JsonNode tableJson) { |
| 106 | - JsonNode json) { | 106 | + validateJsonNode(tableJson, "columns"); |
| 107 | - | ||
| 108 | - if (!json.isObject() || !json.has("columns")) { | ||
| 109 | - throw new AbnormalSchemaException( | ||
| 110 | - "bad tableschema root, expected \"columns\" as child"); | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | Map<String, ColumnSchema> columns = new HashMap<>(); | 107 | Map<String, ColumnSchema> columns = new HashMap<>(); |
| 114 | - for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns") | 108 | + Iterator<Map.Entry<String, JsonNode>> columnsIter = tableJson.get("columns").fields(); |
| 115 | - .fields(); iter.hasNext();) { | 109 | + while (columnsIter.hasNext()) { |
| 116 | - Map.Entry<String, JsonNode> column = iter.next(); | 110 | + Map.Entry<String, JsonNode> column = columnsIter.next(); |
| 117 | - columns.put(column.getKey(), | 111 | + columns.put(column.getKey(), jsonNodeToColumnSchema(column.getKey(), column.getValue())); |
| 118 | - jsonNodeToColumnSchema(column.getKey(), | ||
| 119 | - column.getValue())); | ||
| 120 | } | 112 | } |
| 121 | - | ||
| 122 | return new TableSchema(tableName, columns); | 113 | return new TableSchema(tableName, columns); |
| 123 | } | 114 | } |
| 124 | 115 | ||
| 125 | /** | 116 | /** |
| 126 | * convert JsonNode into ColumnSchema. | 117 | * convert JsonNode into ColumnSchema. |
| 127 | * @param name column name | 118 | * @param name column name |
| 128 | - * @param json JsonNode | 119 | + * @param columnJson column JsonNode |
| 129 | * @return ColumnSchema | 120 | * @return ColumnSchema |
| 130 | - * @throws AbnormalSchemaException this is an abnormal schema exception | 121 | + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception |
| 131 | */ | 122 | */ |
| 132 | - private static ColumnSchema jsonNodeToColumnSchema(String name, | 123 | + private static ColumnSchema jsonNodeToColumnSchema(String name, JsonNode columnJson) { |
| 133 | - JsonNode json) { | 124 | + validateJsonNode(columnJson, "type"); |
| 134 | - if (!json.isObject() || !json.has("type")) { | 125 | + return new ColumnSchema(name, ColumnTypeFactory.getColumnTypeFromJson(columnJson |
| 135 | - throw new AbnormalSchemaException( | ||
| 136 | - "bad column schema root, expected \"type\" as child"); | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - return new ColumnSchema(name, | ||
| 140 | - ColumnTypeFactory.getColumnTypeFromJson(json | ||
| 141 | .get("type"))); | 126 | .get("type"))); |
| 142 | } | 127 | } |
| 143 | 128 | ||
| ... | @@ -147,10 +132,9 @@ public final class FromJsonUtil { | ... | @@ -147,10 +132,9 @@ public final class FromJsonUtil { |
| 147 | * @param methodName the method name of methods in OvsdbRPC class | 132 | * @param methodName the method name of methods in OvsdbRPC class |
| 148 | * @param objectMapper ObjectMapper entity | 133 | * @param objectMapper ObjectMapper entity |
| 149 | * @return Object | 134 | * @return Object |
| 150 | - * @throws UnknownResultException this is an unknown result exception | 135 | + * @throws UnsupportedException this is an unsupported exception |
| 151 | */ | 136 | */ |
| 152 | - private static Object convertResultType(JsonNode resultJsonNode, | 137 | + private static Object convertResultType(JsonNode resultJsonNode, String methodName, |
| 153 | - String methodName, | ||
| 154 | ObjectMapper objectMapper) { | 138 | ObjectMapper objectMapper) { |
| 155 | switch (methodName) { | 139 | switch (methodName) { |
| 156 | case "getSchema": | 140 | case "getSchema": |
| ... | @@ -158,18 +142,13 @@ public final class FromJsonUtil { | ... | @@ -158,18 +142,13 @@ public final class FromJsonUtil { |
| 158 | return resultJsonNode; | 142 | return resultJsonNode; |
| 159 | case "echo": | 143 | case "echo": |
| 160 | case "listDbs": | 144 | case "listDbs": |
| 161 | - return objectMapper | 145 | + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory() |
| 162 | - .convertValue(resultJsonNode, objectMapper.getTypeFactory() | ||
| 163 | .constructParametricType(List.class, String.class)); | 146 | .constructParametricType(List.class, String.class)); |
| 164 | case "transact": | 147 | case "transact": |
| 165 | - return objectMapper | 148 | + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory() |
| 166 | - .convertValue(resultJsonNode, | 149 | + .constructParametricType(List.class, JsonNode.class)); |
| 167 | - objectMapper | ||
| 168 | - .getTypeFactory() | ||
| 169 | - .constructParametricType(List.class, | ||
| 170 | - JsonNode.class)); | ||
| 171 | default: | 150 | default: |
| 172 | - throw new UnknownResultException("Don't know how to handle this"); | 151 | + throw new UnsupportedException("does not support this rpc method" + methodName); |
| 173 | } | 152 | } |
| 174 | } | 153 | } |
| 175 | 154 | ||
| ... | @@ -183,11 +162,10 @@ public final class FromJsonUtil { | ... | @@ -183,11 +162,10 @@ public final class FromJsonUtil { |
| 183 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); | 162 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); |
| 184 | JsonNode error = jsonNode.get("error"); | 163 | JsonNode error = jsonNode.get("error"); |
| 185 | if (error != null && !error.isNull()) { | 164 | if (error != null && !error.isNull()) { |
| 186 | - log.error("Error : {}", error.toString()); | 165 | + log.error("jsonRpcResponse error : {}", error.toString()); |
| 187 | } | 166 | } |
| 188 | JsonNode resultJsonNode = jsonNode.get("result"); | 167 | JsonNode resultJsonNode = jsonNode.get("result"); |
| 189 | - Object result = convertResultType(resultJsonNode, methodName, | 168 | + Object result = convertResultType(resultJsonNode, methodName, objectMapper); |
| 190 | - objectMapper); | ||
| 191 | return result; | 169 | return result; |
| 192 | } | 170 | } |
| 193 | 171 | ||
| ... | @@ -196,10 +174,9 @@ public final class FromJsonUtil { | ... | @@ -196,10 +174,9 @@ public final class FromJsonUtil { |
| 196 | * notification, then call callback function. | 174 | * notification, then call callback function. |
| 197 | * @param jsonNode the result JsonNode | 175 | * @param jsonNode the result JsonNode |
| 198 | * @param callback the callback function | 176 | * @param callback the callback function |
| 199 | - * @throws UnknownResultException this is an unknown result exception | 177 | + * @throws UnsupportedException this is an unsupported exception |
| 200 | */ | 178 | */ |
| 201 | - public static void jsonCallbackRequestParser(JsonNode jsonNode, | 179 | + public static void jsonCallbackRequestParser(JsonNode jsonNode, Callback callback) { |
| 202 | - Callback callback) { | ||
| 203 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); | 180 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); |
| 204 | JsonNode params = jsonNode.get("params"); | 181 | JsonNode params = jsonNode.get("params"); |
| 205 | Object param = null; | 182 | Object param = null; |
| ... | @@ -210,8 +187,7 @@ public final class FromJsonUtil { | ... | @@ -210,8 +187,7 @@ public final class FromJsonUtil { |
| 210 | callback.update((UpdateNotification) param); | 187 | callback.update((UpdateNotification) param); |
| 211 | break; | 188 | break; |
| 212 | default: | 189 | default: |
| 213 | - throw new UnknownResultException("Cannot handle this method: " | 190 | + throw new UnsupportedException("does not support this callback method: " + methodName); |
| 214 | - + methodName); | ||
| 215 | } | 191 | } |
| 216 | } | 192 | } |
| 217 | 193 | ||
| ... | @@ -224,12 +200,11 @@ public final class FromJsonUtil { | ... | @@ -224,12 +200,11 @@ public final class FromJsonUtil { |
| 224 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); | 200 | ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); |
| 225 | String str = null; | 201 | String str = null; |
| 226 | if (jsonNode.get("method").asText().equals("echo")) { | 202 | if (jsonNode.get("method").asText().equals("echo")) { |
| 227 | - JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id") | 203 | + JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id").asText()); |
| 228 | - .asText()); | ||
| 229 | try { | 204 | try { |
| 230 | str = objectMapper.writeValueAsString(response); | 205 | str = objectMapper.writeValueAsString(response); |
| 231 | } catch (JsonProcessingException e) { | 206 | } catch (JsonProcessingException e) { |
| 232 | - log.error("JsonProcessingException while converting JsonNode into string ", e); | 207 | + log.error("JsonProcessingException while converting JsonNode into string: ", e); |
| 233 | } | 208 | } |
| 234 | } | 209 | } |
| 235 | return str; | 210 | return str; |
| ... | @@ -250,8 +225,7 @@ public final class FromJsonUtil { | ... | @@ -250,8 +225,7 @@ public final class FromJsonUtil { |
| 250 | Operation operation = operations.get(i); | 225 | Operation operation = operations.get(i); |
| 251 | if (jsonNode != null && jsonNode.size() > 0) { | 226 | if (jsonNode != null && jsonNode.size() > 0) { |
| 252 | if (i >= operations.size() || operation.getOp() != "select") { | 227 | if (i >= operations.size() || operation.getOp() != "select") { |
| 253 | - OperationResult or = objectMapper.convertValue(jsonNode, | 228 | + OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class); |
| 254 | - OperationResult.class); | ||
| 255 | operationResults.add(or); | 229 | operationResults.add(or); |
| 256 | } else { | 230 | } else { |
| 257 | List<Row> rows = createRows(operation.getTableSchema(), jsonNode); | 231 | List<Row> rows = createRows(operation.getTableSchema(), jsonNode); |
| ... | @@ -269,8 +243,8 @@ public final class FromJsonUtil { | ... | @@ -269,8 +243,8 @@ public final class FromJsonUtil { |
| 269 | * @param rowsNode JsonNode | 243 | * @param rowsNode JsonNode |
| 270 | * @return ArrayList<Row> the List of Row | 244 | * @return ArrayList<Row> the List of Row |
| 271 | */ | 245 | */ |
| 272 | - private static ArrayList<Row> createRows(TableSchema tableSchema, | 246 | + private static ArrayList<Row> createRows(TableSchema tableSchema, JsonNode rowsNode) { |
| 273 | - JsonNode rowsNode) { | 247 | + validateJsonNode(rowsNode, "rows"); |
| 274 | ArrayList<Row> rows = Lists.newArrayList(); | 248 | ArrayList<Row> rows = Lists.newArrayList(); |
| 275 | for (JsonNode rowNode : rowsNode.get("rows")) { | 249 | for (JsonNode rowNode : rowsNode.get("rows")) { |
| 276 | rows.add(createRow(tableSchema, rowNode)); | 250 | rows.add(createRow(tableSchema, rowNode)); |
| ... | @@ -284,15 +258,13 @@ public final class FromJsonUtil { | ... | @@ -284,15 +258,13 @@ public final class FromJsonUtil { |
| 284 | * @param dbSchema DatabaseSchema entity | 258 | * @param dbSchema DatabaseSchema entity |
| 285 | * @return TableUpdates | 259 | * @return TableUpdates |
| 286 | */ | 260 | */ |
| 287 | - public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, | 261 | + public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, DatabaseSchema dbSchema) { |
| 288 | - DatabaseSchema dbSchema) { | ||
| 289 | Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap(); | 262 | Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap(); |
| 290 | - for (Iterator<Map.Entry<String, JsonNode>> itr = updatesJson.fields(); itr | 263 | + Iterator<Map.Entry<String, JsonNode>> tableUpdatesItr = updatesJson.fields(); |
| 291 | - .hasNext();) { | 264 | + while (tableUpdatesItr.hasNext()) { |
| 292 | - Map.Entry<String, JsonNode> entry = itr.next(); | 265 | + Map.Entry<String, JsonNode> entry = tableUpdatesItr.next(); |
| 293 | TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey()); | 266 | TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey()); |
| 294 | - TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, | 267 | + TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, entry.getValue()); |
| 295 | - entry.getValue()); | ||
| 296 | tableUpdateMap.put(entry.getKey(), tableUpdate); | 268 | tableUpdateMap.put(entry.getKey(), tableUpdate); |
| 297 | } | 269 | } |
| 298 | return TableUpdates.tableUpdates(tableUpdateMap); | 270 | return TableUpdates.tableUpdates(tableUpdateMap); |
| ... | @@ -301,19 +273,18 @@ public final class FromJsonUtil { | ... | @@ -301,19 +273,18 @@ public final class FromJsonUtil { |
| 301 | /** | 273 | /** |
| 302 | * convert the params of Update Notification into TableUpdate. | 274 | * convert the params of Update Notification into TableUpdate. |
| 303 | * @param tableSchema TableSchema entity | 275 | * @param tableSchema TableSchema entity |
| 304 | - * @param value the table-update in params of Update Notification | 276 | + * @param updateJson the table-update in params of Update Notification |
| 305 | * @return TableUpdate | 277 | * @return TableUpdate |
| 306 | */ | 278 | */ |
| 307 | - public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, | 279 | + public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) { |
| 308 | - JsonNode value) { | ||
| 309 | Map<UUID, RowUpdate> rows = Maps.newHashMap(); | 280 | Map<UUID, RowUpdate> rows = Maps.newHashMap(); |
| 310 | - Iterator<Entry<String, JsonNode>> fields = value.fields(); | 281 | + Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields(); |
| 311 | - while (fields.hasNext()) { | 282 | + while (tableUpdateItr.hasNext()) { |
| 312 | - Map.Entry<String, JsonNode> idOldNew = fields.next(); | 283 | + Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next(); |
| 313 | - String uuidStr = idOldNew.getKey(); | 284 | + String uuidStr = oldNewRow.getKey(); |
| 314 | UUID uuid = UUID.uuid(uuidStr); | 285 | UUID uuid = UUID.uuid(uuidStr); |
| 315 | - JsonNode newR = idOldNew.getValue().get("new"); | 286 | + JsonNode newR = oldNewRow.getValue().get("new"); |
| 316 | - JsonNode oldR = idOldNew.getValue().get("old"); | 287 | + JsonNode oldR = oldNewRow.getValue().get("old"); |
| 317 | Row newRow = newR != null ? createRow(tableSchema, newR) : null; | 288 | Row newRow = newR != null ? createRow(tableSchema, newR) : null; |
| 318 | Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; | 289 | Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; |
| 319 | RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); | 290 | RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); |
| ... | @@ -329,17 +300,21 @@ public final class FromJsonUtil { | ... | @@ -329,17 +300,21 @@ public final class FromJsonUtil { |
| 329 | * @return Row | 300 | * @return Row |
| 330 | */ | 301 | */ |
| 331 | private static Row createRow(TableSchema tableSchema, JsonNode rowNode) { | 302 | private static Row createRow(TableSchema tableSchema, JsonNode rowNode) { |
| 332 | - List<Column> columns = Lists.newArrayList(); | 303 | + if (tableSchema == null) { |
| 333 | - for (Iterator<Map.Entry<String, JsonNode>> iter = rowNode.fields(); iter | 304 | + return null; |
| 334 | - .hasNext();) { | 305 | + } |
| 335 | - Map.Entry<String, JsonNode> next = iter.next(); | 306 | + Map<String, Column> columns = Maps.newHashMap(); |
| 336 | - ColumnSchema schema = tableSchema.getColumnSchema(next.getKey()); | 307 | + Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields(); |
| 337 | - if (schema != null) { | 308 | + while (rowIter.hasNext()) { |
| 338 | - Object o = TransValueUtil.getValueFromJson(next.getValue(), schema.type()); | 309 | + Map.Entry<String, JsonNode> next = rowIter.next(); |
| 339 | - columns.add(new Column(schema, o)); | 310 | + ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey()); |
| 311 | + if (columnSchema != null) { | ||
| 312 | + String columnName = columnSchema.name(); | ||
| 313 | + Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type()); | ||
| 314 | + columns.put(columnName, new Column(columnName, obj)); | ||
| 340 | } | 315 | } |
| 341 | } | 316 | } |
| 342 | - return new Row(tableSchema, columns); | 317 | + return new Row(tableSchema.name(), columns); |
| 343 | } | 318 | } |
| 344 | 319 | ||
| 345 | } | 320 | } | ... | ... |
| ... | @@ -22,7 +22,7 @@ import java.io.IOException; | ... | @@ -22,7 +22,7 @@ import java.io.IOException; |
| 22 | import java.util.List; | 22 | import java.util.List; |
| 23 | import java.util.Stack; | 23 | import java.util.Stack; |
| 24 | 24 | ||
| 25 | -import org.onosproject.ovsdb.rfc.error.UnsupportedEncodingException; | 25 | +import org.onosproject.ovsdb.rfc.error.UnsupportedException; |
| 26 | import org.onosproject.ovsdb.rfc.jsonrpc.JsonReadContext; | 26 | import org.onosproject.ovsdb.rfc.jsonrpc.JsonReadContext; |
| 27 | 27 | ||
| 28 | import com.fasterxml.jackson.core.JsonEncoding; | 28 | import com.fasterxml.jackson.core.JsonEncoding; |
| ... | @@ -55,8 +55,7 @@ public final class JsonRpcReaderUtil { | ... | @@ -55,8 +55,7 @@ public final class JsonRpcReaderUtil { |
| 55 | * @throws IOException IOException | 55 | * @throws IOException IOException |
| 56 | * @throws JsonParseException JsonParseException | 56 | * @throws JsonParseException JsonParseException |
| 57 | */ | 57 | */ |
| 58 | - public static void readToJsonNode(ByteBuf in, List<Object> out, | 58 | + public static void readToJsonNode(ByteBuf in, List<Object> out, JsonReadContext jrContext) |
| 59 | - JsonReadContext jrContext) | ||
| 60 | throws JsonParseException, IOException { | 59 | throws JsonParseException, IOException { |
| 61 | int lastReadBytes = jrContext.getLastReadBytes(); | 60 | int lastReadBytes = jrContext.getLastReadBytes(); |
| 62 | if (lastReadBytes == 0) { | 61 | if (lastReadBytes == 0) { |
| ... | @@ -97,8 +96,7 @@ public final class JsonRpcReaderUtil { | ... | @@ -97,8 +96,7 @@ public final class JsonRpcReaderUtil { |
| 97 | 96 | ||
| 98 | if (jrContext.isStartMatch() && bufStack.isEmpty()) { | 97 | if (jrContext.isStartMatch() && bufStack.isEmpty()) { |
| 99 | ByteBuf buf = in.readSlice(i - in.readerIndex() + 1); | 98 | ByteBuf buf = in.readSlice(i - in.readerIndex() + 1); |
| 100 | - JsonParser jf = new MappingJsonFactory() | 99 | + JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf)); |
| 101 | - .createParser(new ByteBufInputStream(buf)); | ||
| 102 | JsonNode jsonNode = jf.readValueAsTree(); | 100 | JsonNode jsonNode = jf.readValueAsTree(); |
| 103 | out.add(jsonNode); | 101 | out.add(jsonNode); |
| 104 | lastReadBytes = 0; | 102 | lastReadBytes = 0; |
| ... | @@ -145,8 +143,7 @@ public final class JsonRpcReaderUtil { | ... | @@ -145,8 +143,7 @@ public final class JsonRpcReaderUtil { |
| 145 | * Check whether the encoding is valid. | 143 | * Check whether the encoding is valid. |
| 146 | * @param in input of bytes | 144 | * @param in input of bytes |
| 147 | * @throws IOException this is an IO exception | 145 | * @throws IOException this is an IO exception |
| 148 | - * @throws UnsupportedEncodingException this is an unsupported encode | 146 | + * @throws UnsupportedException this is an unsupported exception |
| 149 | - * exception | ||
| 150 | */ | 147 | */ |
| 151 | private static void checkEncoding(ByteBuf in) throws IOException { | 148 | private static void checkEncoding(ByteBuf in) throws IOException { |
| 152 | int inputStart = 0; | 149 | int inputStart = 0; |
| ... | @@ -154,18 +151,14 @@ public final class JsonRpcReaderUtil { | ... | @@ -154,18 +151,14 @@ public final class JsonRpcReaderUtil { |
| 154 | fliterCharaters(in); | 151 | fliterCharaters(in); |
| 155 | byte[] buff = new byte[4]; | 152 | byte[] buff = new byte[4]; |
| 156 | in.getBytes(in.readerIndex(), buff); | 153 | in.getBytes(in.readerIndex(), buff); |
| 157 | - ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper( | 154 | + ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(), |
| 158 | - new IOContext( | ||
| 159 | - new BufferRecycler(), | ||
| 160 | null, | 155 | null, |
| 161 | false), | 156 | false), |
| 162 | - buff, | 157 | + buff, inputStart, |
| 163 | - inputStart, | ||
| 164 | inputLength); | 158 | inputLength); |
| 165 | JsonEncoding jsonEncoding = strapper.detectEncoding(); | 159 | JsonEncoding jsonEncoding = strapper.detectEncoding(); |
| 166 | if (!JsonEncoding.UTF8.equals(jsonEncoding)) { | 160 | if (!JsonEncoding.UTF8.equals(jsonEncoding)) { |
| 167 | - throw new UnsupportedEncodingException( | 161 | + throw new UnsupportedException("Only UTF-8 encoding is supported."); |
| 168 | - "Only UTF-8 encoding is supported."); | ||
| 169 | } | 162 | } |
| 170 | } | 163 | } |
| 171 | 164 | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.ovsdb.rfc.utils; | 16 | package org.onosproject.ovsdb.rfc.utils; |
| 17 | 17 | ||
| 18 | import java.util.List; | 18 | import java.util.List; |
| 19 | +import java.util.Map; | ||
| 19 | import java.util.Set; | 20 | import java.util.Set; |
| 20 | 21 | ||
| 21 | import org.onosproject.ovsdb.rfc.message.MonitorRequest; | 22 | import org.onosproject.ovsdb.rfc.message.MonitorRequest; |
| ... | @@ -24,20 +25,18 @@ import org.onosproject.ovsdb.rfc.operations.Operation; | ... | @@ -24,20 +25,18 @@ import org.onosproject.ovsdb.rfc.operations.Operation; |
| 24 | import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; | 25 | import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; |
| 25 | import org.onosproject.ovsdb.rfc.schema.TableSchema; | 26 | import org.onosproject.ovsdb.rfc.schema.TableSchema; |
| 26 | 27 | ||
| 27 | -import com.google.common.base.Function; | ||
| 28 | -import com.google.common.collect.ImmutableMap; | ||
| 29 | import com.google.common.collect.Lists; | 28 | import com.google.common.collect.Lists; |
| 30 | import com.google.common.collect.Maps; | 29 | import com.google.common.collect.Maps; |
| 31 | 30 | ||
| 32 | /** | 31 | /** |
| 33 | - * Params utility class. Params of the request object, refer to RFC7047's Section | 32 | + * Params utility class. Params of the request object, refer to RFC7047's |
| 34 | - * 4.1. | 33 | + * Section 4.1. |
| 35 | */ | 34 | */ |
| 36 | public final class ParamUtil { | 35 | public final class ParamUtil { |
| 37 | 36 | ||
| 38 | /** | 37 | /** |
| 39 | - * Constructs a ParamUtil object. Utility classes should not have a | 38 | + * Constructs a ParamUtil object. Utility classes should not have a public |
| 40 | - * public or default constructor, otherwise IDE will compile unsuccessfully. This | 39 | + * or default constructor, otherwise IDE will compile unsuccessfully. This |
| 41 | * class should not be instantiated. | 40 | * class should not be instantiated. |
| 42 | */ | 41 | */ |
| 43 | private ParamUtil() { | 42 | private ParamUtil() { |
| ... | @@ -52,8 +51,7 @@ public final class ParamUtil { | ... | @@ -52,8 +51,7 @@ public final class ParamUtil { |
| 52 | String tableName = tableSchema.name(); | 51 | String tableName = tableSchema.name(); |
| 53 | Set<String> columns = tableSchema.getColumnNames(); | 52 | Set<String> columns = tableSchema.getColumnNames(); |
| 54 | MonitorSelect select = new MonitorSelect(true, true, true, true); | 53 | MonitorSelect select = new MonitorSelect(true, true, true, true); |
| 55 | - MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, | 54 | + MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, select); |
| 56 | - select); | ||
| 57 | return monitorRequest; | 55 | return monitorRequest; |
| 58 | } | 56 | } |
| 59 | 57 | ||
| ... | @@ -63,24 +61,15 @@ public final class ParamUtil { | ... | @@ -63,24 +61,15 @@ public final class ParamUtil { |
| 63 | * @param dbSchema DatabaseSchema entity | 61 | * @param dbSchema DatabaseSchema entity |
| 64 | * @return List of Object, the params of monitor request | 62 | * @return List of Object, the params of monitor request |
| 65 | */ | 63 | */ |
| 66 | - public static List<Object> getMonitorParams(String monotorId, | 64 | + public static List<Object> getMonitorParams(String monotorId, DatabaseSchema dbSchema) { |
| 67 | - DatabaseSchema dbSchema) { | ||
| 68 | Set<String> tables = dbSchema.getTableNames(); | 65 | Set<String> tables = dbSchema.getTableNames(); |
| 69 | - List<MonitorRequest> monitorRequests = Lists.newArrayList(); | 66 | + Map<String, MonitorRequest> mrMap = Maps.newHashMap(); |
| 70 | for (String tableName : tables) { | 67 | for (String tableName : tables) { |
| 71 | TableSchema tableSchema = dbSchema.getTableSchema(tableName); | 68 | TableSchema tableSchema = dbSchema.getTableSchema(tableName); |
| 72 | - monitorRequests.add(getAllColumnsMonitorRequest(tableSchema)); | 69 | + MonitorRequest monitorRequest = getAllColumnsMonitorRequest(tableSchema); |
| 70 | + mrMap.put(tableName, monitorRequest); | ||
| 73 | } | 71 | } |
| 74 | - ImmutableMap<String, MonitorRequest> reqMap = Maps | 72 | + return Lists.newArrayList(dbSchema.name(), monotorId, mrMap); |
| 75 | - .uniqueIndex(monitorRequests, | ||
| 76 | - new Function<MonitorRequest, String>() { | ||
| 77 | - @Override | ||
| 78 | - public String apply(MonitorRequest input) { | ||
| 79 | - return input.getTableName(); | ||
| 80 | - } | ||
| 81 | - }); | ||
| 82 | - return Lists.<Object>newArrayList(dbSchema.name(), monotorId, | ||
| 83 | - reqMap); | ||
| 84 | } | 73 | } |
| 85 | 74 | ||
| 86 | /** | 75 | /** |
| ... | @@ -89,10 +78,7 @@ public final class ParamUtil { | ... | @@ -89,10 +78,7 @@ public final class ParamUtil { |
| 89 | * @param operations operation*, refer to RFC7047's Section 4.1.3. | 78 | * @param operations operation*, refer to RFC7047's Section 4.1.3. |
| 90 | * @return List of Object, the params of transact request | 79 | * @return List of Object, the params of transact request |
| 91 | */ | 80 | */ |
| 92 | - public static List<Object> getTransactParams(DatabaseSchema dbSchema, | 81 | + public static List<Object> getTransactParams(DatabaseSchema dbSchema, List<Operation> operations) { |
| 93 | - List<Operation> operations) { | 82 | + return Lists.newArrayList(dbSchema.name(), operations); |
| 94 | - List<Object> lists = Lists.newArrayList((Object) dbSchema.name()); | ||
| 95 | - lists.addAll(operations); | ||
| 96 | - return lists; | ||
| 97 | } | 83 | } |
| 98 | } | 84 | } | ... | ... |
| ... | @@ -87,33 +87,29 @@ public final class TransValueUtil { | ... | @@ -87,33 +87,29 @@ public final class TransValueUtil { |
| 87 | * @param atoType AtomicColumnType entity | 87 | * @param atoType AtomicColumnType entity |
| 88 | * @return Object OvsdbSet or the value of JsonNode | 88 | * @return Object OvsdbSet or the value of JsonNode |
| 89 | */ | 89 | */ |
| 90 | - private static Object getValueFromAtoType(JsonNode json, | 90 | + private static Object getValueFromAtoType(JsonNode json, AtomicColumnType atoType) { |
| 91 | - AtomicColumnType atoType) { | ||
| 92 | BaseType baseType = atoType.baseType(); | 91 | BaseType baseType = atoType.baseType(); |
| 93 | // If "min" or "max" is not specified, If "min" is not 1 or "max" is not | 92 | // If "min" or "max" is not specified, If "min" is not 1 or "max" is not |
| 94 | - // 1, | 93 | + // 1, or both, and "value" is not specified, the type is a set of scalar |
| 95 | - // or both, and "value" is not specified, the type is a set of scalar | 94 | + // type "key". Refer to RFC 7047, Section 3.2 <type>. |
| 96 | - // type "key". | ||
| 97 | - // Refer to RFC 7047, Section 3.2 <type>. | ||
| 98 | if (atoType.min() != atoType.max()) { | 95 | if (atoType.min() != atoType.max()) { |
| 99 | Set set = Sets.newHashSet(); | 96 | Set set = Sets.newHashSet(); |
| 100 | if (json.isArray()) { | 97 | if (json.isArray()) { |
| 101 | if (json.size() == 2) { | 98 | if (json.size() == 2) { |
| 102 | - if (json.get(0).isTextual() | 99 | + if (json.get(0).isTextual() && "set".equals(json.get(0).asText())) { |
| 103 | - && "set".equals(json.get(0).asText())) { | ||
| 104 | for (JsonNode node : json.get(1)) { | 100 | for (JsonNode node : json.get(1)) { |
| 105 | - set.add(TransValueUtil.transToValue(node, baseType)); | 101 | + set.add(transToValue(node, baseType)); |
| 106 | } | 102 | } |
| 107 | } else { | 103 | } else { |
| 108 | - set.add(TransValueUtil.transToValue(json, baseType)); | 104 | + set.add(transToValue(json, baseType)); |
| 109 | } | 105 | } |
| 110 | } | 106 | } |
| 111 | } else { | 107 | } else { |
| 112 | - set.add(TransValueUtil.transToValue(json, baseType)); | 108 | + set.add(transToValue(json, baseType)); |
| 113 | } | 109 | } |
| 114 | return OvsdbSet.ovsdbSet(set); | 110 | return OvsdbSet.ovsdbSet(set); |
| 115 | } else { | 111 | } else { |
| 116 | - return TransValueUtil.transToValue(json, baseType); | 112 | + return transToValue(json, baseType); |
| 117 | } | 113 | } |
| 118 | } | 114 | } |
| 119 | 115 | ||
| ... | @@ -123,19 +119,15 @@ public final class TransValueUtil { | ... | @@ -123,19 +119,15 @@ public final class TransValueUtil { |
| 123 | * @param kvType KeyValuedColumnType entity | 119 | * @param kvType KeyValuedColumnType entity |
| 124 | * @return Object OvsdbMap | 120 | * @return Object OvsdbMap |
| 125 | */ | 121 | */ |
| 126 | - private static Object getValueFromKvType(JsonNode json, | 122 | + private static Object getValueFromKvType(JsonNode json, KeyValuedColumnType kvType) { |
| 127 | - KeyValuedColumnType kvType) { | ||
| 128 | if (json.isArray()) { | 123 | if (json.isArray()) { |
| 129 | if (json.size() == 2) { | 124 | if (json.size() == 2) { |
| 130 | - if (json.get(0).isTextual() | 125 | + if (json.get(0).isTextual() && "map".equals(json.get(0).asText())) { |
| 131 | - && "map".equals(json.get(0).asText())) { | ||
| 132 | Map map = Maps.newHashMap(); | 126 | Map map = Maps.newHashMap(); |
| 133 | for (JsonNode pairNode : json.get(1)) { | 127 | for (JsonNode pairNode : json.get(1)) { |
| 134 | if (pairNode.isArray() && json.size() == 2) { | 128 | if (pairNode.isArray() && json.size() == 2) { |
| 135 | - Object key = TransValueUtil.transToValue(pairNode | 129 | + Object key = transToValue(pairNode.get(0), kvType.keyType()); |
| 136 | - .get(0), kvType.keyType()); | 130 | + Object value = transToValue(pairNode.get(1), kvType.valueType()); |
| 137 | - Object value = TransValueUtil.transToValue(pairNode | ||
| 138 | - .get(1), kvType.valueType()); | ||
| 139 | map.put(key, value); | 131 | map.put(key, value); |
| 140 | } | 132 | } |
| 141 | } | 133 | } |
| ... | @@ -166,14 +158,13 @@ public final class TransValueUtil { | ... | @@ -166,14 +158,13 @@ public final class TransValueUtil { |
| 166 | if (valueNode.isArray()) { | 158 | if (valueNode.isArray()) { |
| 167 | if (valueNode.size() == 2) { | 159 | if (valueNode.size() == 2) { |
| 168 | if (valueNode.get(0).isTextual() | 160 | if (valueNode.get(0).isTextual() |
| 169 | - && "uuid".equals(valueNode.get(0).asText()) | 161 | + && ("uuid".equals(valueNode.get(0).asText()) || "named-uuid" |
| 170 | - || "named-uuid".equals(valueNode.get(0).asText())) { | 162 | + .equals(valueNode.get(0).asText()))) { |
| 171 | return UUID.uuid(valueNode.get(1).asText()); | 163 | return UUID.uuid(valueNode.get(1).asText()); |
| 172 | } | 164 | } |
| 173 | } | 165 | } |
| 174 | } else { | 166 | } else { |
| 175 | - return new RefTableRow(((UuidBaseType) baseType).getRefTable(), | 167 | + return new RefTableRow(((UuidBaseType) baseType).getRefTable(), valueNode); |
| 176 | - valueNode); | ||
| 177 | } | 168 | } |
| 178 | } | 169 | } |
| 179 | return null; | 170 | return null; | ... | ... |
-
Please register or login to post a comment