01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.lucene.engine.store.jdbc;
18:
19: import java.beans.PropertyVetoException;
20: import javax.sql.DataSource;
21:
22: import com.mchange.v2.c3p0.ComboPooledDataSource;
23: import org.compass.core.CompassException;
24: import org.compass.core.config.CompassSettings;
25:
26: /**
27: * A c3p0 data source provider. Creates a new C3P0 pooled data source. For configuration, use a
28: * file called c3p0.properties and storing it as a top-level resource in the same
29: * CLASSPATH / classloader that loads c3p0's jar file.
30: * <p/>
31: * Will set the url, driverClass, user and password based on compass configuration settings.
32: *
33: * @author kimchy
34: */
35: public class C3P0DataSourceProvider extends AbstractDataSourceProvider {
36:
37: protected DataSource doCreateDataSource(String url,
38: CompassSettings settings) throws CompassException {
39: ComboPooledDataSource dataSource = new ComboPooledDataSource();
40: try {
41: dataSource.setDriverClass(driverClass);
42: } catch (PropertyVetoException e) {
43: throw new CompassException("Failed to set driverClass ["
44: + driverClass + "] in c3p0", e);
45: }
46: dataSource.setJdbcUrl(url);
47: dataSource.setUser(username);
48: dataSource.setPassword(password);
49: if (!externalAutoCommit) {
50: dataSource.setAutoCommitOnClose(autoCommit);
51: }
52: return dataSource;
53: }
54: }
|