Merge "Updating fix for bug 3989 based on discussion in OVSDB meeting"
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / operations / TransactionBuilder.java
1 /*
2  * Copyright (c) 2014 EBay Software Foundation and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.lib.operations;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.ovsdb.lib.OvsdbClient;
15 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
16
17 import com.google.common.collect.Lists;
18 import com.google.common.util.concurrent.ListenableFuture;
19
20 public class TransactionBuilder {
21
22     private DatabaseSchema databaseSchema;
23     OvsdbClient ovs;
24     ArrayList<Operation> operations = Lists.newArrayList();
25
26     public TransactionBuilder(OvsdbClient ovs, DatabaseSchema schema) {
27         this.ovs = ovs;
28         databaseSchema = schema;
29     }
30
31     public List<Operation> getOperations() {
32         return operations;
33     }
34
35     public TransactionBuilder add(Operation operation) {
36         operations.add(operation);
37         return this;
38     }
39
40     public List<Operation> build() {
41         return operations;
42     }
43
44     public ListenableFuture<List<OperationResult>> execute() {
45         return ovs.transact(databaseSchema, operations);
46     }
47
48     public DatabaseSchema getDatabaseSchema() {
49         return databaseSchema;
50     }
51 }