提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.base.db.factory; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.db.model.params.DatabaseInfoParam; |
|
4 |
import cn.stylefeng.roses.core.config.properties.DruidProperties; |
|
5 |
|
|
6 |
/** |
|
7 |
* 数据库信息工厂 |
|
8 |
* |
|
9 |
* @author fengshuonan |
|
10 |
* @date 2019-06-15-20:05 |
|
11 |
*/ |
|
12 |
public class DataBaseInfoFactory { |
|
13 |
|
|
14 |
/** |
|
15 |
* 数据库信息工厂 |
|
16 |
* |
|
17 |
* @author fengshuonan |
|
18 |
* @Date 2019-06-15 20:05 |
|
19 |
*/ |
|
20 |
public static DatabaseInfoParam createDataBaseInfo(DruidProperties druidProperties, String databaseName) { |
|
21 |
|
|
22 |
DatabaseInfoParam databaseInfo = new DatabaseInfoParam(); |
|
23 |
|
|
24 |
databaseInfo.setDbName(databaseName); |
|
25 |
databaseInfo.setJdbcDriver(druidProperties.getDriverClassName()); |
|
26 |
databaseInfo.setUserName(druidProperties.getUsername()); |
|
27 |
databaseInfo.setPassword(druidProperties.getPassword()); |
|
28 |
|
|
29 |
//根据旧的url,拼接新的url |
|
30 |
String jdbcUrl = druidProperties.getUrl(); |
|
31 |
int first = jdbcUrl.lastIndexOf("/") + 1; |
|
32 |
int last = jdbcUrl.indexOf("?"); |
|
33 |
|
|
34 |
//替换旧的名称 |
|
35 |
String newUrl = jdbcUrl.substring(0, first) + databaseName + jdbcUrl.substring(last); |
|
36 |
databaseInfo.setJdbcUrl(newUrl); |
|
37 |
|
|
38 |
return databaseInfo; |
|
39 |
} |
|
40 |
|
|
41 |
} |