fast config for ComboPooledDataSource
来源:互联网 发布:算法问题实战策略好吗 编辑:程序博客网 时间:2024/06/02 03:37
spring环境下,c3p0数据库连接池简易工厂类
import com.mchange.v2.c3p0.ComboPooledDataSource;import org.springframework.beans.factory.FactoryBean;import org.springframework.beans.factory.InitializingBean;import org.springframework.core.io.UrlResource;import org.springframework.core.io.support.PropertiesLoaderUtils;import org.springframework.util.Assert;import org.springframework.util.ResourceUtils;import java.beans.PropertyVetoException;import java.util.Properties;/** * Created by guor on 2015/3/19. */public class C3P0DataSourceFactoryBean implements FactoryBean<ComboPooledDataSource>, InitializingBean { private String resourceLocation; private ComboPooledDataSource dataSource; @Override public ComboPooledDataSource getObject() throws Exception { return this.dataSource; } @Override public Class<?> getObjectType() { return ComboPooledDataSource.class; } @Override public boolean isSingleton() { return false; } @Override public void afterPropertiesSet() throws Exception { Assert.notNull(this.getResourceLocation(), "resourceLocation cannot be null."); Properties p = PropertiesLoaderUtils.loadProperties(new UrlResource(ResourceUtils.getURL(getResourceLocation()))); try { this.dataSource = initC3p0Properties(p); } catch (PropertyVetoException e) { throw new Exception("初始化数据库连接池失败.", e); } } private ComboPooledDataSource initC3p0Properties(Properties prop) throws PropertyVetoException { ComboPooledDataSource ds = new ComboPooledDataSource(false); ds.setJdbcUrl(prop.getProperty("jdbcUrl")); ds.setUser(prop.getProperty("user")); ds.setPassword(prop.getProperty("password")); ds.setDriverClass(prop.getProperty("driverClass")); ds.setMaxIdleTime(Integer.parseInt(prop.getProperty("maxIdleTime"))); ds.setMaxPoolSize(Integer.parseInt(prop.getProperty("maxPoolSize"))); ds.setMinPoolSize(Integer.parseInt(prop.getProperty("minPoolSize"))); ds.setInitialPoolSize(Integer.parseInt(prop.getProperty("initialPoolSize"))); ds.setAcquireIncrement(Integer.parseInt(prop.getProperty("acquireIncrement"))); return ds; } public String getResourceLocation() { return resourceLocation; } public void setResourceLocation(String resourceLocation) { this.resourceLocation = resourceLocation; }}
使用范例:
<bean id="dataSource" class="com.peony.C3P0DataSourceFactoryBean"> <property name="resourceLocation" value="classpath:jdbc.properties"/></bean>
0 0
- fast config for ComboPooledDataSource
- fast report for delphi
- FAST-RCNN makefile.config 参考配置
- Notepad++ Tips For Fast Development
- A Fast PWM for CSR101x
- FAST Algorithm for Corner Detection
- config for vi&vim
- emacs config for my
- Ubuntu config for SLAM
- A fast equivalent for System.Random
- Flexible Architecture for Simulation and Testing (FAST)
- FAST Search Server 2010 for SharePoint
- 2D Trie for Fast Parsing-1
- Fast report 4.8.11 for Delphi2010
- A fast lock-free queue for C++
- A fast lock-free queue for C++
- git for ubuntu ----non-fast forward 解决办法
- Fast Precomputed Ambient Occlusion for Proximity Shadows
- eclipse hadoop 插件安装步骤
- 习题二
- spring mvc session 超时重定向登录页面解决方法
- stock
- SQLServer2008提供的新的表值参数
- fast config for ComboPooledDataSource
- UI/Application Exerciser Monkey----压力测试
- 数组、模板类vector对象、模板类array对象
- Android常见的漏洞与分析(阿里聚安全博客文章)
- java获取当前系统前一天,当天,后天日期
- stringByAppendingPathComponent及他的删除函数 等系列函数
- getContextPath、getServletPath、getRequestURI的区别
- Objective C中数组排序几种情况的总结
- 11家PaaS公有云供应商服务功能要点比较