8a34a57b14bf4386d197cf46899a6a73e0e32423
[ovsdb.git] / ovsdb / src / main / java / org / opendaylight / ovsdb / lib / operations / Insert.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.operations;
11
12 import com.fasterxml.jackson.annotation.JsonProperty;
13 import com.google.common.collect.Maps;
14 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
15 import org.opendaylight.ovsdb.lib.schema.TableSchema;
16
17 import java.util.Map;
18
19
20 public class Insert<E extends TableSchema<E>> extends Operation<E> {
21
22     public static final String INSERT = "insert";
23
24     String uuid;
25
26     @JsonProperty("uuid-name")
27     private String uuidName;
28
29     private Map<String, Object> row = Maps.newHashMap();
30
31     public Insert on(TableSchema schema){
32         this.setTableSchema(schema);
33         return this;
34     }
35
36     public Insert withId(String name) {
37         this.uuidName = name;
38         this.setOp(INSERT);
39         return this;
40     }
41
42
43     public Insert(TableSchema<E> schema) {
44         super(schema, INSERT);
45     }
46
47     public <D, C extends TableSchema<C>> Insert<E> value(ColumnSchema<C, D> columnSchema, D value) {
48         row.put(columnSchema.getName(), value);
49         return this;
50     }
51
52     public String getUuid() {
53         return uuid;
54     }
55
56     public void setUuid(String uuid) {
57         this.uuid = uuid;
58     }
59
60     public String getUuidName() {
61         return uuidName;
62     }
63
64     public void setUuidName(String uuidName) {
65         this.uuidName = uuidName;
66     }
67
68     public Map<String, Object> getRow() {
69         return row;
70     }
71
72     public void setRow(Map<String, Object> row) {
73         this.row = row;
74     }
75
76 }