本文整理汇总了Java中com.alibaba.druid.util.JdbcUtils.getDbType方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcUtils.getDbType方法的具体用法?Java JdbcUtils.getDbType怎么用?Java JdbcUtils.getDbType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.util.JdbcUtils
的用法示例。
在下文中一共展示了JdbcUtils.getDbType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DynamicDataSource
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
public DynamicDataSource(MybatisNodeProperties druidNode, DruidProperties defaultDruidProperties, String dataSourceName) throws SQLException {
this.dataSourceName=dataSourceName;
DruidProperties master = druidNode.getMaster();
if (master == null)
master = new DruidProperties();
master.merge(defaultDruidProperties).defaultEmpty().setDefaultReadOnly(false);
this.masterDataSource = master.createDataSource();
this.masterDataSource.setName(dataSourceName + "-Master");
List<DruidProperties> slaves = druidNode.getSlaves();
if (slaves != null && !slaves.isEmpty()) {
for (int i = 0; i < slaves.size(); i++) {
DruidProperties slave = slaves.get(i);
if (slave == null)
continue;
slave.merge(defaultDruidProperties).defaultEmpty().setDefaultReadOnly(true);
String slaveDatasourceName = dataSourceName + "-Slave-" + i;
this.slavesDataSourceNames.add(slaveDatasourceName);
DruidDataSource datasourc = slave.createDataSource();
datasourc.setName(slaveDatasourceName);
this.slaveDataSources.put(slaveDatasourceName, datasourc);
}
}
String rawUrl=master.getUrl();
String dbType = JdbcUtils.getDbType(rawUrl,null);
this.dialect=Dialect.valoueOfName(dbType);
}
示例2: getDbType
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
protected String getDbType(DruidProperties nodeProperties, DruidProperties defaultProperties) {
String rawUrl = nodeProperties.getUrl();
if (StringUtils.isEmpty(nodeProperties.getUrl())) {
rawUrl = defaultProperties.getUrl();
}
return JdbcUtils.getDbType(rawUrl, null);
}
示例3: getDbtypeByDatasource
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
/**
* 根据数据源获取数据库类型 <br/>
* @author jingma
* @param dataSource
* @return
*/
public static String getDbtypeByDatasource(DataSource dataSource) {
String dbType = null;
if(dataSource instanceof DruidDataSource){
dbType = JdbcUtils.getDbType(((DruidDataSource)dataSource).getUrl(), null);
}else if(dataSource instanceof SJDataSource){
dbType = JdbcUtils.getDbType(
((SJDataSource)dataSource).toString().split("::::")[1],
null);
}
return dbType;
}
示例4: getDbtypeByDatasource
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
/**
* 根据数据源获取数据库类型 <br/>
* @author jingma
* @param dataSource
* @return
*/
public static String getDbtypeByDatasource(DataSource dataSource) {
String dbType = null;
if(dataSource instanceof DruidDataSource){
dbType = ((DruidDataSource)dataSource).getDbType();
}else if(dataSource instanceof SJDataSource){
dbType = JdbcUtils.getDbType(
((SJDataSource)dataSource).toString().split("::::")[1],
null);
}
return dbType;
}
示例5: tableBindPlugin
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
public static TableBindPlugin tableBindPlugin(
String configName,
DruidPlugin druidPlugin,
Properties dbProp
) {
String dbUrl = dbProp.getProperty(GojaPropConst.DBURL);
if (!Strings.isNullOrEmpty(dbUrl)) {
String dbtype = JdbcUtils.getDbType(dbUrl, StringUtils.EMPTY);
// setting db table name like 'dev_info'
final TableBindPlugin atbp = new TableBindPlugin(configName, druidPlugin);
if (!StringUtils.equals(dbtype, JdbcConstants.MYSQL)) {
if (StringUtils.equals(dbtype, JdbcConstants.ORACLE)) {
atbp.setDialect(new OracleDialect());
atbp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
} else if (StringUtils.equals(dbtype, JdbcConstants.POSTGRESQL)) {
atbp.setDialect(new PostgreSqlDialect());
atbp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
} else if (StringUtils.equals(dbtype, JdbcConstants.H2)) {
atbp.setDialect(new AnsiSqlDialect());
atbp.setContainerFactory(new CaseInsensitiveContainerFactory(true));
} else if (StringUtils.equals(dbtype, "sqlite")) {
atbp.setDialect(new Sqlite3Dialect());
} else if (StringUtils.equals(dbtype, JdbcConstants.JTDS)) {
atbp.setDialect(new SqlServerDialect());
} else {
System.err.println("database type is use mysql.");
}
}
atbp.setShowSql(GojaConfig.getApplicationMode().isDev());
return atbp;
}
return null;
}
示例6: buildProperties
import com.alibaba.druid.util.JdbcUtils; //导入方法依赖的package包/类
private void buildProperties(Properties properties, MybatisNodeProperties node) throws SQLException {
DruidProperties master = node.getMaster().defaultEmpty();
String driverClassName = JdbcUtils.getDriverClassName(master.getUrl());
String dbtype = JdbcUtils.getDbType(master.getUrl(), driverClassName);
Dialect dialect = node.getDialect();
if (null == dialect) {
dialect = Dialect.valoueOfName(dbtype);
}
Mapper mapper = node.getMapper();
if (mapper == null) {
mapper = Mapper.valueOfDialect(dialect);
}
properties.setProperty("jdbc.url", master.getUrl());
properties.setProperty("jdbc.username", master.getUsername());
properties.setProperty("jdbc.password", master.getPassword());
properties.setProperty("jdbc.driverClassName", driverClassName);
properties.setProperty("jdbc.type", dbtype);
properties.setProperty("extends.Mapper", mapper.toString());
if (!StringUtils.hasText(properties.getProperty("extends.modelClass"))) {
properties.setProperty("extends.modelClass", Object.class.getName());
}
if (!StringUtils.hasText(properties.getProperty("java.delimiter"))) {
properties.setProperty("java.delimiter", "");
}
if (!StringUtils.hasText(properties.getProperty("java.encoding"))) {
properties.setProperty("java.encoding", "UTF-8");
}
if (!StringUtils.hasText(properties.getProperty("package.model"))) {
properties.setProperty("package.model", this.getFirstPackage(node.getTypeAliasesPackage()));
}
if (!StringUtils.hasText(properties.getProperty("package.repo"))) {
properties.setProperty("package.repo", this.getFirstPackage(node.getBasePackage()));
}
if (!StringUtils.hasText(properties.getProperty("package.mapper"))) {
String alias=this.getFirstPackage(node.getMapperPackage());
if(StringUtils.hasText(alias)){
alias=ClassUtils.convertClassNameToResourcePath(alias);
}else{
alias="";
}
properties.setProperty("package.mapper",alias);
}
}