use of com.baomidou.mybatisplus.annotation.DbType in project diboot by dibo-software.
the class ContextHelper method getDatabaseType.
/**
* 获取数据库类型
* @return
*/
public static String getDatabaseType() {
if (DATABASE_TYPE != null) {
return DATABASE_TYPE;
}
String jdbcUrl = getJdbcUrl();
if (jdbcUrl != null) {
DbType dbType = JdbcUtils.getDbType(jdbcUrl);
DATABASE_TYPE = dbType.getDb();
if (DATABASE_TYPE.startsWith(DbType.SQL_SERVER.getDb())) {
DATABASE_TYPE = DbType.SQL_SERVER.getDb();
}
} else {
SqlSessionFactory sqlSessionFactory = getBean(SqlSessionFactory.class);
if (sqlSessionFactory != null) {
DATABASE_TYPE = sqlSessionFactory.getConfiguration().getDatabaseId();
}
}
if (DATABASE_TYPE == null) {
log.warn("无法识别数据库类型,请检查数据源配置:spring.datasource.url等");
}
return DATABASE_TYPE;
}
use of com.baomidou.mybatisplus.annotation.DbType in project chao-cloud by chaojunzi.
the class MybatisUtil method getOne.
/**
* 获取一条数据;<br>
* 注:<br>
* 1.请注入 @EnableMybatisPlusConfig <br>
* 2.目前只支持一种数据源类型 <br>
* 3.oracle|mysql
*
* @param <T> 数据实体
* @param service 实体对应的service层
* @param wrapper 封装条件
* @return 实体
*/
static <T> T getOne(IService<T> service, AbstractWrapper<T, ?, ?> wrapper) {
// 判断方言
String dbType = SpringUtil.getProperty(Constants.MYBATIS_PLUS + ".db-type");
DbType type = DbType.getDbType(dbType);
switch(type) {
case ORACLE:
wrapper.apply(MybatisConstant.LIMIT_1_ORACLE);
break;
case MYSQL:
default:
// 默认mysql
wrapper.last(MybatisConstant.LIMIT_1_MYSQL);
break;
}
return service.getOne(wrapper);
}
use of com.baomidou.mybatisplus.annotation.DbType in project chao-cloud by chaojunzi.
the class DateTableNameHandler method getTableNodesComplete.
private TableNodesComplete getTableNodesComplete() {
Map<String, TableNodesComplete> beans = SpringUtil.getBeansOfType(TableNodesComplete.class);
Assert.notNull(beans, "请注入一个生成表的实现类:{}", TableNodesComplete.class.getSimpleName());
DbType dbType = rule.getDbType();
TableNodesComplete complete = CollUtil.findOne(beans.values(), b -> b.getDbType() == dbType);
Assert.notNull(complete, "未找到该数据库表生成插件:{}", dbType);
return complete;
}
use of com.baomidou.mybatisplus.annotation.DbType in project mybatis-plus-samples by baomidou.
the class MpConfig method globalConfiguration.
@Bean
public GlobalConfig globalConfiguration() {
GlobalConfig conf = new GlobalConfig();
conf.setDbConfig(new GlobalConfig.DbConfig().setKeyGenerators(Arrays.asList(// h2 1.x 的写法(默认 2.x 的写法)
new IKeyGenerator() {
@Override
public String executeSql(String incrementerName) {
return "select " + incrementerName + ".nextval";
}
@Override
public DbType dbType() {
return DbType.POSTGRE_SQL;
}
})));
return conf;
}
use of com.baomidou.mybatisplus.annotation.DbType in project chao-cloud by chaojunzi.
the class ShardingActualNodesComplete method sourceOfTableName.
/**
* 根据表名生成表结构<br>
* 格式: table:ds.table_202001
*
* @param shardingDataSource 数据源
* @param tableNodes 源表_节点
* @param defaultDsName 默认数据源
*/
default void sourceOfTableName(ShardingDataSource shardingDataSource, Map<String, List<String>> tableNodes, String defaultDsName) {
DbType type = DbType.getDbType(shardingDataSource.getDatabaseType().getName());
switch(type) {
case // 目前只支持mysql
MYSQL:
Map<String, DataSource> dsMap = shardingDataSource.getDataSourceMap();
// 节点分组
Map<String, Map<String, List<String>>> dsTableNodes = build(tableNodes);
// 生成表结构
dsTableNodes.forEach((dsName, tNodesMap) -> {
DataSource ds = dsMap.get(dsName);
List<String> tables = MetaUtil.getTables(ds);
// 生成数据表
tNodesMap.forEach((sourceTable, nodes) -> {
// 整合需要缓存表节点
cacheTableNodes(dsName, sourceTable, nodes, tables);
// 需要生成的表
Collection<String> needTables = CollUtil.subtract(nodes, tables);
// 生成表节点
if (CollUtil.isEmpty(needTables)) {
return;
}
String sourceTableDDL = getSourceTableDDL(dsMap.get(defaultDsName), sourceTable);
createTable(sourceTable, sourceTableDDL, dsName, ds, needTables);
});
});
default:
break;
}
}
Aggregations