cn.hutool.db.ds.jndi.JndiDSFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.db.ds.jndi;
import javax.sql.DataSource;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.db.ds.AbstractDSFactory;
import cn.hutool.setting.Setting;
/**
* JNDI数据源工厂类
* Setting配置样例:
* ---------------------
* [group]
* jndi = jdbc/TestDB
* ---------------------
*
* @author Looly
*
*/
public class JndiDSFactory extends AbstractDSFactory {
private static final long serialVersionUID = 1573625812927370432L;
public static final String DS_NAME = "JNDI DataSource";
public JndiDSFactory() {
this(null);
}
public JndiDSFactory(Setting setting) {
super(DS_NAME, DataSource.class, setting);
}
@Override
protected DataSource createDataSource(String jdbcUrl, String driver, String user, String pass, Setting poolSetting) {
String jndiName = poolSetting.getStr("jndi");
if (StrUtil.isEmpty(jndiName)) {
throw new DbRuntimeException("No setting name [jndi] for this group.");
}
return DbUtil.getJndiDs(jndiName);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy