Subversion Repositories SmartDukaan

Rev

Rev 23568 | Rev 35596 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23568 Rev 35383
Line 1... Line 1...
1
package com.spice.profitmandi.dao.config;
1
package com.spice.profitmandi.dao.config;
2
import java.io.IOException;
-
 
3
 
2
 
-
 
3
import java.io.IOException;
-
 
4
import java.sql.Driver;
-
 
5
import java.sql.DriverManager;
-
 
6
import java.sql.SQLException;
-
 
7
import java.util.Enumeration;
4
import java.util.Properties;
8
import java.util.Properties;
5
 
9
 
-
 
10
import javax.annotation.PreDestroy;
6
import javax.sql.DataSource;
11
import javax.sql.DataSource;
7
 
12
 
-
 
13
import com.mysql.cj.jdbc.AbandonedConnectionCleanupThread;
8
import org.hibernate.SessionFactory;
14
import org.hibernate.SessionFactory;
9
import org.apache.logging.log4j.Logger;
15
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.LogManager;
11
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.context.annotation.Bean;
18
import org.springframework.context.annotation.Bean;
Line 23... Line 29...
23
 
29
 
24
 
30
 
25
@Configuration
31
@Configuration
26
@EnableTransactionManagement
32
@EnableTransactionManagement
27
@ComponentScan({ "com.spice.profitmandi.*" })
33
@ComponentScan({ "com.spice.profitmandi.*" })
28
public class WebDBContextConfigure{
34
public class WebDBContextConfigure {
-
 
35
 
-
 
36
	private static final Logger LOGGER = LogManager.getLogger(WebDBContextConfigure.class);
29
	
37
	
30
	
38
	
31
	
39
	
32
	
40
	
33
	private static final String HIBERNATE_DRIVER_CLASS = "hibernate.driver.class";
41
	private static final String HIBERNATE_DRIVER_CLASS = "hibernate.driver.class";
Line 96... Line 104...
96
	public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
104
	public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
97
		HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
105
		HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
98
		return transactionManager;
106
		return transactionManager;
99
	}
107
	}
100
	
108
	
101
	@Bean
109
	@Bean(destroyMethod = "close")
102
	public Mongo mongoClient() {
110
	public Mongo mongoClient() {
103
		Properties properties = new Properties();
111
		Properties properties = new Properties();
104
		try {
112
		try {
105
			properties.load(resource.getInputStream());
113
			properties.load(resource.getInputStream());
106
		} catch (IOException e) {
114
		} catch (IOException e) {
107
			e.printStackTrace();
115
			e.printStackTrace();
108
		}
116
		}
109
		return new Mongo(properties.getProperty("mongo.host"), properties.getProperty("content.mongo.host"));
117
		return new Mongo(properties.getProperty("mongo.host"), properties.getProperty("content.mongo.host"));
110
	}
118
	}
-
 
119
 
-
 
120
	/**
-
 
121
	 * Cleanup method to prevent memory leaks on shutdown.
-
 
122
	 * Deregisters JDBC drivers and stops MySQL cleanup thread.
-
 
123
	 */
-
 
124
	@PreDestroy
-
 
125
	public void cleanup() {
-
 
126
		LOGGER.info("WebDBContextConfigure cleanup started...");
-
 
127
 
-
 
128
		// Stop MySQL AbandonedConnectionCleanupThread
-
 
129
		try {
-
 
130
			AbandonedConnectionCleanupThread.checkedShutdown();
-
 
131
			LOGGER.info("MySQL AbandonedConnectionCleanupThread stopped");
-
 
132
		} catch (Exception e) {
-
 
133
			LOGGER.error("Error stopping MySQL cleanup thread", e);
-
 
134
		}
-
 
135
 
-
 
136
		// Deregister JDBC drivers loaded by this webapp's classloader
-
 
137
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
 
138
		Enumeration<Driver> drivers = DriverManager.getDrivers();
-
 
139
		while (drivers.hasMoreElements()) {
-
 
140
			Driver driver = drivers.nextElement();
-
 
141
			if (driver.getClass().getClassLoader() == cl) {
-
 
142
				try {
-
 
143
					DriverManager.deregisterDriver(driver);
-
 
144
					LOGGER.info("Deregistered JDBC driver: {}", driver);
-
 
145
				} catch (SQLException e) {
-
 
146
					LOGGER.error("Error deregistering JDBC driver {}", driver, e);
-
 
147
				}
-
 
148
			}
-
 
149
		}
-
 
150
 
-
 
151
		LOGGER.info("WebDBContextConfigure cleanup completed");
-
 
152
	}
111
}
153
}