Merge branch 'master' into topic/schema
[ovsdb.git] / library / src / main / java / org / opendaylight / ovsdb / lib / operations / Update.java
1 /*
2  *
3  *  * Copyright (C) 2014 EBay Software Foundation
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *  *
9  *  * Authors : Ashwin Raveendran
10  *
11  */
12
13 package org.opendaylight.ovsdb.lib.operations;
14
15 import java.util.List;
16 import java.util.Map;
17
18 import org.opendaylight.ovsdb.lib.notation.Column;
19 import org.opendaylight.ovsdb.lib.notation.Condition;
20 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
21 import org.opendaylight.ovsdb.lib.schema.TableSchema;
22
23 import com.google.common.collect.Lists;
24 import com.google.common.collect.Maps;
25
26 public class Update<E extends TableSchema<E>> extends Operation<E> implements ConditionalOperation {
27
28     public static final String UPDATE = "update";
29
30     Map<String, Object> row = Maps.newHashMap();
31     String uuid;
32     //Where where;
33     List<Condition> where = Lists.newArrayList();
34
35     private String uuidName;
36
37     public Update(TableSchema<E> schema) {
38         super(schema, UPDATE);
39     }
40
41     public Update<E> on(TableSchema schema){
42         return this;
43     }
44
45     public <T extends TableSchema<T>, D> Update<E> set(ColumnSchema<T, D> columnSchema, D value) {
46         columnSchema.validate(value);
47         Object untypedValue = columnSchema.getNormalizeData(value);
48         this.row.put(columnSchema.getName(), untypedValue);
49         return this;
50     }
51
52     public <T extends TableSchema<T>, D> Update<E> set(Column<T, D> column) {
53         ColumnSchema<T, D> columnSchema = column.getSchema();
54         D value = column.getData();
55         return this.set(columnSchema, value);
56     }
57
58     public Where where(Condition condition) {
59         where.add(condition);
60         return new Where(this);
61     }
62
63     public String getUuid() {
64         return uuid;
65     }
66
67     public void setUuid(String uuid) {
68         this.uuid = uuid;
69     }
70
71     public String getUuidName() {
72         return uuidName;
73     }
74
75     public void setUuidName(String uuidName) {
76         this.uuidName = uuidName;
77     }
78
79     public Map<String, Object> getRow() {
80         return row;
81     }
82
83     public void setRow(Map<String, Object> row) {
84         this.row = row;
85     }
86
87     @Override
88     public void addCondition(Condition condition) {
89         this.where.add(condition);
90     }
91
92     public List<Condition> getWhere() {
93         return where;
94     }
95
96     public void setWhere(List<Condition> where) {
97         this.where = where;
98     }
99 }