0f17a1f226333b4e52095f16433bcc1f91fd540c
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / operations / TransactionBuilder.java
1 /*
2  * Copyright © 2014, 2017 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 com.google.common.util.concurrent.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.ovsdb.lib.OvsdbClient;
15 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
16
17 public class TransactionBuilder {
18
19     private DatabaseSchema databaseSchema;
20     OvsdbClient ovs;
21     List<Operation> operations = new ArrayList<>();
22
23     public TransactionBuilder(OvsdbClient ovs, DatabaseSchema schema) {
24         this.ovs = ovs;
25         databaseSchema = schema;
26     }
27
28     public List<Operation> getOperations() {
29         return operations;
30     }
31
32     public TransactionBuilder add(Operation operation) {
33         operations.add(operation);
34         return this;
35     }
36
37     public List<Operation> build() {
38         return operations;
39     }
40
41     public ListenableFuture<List<OperationResult>> execute() {
42         return ovs.transact(databaseSchema, operations);
43     }
44
45     public DatabaseSchema getDatabaseSchema() {
46         return databaseSchema;
47     }
48 }