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

io.robe.hibernate.RobeSessionFactoryFactory Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.hibernate;

import io.dropwizard.hibernate.SessionFactoryFactory;
import io.robe.hibernate.conf.RobeHibernateNamingStrategy;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.service.ServiceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RobeSessionFactoryFactory extends SessionFactoryFactory {
    private static final Logger LOGGER = LoggerFactory.getLogger(RobeSessionFactoryFactory.class);

    @Override
    protected void configure(Configuration configuration, ServiceRegistry registry) {
        determineNamingStrategy(configuration);
    }

    private void determineNamingStrategy(Configuration configuration) {
        String prefix = configuration.getProperty("hibernate.prefix");
        if (prefix != null) {
            configuration.setNamingStrategy(new RobeHibernateNamingStrategy(prefix));
            LOGGER.info("Table Prefix: ", prefix);
        }

        String namingStrategy = configuration.getProperty("hibernate.namingStrategy");
        if (namingStrategy != null) {
            LOGGER.warn("Hibernate.prefix property will be ignored, cause: another type of naming strategy selected");
            try {
                configuration.setNamingStrategy((NamingStrategy) Class.forName(namingStrategy).newInstance());
            } catch (Exception e) {
                LOGGER.error("Can't set Hibernate Naming Strategy", e);
            }
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy