Commit 375667ac authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

More JDBC enhancements.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1751 b35dd754-fafc-0310-a699-88a17e54d16e
parent 53104675
......@@ -187,6 +187,8 @@ public class RosterItemProvider {
pstmt.setLong(1, rosterItemID);
pstmt.executeUpdate();
// Close now the statement (do not wait to be GC'ed)
pstmt.close();
// Remove roster
pstmt = con.prepareStatement(DELETE_ROSTER_ITEM);
......@@ -280,15 +282,19 @@ public class RosterItemProvider {
public Iterator<RosterItem> getItems(String username) {
LinkedList<RosterItem> itemList = new LinkedList<RosterItem>();
Connection con = null;
Connection con2 = null;
PreparedStatement pstmt = null;
PreparedStatement gstmt = null;
try {
con2 = DbConnectionManager.getConnection();
gstmt = con2.prepareStatement(LOAD_ROSTER_ITEM_GROUPS);
// Load all the contacts in the roster
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_ROSTER);
pstmt.setString(1, username);
ResultSet rs = pstmt.executeQuery();
// TODO: this code must be refactored ASAP. Not legal to have two open pstmts
// TODO: on many databases.
while (rs.next()) {
// Create a new RosterItem (ie. user contact) from the stored information
RosterItem item = new RosterItem(rs.getLong(2),
new JID(rs.getString(1)),
RosterItem.SubType.getTypeFromInt(rs.getInt(3)),
......@@ -296,25 +302,18 @@ public class RosterItemProvider {
RosterItem.RecvType.getTypeFromInt(rs.getInt(5)),
rs.getString(6),
null);
Connection con2 = DbConnectionManager.getConnection();
PreparedStatement gstmt = null;
// Load the groups for the loaded contact
ResultSet gs = null;
try {
gstmt = con2.prepareStatement(LOAD_ROSTER_ITEM_GROUPS);
gstmt.setLong(1, item.getID());
gs = gstmt.executeQuery();
while (gs.next()) {
item.getGroups().add(gs.getString(1));
}
// Close the result set
gs.close();
// Add the loaded RosterItem (ie. user contact) to the result
itemList.add(item);
}
finally {
try { if (gstmt != null) { gstmt.close(); } }
catch (Exception e) { Log.error(e); }
try { if (con2 != null) { con2.close(); } }
catch (Exception e) { Log.error(e); }
}
}
}
catch (SQLException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
......@@ -324,6 +323,10 @@ public class RosterItemProvider {
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
try { if (gstmt != null) { gstmt.close(); } }
catch (Exception e) { Log.error(e); }
try { if (con2 != null) { con2.close(); } }
catch (Exception e) { Log.error(e); }
}
return itemList.iterator();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment