com.cvent.dropwizard.mybatis.MyBatisHealthCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-mybatis Show documentation
Show all versions of dropwizard-mybatis Show documentation
An open source bridge layer so that you can use mybatis with dropwizard + other useful utility methods often used within an enterprise.
package com.cvent.dropwizard.mybatis;
import com.codahale.metrics.health.HealthCheck;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.sql.CallableStatement;
/**
* A standard MyBatis healthcheck
*
* @author bryan
*/
public class MyBatisHealthCheck extends HealthCheck {
/**
* The MyBatis instance to check
*/
private final SqlSessionFactory sessionFactory;
/**
* The validation SQL query to run
*/
private final String validationQuery;
/**
* Create a new dropwizard healthcheck
*
* @param sessionFactory The MyBatis instance we want to check
* @param validationQuery The validation SQL query to run
*/
public MyBatisHealthCheck(SqlSessionFactory sessionFactory, String validationQuery) {
this.sessionFactory = sessionFactory;
this.validationQuery = validationQuery;
}
@Override
protected HealthCheck.Result check() throws Exception {
try (SqlSession session = sessionFactory.openSession();
CallableStatement callableStatement = session.getConnection().prepareCall(validationQuery)) {
callableStatement.execute();
}
return Result.healthy();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy