All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.ovsdb.lib.operations.Update Maven / Gradle / Ivy

/*
 * Copyright © 2014, 2017 EBay Software Foundation and others. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

package org.opendaylight.ovsdb.lib.operations;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opendaylight.ovsdb.lib.notation.Column;
import org.opendaylight.ovsdb.lib.notation.Condition;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;

public class Update> extends Operation implements ConditionalOperation {

    public static final String UPDATE = "update";

    private final Map row = new HashMap<>();
    private String uuid;

    private final List where = new ArrayList<>();

    private String uuidName;

    public Update(TableSchema schema) {
        super(schema, UPDATE);
    }

    public Update on(TableSchema schema) {
        return this;
    }

    public Update(TableSchema schema, Row row) {
        super(schema, UPDATE);
        Collection> columns = row.getColumns();
        for (Column column : columns) {
            this.set(column);
        }
    }

    public Update(TypedBaseTable typedTable) {
        this(typedTable.getSchema(), typedTable.getRow());
    }

    @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT") // validate call below
    public , D> Update set(ColumnSchema columnSchema, D value) {
        columnSchema.validate(value);
        Object untypedValue = columnSchema.getNormalizeData(value);
        this.row.put(columnSchema.getName(), untypedValue);
        return this;
    }

    public , D> Update set(Column column) {
        ColumnSchema columnSchema = column.getSchema();
        D value = column.getData();
        return this.set(columnSchema, value);
    }

    public Where where(Condition condition) {
        where.add(condition);
        return new Where(this);
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUuidName() {
        return uuidName;
    }

    public void setUuidName(String uuidName) {
        this.uuidName = uuidName;
    }

    public Map getRow() {
        return row;
    }

    public void setRow(Map row) {
        this.row.clear();
        this.row.putAll(row);
    }

    @Override
    public void addCondition(Condition condition) {
        this.where.add(condition);
    }

    public List getWhere() {
        return where;
    }

    public void setWhere(List where) {
        this.where.clear();
        this.where.addAll(where);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy