org.fluentjdbc.DbInsertContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-jdbc Show documentation
Show all versions of fluent-jdbc Show documentation
A Java library used to execute JDBC statements and build SQL
package org.fluentjdbc;
import java.sql.SQLException;
import java.util.Collection;
import org.fluentjdbc.util.ExceptionUtil;
public class DbInsertContext implements DatabaseUpdateable {
public class DbInsertContextWithPk {
private DatabaseInsertWithPkBuilder builder2;
public DbInsertContextWithPk(DatabaseInsertWithPkBuilder builder) {
builder2 = builder;
}
public DbInsertContextWithPk setField(String fieldName, Object parameter) {
builder2.setField(fieldName, parameter);
return this;
}
public T execute() {
try {
return builder2.execute(dbTableContext.getConnection());
} catch (SQLException e) {
throw ExceptionUtil.softenCheckedException(e);
}
}
}
private DatabaseInsertBuilder builder;
private DbTableContext dbTableContext;
public DbInsertContext(DbTableContext dbTableContext) {
this.dbTableContext = dbTableContext;
builder = dbTableContext.getTable().insert();
}
public DbInsertContextWithPk setPrimaryKey(String idField, T idValue) {
DatabaseInsertWithPkBuilder setPrimaryKey = builder.setPrimaryKey(idField, idValue);
return new DbInsertContextWithPk<>(setPrimaryKey);
}
public DbInsertContext setField(String fieldName, Object parameter) {
builder.setField(fieldName, parameter);
return this;
}
@Override
public DbInsertContext setFields(Collection fields, Collection> values) {
builder.setFields(fields, values);
return this;
}
public int execute() {
return builder.execute(dbTableContext.getConnection());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy