Skip to content

Commit

Permalink
feat: add toBuilder() method to Statement
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Mar 12, 2020
1 parent 160970b commit 7e6b799
Showing 1 changed file with 13 additions and 1 deletion.
Expand Up @@ -68,16 +68,24 @@ private Statement(String sql, ImmutableMap<String, Value> parameters, QueryOptio

/** Builder for {@code Statement}. */
public static final class Builder {
final Map<String, Value> parameters = new HashMap<>();
final Map<String, Value> parameters;
private final StringBuilder sqlBuffer;
private String currentBinding;
private final ValueBinder<Builder> binder = new Binder();
private QueryOptions queryOptions;

private Builder(String sql) {
parameters = new HashMap<>();
sqlBuffer = new StringBuilder(sql);
}

private Builder(Statement statement) {
sqlBuffer = new StringBuilder(statement.sql);
parameters = new HashMap<>(statement.parameters);
queryOptions =
statement.queryOptions == null ? null : statement.queryOptions.toBuilder().build();
}

/** Appends {@code sqlFragment} to the statement. */
public Builder append(String sqlFragment) {
sqlBuffer.append(checkNotNull(sqlFragment));
Expand Down Expand Up @@ -171,6 +179,10 @@ public Map<String, Value> getParameters() {
return parameters;
}

public Builder toBuilder() {
return new Builder(this);
}

@Override
public String toString() {
return toString(new StringBuilder()).toString();
Expand Down

0 comments on commit 7e6b799

Please sign in to comment.