aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/MessagesQueries.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/MessagesQueries.java')
-rw-r--r--src/main/java/com/juick/server/MessagesQueries.java173
1 files changed, 89 insertions, 84 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 82fef672..4d5683bd 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -25,6 +25,9 @@ import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
*
@@ -32,11 +35,13 @@ import java.util.Collections;
*/
public class MessagesQueries {
- public static int createMessage(Connection sql, int uid, String txt, String attachment, ArrayList<com.juick.Tag> tags) {
+ private static final Logger logger = Logger.getLogger(MessagesQueries.class.getName());
+
+ public static int createMessage(Connection sql, int uid, String txt, String attachment, List<com.juick.Tag> tags) {
int mid = 0;
PreparedStatement stmt = null;
- ResultSet rs = null;
+ ResultSet rs;
try {
stmt = sql.prepareStatement("INSERT INTO messages(user_id,attach) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, uid);
@@ -51,7 +56,7 @@ public class MessagesQueries {
mid = rs.getInt(1);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -73,7 +78,7 @@ public class MessagesQueries {
stmt = sql.prepareStatement("INSERT INTO messages_tags(message_id,tag_id) VALUES " + tagsIDs);
stmt.executeUpdate();
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -81,7 +86,7 @@ public class MessagesQueries {
try {
stmt = sql.prepareStatement("INSERT INTO messages_txt(message_id,tags,txt) VALUES (?,?,?)");
stmt.setInt(1, mid);
- if (tagsNames == "") {
+ if (tagsNames.isEmpty()) {
stmt.setNull(2, Types.VARCHAR);
} else {
stmt.setString(2, tagsNames);
@@ -89,7 +94,7 @@ public class MessagesQueries {
stmt.setString(3, txt);
stmt.executeUpdate();
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -118,7 +123,7 @@ public class MessagesQueries {
ridnew = 0;
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -166,7 +171,7 @@ public class MessagesQueries {
privacy = rs.getInt(2);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -189,7 +194,7 @@ public class MessagesQueries {
ret = rs.getInt(1) == 1;
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -210,7 +215,7 @@ public class MessagesQueries {
ret = rs.getInt(1) == 1;
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -255,7 +260,7 @@ public class MessagesQueries {
msg.Hidden = rs.getBoolean(13);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -276,7 +281,7 @@ public class MessagesQueries {
msg.Text = rs.getString(3);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -307,7 +312,7 @@ public class MessagesQueries {
msg.Text = rs.getString(6);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -330,15 +335,15 @@ public class MessagesQueries {
user.UName = rs.getString(2);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return user;
}
- public static ArrayList<com.juick.Tag> getMessageTags(Connection sql, int mid) {
- ArrayList<com.juick.Tag> tags = new ArrayList<com.juick.Tag>();
+ public static List<com.juick.Tag> getMessageTags(Connection sql, int mid) {
+ List<com.juick.Tag> tags = new ArrayList<>();
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -356,7 +361,7 @@ public class MessagesQueries {
tags.add(t);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -364,8 +369,8 @@ public class MessagesQueries {
return tags;
}
- public static ArrayList<Integer> getMessageTagsIDs(Connection sql, int mid) {
- ArrayList<Integer> tids = new ArrayList<Integer>();
+ public static List<Integer> getMessageTagsIDs(Connection sql, int mid) {
+ List<Integer> tids = new ArrayList<>();
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -378,7 +383,7 @@ public class MessagesQueries {
tids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -387,7 +392,7 @@ public class MessagesQueries {
}
public static ArrayList<String> getMessageRecommendations(Connection sql, int mid) {
- ArrayList<String> users = new ArrayList<String>();
+ ArrayList<String> users = new ArrayList<>();
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -400,7 +405,7 @@ public class MessagesQueries {
users.add(rs.getString(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -408,8 +413,8 @@ public class MessagesQueries {
return users;
}
- public static ArrayList<Integer> getAll(Connection sql, int visitor_uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getAll(Connection sql, int visitor_uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -448,15 +453,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getTag(Connection sql, int tid, int visitor_uid, int before, int cnt) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -483,15 +488,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getTags(Connection sql, String tids, int visitor_uid, int before, int cnt) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -512,15 +517,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getPlace(Connection sql, int place_id, int visitor_uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getPlace(Connection sql, int place_id, int visitor_uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -541,15 +546,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getMyFeed(Connection sql, int uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(40);
+ public static List<Integer> getMyFeed(Connection sql, int uid, int before) {
+ List<Integer> mids = new ArrayList<>(40);
PreparedStatement stmt = null;
ResultSet rs = null;
try {
@@ -569,7 +574,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -589,7 +594,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -603,8 +608,8 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList<Integer> getPrivate(Connection sql, int uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getPrivate(Connection sql, int uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -623,15 +628,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getDiscussions(Connection sql, int uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getDiscussions(Connection sql, int uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -650,7 +655,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -658,8 +663,8 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList<Integer> getRecommended(Connection sql, int uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getRecommended(Connection sql, int uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -678,7 +683,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -687,8 +692,8 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList<Integer> getPopular(Connection sql, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getPopular(Connection sql, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -705,15 +710,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getPhotos(Connection sql, int visitor_uid, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getPhotos(Connection sql, int visitor_uid, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -732,15 +737,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getSearch(Connection sql, Connection sqlSearch, String search, int before) {
- ArrayList<Integer> mids0 = new ArrayList<Integer>(20);
+ public static List<Integer> getSearch(Connection sql, Connection sqlSearch, String search, int before) {
+ List<Integer> mids0 = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -760,12 +765,12 @@ public class MessagesQueries {
mids0.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ List<Integer> mids = new ArrayList<>(20);
if (mids0.size() > 0) {
try {
stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20");
@@ -775,7 +780,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -784,8 +789,8 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList<Integer> getUserBlog(Connection sql, int UID, int privacy, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getUserBlog(Connection sql, int UID, int privacy, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -804,15 +809,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getUserTag(Connection sql, int UID, int TID, int privacy, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getUserTag(Connection sql, int UID, int TID, int privacy, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -833,15 +838,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getUserRecommendations(Connection sql, int UID, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getUserRecommendations(Connection sql, int UID, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -860,15 +865,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getUserPhotos(Connection sql, int UID, int privacy, int before) {
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ public static List<Integer> getUserPhotos(Connection sql, int UID, int privacy, int before) {
+ List<Integer> mids = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -887,15 +892,15 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
return mids;
}
- public static ArrayList<Integer> getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
- ArrayList<Integer> mids0 = new ArrayList<Integer>(20);
+ public static List<Integer> getUserSearch(Connection sql, Connection sqlSearch, int UID, String search, int privacy, int before) {
+ List<Integer> mids0 = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -916,12 +921,12 @@ public class MessagesQueries {
mids0.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
- ArrayList<Integer> mids = new ArrayList<Integer>(20);
+ List<Integer> mids = new ArrayList<>(20);
if (mids0.size() > 0) {
try {
stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id IN (" + Utils.convertArrayInt2String(mids0) + ") AND privacy>=" + privacy + " ORDER BY message_id DESC");
@@ -931,7 +936,7 @@ public class MessagesQueries {
mids.add(rs.getInt(1));
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -940,8 +945,8 @@ public class MessagesQueries {
return mids;
}
- public static ArrayList<com.juick.Message> getMessages(Connection sql, ArrayList<Integer> mids) {
- ArrayList<com.juick.Message> msgs = new ArrayList<com.juick.Message>(20);
+ public static List<com.juick.Message> getMessages(Connection sql, List<Integer> mids) {
+ List<com.juick.Message> msgs = new ArrayList<>(20);
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -978,7 +983,7 @@ public class MessagesQueries {
msgs.add(msg);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -986,8 +991,8 @@ public class MessagesQueries {
return msgs;
}
- public static ArrayList<com.juick.Message> getReplies(Connection sql, int mid) {
- ArrayList<com.juick.Message> replies = new ArrayList<com.juick.Message>();
+ public static List<com.juick.Message> getReplies(Connection sql, int mid) {
+ List<com.juick.Message> replies = new ArrayList<>();
PreparedStatement stmt = null;
ResultSet rs = null;
@@ -1013,7 +1018,7 @@ public class MessagesQueries {
replies.add(msg);
}
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(rs, stmt);
}
@@ -1039,7 +1044,7 @@ public class MessagesQueries {
}
ret = stmt.executeUpdate() > 0;
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -1050,7 +1055,7 @@ public class MessagesQueries {
stmt.setInt(1, mid);
stmt.executeUpdate();
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}
@@ -1068,7 +1073,7 @@ public class MessagesQueries {
stmt.setInt(1, mid);
ret = stmt.executeUpdate() > 0;
} catch (SQLException e) {
- System.err.println(e);
+ logger.log(Level.SEVERE, "sql exception", e);
} finally {
Utils.finishSQL(null, stmt);
}