| Line 26... |
Line 26... |
| 26 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
26 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
| 27 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
27 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 28 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
28 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
| 29 |
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
29 |
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
| 30 |
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
30 |
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
| - |
|
31 |
import com.google.gson.Gson;
|
| - |
|
32 |
import com.google.gson.GsonBuilder;
|
| - |
|
33 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| 31 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
34 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 32 |
|
35 |
|
| 33 |
@Configuration
|
36 |
@Configuration
|
| 34 |
@EnableTransactionManagement
|
37 |
@EnableTransactionManagement
|
| 35 |
@ComponentScan("com.spice.profitmandi.*")
|
38 |
@ComponentScan("com.spice.profitmandi.*")
|
| 36 |
@PropertySource("classpath:META-INF/env.properties")
|
39 |
@PropertySource("classpath:META-INF/env.properties")
|
| 37 |
public class DBConfig {
|
40 |
public class DBConfig {
|
| 38 |
|
41 |
|
| 39 |
private static final Logger LOGGER=LogManager.getLogger(DBConfig.class);
|
42 |
private static final Logger LOGGER = LogManager.getLogger(DBConfig.class);
|
| 40 |
|
43 |
|
| 41 |
|
- |
|
| 42 |
private static final String HIBERNATE_DIALECT = "hibernate.dialect";
|
44 |
private static final String HIBERNATE_DIALECT = "hibernate.dialect";
|
| 43 |
|
45 |
|
| 44 |
private static final String HIBERNATE_SHOW_SQL = "hibernate.show_sql";
|
46 |
private static final String HIBERNATE_SHOW_SQL = "hibernate.show_sql";
|
| 45 |
|
47 |
|
| 46 |
private static final String HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
|
48 |
private static final String HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
|
| Line 93... |
Line 95... |
| 93 |
@Value("${hibernate.c3p0.max_statements}")
|
95 |
@Value("${hibernate.c3p0.max_statements}")
|
| 94 |
private String hibernateMaxStatements;
|
96 |
private String hibernateMaxStatements;
|
| 95 |
|
97 |
|
| 96 |
@Value("${hibernate.c3p0.idle_test_period}")
|
98 |
@Value("${hibernate.c3p0.idle_test_period}")
|
| 97 |
private String hibernateIdleTestPeriod;
|
99 |
private String hibernateIdleTestPeriod;
|
| 98 |
|
100 |
|
| 99 |
@Value("${mongo.host}")
|
101 |
@Value("${mongo.host}")
|
| 100 |
private String mongoHost;
|
102 |
private String mongoHost;
|
| 101 |
|
103 |
|
| 102 |
@Value("${content.mongo.host}")
|
104 |
@Value("${content.mongo.host}")
|
| 103 |
private String contentMongoHost;
|
105 |
private String contentMongoHost;
|
| 104 |
|
106 |
|
| 105 |
@Primary
|
107 |
@Primary
|
| 106 |
@Bean(name = "dataSource")
|
108 |
@Bean(name = "dataSource")
|
| 107 |
public DataSource dataSource() {
|
109 |
public DataSource dataSource() {
|
| 108 |
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
110 |
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
| 109 |
dataSource.setDriverClassName(hibernateDriverClass);
|
111 |
dataSource.setDriverClassName(hibernateDriverClass);
|
| Line 111... |
Line 113... |
| 111 |
dataSource.setUsername(hibernateUserName);
|
113 |
dataSource.setUsername(hibernateUserName);
|
| 112 |
dataSource.setPassword(hibernatePassword);
|
114 |
dataSource.setPassword(hibernatePassword);
|
| 113 |
LOGGER.info("DataSource returned {}", dataSource);
|
115 |
LOGGER.info("DataSource returned {}", dataSource);
|
| 114 |
return dataSource;
|
116 |
return dataSource;
|
| 115 |
}
|
117 |
}
|
| 116 |
|
118 |
|
| 117 |
@Bean
|
119 |
@Bean
|
| 118 |
public ObjectMapper objectMapper() {
|
120 |
public ObjectMapper objectMapper() {
|
| 119 |
DateTimeFormatter df = new DateTimeFormatterBuilder()
|
121 |
DateTimeFormatter df = new DateTimeFormatterBuilder().parseCaseInsensitive()
|
| 120 |
.parseCaseInsensitive()
|
- |
|
| 121 |
.append(DateTimeFormatter.ISO_LOCAL_DATE)
|
122 |
.append(DateTimeFormatter.ISO_LOCAL_DATE).optionalStart().appendLiteral('T').optionalEnd()
|
| 122 |
.optionalStart()
|
- |
|
| 123 |
.appendLiteral('T')
|
- |
|
| 124 |
.optionalEnd()
|
- |
|
| 125 |
.appendLiteral(' ')
|
- |
|
| 126 |
.append(DateTimeFormatter.ISO_LOCAL_TIME)
|
123 |
.appendLiteral(' ').append(DateTimeFormatter.ISO_LOCAL_TIME).toFormatter();
|
| 127 |
.toFormatter();
|
- |
|
| 128 |
DateTimeFormatter sf = new DateTimeFormatterBuilder()
|
124 |
DateTimeFormatter sf = new DateTimeFormatterBuilder().parseCaseInsensitive()
|
| 129 |
.parseCaseInsensitive()
|
- |
|
| 130 |
.append(DateTimeFormatter.ISO_LOCAL_DATE)
|
- |
|
| 131 |
.appendLiteral('T')
|
- |
|
| 132 |
.append(DateTimeFormatter.ISO_LOCAL_TIME)
|
125 |
.append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(DateTimeFormatter.ISO_LOCAL_TIME)
|
| 133 |
.toFormatter();
|
126 |
.toFormatter();
|
| 134 |
LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
|
127 |
LocalDateTimeSerializer serializer = new LocalDateTimeSerializer(sf);
|
| 135 |
LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
|
128 |
LocalDateTimeDeserializer deserializer = new LocalDateTimeDeserializer(df);
|
| 136 |
JavaTimeModule jtm = new JavaTimeModule();
|
129 |
JavaTimeModule jtm = new JavaTimeModule();
|
| 137 |
jtm.addSerializer(LocalDateTime.class, serializer);
|
130 |
jtm.addSerializer(LocalDateTime.class, serializer);
|
| 138 |
jtm.addDeserializer(LocalDateTime.class, deserializer);
|
131 |
jtm.addDeserializer(LocalDateTime.class, deserializer);
|
| 139 |
ObjectMapper mapper = new ObjectMapper()
|
- |
|
| 140 |
.registerModule(new ParameterNamesModule())
|
132 |
ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
|
| 141 |
.registerModule(new Jdk8Module())
|
- |
|
| 142 |
.registerModule(jtm); // new module, NOT JSR310Module
|
133 |
.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
|
| 143 |
return mapper;
|
134 |
return mapper;
|
| 144 |
}
|
135 |
}
|
| 145 |
|
136 |
|
| 146 |
@Bean
|
137 |
@Bean
|
| 147 |
public Properties getHibernateProperties() {
|
138 |
public Properties getHibernateProperties() {
|
| Line 155... |
Line 146... |
| 155 |
dbProperties.put(HIBERNATE_C3P0_TIMEOUT, hibernateTimeout);
|
146 |
dbProperties.put(HIBERNATE_C3P0_TIMEOUT, hibernateTimeout);
|
| 156 |
dbProperties.put(HIBERNATE_C3P0_MAX_STATEMENTS, hibernateMaxStatements);
|
147 |
dbProperties.put(HIBERNATE_C3P0_MAX_STATEMENTS, hibernateMaxStatements);
|
| 157 |
dbProperties.put(HIBERNATE_C3P0_IDLE_TEST_PERIOD, hibernateIdleTestPeriod);
|
148 |
dbProperties.put(HIBERNATE_C3P0_IDLE_TEST_PERIOD, hibernateIdleTestPeriod);
|
| 158 |
return dbProperties;
|
149 |
return dbProperties;
|
| 159 |
}
|
150 |
}
|
| 160 |
|
151 |
|
| 161 |
@Primary
|
152 |
@Primary
|
| 162 |
@Autowired
|
153 |
@Autowired
|
| 163 |
@Bean(name = "sessionFactory")
|
154 |
@Bean(name = "sessionFactory")
|
| 164 |
public SessionFactory getSessionFactory(DataSource dataSource) {
|
155 |
public SessionFactory getSessionFactory(DataSource dataSource) {
|
| 165 |
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
|
156 |
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
|
| 166 |
sessionBuilder.addProperties(getHibernateProperties());
|
157 |
sessionBuilder.addProperties(getHibernateProperties());
|
| 167 |
sessionBuilder.scanPackages("com.spice.profitmandi.dao.*");
|
158 |
sessionBuilder.scanPackages("com.spice.profitmandi.dao.*");
|
| 168 |
return sessionBuilder.buildSessionFactory();
|
159 |
return sessionBuilder.buildSessionFactory();
|
| 169 |
}
|
160 |
}
|
| 170 |
|
161 |
|
| 171 |
@Primary
|
162 |
@Primary
|
| 172 |
@Autowired
|
163 |
@Autowired
|
| 173 |
@Bean(name = "transactionManager")
|
164 |
@Bean(name = "transactionManager")
|
| 174 |
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
|
165 |
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
|
| 175 |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
|
166 |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
|
| 176 |
return transactionManager;
|
167 |
return transactionManager;
|
| 177 |
}
|
168 |
}
|
| 178 |
|
169 |
|
| 179 |
@Bean
|
170 |
@Bean
|
| 180 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
171 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
| 181 |
return new Mongo(mongoHost, contentMongoHost);
|
172 |
return new Mongo(mongoHost, contentMongoHost);
|
| 182 |
}
|
173 |
}
|
| - |
|
174 |
|
| - |
|
175 |
@Bean(name = "gson")
|
| - |
|
176 |
public Gson gson() {
|
| - |
|
177 |
|
| - |
|
178 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
| - |
|
179 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
| - |
|
180 |
|
| - |
|
181 |
return gson;
|
| - |
|
182 |
|
| - |
|
183 |
}
|
| 183 |
}
|
184 |
}
|