/*
* Copyright 2008-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.test.hasor.db._02_datasource.warp;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.beans.PropertyVetoException;
/**
*
* @version : 2014年7月23日
* @author 赵永春(zyc@hasor.net)
*/
public class C3p0DataSourceFactory {
protected static Logger logger = LoggerFactory.getLogger(C3p0DataSourceFactory.class);
public static DataSource createDataSource(String driverString, String urlString, String userString, String pwdString) throws PropertyVetoException {
int poolMaxSize = 40;
logger.info("C3p0 Pool Info maxSize is ‘%s’ driver is ‘%s’ jdbcUrl is‘%s’", poolMaxSize, driverString, urlString);
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(driverString);
dataSource.setJdbcUrl(urlString);
dataSource.setUser(userString);
dataSource.setPassword(pwdString);
dataSource.setMaxPoolSize(poolMaxSize);
dataSource.setInitialPoolSize(1);
//dataSource.setAutomaticTestTable("DB_TEST_ATest001");
dataSource.setIdleConnectionTestPeriod(18000);
dataSource.setCheckoutTimeout(3000);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setAcquireRetryDelay(1000);
dataSource.setAcquireRetryAttempts(30);
dataSource.setAcquireIncrement(1);
dataSource.setMaxIdleTime(25000);
return dataSource;
}
}