2 * Copyright (C) 2014 EBay Software Foundation
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Ashwin Raveendran
10 package org.opendaylight.ovsdb.lib.schema;
12 import com.fasterxml.jackson.databind.JsonNode;
13 import org.opendaylight.ovsdb.lib.notation.Condition;
14 import org.opendaylight.ovsdb.lib.notation.Function;
17 public class ColumnSchema<E extends TableSchema<E>, D> {
23 public ColumnSchema(String name, ColumnType columnType) {
25 this.type = columnType;
28 public static ColumnSchema fromJson(String name, JsonNode json) {
29 if (!json.isObject() || !json.has("type")) {
30 //todo specific types of exception
31 throw new RuntimeException("bad column schema root, expected \"type\" as child");
34 return new ColumnSchema(name, ColumnType.fromJson(json.get("type")));
37 public String getName() {
41 public ColumnType getType() { return type; }
43 // --- Operations on the column ----------//
45 public Condition opEqual(D data) {
46 return new Condition(this.getName(), Function.EQUALS, data);
49 public Condition opGreaterThan(D data) {
50 return new Condition(this.getName(), Function.GREATER_THAN, data);
53 public Condition opLesserThan(D data) {
54 return new Condition(this.getName(), Function.GREATER_THAN, data);
57 public Condition opLesserThanOrEquals(D data) {
58 return new Condition(this.getName(), Function.LESS_THAN_OR_EQUALS, data);
61 // --- Operations on the column ----------//:w
64 public String toString() {
65 return "ColumnType [type=" + type + ", ephemeral=" + ephemeral
66 + ", mutable=" + mutable + "]";
70 * Validates the passed in value against the constraints set for this ColumnSchema
72 * @throws java.lang.RuntimeException (validation exception)
74 public void validate(Object value)throws RuntimeException {
75 //todo(type check and validate based on constraints set)