이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 7. Configuring Data Grid Server Datasources
Create managed datasources to optimize connection pooling and performance for database connections.
You can specify database connection properties as part of a JDBC cache store configuration. However you must do this for each cache definition, which duplicates configuration and wastes resources by creating multiple distinct connection pools.
By using shared, managed datasources, you centralize connection configuration and pooling for more efficient usage.
7.1. Datasource Configuration for JDBC Cache Stores
Data Grid server configuration for datasources is composed of two sections:
-
A
connection factory
that defines how to connect to the database. -
A
connection pool
that defines how to pool and reuse connections.
<data-sources> <data-source name="ds" jndi-name="jdbc/datasource" statistics="true"> 1 <connection-factory driver="org.database.Driver" 2 username="db_user" 3 password="secret" 4 url="jdbc:db://database-host:10000/dbname" 5 new-connection-sql="SELECT 1" 6 transaction-isolation="READ_COMMITTED"> 7 <connection-property name="name">value</connection-property> 8 </connection-factory> <connection-pool initial-size="1" 9 max-size="10" 10 min-size="3" 11 background-validation="1000" 12 idle-removal="1" 13 blocking-timeout="1000" 14 leak-detection="10000"/> 15 </data-source> </data-sources>
- 1
- Defines a datasource name, JNDI name, and whether to enable statistics collection.
- 2
- Specifies the JDBC driver that creates connections. Place driver JARs in the
server/lib
directory. - 3
- Specifies a username for the connection.
- 4
- Specifies a corresponding password for the connection.
- 5
- Specifies the JDBC URL specific to the driver in use.
- 6
- Adds a query that verifies new connections.
- 7
- Configures one of the transaction isolation levels for the connection:
NONE
,READ_UNCOMMITTED
,READ_COMMITTED
,REPEATABLE_READ
,SERIALIZABLE
. - 8
- Sets optional JDBC driver-specific connection properties.
- 9
- Defines the initial number of connections the pool contains.
- 10
- Sets the maximum number of connections in the pool.
- 11
- Sets the minimum number of connections the pool should contain.
- 12
- Specifies the time, in milliseconds, between background validation runs.
- 13
- Specifies the time, in minutes, a connections can remain idle before it is removed.
- 14
- Specifies the amount of time, in milliseconds, to block while waiting for a connection, after which an exception is thrown.
- 15
- Specifies the time, in milliseconds, a connection can be held before a leak warning occurs.
7.2. Using Datasources in JDBC Cache Stores
Use a shared, managed datasource in your JDBC cache store configuration instead of specifying individual connection properties for each cache definition.
Prerequisites
Create a managed datasource for JDBC cache stores in your Data Grid server configuration.
Procedure
- Reference the JNDI name of the datasource in the JDBC cache store configuration of your cache configuration, as in the following example:
<distributed-cache-configuration name="persistent-cache" xmlns:jdbc="urn:infinispan:config:store:jdbc:11.0">
<persistence>
<jdbc:string-keyed-jdbc-store>
<jdbc:data-source jndi-url="jdbc/postgres"/> 1
<jdbc:string-keyed-table drop-on-exit="true"
create-on-start="true"
prefix="TBL">
<jdbc:id-column name="ID" type="VARCHAR(255)"/>
<jdbc:data-column name="DATA" type="BYTEA"/>
<jdbc:timestamp-column name="TS" type="BIGINT"/>
<jdbc:segment-column name="S" type="INT"/>
</jdbc:string-keyed-table>
</jdbc:string-keyed-jdbc-store>
</persistence>
</distributed-cache-configuration>
- 1
- Specifies the JNDI name that you provided for the datasource connection in your Data Grid server configuration.