Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package io.dropwizard.hibernate;
  
 
 import java.util.List;
 import java.util.Map;
 
 public class SessionFactoryFactory {
     private static final Logger LOGGER = LoggerFactory.getLogger(SessionFactoryFactory.class);
     private static final String DEFAULT_NAME = "hibernate";
 
     public SessionFactory build(HibernateBundle<?> bundle,
                                 Environment environment,
                                 PooledDataSourceFactory dbConfig,
                                 List<Class<?>> entities) {
         return build(bundleenvironmentdbConfigentities);
     }
 
     public SessionFactory build(HibernateBundle<?> bundle,
                                 Environment environment,
                                 PooledDataSourceFactory dbConfig,
                                 List<Class<?>> entities,
                                 String name) {
         final ManagedDataSource dataSource = dbConfig.build(environment.metrics(), name);
         return build(bundleenvironmentdbConfigdataSourceentities);
     }
 
     public SessionFactory build(HibernateBundle<?> bundle,
                                 Environment environment,
                                 PooledDataSourceFactory 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;
     }
 
     private SessionFactory buildSessionFactory(HibernateBundle<?> bundle,
                                                PooledDataSourceFactory 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