Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.dropwizard.hibernate;
 
public class SessionFactoryHealthCheck extends HealthCheck {
    private final SessionFactory sessionFactory;
    private final String validationQuery;
    public SessionFactoryHealthCheck(SessionFactory sessionFactory,
                                     String validationQuery) {
        this(MoreExecutors.newDirectExecutorService(), Duration.seconds(0), sessionFactoryvalidationQuery);
    }
    public SessionFactoryHealthCheck(ExecutorService executorService,
                                     Duration duration,
                                     SessionFactory sessionFactory,
                                     String validationQuery) {
        this. = sessionFactory;
        this. = validationQuery;
        this. = new TimeBoundHealthCheck(executorServiceduration);
    }
    
    public SessionFactory getSessionFactory() {
        return ;
    }
    public String getValidationQuery() {
        return ;
    }
    @Override
    protected Result check() throws Exception {
        return .check(new Callable<Result>() {
            @Override
            public Result call() throws Exception {
                final Session session = .openSession();
                try {
                    final Transaction txn = session.beginTransaction();
                    try {
                        session.createSQLQuery().list();
                        txn.commit();
                    } catch (Exception e) {
                        if (txn.isActive()) {
                            txn.rollback();
                        }
                        throw e;
                    }
                } finally {
                    session.close();
                }
                return Result.healthy();
            }
        });
    }
New to GrepCode? Check out our FAQ X