package com.hida.configuration;

import java.util.Properties;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * missing javadocs
 *
 */
@Configuration
@EnableTransactionManagement
@ComponentScan({"com.hida.configuration"})
@PropertySource(value = {"classpath:minter_config.properties"})
public class HibernateConfiguration {

    /**
     * missing javadocs
     */
    @Autowired
    private Environment environment;

    /**
     * missing javadocs
     *
     * @return
     */
    @Bean
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource());
        sessionFactory.setPackagesToScan(new String[]{"com.hida.model"});
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
    }

    /**
     * missing javadocs
     *
     * @return
     */
    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
        dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
        dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
        dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
        return dataSource;
    }

    /**
     * missing javadocs
     *
     * @return
     */
    private Properties hibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
        return properties;
    }

    /**
     * missing javadocs
     *
     * @param s
     * @return
     */
    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory s) {
        HibernateTransactionManager txManager = new HibernateTransactionManager();
        txManager.setSessionFactory(s);
        return txManager;
    }
}

@@ -768,27 +768,89 @@
 %0A * 
-missing javadocs%0A *
+This class is used to configure Hibernate and Spring Beans.%0A *%0A * @author lruffin
 %0A */
@@ -1043,48 +1043,12 @@
 n %7B%0A
-%0A
     
-/**%0A     * missing javadocs%0A     */
 %0A   
@@ -1100,70 +1100,12 @@
 nt;%0A
-%0A
     
-/**%0A     * missing javadocs%0A     *%0A     * @return%0A     */
 %0A   
@@ -1482,70 +1482,12 @@
   %7D%0A
-%0A
     
-/**%0A     * missing javadocs%0A     *%0A     * @return%0A     */
 %0A   
@@ -1975,70 +1975,12 @@
   %7D%0A
-%0A
     
-/**%0A     * missing javadocs%0A     *%0A     * @return%0A     */
 %0A   
@@ -2213,24 +2213,41 @@
 .show_sql%22, 
+%0A                
 environment.
@@ -2337,16 +2337,33 @@
 t_sql%22, 
+%0A                
 environm
@@ -2461,16 +2461,33 @@
 .auto%22, 
+%0A                
 environm
@@ -2575,86 +2575,12 @@
   %7D%0A
-%0A
     
-/**%0A     * missing javadocs%0A     *%0A     * @param s%0A     * @return%0A     */
 %0A   

Clean HibernateConfiguration