aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/server/UserQueries.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/juick/server/UserQueries.java')
-rw-r--r--src/com/juick/server/UserQueries.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java
index c170b6cd..bb4d19df 100644
--- a/src/com/juick/server/UserQueries.java
+++ b/src/com/juick/server/UserQueries.java
@@ -79,6 +79,28 @@ public class UserQueries {
return uid;
}
+ public static com.juick.User getUserByUID(Connection sql, int uid) {
+ com.juick.User user = null;
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT nick FROM users WHERE id=?");
+ stmt.setInt(1, uid);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ user = new com.juick.User();
+ user.UID = uid;
+ user.UName = rs.getString(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return user;
+ }
+
public static com.juick.User getUserByName(Connection sql, String username) {
com.juick.User user = null;
@@ -148,6 +170,42 @@ public class UserQueries {
return users;
}
+ public static boolean fillUsersByID(Connection sql, ArrayList<com.juick.User> users) {
+ boolean ret = false;
+
+ String uids = "";
+ final int usersSize = users.size();
+ for (int i = 0; i < usersSize; i++) {
+ if (i > 0) {
+ uids += ",";
+ }
+ uids += users.get(i).UID;
+ }
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement("SELECT id,nick FROM users WHERE id IN (" + uids + ")");
+ rs = stmt.executeQuery();
+ rs.beforeFirst();
+ while (rs.next()) {
+ int uid = rs.getInt(1);
+ for (int i = 0; i < usersSize; i++) {
+ if (users.get(i).UID == uid) {
+ users.get(i).UName = rs.getString(2);
+ ret = true;
+ }
+ }
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+
+ return ret;
+ }
+
public static ArrayList<com.juick.User> getUsersByJID(Connection sql, ArrayList<String> jids) {
ArrayList<com.juick.User> users = new ArrayList<com.juick.User>();
@@ -180,6 +238,10 @@ public class UserQueries {
return SQLHelpers.getInt(sql, "SELECT user_id FROM jids WHERE jid=?", jid, 0);
}
+ public static int getUIDbyName(Connection sql, String uname) {
+ return SQLHelpers.getInt(sql, "SELECT id FROM users WHERE nick=?", uname, 0);
+ }
+
public static int getUIDbyHash(Connection sql, String hash) {
return SQLHelpers.getInt(sql, "SELECT user_id FROM logins WHERE hash=?", hash, 0);
}