| Line 43... |
Line 43... |
| 43 |
private static final String HIKARI_MAX_LIFETIME = "hikari.maxLifetime";
|
43 |
private static final String HIKARI_MAX_LIFETIME = "hikari.maxLifetime";
|
| 44 |
private static final String HIKARI_CONNECTION_TIMEOUT = "hikari.connectionTimeout";
|
44 |
private static final String HIKARI_CONNECTION_TIMEOUT = "hikari.connectionTimeout";
|
| 45 |
|
45 |
|
| 46 |
private Resource resource = AppConfig.getResource();
|
46 |
private Resource resource = AppConfig.getResource();
|
| 47 |
|
47 |
|
| 48 |
@Bean(name = "dataSource", destroyMethod = "close")
|
- |
|
| 49 |
public DataSource dataSource() {
|
48 |
private Properties loadAllProperties() {
|
| 50 |
Properties properties = new Properties();
|
49 |
Properties properties = new Properties();
|
| 51 |
try {
|
50 |
try {
|
| - |
|
51 |
Resource sharedRes = AppConfig.getSharedResource();
|
| - |
|
52 |
if (sharedRes != null && sharedRes.exists()) {
|
| - |
|
53 |
properties.load(sharedRes.getInputStream());
|
| - |
|
54 |
}
|
| 52 |
properties.load(resource.getInputStream());
|
55 |
properties.load(resource.getInputStream());
|
| 53 |
} catch (IOException e) {
|
56 |
} catch (IOException e) {
|
| 54 |
e.printStackTrace();
|
57 |
LOGGER.error("Failed to load properties", e);
|
| 55 |
}
|
58 |
}
|
| - |
|
59 |
return properties;
|
| - |
|
60 |
}
|
| - |
|
61 |
|
| - |
|
62 |
@Bean(name = "dataSource", destroyMethod = "close")
|
| - |
|
63 |
public DataSource dataSource() {
|
| - |
|
64 |
Properties properties = loadAllProperties();
|
| 56 |
|
65 |
|
| 57 |
HikariConfig config = new HikariConfig();
|
66 |
HikariConfig config = new HikariConfig();
|
| 58 |
config.setDriverClassName(properties.getProperty(HIBERNATE_DRIVER_CLASS));
|
67 |
config.setDriverClassName(properties.getProperty(HIBERNATE_DRIVER_CLASS));
|
| 59 |
config.setJdbcUrl(properties.getProperty(HIBERNATE_URL));
|
68 |
config.setJdbcUrl(properties.getProperty(HIBERNATE_URL));
|
| 60 |
config.setUsername(properties.getProperty(HIBERNATE_USER_NAME));
|
69 |
config.setUsername(properties.getProperty(HIBERNATE_USER_NAME));
|
| Line 70... |
Line 79... |
| 70 |
}
|
79 |
}
|
| 71 |
|
80 |
|
| 72 |
@Bean
|
81 |
@Bean
|
| 73 |
public Properties getHibernateProperties() {
|
82 |
public Properties getHibernateProperties() {
|
| 74 |
Properties dbProperties = new Properties();
|
83 |
Properties dbProperties = new Properties();
|
| 75 |
Properties properties = new Properties();
|
84 |
Properties properties = loadAllProperties();
|
| 76 |
try {
|
- |
|
| 77 |
properties.load(resource.getInputStream());
|
- |
|
| 78 |
} catch (IOException e) {
|
- |
|
| 79 |
e.printStackTrace();
|
- |
|
| 80 |
}
|
- |
|
| 81 |
dbProperties.put("hibernate.dialect", properties.getProperty("hibernate.dialect"));
|
85 |
dbProperties.put("hibernate.dialect", properties.getProperty("hibernate.dialect"));
|
| 82 |
dbProperties.put("hibernate.show_sql", properties.getProperty("hibernate.show_sql"));
|
86 |
dbProperties.put("hibernate.show_sql", properties.getProperty("hibernate.show_sql"));
|
| 83 |
dbProperties.put("hibernate.format_sql", properties.getProperty("hibernate.format_sql"));
|
87 |
dbProperties.put("hibernate.format_sql", properties.getProperty("hibernate.format_sql"));
|
| 84 |
dbProperties.put("hibernate.jdbc.batch_size", properties.getProperty("hibernate.jdbc.batch_size"));
|
88 |
dbProperties.put("hibernate.jdbc.batch_size", properties.getProperty("hibernate.jdbc.batch_size"));
|
| 85 |
dbProperties.put("hibernate.order_inserts", properties.getProperty("hibernate.order_inserts", "true"));
|
89 |
dbProperties.put("hibernate.order_inserts", properties.getProperty("hibernate.order_inserts", "true"));
|
| Line 102... |
Line 106... |
| 102 |
return new HibernateTransactionManager(sessionFactory);
|
106 |
return new HibernateTransactionManager(sessionFactory);
|
| 103 |
}
|
107 |
}
|
| 104 |
|
108 |
|
| 105 |
@Bean(destroyMethod = "close")
|
109 |
@Bean(destroyMethod = "close")
|
| 106 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
110 |
public Mongo mongoClient(SessionFactory sessionFactory) {
|
| 107 |
Properties properties = new Properties();
|
111 |
Properties properties = loadAllProperties();
|
| 108 |
try {
|
- |
|
| 109 |
properties.load(resource.getInputStream());
|
- |
|
| 110 |
} catch (IOException e) {
|
- |
|
| 111 |
e.printStackTrace();
|
- |
|
| 112 |
}
|
- |
|
| 113 |
return new Mongo(properties.getProperty("content.mongo.host"),
|
112 |
return new Mongo(properties.getProperty("mongo.host"),
|
| 114 |
properties.getProperty("content.mongo.host"));
|
113 |
properties.getProperty("content.mongo.host"));
|
| 115 |
}
|
114 |
}
|
| 116 |
|
115 |
|
| 117 |
/**
|
116 |
/**
|
| 118 |
* Cleanup method to prevent memory leaks on shutdown.
|
117 |
* Cleanup method to prevent memory leaks on shutdown.
|