tech.guyi.ipojo.module.h2.utils.TableUtils Maven / Gradle / Ivy
The newest version!
package tech.guyi.ipojo.module.h2.utils;
import org.apache.commons.dbutils.QueryRunner;
import org.osgi.service.log.Logger;
import tech.guyi.ipojo.application.annotation.Component;
import tech.guyi.ipojo.application.annotation.Resource;
import tech.guyi.ipojo.application.osgi.log.Log;
import tech.guyi.ipojo.module.h2.entry.FieldEntry;
import tech.guyi.ipojo.module.h2.executor.JdbcExecutor;
import tech.guyi.ipojo.module.h2.executor.JdbcInvoker;
import tech.guyi.ipojo.module.h2.executor.handler.SingleIntegerResultHandler;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Component
public class TableUtils {
@Log
private Logger logger;
@Resource
private JdbcExecutor executor;
private SingleIntegerResultHandler integerResultHandler = new SingleIntegerResultHandler();
public void addField(String tableName,String fieldName,String type) {
final String sql = String.format(
"alter table %s add column `%s` %s default null",
tableName,
fieldName,
type
);
try {
this.executor.execute(new JdbcInvoker