| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.config;
|
1 |
package com.smartdukaan.cron.config;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDate;
|
- |
|
| 4 |
import java.time.LocalDateTime;
|
- |
|
| 5 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 6 |
import java.time.format.DateTimeFormatterBuilder;
|
- |
|
| 7 |
import java.util.Properties;
|
- |
|
| 8 |
|
- |
|
| 9 |
import javax.sql.DataSource;
|
- |
|
| 10 |
|
- |
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 12 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 13 |
import org.hibernate.SessionFactory;
|
- |
|
| 14 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 15 |
import org.springframework.beans.factory.annotation.Value;
|
- |
|
| 16 |
import org.springframework.context.annotation.Bean;
|
- |
|
| 17 |
import org.springframework.context.annotation.ComponentScan;
|
- |
|
| 18 |
import org.springframework.context.annotation.Configuration;
|
- |
|
| 19 |
import org.springframework.context.annotation.Primary;
|
- |
|
| 20 |
import org.springframework.context.annotation.PropertySource;
|
- |
|
| 21 |
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
- |
|
| 22 |
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
- |
|
| 23 |
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
- |
|
| 24 |
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
- |
|
| 25 |
|
- |
|
| 26 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 27 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
4 |
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
| 28 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
5 |
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
| 29 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
6 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
| 30 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
7 |
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
| Line 34... |
Line 11... |
| 34 |
import com.google.gson.Gson;
|
11 |
import com.google.gson.Gson;
|
| 35 |
import com.google.gson.GsonBuilder;
|
12 |
import com.google.gson.GsonBuilder;
|
| 36 |
import com.spice.profitmandi.dao.convertor.LocalDateJsonConverter;
|
13 |
import com.spice.profitmandi.dao.convertor.LocalDateJsonConverter;
|
| 37 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
14 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| 38 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
15 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
16 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
17 |
import org.apache.logging.log4j.Logger;
|
| - |
|
18 |
import org.hibernate.SessionFactory;
|
| - |
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
20 |
import org.springframework.beans.factory.annotation.Value;
|
| - |
|
21 |
import org.springframework.context.annotation.*;
|
| - |
|
22 |
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
| - |
|
23 |
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
| - |
|
24 |
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
|
| - |
|
25 |
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
| - |
|
26 |
|
| - |
|
27 |
import javax.sql.DataSource;
|
| - |
|
28 |
import java.time.LocalDate;
|
| - |
|
29 |
import java.time.LocalDateTime;
|
| - |
|
30 |
import java.time.format.DateTimeFormatter;
|
| - |
|
31 |
import java.time.format.DateTimeFormatterBuilder;
|
| - |
|
32 |
import java.util.Properties;
|
| 39 |
|
33 |
|
| 40 |
@Configuration
|
34 |
@Configuration
|
| 41 |
@EnableTransactionManagement
|
35 |
@EnableTransactionManagement
|
| 42 |
@ComponentScan("com.spice.profitmandi.*")
|
36 |
@ComponentScan("com.spice.profitmandi.*")
|
| 43 |
@PropertySource("classpath:META-INF/env.properties")
|
37 |
@PropertySource("classpath:META-INF/env.properties")
|
| Line 137... |
Line 131... |
| 137 |
jtm.addSerializer(LocalDate.class, serializer1);
|
131 |
jtm.addSerializer(LocalDate.class, serializer1);
|
| 138 |
jtm.addDeserializer(LocalDateTime.class, deserializer);
|
132 |
jtm.addDeserializer(LocalDateTime.class, deserializer);
|
| 139 |
jtm.addDeserializer(LocalDate.class, deserializer1);
|
133 |
jtm.addDeserializer(LocalDate.class, deserializer1);
|
| 140 |
ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
|
134 |
ObjectMapper mapper = new ObjectMapper().registerModule(new ParameterNamesModule())
|
| 141 |
.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
|
135 |
.registerModule(new Jdk8Module()).registerModule(jtm); // new module, NOT JSR310Module
|
| - |
|
136 |
LOGGER.info("ObjectMapper returned {}", objectMapper());
|
| 142 |
return mapper;
|
137 |
return mapper;
|
| 143 |
}
|
138 |
}
|
| 144 |
|
139 |
|
| 145 |
@Bean
|
140 |
@Bean
|
| 146 |
public Properties getHibernateProperties() {
|
141 |
public Properties getHibernateProperties() {
|
| Line 162... |
Line 157... |
| 162 |
@Bean(name = "sessionFactory")
|
157 |
@Bean(name = "sessionFactory")
|
| 163 |
public SessionFactory getSessionFactory(DataSource dataSource) {
|
158 |
public SessionFactory getSessionFactory(DataSource dataSource) {
|
| 164 |
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
|
159 |
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
|
| 165 |
sessionBuilder.addProperties(getHibernateProperties());
|
160 |
sessionBuilder.addProperties(getHibernateProperties());
|
| 166 |
sessionBuilder.scanPackages("com.spice.profitmandi.dao.*");
|
161 |
sessionBuilder.scanPackages("com.spice.profitmandi.dao.*");
|
| - |
|
162 |
LOGGER.info("Session Factory returned {}", "sessionFactory");
|
| 167 |
return sessionBuilder.buildSessionFactory();
|
163 |
return sessionBuilder.buildSessionFactory();
|
| 168 |
}
|
164 |
}
|
| 169 |
|
165 |
|
| 170 |
@Primary
|
166 |
@Primary
|
| 171 |
@Autowired
|
167 |
@Autowired
|
| 172 |
@Bean(name = "transactionManager")
|
168 |
@Bean(name = "transactionManager")
|
| 173 |
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
|
169 |
public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
|
| 174 |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
|
170 |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
|
| - |
|
171 |
LOGGER.info("Transaction Manager returned {}", transactionManager);
|
| 175 |
return transactionManager;
|
172 |
return transactionManager;
|
| 176 |
}
|
173 |
}
|
| 177 |
|
174 |
|
| 178 |
@Bean
|
175 |
@Bean
|
| 179 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
176 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
| 180 |
return new Mongo(mongoHost, contentMongoHost);
|
177 |
return new Mongo(mongoHost, contentMongoHost);
|
| 181 |
}
|
178 |
}
|
| 182 |
|
179 |
|
| 183 |
@Bean(name = "gson")
|
180 |
@Bean(name = "gson")
|
| 184 |
public Gson gson() {
|
181 |
public Gson gson() {
|
| 185 |
|
- |
|
| 186 |
Gson gson = new GsonBuilder().serializeNulls()
|
182 |
Gson gson = new GsonBuilder().serializeNulls()
|
| 187 |
.registerTypeAdapter(LocalDate.class, new LocalDateJsonConverter())
|
183 |
.registerTypeAdapter(LocalDate.class, new LocalDateJsonConverter())
|
| 188 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
184 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
| - |
|
185 |
LOGGER.info("Gson returned {}", gson);
|
| 189 |
return gson;
|
186 |
return gson;
|
| 190 |
|
187 |
|
| 191 |
}
|
188 |
}
|
| 192 |
}
|
189 |
}
|