/* * Copyright (C) 2014 Matt Oswalt * * 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 * * Authors : Matt Oswalt * */ package org.opendaylight.ovsdb.lib.operations; import java.util.List; import java.util.Set; import org.opendaylight.ovsdb.lib.notation.Condition; import org.opendaylight.ovsdb.lib.notation.Mutation; import org.opendaylight.ovsdb.lib.notation.Mutator; import org.opendaylight.ovsdb.lib.notation.OvsDBSet; import org.opendaylight.ovsdb.lib.schema.ColumnSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; public class Mutate> extends Operation implements ConditionalOperation { public static final String MUTATE = "mutate"; List where = Lists.newArrayList(); private List mutations = Lists.newArrayList(); public Mutate on(TableSchema schema){ this.setTableSchema(schema); return this; } public Mutate(TableSchema schema) { super(schema, MUTATE); } public , D> Mutate addMutation(ColumnSchema columnSchema, Mutator mutator, D value) { columnSchema.validate(value); Object untypedValue = null; if (columnSchema.getType().isMultiValued()) { Preconditions.checkArgument((value instanceof Set),"expected a set for multivalued item") ; untypedValue = OvsDBSet.fromSet((Set) value); } else { untypedValue = value; } mutations.add(new Mutation(columnSchema.getName(), mutator, untypedValue)); return this; } public List getMutations() { return mutations; } public void setMutations(List mutations) { this.mutations = mutations; } @Override public void addCondition(Condition condition) { this.where.add(condition); } public Where where(Condition condition) { this.where.add(condition); return new Where(this); } public List getWhere() { return where; } public void setWhere(List where) { this.where = where; } }