diff options
author | Vitaly Takmazov | 2016-06-27 13:16:43 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-06-27 13:16:43 +0300 |
commit | 606f43f50904f7d811cf9b438e0e820e586be900 (patch) | |
tree | 55904b790d79ba15033469bd378342883322bb5d /src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | |
parent | 0d93073c6988a22246db61a59b97c2fd7c9f462b (diff) |
spring-jdbc near complete
Diffstat (limited to 'src/main/java/com/juick/xmpp/s2s/XMPPComponent.java')
-rw-r--r-- | src/main/java/com/juick/xmpp/s2s/XMPPComponent.java | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java index 13df5fd0..70f01553 100644 --- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java @@ -3,6 +3,8 @@ 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 org.springframework.jdbc.datasource.DriverManagerDataSource; import org.xmlpull.v1.XmlPullParserException; import javax.servlet.ServletContextEvent; @@ -42,7 +44,7 @@ public class XMPPComponent implements ServletContextListener { 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) { @@ -176,9 +178,12 @@ public class XMPPComponent implements ServletContextListener { keystore = conf.getProperty("keystore"); keystorePassword = conf.getProperty("keystore_password"); brokenSSLhosts = Arrays.asList(conf.getProperty("broken_ssl_hosts", "").split(",")); - 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", "")); + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); + dataSource.setUrl(conf.getProperty("datasource_url")); + DriverManagerDataSource dataSourceSearch = new DriverManagerDataSource(); + dataSourceSearch.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver")); + sql = new JdbcTemplate(dataSource); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); executorService.submit(() -> connRouter = new ConnectionRouter(componentName, conf.getProperty("xmpp_password"))); @@ -215,17 +220,6 @@ public class XMPPComponent implements ServletContextListener { } catch (IOException e) { LOGGER.log(Level.WARNING, "router warning", e); } - - 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(); |