All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.leanix.dropkit.persistence.DropkitHibernateBundle Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package net.leanix.dropkit.persistence;

import com.google.common.collect.ImmutableList;
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import io.dropwizard.hibernate.SessionFactoryFactory;
import org.hibernate.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Implementation of HibernateBundle that set a Hibernate interceptor in
 * the configure method.
 * @param  the dropizard configuration type
 */
public class DropkitHibernateBundle extends HibernateBundle {

    private final Logger log = LoggerFactory.getLogger(DropkitHibernateBundle.class);

    private final Interceptor interceptor;

    public DropkitHibernateBundle(ImmutableList> entities, SessionFactoryFactory sessionFactoryFactory) {
        super(entities, sessionFactoryFactory);
        this.interceptor = null;
    }

    @Override
    public DataSourceFactory getDataSourceFactory(T configuration) {
        return configuration.getDataSourceFactory();
    }

    @Override
    protected void configure(org.hibernate.cfg.Configuration configuration) {
        if (interceptor != null) {
            log.debug("setting hibernate interceptor");
            configuration.setInterceptor(interceptor);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy