io.ebeaninternal.server.persist.dml.GenerateDmlRequest Maven / Gradle / Ivy
package io.ebeaninternal.server.persist.dml;
import java.util.ArrayList;
import java.util.List;
/**
* Helper to support the generation of DML statements.
*/
public final class GenerateDmlRequest {
private final StringBuilder sb = new StringBuilder(100);
private final List columns = new ArrayList<>();
private StringBuilder insertBindBuffer;
private String prefix;
private String prefix2;
private int insertMode;
private int bindColumnCount;
GenerateDmlRequest append(String s) {
sb.append(s);
return this;
}
public void appendColumn(String column) {
//String bind = (insertMode > 0) ? "?" : "=?";
appendColumn(column, "?");
}
public void appendColumn(String column, String bind) {
++bindColumnCount;
sb.append(prefix);
sb.append(column);
columns.add(column);
if (insertMode > 0) {
if (insertMode++ > 1) {
insertBindBuffer.append(',');
}
insertBindBuffer.append(bind);
} else {
sb.append('=');
sb.append(bind);
}
if (prefix2 != null) {
prefix = prefix2;
prefix2 = null;
}
}
int bindColumnCount() {
return bindColumnCount;
}
String insertBindBuffer() {
return insertBindBuffer.toString();
}
@Override
public String toString() {
return sb.toString();
}
void setWhereIdMode() {
this.prefix = "";
this.prefix2 = " and ";
}
void setInsertSetMode() {
this.insertBindBuffer = new StringBuilder(100);
this.insertMode = 1;
this.prefix = "";
this.prefix2 = ", ";
}
void setUpdateSetMode() {
this.prefix = "";
this.prefix2 = ", ";
}
public boolean isUpdate() {
return insertMode == 0;
}
public List columns() {
return columns;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy