forked from apolloconfig/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use custom connection validator instead of sending SELECT 1 query
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
apollo-common/src/main/java/com/ctrip/framework/apollo/common/utils/DataSourceValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ctrip.framework.apollo.common.utils; | ||
|
||
import org.apache.tomcat.jdbc.pool.Validator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.sql.Connection; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public class DataSourceValidator implements Validator { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceValidator.class); | ||
private static final int DEFAULT_VALIDATE_TIMEOUT_IN_SECONDS = 5; | ||
|
||
@Override | ||
public boolean validate(Connection connection, int validateAction) { | ||
boolean isValid = false; | ||
try { | ||
isValid = connection.isValid(DEFAULT_VALIDATE_TIMEOUT_IN_SECONDS); | ||
} catch (Throwable ex) { | ||
LOGGER.warn("Data source validation error", ex); | ||
} | ||
|
||
return isValid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters