Network topology and inventory init
[transportpce.git] / inventory / src / main / java / org / opendaylight / transportpce / inventory / query / StatementBuilder.java
1 /*
2  * Copyright © 2017 AT&T 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 package org.opendaylight.transportpce.inventory.query;
9
10 import java.sql.PreparedStatement;
11 import java.sql.SQLException;
12
13 public class StatementBuilder {
14
15     private final PreparedStatement statement;
16     private int index;
17
18     private StatementBuilder(PreparedStatement statement) {
19         this.statement = statement;
20         this.index = 1;
21     }
22
23     public StatementBuilder setParameter(String value) throws SQLException {
24         this.statement.setString(this.index++, value);
25         return this;
26     }
27
28     public StatementBuilder setParameter(Long value) throws SQLException {
29         this.statement.setLong(this.index++, value);
30         return this;
31     }
32
33     public StatementBuilder setParameters(String... strings) throws SQLException {
34         for (int i = 0; i < strings.length; i++) {
35             statement.setString(i + 1, strings[i]);
36         }
37         return this;
38     }
39
40     public StatementBuilder reset() {
41         this.index = 1;
42         return this;
43     }
44
45     public static StatementBuilder builder(PreparedStatement statement) {
46         return new StatementBuilder(statement);
47     }
48 }