Removing the Open_vSwitch schema hardcoding in OvsDBClient.
[ovsdb.git] / library / src / test / java / org / opendaylight / ovsdb / lib / schema / temp / SchemaObjs.java
1 /*
2  * Copyright (C) 2014 EBay Software Foundation
3  *
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
7  *
8  * Authors : Ashwin Raveendran
9  */
10 package org.opendaylight.ovsdb.lib.schema.temp;
11
12 import java.util.concurrent.ExecutionException;
13
14 import org.opendaylight.ovsdb.lib.OvsDBClientImpl;
15 import org.opendaylight.ovsdb.lib.OvsdbTestBase;
16 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
17 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
18 import org.opendaylight.ovsdb.lib.schema.TableSchema;
19
20
21 public class SchemaObjs {
22     public static class Bridge extends TableSchema<Bridge> {
23         public static String NAME = "Bridge";
24         TableSchema target;
25
26         ColumnSchema<Bridge, String> name;
27         ColumnSchema<Bridge, Boolean> flood_vlans;
28
29
30         public Bridge(TableSchema<Bridge> target) {
31             this.target = target;
32             name = target.column("name", String.class);
33             flood_vlans = target.column("statistics", Boolean.class);
34         }
35
36     }
37
38     public static class Port extends TableSchema<Port> {
39         public static String NAME = "Port";
40         TableSchema target;
41
42         ColumnSchema<Port, String> name;
43         ColumnSchema<Port, String> statistics;
44
45         public Port(TableSchema<Port> target) {
46             this.target = target;
47             name = target.column("name", String.class);
48             statistics = target.column("statistics", String.class);
49         }
50
51     }
52
53     public static void main(String[] args) throws ExecutionException, InterruptedException {
54
55         OvsDBClientImpl ovs = new OvsDBClientImpl(null, null);
56         DatabaseSchema db = ovs.getSchema(OvsdbTestBase.OPEN_VSWITCH_SCHEMA, true).get();
57         Bridge bridge = db.table(Bridge.NAME, Bridge.class);
58         Port port = db.table(Port.NAME, Port.class);
59
60         db.beginTransaction()
61                 .add(bridge.insert()
62                         .value(bridge.flood_vlans, true)
63                         .value(bridge.name, "br-int"))
64                 .add(port.insert()
65                         .value(port.statistics, "stats")
66                         //.value(port.statistics, 2) ## will not type check as stats is a string
67                         .value(port.name, "newport")
68                 )
69                 .execute();
70
71         //todo untyped version
72
73     }
74 }