aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/api/Main.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-16 18:33:36 +0300
committerGravatar Vitaly Takmazov2016-01-16 18:33:36 +0300
commitf0834c91bfcd8b5d6f658c946334ad6b89ad36a3 (patch)
tree67874955dab381f40fd6a1540954750fb8ab0d72 /src/main/java/com/juick/api/Main.java
parented24ebac9a717fbec3357a168438e2617955d609 (diff)
almost working with spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/api/Main.java')
-rw-r--r--src/main/java/com/juick/api/Main.java39
1 files changed, 5 insertions, 34 deletions
diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java
index 4233c45d..cdced593 100644
--- a/src/main/java/com/juick/api/Main.java
+++ b/src/main/java/com/juick/api/Main.java
@@ -33,9 +33,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
import java.util.Properties;
/**
@@ -46,8 +43,6 @@ import java.util.Properties;
@MultipartConfig
public class Main extends HttpServlet implements Stream.StreamListener {
- Connection sql;
- Connection sqlSearch;
JdbcTemplate jdbc;
Stream xmpp;
Messages messages;
@@ -62,11 +57,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Properties conf = new Properties();
conf.load(new FileInputStream("/etc/juick/api.conf"));
final String driverClassName = "com.mysql.jdbc.Driver";
- Class.forName(driverClassName);
- sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
- sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306/juick?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000&relaxAutoCommit=true&user=root&password=");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setUrl(sql.getMetaData().getURL());
+ dataSource.setUrl("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
dataSource.setDriverClassName(driverClassName);
jdbc = new JdbcTemplate(dataSource);
messages = new Messages(jdbc);
@@ -76,8 +68,8 @@ public class Main extends HttpServlet implements Stream.StreamListener {
setupXmppComponent(conf.getProperty("xmpp_password"));
- } catch (IOException | ClassNotFoundException | SQLException e) {
- log(null, e);
+ } catch (IOException e) {
+ log("API initialization error", e);
}
}
@@ -105,27 +97,6 @@ public class Main extends HttpServlet implements Stream.StreamListener {
System.err.println("XMPP STREAM READY");
}
- @Override
- public void destroy() {
- super.destroy();
- if (sql != null) {
- try {
- sql.close();
- sql = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- if (sqlSearch != null) {
- try {
- sqlSearch.close();
- sqlSearch = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- }
-
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
@@ -139,7 +110,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
request.setCharacterEncoding("UTF-8");
}
- int vuid = Utils.getHttpAuthUID(sql, request);
+ int vuid = Utils.getHttpAuthUID(jdbc, request);
if (vuid == 0) {
vuid = Utils.getVisitorQueryStringUID(jdbc, request);
}
@@ -197,7 +168,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
request.setCharacterEncoding("UTF-8");
}
- int vuid = Utils.getHttpAuthUID(sql, request);
+ int vuid = Utils.getHttpAuthUID(jdbc, request);
if (vuid == 0) {
vuid = Utils.getVisitorQueryStringUID(jdbc, request);
}