Ibatis itself does not directly support proxool data source connection. We can achieve this through the following methods:
First, use spring to integrate ibatis with proxool, and use spring to inject the proxool data source into sqlmapclient. For specific configuration, see spring + ibatis integration on the Internet.
The second method is completely independent from spring. First, we need to customize a performancefactory class, which must implement the com. ibatis. sqlmap. Engine. datasource. performancefactory interface.
CodeImplementation:
Code
Package Mycom. util. dB;
ImportJava. util. Map;
ImportJavax. SQL. datasource;
ImportOrg. logicalcobwebs. proxool. proxooldatasource;
ImportCom. ibatis. sqlmap. Engine. datasource. performancefactory;
Public ClassProxooldatasourcefactoryImplementsPerformancefactory {
Private Proxooldatasource;
Public Datasource getdatasource (){
Return Datasource;
}
/**
* This method sets the properties of the proxooldatasource class.
* House-keeping-sleep-time
* The thread remains dormant for 30 seconds. The house keeper checks the status of all connections and tests whether to destroy or create them. The default time is 30 seconds.
* House-keeping-test-SQL
* If the House keep thread finds idle connections, it tests the SQL statement and runs the statement quickly. For example, the SQL statement of the query date.
* Maximum-active-time
* Maximum thread activity time.
* Maximum-connection-count
* Maximum number of connections to the database (default value: 15)
* Maximum-connection-count
* The maximum time for a connection to remain active. The default value is 4 hours, in milliseconds
* Overload-without-Refusal-lifetime
* This helps us determine the connection pool status. If a connection is rejected within the time threshold (in milliseconds), the connection is deemed to be overloaded. The default time is 60 seconds.
*/
Public Void Initialize (MAP map ){
Datasource = New Proxooldatasource ();
Datasource. setdriver (string) map. Get ( " Driver " ));
Datasource. setdriverurl (string) map. Get ( " Driverurl " ));
Datasource. setuser (string) map. Get ( " User " ));
Datasource. setpassword (string) map. Get ( " Password " ));
Datasource. setalias ( " Alias " );
// The thread remains dormant for 30 seconds. The house keeper checks the status of all connections and tests whether to destroy or create them. The default time is 30 seconds.
If (Map. containskey ( " House-keeping-sleep-time " )){
Datasource. sethousekeepingsleeptime (integer. parseint (Map. Get ( " House-keeping-sleep-time " ). Tostring ()));
}
// If the House keep thread finds idle connections, it will test and use this SQL statement for testing. This statement should be executed quickly. For example, the SQL statement of the query date.
If (Map. containskey ( " House-keeping-test-SQL " )){
Datasource. sethousekeepingtestsql (Map. Get ( " House-keeping-test-SQL " ). Tostring ());
}
// Maximum thread activity time.
// If housekeeper encounters a thread activity time that exceeds the defined time, the thread will be terminated.
// Therefore, you need to set a time later than the expected slowest response time (the default time is 5 minutes ).
If (Map. containskey ( " Maximum-active-time " )){
Datasource. setmaximumactivetime (integer. parseint (Map. Get ( " Maximum-active-time " ). Tostring ()));
}
// Maximum number of connections to the database (default value: 15)
If (Map. containskey ( " Maximum-connection-count " )){
Datasource. setmaximumconnectioncount (integer. parseint (Map. Get ( " Maximum-connection-count " ). Tostring ()));
}
// The maximum time for a connection to remain active. The default value is 4 hours, in milliseconds.
If (Map. containskey ( " Maximum-connection-lifetime " )){
Datasource. setmaximumconnectionlifetime (integer. parseint (Map. Get ( " Maximum-connection-lifetime " ). Tostring ()));
}
// The minimum number of connections to be opened. The default value is 5, no matter whether or not it is required.
If (Map. containskey ( " Minimum-connection-count " )){
Datasource. setmaximumconnectionlifetime (integer. parseint (Map. Get ( " Minimum-connection-count " ). Tostring ()));
}
// This helps us determine the connection pool status. If a connection is rejected within the time threshold (in milliseconds), the connection is deemed to be overloaded. The default time is 60 seconds.
If (Map. containskey ( " Overload-without-Refusal-lifetime " )){
Datasource. setmaximumconnectionlifetime (integer. parseint (Map. Get ( " Overload-without-Refusal-lifetime " ). Tostring ()));
}
}
}
Configure the sqlmap. xml file
Code
< Datasource Type = "Mycom. util. DB. proxooldatasourcefactory" >
< Property Name = "Driver" Value = "Com. Microsoft. sqlserver. JDBC. sqlserverdriver" />
< Property Name = "Driverurl" Value = "JDBC: sqlserver: // localhost: 1433; databasename = mydb ;" />
< Property Name = "User" Value = "Sa" />
< Property Name = "Password" Value = "Sasa" />
< Property Name = "Maximum-connection-count" Value = "40" />
< Property Name = "Overload-without-Refusal-Lifetime" Value = "60" />
< Property Name = "House-keeping-test-SQL" Value = "Select getdate ()" />
</ Datasource >
With proxool:
Http://proxool.sourceforge.net/