| 23723 |
amit.gupta |
1 |
package com.smartdukaan.cron.config;
|
|
|
2 |
|
| 23738 |
amit.gupta |
3 |
import java.io.IOException;
|
| 23723 |
amit.gupta |
4 |
import java.util.Properties;
|
|
|
5 |
|
|
|
6 |
import javax.sql.DataSource;
|
|
|
7 |
|
|
|
8 |
import org.hibernate.SessionFactory;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
11 |
import org.springframework.context.annotation.Bean;
|
|
|
12 |
import org.springframework.context.annotation.Configuration;
|
|
|
13 |
import org.springframework.context.annotation.PropertySource;
|
|
|
14 |
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
|
15 |
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
|
|
16 |
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
|
|
17 |
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
18 |
|
| 23738 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
|
|
20 |
|
| 23723 |
amit.gupta |
21 |
@Configuration
|
|
|
22 |
@EnableTransactionManagement
|
|
|
23 |
@PropertySource("classpath:META-INF/env.properties")
|
|
|
24 |
public class DBConfig {
|
|
|
25 |
|
|
|
26 |
private static final Object HIBERNATE_DIALECT = "hibernate.dialect";
|
|
|
27 |
|
|
|
28 |
private static final Object HIBERNATE_SHOW_SQL = "hibernate.show_sql";
|
|
|
29 |
|
|
|
30 |
private static final Object HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
|
|
|
31 |
|
|
|
32 |
private static final Object HIBERNATE_JDBC_BATCH_SIZE = "hibernate.jdbc.batch_size";
|
|
|
33 |
|
|
|
34 |
private static final Object HIBERNATE_C3P0_MIN_SIZE = "hibernate.c3p0.min_size";
|
|
|
35 |
|
|
|
36 |
private static final Object HIBERNATE_C3P0_MAX_SIZE = "hibernate.c3p0.max_size";
|
|
|
37 |
|
|
|
38 |
private static final Object HIBERNATE_C3P0_TIMEOUT = "hibernate.c3p0.timeout";
|
|
|
39 |
|
|
|
40 |
private static final Object HIBERNATE_C3P0_MAX_STATEMENTS = "hibernate.c3p0.max_statements";
|
|
|
41 |
|
|
|
42 |
private static final Object HIBERNATE_C3P0_IDLE_TEST_PERIOD = "hibernate.c3p0.idle_test_period";
|
|
|
43 |
|
|
|
44 |
@Value("${hibernate.driver.class}")
|
|
|
45 |
private String hibernateDriverClass;
|
|
|
46 |
|
|
|
47 |
@Value("${hibernate.url}")
|
|
|
48 |
private String hibernateUrl;
|
|
|
49 |
|
|
|
50 |
@Value("${hibernate.user.name}")
|
|
|
51 |
private String hibernateUserName;
|
|
|
52 |
|
|
|
53 |
@Value("${hibernate.password}")
|
|
|
54 |
private String hibernatePassword;
|
|
|
55 |
|
|
|
56 |
@Value("${hibernate.dialect}")
|
|
|
57 |
private String hibernateDialect;
|
|
|
58 |
|
|
|
59 |
@Value("${hibernate.show_sql}")
|
|
|
60 |
private String hibernateShowSql;
|
|
|
61 |
|
|
|
62 |
@Value("${hibernate.format_sql}")
|
|
|
63 |
private String hibernateFormatSql;
|
|
|
64 |
|
|
|
65 |
@Value("${hibernate.jdbc.batch_size}")
|
|
|
66 |
private String hibernateBatchSize;
|
|
|
67 |
|
|
|
68 |
@Value("${hibernate.c3p0.min_size}")
|
|
|
69 |
private String hibernateMinSize;
|
|
|
70 |
|
|
|
71 |
@Value("${hibernate.c3p0.max_size}")
|
|
|
72 |
private String hibernateMaxSize;
|
|
|
73 |
|
|
|
74 |
@Value("${hibernate.c3p0.timeout}")
|
|
|
75 |
private String hibernateTimeout;
|
|
|
76 |
|
|
|
77 |
@Value("${hibernate.c3p0.max_statements}")
|
|
|
78 |
private String hibernateMaxStatements;
|
|
|
79 |
|
|
|
80 |
@Value("${hibernate.c3p0.idle_test_period}")
|
|
|
81 |
private String hibernateIdleTestPeriod;
|
| 23738 |
amit.gupta |
82 |
|
|
|
83 |
@Value("${mongo.host}")
|
|
|
84 |
private String mongoHost;
|
| 23723 |
amit.gupta |
85 |
|
| 23738 |
amit.gupta |
86 |
@Value("${content.mongo.host}")
|
|
|
87 |
private String contentMongoHost;
|
|
|
88 |
|
| 23723 |
amit.gupta |
89 |
@Bean(name = "dataSource")
|
|
|
90 |
public DataSource dataSource() {
|
|
|
91 |
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
|
|
92 |
dataSource.setDriverClassName(hibernateDriverClass);
|
|
|
93 |
dataSource.setUrl(hibernateUrl);
|
|
|
94 |
dataSource.setUsername(hibernateUserName);
|
|
|
95 |
dataSource.setPassword(hibernatePassword);
|
|
|
96 |
|
|
|
97 |
return dataSource;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
@Bean
|
|
|
101 |
public Properties getHibernateProperties() {
|
|
|
102 |
Properties dbProperties = new Properties();
|
|
|
103 |
dbProperties.put(HIBERNATE_DIALECT, hibernateDialect);
|
|
|
104 |
dbProperties.put(HIBERNATE_SHOW_SQL, hibernateShowSql);
|
|
|
105 |
dbProperties.put(HIBERNATE_FORMAT_SQL, hibernateFormatSql);
|
|
|
106 |
dbProperties.put(HIBERNATE_JDBC_BATCH_SIZE, hibernateBatchSize);
|
|
|
107 |
dbProperties.put(HIBERNATE_C3P0_MIN_SIZE, hibernateMinSize);
|
|
|
108 |
dbProperties.put(HIBERNATE_C3P0_MAX_SIZE, hibernateMaxSize);
|
|
|
109 |
dbProperties.put(HIBERNATE_C3P0_TIMEOUT, hibernateTimeout);
|
|
|
110 |
dbProperties.put(HIBERNATE_C3P0_MAX_STATEMENTS, hibernateMaxStatements);
|
|
|
111 |
dbProperties.put(HIBERNATE_C3P0_IDLE_TEST_PERIOD, hibernateIdleTestPeriod);
|
|
|
112 |
return dbProperties;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Autowired
|
|
|
116 |
@Bean(name = "sessionFactory")
|
|
|
117 |
public SessionFactory getSessionFactory(DataSource dataSource) {
|
|
|
118 |
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
|
|
|
119 |
sessionBuilder.addProperties(getHibernateProperties());
|
|
|
120 |
sessionBuilder.scanPackages("com.spice.profitmandi.dao.*");
|
|
|
121 |
return sessionBuilder.buildSessionFactory();
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
@Autowired
|
|
|
125 |
@Bean(name = "transactionManager")
|
|
|
126 |
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
|
|
|
127 |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
|
|
|
128 |
return transactionManager;
|
|
|
129 |
}
|
| 23738 |
amit.gupta |
130 |
|
|
|
131 |
@Bean
|
|
|
132 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
|
|
133 |
return new Mongo(mongoHost, contentMongoHost);
|
|
|
134 |
}
|
| 23723 |
amit.gupta |
135 |
}
|