Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.dropwizard.hibernate;
 
public class SessionFactoryFactory {
    private static final Logger LOGGER = LoggerFactory.getLogger(SessionFactoryFactory.class);
    public SessionFactory build(HibernateBundle<?> bundle,
                                Environment environment,
                                DataSourceFactory dbConfig,
                                List<Class<?>> entities) {
        final ManagedDataSource dataSource = dbConfig.build(environment.metrics(), "hibernate");
        return build(bundleenvironmentdbConfigdataSourceentities);
    }
    public SessionFactory build(HibernateBundle<?> bundle,
                                Environment environment,
                                DataSourceFactory dbConfig,
                                ManagedDataSource dataSource,
                                List<Class<?>> entities) {
        final ConnectionProvider provider = buildConnectionProvider(dataSource,
                                                                    dbConfig.getProperties());
        final SessionFactory factory = buildSessionFactory(bundle,
                                                           dbConfig,
                                                           provider,
                                                           dbConfig.getProperties(),
                                                           entities);
        final SessionFactoryManager managedFactory = new SessionFactoryManager(factorydataSource);
        environment.lifecycle().manage(managedFactory);
        return factory;
    }
                                                       Map<StringStringproperties) {
        final DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl();
        connectionProvider.setDataSource(dataSource);
        connectionProvider.configure(properties);
        return connectionProvider;
    }
                                               DataSourceFactory dbConfig,
                                               ConnectionProvider connectionProvider,
                                               Map<StringStringproperties,
                                               List<Class<?>> entities) {
        final Configuration configuration = new Configuration();
        configuration.setProperty(."managed");
        configuration.setProperty(., Boolean.toString(dbConfig.isAutoCommentsEnabled()));
        configuration.setProperty(."true");
        configuration.setProperty(."true");
        configuration.setProperty(."true");
        configuration.setProperty(."true");
        configuration.setProperty(."true");
        configuration.setProperty(."true");
        configuration.setProperty("jadira.usertype.autoRegisterUserTypes""true");
        for (Map.Entry<StringStringproperty : properties.entrySet()) {
            configuration.setProperty(property.getKey(), property.getValue());
        }
        addAnnotatedClasses(configurationentities);
        bundle.configure(configuration);
        final ServiceRegistry registry = new StandardServiceRegistryBuilder()
                .addService(ConnectionProvider.classconnectionProvider)
                .applySettings(properties)
                .build();
        return configuration.buildSessionFactory(registry);
    }
    private void addAnnotatedClasses(Configuration configuration,
                                     Iterable<Class<?>> entities) {
        final SortedSet<StringentityClasses = Sets.newTreeSet();
        for (Class<?> klass : entities) {
            configuration.addAnnotatedClass(klass);
            entityClasses.add(klass.getCanonicalName());
        }
        .info("Entity classes: {}"entityClasses);
    }
New to GrepCode? Check out our FAQ X