diff options
author | Vitaly Takmazov | 2016-02-02 14:36:04 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-02-02 14:36:04 +0300 |
commit | bd3892546b51f0d31e959d45c138b009d35b2692 (patch) | |
tree | 3c3945f114472344cc3a8866391fa08f02975143 /src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | |
parent | f2a2660e753fa11478fd3edadfdff9c000b22cc9 (diff) |
spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/XMPPComponent.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java index 50d2c1e4..1dfdd38d 100644 --- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java @@ -3,6 +3,7 @@ package com.juick.xmpp.s2s; import com.juick.xmpp.Stanza; import com.juick.xmpp.StanzaChild; import com.juick.xmpp.extensions.JuickMessage; +import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -32,8 +33,7 @@ public class XMPPComponent implements ServletContextListener { static final List<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>()); static final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>()); static final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>()); - static final Integer sqlSync = 0; - static java.sql.Connection sql; + static JdbcTemplate sql; final public static HashMap<String, StanzaChild> childParsers = new HashMap<>(); public static void addConnectionIn(ConnectionIn c) { @@ -159,10 +159,7 @@ public class XMPPComponent implements ServletContextListener { HOSTNAME = conf.getProperty("hostname"); String componentName = conf.getProperty("componentname"); STATSFILE = conf.getProperty("statsfile"); - - Class.forName("com.mysql.jdbc.Driver"); - sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + - conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); + sql = (JdbcTemplate) sce.getServletContext().getAttribute("sql"); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); @@ -170,7 +167,7 @@ public class XMPPComponent implements ServletContextListener { executorService.submit(connRouter); executorService.submit(new ConnectionListener()); executorService.submit(new CleaningUp()); - } catch (IOException | ClassNotFoundException | SQLException e) { + } catch (IOException e) { LOGGER.log(Level.SEVERE, "XMPPComponent error", e); } }); @@ -195,39 +192,7 @@ public class XMPPComponent implements ServletContextListener { i.remove(); } } - XMPPComponent.connRouter.closeConnection(); - - synchronized (XMPPComponent.sqlSync) { - if (XMPPComponent.sql != null) { - try { - XMPPComponent.sql.close(); - XMPPComponent.sql = null; - } catch (SQLException e) { - LOGGER.warning("SQL ERROR: " + e); - } - } - } - // Now deregister JDBC drivers in this context's ClassLoader: - // Get the webapp's ClassLoader - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - // Loop through all drivers - Enumeration<Driver> drivers = DriverManager.getDrivers(); - while (drivers.hasMoreElements()) { - Driver driver = drivers.nextElement(); - if (driver.getClass().getClassLoader() == cl) { - // This driver was registered by the webapp's ClassLoader, so deregister it: - try { - LOGGER.info(String.format("Deregistering JDBC driver %s", driver.toString())); - DriverManager.deregisterDriver(driver); - } catch (SQLException ex) { - LOGGER.log(Level.SEVERE, String.format("Error deregistering JDBC driver %s", driver), ex); - } - } else { - // driver was not registered by the webapp's ClassLoader and may be in use elsewhere - LOGGER.log(Level.SEVERE, String.format("Not deregistering JDBC driver %s as it does not belong to this webapp's ClassLoader", driver)); - } - } executorService.shutdown(); LOGGER.info("component destroyed"); } |