My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright 2011 Global Biodiversity Information Facility (GBIF)
*
* 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 org.gbif.common.mybatis;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;

/**
* A simple {@link DataSourceFactory} for MyBatis to create a connection pool using C3P0.
* <p/>
* The properties to use in the MyBatis configuration are different from the included default pooled data source.
* <p/>
* Make sure to specify at least:
* <ul>
* <li>jdbcUrl</li>
* <li>driverClass (if it is not preloaded somehow)</li>
* </ul>
* <p/>
* But you usually also want:
* <ul>
* <li>user</li>
* <li>password</li>
* </ul>
* <p/>
* A sample usage would look like this:
* <pre>
* {@code
*
* <dataSource type="org.gbif.common.mybatis.C3P0DataSourceFactory">
* <property name="driverClass" value="org.postgresql.Driver"/>
* <property name="jdbcUrl" value="${url}"/>
* <property name="user" value="${username}"/>
* <property name="password" value="${password}"/>
* <property name="idleConnectionTestPeriod" value="60"/>
* <property name="maxPoolSize" value="20"/>
* <property name="maxIdleTime" value="600"/>
* <property name="preferredTestQuery" value="SELECT 1"/>
* </dataSource>
* }
* </pre>
*
* @see <a href="http://www.mchange.com/projects/c3p0/index.html#configuration_properties">C3P0 Configuration</a>
*/
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {

public C3P0DataSourceFactory() {
this.dataSource = new ComboPooledDataSource();
}
}

Change log

r282 by lars.francke on Sep 8, 2011   Diff
Update Mother POM and Code style changes.
Go to: 
Project members, sign in to write a code review

Older revisions

r225 by lars.francke on Aug 3, 2011   Diff
Adds a comment about the usage.
r224 by lars.francke on Aug 3, 2011   Diff
Add project mybatis-c3p0
All revisions of this file

File info

Size: 2174 bytes, 63 lines
Powered by Google Project Hosting