daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ar.com.impripost.impresion.config;
  2.  
  3. import java.util.Properties;
  4.  
  5. import org.hibernate.SessionFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.context.annotation.PropertySource;
  10. import org.springframework.core.env.Environment;
  11. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  12. import org.springframework.orm.hibernate5.HibernateTransactionManager;
  13. import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
  14. import org.springframework.transaction.annotation.EnableTransactionManagement;
  15.  
  16.  
  17.  
  18. import javax.sql.DataSource;
  19.  
  20. @Configuration
  21. @EnableTransactionManagement
  22. @PropertySource(value = {"classpath:jdbc.properties"})
  23.  
  24. public class ApplicationContextConfig {
  25.    
  26.     @Autowired
  27.     private Environment env;
  28.    
  29.     @Bean
  30.     public DataSource dataSource() {
  31.         DriverManagerDataSource dataSource = new DriverManagerDataSource();
  32.        
  33.         dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
  34.         dataSource.setUrl(env.getProperty("jdbc.url"));
  35.         dataSource.setUsername(env.getProperty("jdbc.user"));
  36.         dataSource.setPassword(env.getProperty("jdbc.password"));
  37.        
  38.         return dataSource;
  39.     }
  40.    
  41.     @Bean
  42.     public LocalSessionFactoryBean sessionFactory(){
  43.         LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
  44.        
  45.         sessionFactory.setDataSource(dataSource());
  46.         sessionFactory.setPackagesToScan(new String [] {"ar.com.impripost.impresion.model"});
  47.         sessionFactory.setHibernateProperties(getHibernateProperties());
  48.        
  49.         return sessionFactory;
  50.     }
  51.  
  52.     private Properties getHibernateProperties() {
  53.         Properties prop = new Properties();
  54.        
  55.         prop.put("hibernate.dialect", env.getProperty("sqlserver.dialect"));
  56.         prop.put("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
  57.         prop.put("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
  58.         prop.put("hibernate.query.substitutions", env.getProperty("hibernate.query.substitutions"));
  59.         prop.put("hibernate.connection.release_mode", env.getProperty("hibernate.connection.release_mode"));
  60.         prop.put("hibernate.generate_statistics", env.getProperty("hibernate.generate_statistics"));
  61.        
  62.         return prop;
  63.     }
  64.    
  65.     @Bean
  66.     @Autowired
  67.     public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {     
  68.         HibernateTransactionManager txtManager = new HibernateTransactionManager();
  69.         txtManager.setSessionFactory(sessionFactory);
  70.        
  71.         return txtManager;     
  72.     }
  73.    
  74.  
  75.    
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  84. # * Parametros de Conexion con la Base de Datos sql  *
  85. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  86.  
  87. jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
  88. jdbc.user=sistemas
  89. jdbc.password=santana
  90. jdbc.url=jdbc:jtds:sqlserver://W2008R2DB;instance=SIEDI;DatabaseName=SIEDI;
  91.  
  92.  
  93.  
  94.  
  95. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  96. # *      Parametros de Configuracion de hibernate       *
  97. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  98. sqlserver.dialect=org.hibernate.dialect.SQLServerDialect
  99. hibernate.show_sql=true
  100. hibernate.query.substitutions=true 'T', false 'F'
  101. hibernate.connection.release_mode=after_transaction
  102. hibernate.generate_statistics=true
  103. hibernate.format_sql=true
  104.  
  105.  
  106. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  107. # *   Parametros del pool de conexiones para c3p0       *
  108. # * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  109. c3p0.minPoolSize=5
  110. c3p0.maxPoolSize=20
  111. c3p0.timeout=300
  112. c3p0.max_statement=50
  113. c3p0.testConnectionOnCheckout=false
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top