org.test4j.module.database.operator.InsertOp Maven / Gradle / Ivy
package org.test4j.module.database.operator;
import org.test4j.exception.Exceptions;
import org.test4j.module.database.enviroment.DBEnvironment;
import org.test4j.module.database.enviroment.DBEnvironmentFactory;
import org.test4j.module.database.enviroment.TableMeta;
import org.test4j.tools.datagen.IDataMap;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Map;
/**
* 插入数据操作
*
* @author wudarui
*/
@SuppressWarnings({"unchecked", "rawtypes", "unused"})
public class InsertOp implements IInsertOp {
private String table;
private final DBEnvironment env;
private TableMeta tableMeta;
public InsertOp() {
this(DBEnvironmentFactory.getDefaultDBEnvironment());
}
public InsertOp(DBEnvironment environment) {
this.env = environment;
}
public static void insertNoException(DBEnvironment env, String table, IDataMap data) {
try {
InsertOp op = new InsertOp(env);
op.insert(table, data);
} catch (Exception e) {
throw Exceptions.getUndeclaredThrowableExceptionCaused(e);
}
}
/**
* 往数据库中插入数据
*
* @param table 表
* @param data 要插入的数据
*/
@Override
public void insert(String table, IDataMap data) {
this.table = table;
this.tableMeta = env.getTableMetaData(table);
tableMeta.fillData(data, env);
List