diff options
author | Ippolitov A. Igor | 2015-10-26 13:12:51 +0300 |
---|---|---|
committer | Ippolitov A. Igor | 2015-10-26 13:12:51 +0300 |
commit | 151e8af414215029d0c2bb255df17cb8fa32bd29 (patch) | |
tree | 36384b8af7df6f2271461e75c767009c618f39da | |
parent | 51c4828bf113780391180972cfaa8103946e7875 (diff) |
Revert "sql search connection is opened and closed each time"
This reverts commit 3880090a06f6d62ab4040373c5312f1b36506cc2.
-rw-r--r-- | src/main/java/com/juick/http/www/Main.java | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java index e4c6b8ee..56aa439f 100644 --- a/src/main/java/com/juick/http/www/Main.java +++ b/src/main/java/com/juick/http/www/Main.java @@ -47,7 +47,6 @@ public class Main extends HttpServlet implements Stream.StreamListener { Connection sql; Connection sqlSearch; - String sqlSearchConnStr = "jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000"; Stream xmpp; Home home = new Home(); Discover discover = new Discover(); @@ -65,7 +64,6 @@ public class Main extends HttpServlet implements Stream.StreamListener { @Override public void init() throws ServletException { - super.init(); try { Properties conf = new Properties(); @@ -73,7 +71,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { 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", "")); - sqlSearch = getSqlSearch(); + sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000", "", ""); setupXmppComponent(conf.getProperty("xmpp_password")); @@ -82,27 +80,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { log(null, e); } } - public void closeSqlSearch() { - if (sqlSearch != null) { - try { - sqlSearch.close(); - sqlSearch = null; - } catch (SQLException e) { - log("An error on closing sql search connection", e); - } - } - }; - public Connection getSqlSearch() { - if (sqlSearch == null) { - try { - sqlSearch = DriverManager.getConnection(sqlSearchConnStr, "", ""); - } - catch (Exception e) { - log("Couldn't open sqlSearch connection",e); - } - } - return sqlSearch; - } + public void setupXmppComponent(final String password) { Thread thr = new Thread(new Runnable() { @@ -172,8 +150,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, "UTF-8")); } else { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - home.doGet(sql, getSqlSearch(), request, response, visitor); - closeSqlSearch(); + home.doGet(sql, sqlSearch, request, response, visitor); } } else if (uri.equals("/post")) { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); @@ -224,8 +201,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { } else if (uri.startsWith("/help/")) { help.doGetHelp(sql, request, response); } else if (uri.startsWith("/tag/")) { - discover.doGet(sql, getSqlSearch(), request, response); - closeSqlSearch(); + discover.doGet(sql, sqlSearch, request, response); } else if (uri.matches("^/\\d+$")) { String strID = request.getRequestURI().substring(1); int mid = 0; @@ -253,8 +229,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, uriparts[1]); if (user != null && user.UName.equals(uriparts[1]) && user.Banned == false) { if (uriparts.length == 2) { // http://juick.com/username/ - pagesUser.doGetBlog(sql, getSqlSearch(), request, response, user); - closeSqlSearch(); + pagesUser.doGetBlog(sql, sqlSearch, request, response, user); } else if (uriparts[2].equals("tags")) { pagesUser.doGetTags(sql, request, response, user); } else if (uriparts[2].equals("friends")) { |