Files
meta-kit/src/main/java/net/tccn/dbq/jdbc/api/DbKit.java
2019-04-22 19:01:59 +08:00

62 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package net.tccn.dbq.jdbc.api;
import java.util.List;
/**
* Created by liangxianyou at 2019/3/12 14:11.
*/
public class DbKit implements DbSource{
private DbAccount dbAccount;
private DbSource dbSource;
private String catalog;
public DbKit(DbAccount dbAccount) {
this.dbAccount = dbAccount;
if ("mysql".equalsIgnoreCase(dbAccount.getCate())) {
dbSource = new DbSourceMysql(dbAccount);
} else {
throw new IllegalArgumentException(String.format("创建DbKit失败数据库类型[cate:%s]未知", dbAccount.getCate()));
}
}
public DbKit(DbAccount dbAccount, String catalog) {
this.dbAccount = dbAccount;
this.catalog = catalog;
if ("mysql".equalsIgnoreCase(dbAccount.getCate())) {
dbSource = new DbSourceMysql(dbAccount, catalog);
} else {
throw new IllegalArgumentException(String.format("创建DbKit失败数据库类型[cate:%s]未知", dbAccount.getCate()));
}
}
@Override
public <T> List<T> findList(String sql, Class<T> type) {
return dbSource.findList(sql, type);
}
@Override
public <T> T findfirst(String sql, Class<T> type) {
return dbSource.findfirst(sql, type);
}
@Override
public <T> T queryColumn(String sql, Class<T> type) {
return dbSource.queryColumn(sql, type);
}
@Override
public void createTable(String sql) {
dbSource.createTable(sql);
}
@Override
public void dropTable(String tableName) {
dbSource.dropTable(tableName);
}
public void exetute(String sql) {
dbSource.exetute(sql);
}
}