db.sql.api.impl.cmd.executor.AbstractInsert Maven / Gradle / Ivy
package db.sql.api.impl.cmd.executor;
import db.sql.api.Cmd;
import db.sql.api.Getter;
import db.sql.api.SqlBuilderContext;
import db.sql.api.cmd.executor.IInsert;
import db.sql.api.cmd.executor.IQuery;
import db.sql.api.impl.cmd.CmdFactory;
import db.sql.api.impl.cmd.Methods;
import db.sql.api.impl.cmd.basic.Table;
import db.sql.api.impl.cmd.basic.TableField;
import db.sql.api.impl.cmd.struct.insert.InsertFields;
import db.sql.api.impl.cmd.struct.insert.InsertSelect;
import db.sql.api.impl.cmd.struct.insert.InsertTable;
import db.sql.api.impl.cmd.struct.insert.InsertValues;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
public abstract class AbstractInsert,
CMD_FACTORY extends CmdFactory
>
extends BaseExecutor
implements IInsert {
protected final CMD_FACTORY $;
protected InsertTable insertTable;
protected InsertFields insertFields;
protected InsertValues insertValues;
protected InsertSelect insertSelect;
public AbstractInsert(CMD_FACTORY $) {
this.$ = $;
}
public TableField $(Getter getter) {
return this.$(getter, 1);
}
public TableField $(Getter getter, int storey) {
return $().field(getter, storey);
}
public Table $(Class entityType) {
return this.$(entityType, 1);
}
public Table $(Class entityType, int storey) {
return $().table(entityType, storey);
}
public TableField $(Class entityType, String fieldName) {
return this.$(entityType, fieldName, 1);
}
public TableField $(Class entityType, String fieldName, int storey) {
return $().field(entityType, fieldName, storey);
}
@Override
public CMD_FACTORY $() {
return $;
}
@Override
public InsertTable $insert(Table table) {
if (this.insertTable == null) {
this.insertTable = new InsertTable(table);
this.append(this.insertTable);
}
return this.insertTable;
}
@Override
public InsertFields $field(TableField... fields) {
if (this.insertFields == null) {
this.insertFields = new InsertFields();
this.append(this.insertFields);
}
this.insertFields.filed(fields);
return this.insertFields;
}
@Override
public InsertFields $field(List fields) {
if (this.insertFields == null) {
this.insertFields = new InsertFields();
this.append(this.insertFields);
}
this.insertFields.filed(fields);
return this.insertFields;
}
@Override
public InsertValues $values(List values) {
if (this.insertValues == null) {
this.insertValues = new InsertValues();
this.append(this.insertValues);
}
this.insertValues.add(values);
return this.insertValues;
}
@Override
public InsertSelect $fromSelect(IQuery query) {
if (this.insertSelect != null) {
this.cmds.remove(this.insertSelect);
}
this.insertSelect = new InsertSelect(query);
this.cmds.add(this.insertSelect);
return this.insertSelect;
}
@Override
public SELF insert(Class entity) {
return this.insert($.table(entity));
}
@Override
public SELF insert(Class entity, Consumer consumer) {
this.insert(entity);
consumer.accept(this.getInsertTable().getTable());
return (SELF) this;
}
@Override
public SELF insertIgnore() {
this.insertTable.setInsertIgnore(true);
return (SELF) this;
}
@Override
public SELF field(Getter... fields) {
TableField[] tableField = new TableField[fields.length];
for (int i = 0; i < fields.length; i++) {
tableField[i] = $.field(fields[i]);
}
return this.field(tableField);
}
@Override
public SELF values(List