Skip to content

Commit 6a9d1b9

Browse files
committed
Docs for configuring 3rd party Datasources.
1 parent c99fde8 commit 6a9d1b9

File tree

5 files changed

+180
-10
lines changed

5 files changed

+180
-10
lines changed

src/site/es/xdoc/configuration.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,42 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
13501350
<p>
13511351
Enviará la propiedad “encoding” y el valor “UTF-8” al constructor del InitialContext durante su instanciación.
13521352
</p>
1353+
1354+
<p>
1355+
You can plug any 3rd party DataSource by implementing the interface <code>org.apache.ibatis.datasource.DataSourceFactory</code>:
1356+
</p>
1357+
1358+
<source><![CDATA[public interface DataSourceFactory {
1359+
void setProperties(Properties props);
1360+
DataSource getDataSource();
1361+
}]]></source>
1362+
1363+
<p>
1364+
The <code>org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code> puede extenderse para crear nuevos
1365+
adaptadores. Por ejemplo, este es el código necesario para integrar C3P0:
1366+
</p>
1367+
1368+
<source><![CDATA[import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1369+
import com.mchange.v2.c3p0.ComboPooledDataSource;
1370+
1371+
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1372+
1373+
public C3P0DataSourceFactory() {
1374+
this.dataSource = new ComboPooledDataSource();
1375+
}
1376+
}]]></source>
1377+
1378+
<p>Para configurarlo, añade una propiedad por cada método al que quieres que llame MyBatis.
1379+
A continuación se muestra una configuración de ejemplo para conectar con una base de datos PostgresSQL:</p>
1380+
1381+
<source><![CDATA[<dataSource type="org.myproject.C3P0DataSourceFactory">
1382+
<property name="driver" value="org.postgresql.Driver"/>
1383+
<property name="url" value="jdbc:postgresql:mydb"/>
1384+
<property name="username" value="postgres"/>
1385+
<property name="password" value="root"/>
1386+
</dataSource>
1387+
]]></source>
1388+
13531389
</subsection>
13541390

13551391
<subsection name="databaseIdProvider">
@@ -1391,9 +1427,7 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
13911427
</p>
13921428

13931429
<source><![CDATA[public interface DatabaseIdProvider {
1394-
13951430
void setProperties(Properties p);
1396-
13971431
String getDatabaseId(DataSource dataSource) throws SQLException;
13981432
}]]></source>
13991433

src/site/ja/xdoc/configuration.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,42 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
14731473
<p>
14741474
上記のように指定すると、"encoding=UTF8" というプロパティが InitialContext のインスタンス生成時にコンストラクタに渡されます。
14751475
</p>
1476+
1477+
<p>
1478+
You can plug any 3rd party DataSource by implementing the interface <code>org.apache.ibatis.datasource.DataSourceFactory</code>:
1479+
</p>
1480+
1481+
<source><![CDATA[public interface DataSourceFactory {
1482+
void setProperties(Properties props);
1483+
DataSource getDataSource();
1484+
}]]></source>
1485+
1486+
<p>
1487+
<code>org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code> can be used as super class
1488+
class to build new datasource adapters. For example this is the code needed to plug C3P0:
1489+
</p>
1490+
1491+
<source><![CDATA[import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1492+
import com.mchange.v2.c3p0.ComboPooledDataSource;
1493+
1494+
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1495+
1496+
public C3P0DataSourceFactory() {
1497+
this.dataSource = new ComboPooledDataSource();
1498+
}
1499+
}]]></source>
1500+
1501+
<p>To set it up, add a property for each setter method you want MyBatis to call.
1502+
Below depicts a sample configuration which connects to a PostgreSQL database:</p>
1503+
1504+
<source><![CDATA[<dataSource type="org.myproject.C3P0DataSourceFactory">
1505+
<property name="driver" value="org.postgresql.Driver"/>
1506+
<property name="url" value="jdbc:postgresql:mydb"/>
1507+
<property name="username" value="postgres"/>
1508+
<property name="password" value="root"/>
1509+
</dataSource>
1510+
]]></source>
1511+
14761512
</subsection>
14771513

14781514
<subsection name="databaseIdProvider">
@@ -1508,9 +1544,7 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
15081544
</p>
15091545

15101546
<source><![CDATA[public interface DatabaseIdProvider {
1511-
15121547
void setProperties(Properties p);
1513-
15141548
String getDatabaseId(DataSource dataSource) throws SQLException;
15151549
}]]></source>
15161550

src/site/ko/xdoc/configuration.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,42 @@ data_source 프로퍼티가 InitialContext 에서 직접 찾을 것이다.</li>
12911291
<li><code>env.encoding=UTF8</code></li>
12921292
</ul>
12931293
<p>이 설정은 인스턴스화할 때 InitialContext 생성자에 “encoding” 프로퍼티를 “UTF8” 로 전달한다.</p>
1294+
1295+
<p>
1296+
You can plug any 3rd party DataSource by implementing the interface <code>org.apache.ibatis.datasource.DataSourceFactory</code>:
1297+
</p>
1298+
1299+
<source><![CDATA[public interface DataSourceFactory {
1300+
void setProperties(Properties props);
1301+
DataSource getDataSource();
1302+
}]]></source>
1303+
1304+
<p>
1305+
<code>org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code> can be used as super class
1306+
class to build new datasource adapters. For example this is the code needed to plug C3P0:
1307+
</p>
1308+
1309+
<source><![CDATA[import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1310+
import com.mchange.v2.c3p0.ComboPooledDataSource;
1311+
1312+
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1313+
1314+
public C3P0DataSourceFactory() {
1315+
this.dataSource = new ComboPooledDataSource();
1316+
}
1317+
}]]></source>
1318+
1319+
<p>To set it up, add a property for each setter method you want MyBatis to call.
1320+
Below depicts a sample configuration which connects to a PostgreSQL database:</p>
1321+
1322+
<source><![CDATA[<dataSource type="org.myproject.C3P0DataSourceFactory">
1323+
<property name="driver" value="org.postgresql.Driver"/>
1324+
<property name="url" value="jdbc:postgresql:mydb"/>
1325+
<property name="username" value="postgres"/>
1326+
<property name="password" value="root"/>
1327+
</dataSource>
1328+
]]></source>
1329+
12941330
</subsection>
12951331

12961332
<subsection name="databaseIdProvider">
@@ -1320,9 +1356,7 @@ data_source 프로퍼티가 InitialContext 에서 직접 찾을 것이다.</li>
13201356
</p>
13211357

13221358
<source><![CDATA[public interface DatabaseIdProvider {
1323-
13241359
void setProperties(Properties p);
1325-
13261360
String getDatabaseId(DataSource dataSource) throws SQLException;
13271361
}]]></source>
13281362

src/site/xdoc/configuration.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,42 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
16771677
to the
16781678
constructor of the InitialContext upon instantiation.
16791679
</p>
1680+
1681+
<p>
1682+
You can plug any 3rd party DataSource by implementing the interface <code>org.apache.ibatis.datasource.DataSourceFactory</code>:
1683+
</p>
1684+
1685+
<source><![CDATA[public interface DataSourceFactory {
1686+
void setProperties(Properties props);
1687+
DataSource getDataSource();
1688+
}]]></source>
1689+
1690+
<p>
1691+
<code>org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code> can be used as super class
1692+
class to build new datasource adapters. For example this is the code needed to plug C3P0:
1693+
</p>
1694+
1695+
<source><![CDATA[import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1696+
import com.mchange.v2.c3p0.ComboPooledDataSource;
1697+
1698+
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1699+
1700+
public C3P0DataSourceFactory() {
1701+
this.dataSource = new ComboPooledDataSource();
1702+
}
1703+
}]]></source>
1704+
1705+
<p>To set it up, add a property for each setter method you want MyBatis to call.
1706+
Follows below a sample configuration which connects to a PostgreSQL database:</p>
1707+
1708+
<source><![CDATA[<dataSource type="org.myproject.C3P0DataSourceFactory">
1709+
<property name="driver" value="org.postgresql.Driver"/>
1710+
<property name="url" value="jdbc:postgresql:mydb"/>
1711+
<property name="username" value="postgres"/>
1712+
<property name="password" value="root"/>
1713+
</dataSource>
1714+
]]></source>
1715+
16801716
</subsection>
16811717

16821718
<subsection name="databaseIdProvider">
@@ -1718,9 +1754,7 @@ SqlSessionFactory factory = sqlSessionFactoryBuilder.build(reader,properties);]]
17181754
</p>
17191755

17201756
<source><![CDATA[public interface DatabaseIdProvider {
1721-
17221757
void setProperties(Properties p);
1723-
17241758
String getDatabaseId(DataSource dataSource) throws SQLException;
17251759
}]]></source>
17261760

src/site/zh/xdoc/configuration.xml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,42 @@ data_source 属性将会直接以 initialContext 为背景再次寻找。
15691569
在初始化之后,这就会以值“UTF8”向初始上下文的构造方法传递名为“encoding”
15701570
的属性。
15711571
</p>
1572+
1573+
<p>
1574+
You can plug any 3rd party DataSource by implementing the interface <code>org.apache.ibatis.datasource.DataSourceFactory</code>:
1575+
</p>
1576+
1577+
<source><![CDATA[public interface DataSourceFactory {
1578+
void setProperties(Properties props);
1579+
DataSource getDataSource();
1580+
}]]></source>
1581+
1582+
<p>
1583+
<code>org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory</code> can be used as super class
1584+
class to build new datasource adapters. For example this is the code needed to plug C3P0:
1585+
</p>
1586+
1587+
<source><![CDATA[import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
1588+
import com.mchange.v2.c3p0.ComboPooledDataSource;
1589+
1590+
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
1591+
1592+
public C3P0DataSourceFactory() {
1593+
this.dataSource = new ComboPooledDataSource();
1594+
}
1595+
}]]></source>
1596+
1597+
<p>To set it up, add a property for each setter method you want MyBatis to call.
1598+
Below depicts a sample configuration which connects to a PostgreSQL database:</p>
1599+
1600+
<source><![CDATA[<dataSource type="org.myproject.C3P0DataSourceFactory">
1601+
<property name="driver" value="org.postgresql.Driver"/>
1602+
<property name="url" value="jdbc:postgresql:mydb"/>
1603+
<property name="username" value="postgres"/>
1604+
<property name="password" value="root"/>
1605+
</dataSource>
1606+
]]></source>
1607+
15721608
</subsection>
15731609

15741610
<subsection name="databaseIdProvider">
@@ -1610,9 +1646,7 @@ data_source 属性将会直接以 initialContext 为背景再次寻找。
16101646
</p>
16111647

16121648
<source><![CDATA[public interface DatabaseIdProvider {
1613-
16141649
void setProperties(Properties p);
1615-
16161650
String getDatabaseId(DataSource dataSource) throws SQLException;
16171651
}]]></source>
16181652

0 commit comments

Comments
 (0)