Commit 8f647230 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Cleaned up db logic.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4019 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0cf31aa2
...@@ -72,11 +72,12 @@ public class PrivacyListProvider { ...@@ -72,11 +72,12 @@ public class PrivacyListProvider {
Map<String, Boolean> names = new HashMap<String, Boolean>(); Map<String, Boolean> names = new HashMap<String, Boolean>();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_LIST_NAMES); pstmt = con.prepareStatement(LOAD_LIST_NAMES);
pstmt.setString(1, username); pstmt.setString(1, username);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
names.put(rs.getString(1), rs.getInt(2) == 1); names.put(rs.getString(1), rs.getInt(2) == 1);
} }
...@@ -85,10 +86,7 @@ public class PrivacyListProvider { ...@@ -85,10 +86,7 @@ public class PrivacyListProvider {
Log.error("Error loading names of privacy lists for username: " + username, e); Log.error("Error loading names of privacy lists for username: " + username, e);
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(rs, pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
return names; return names;
} }
...@@ -106,6 +104,7 @@ public class PrivacyListProvider { ...@@ -106,6 +104,7 @@ public class PrivacyListProvider {
PrivacyList privacyList = null; PrivacyList privacyList = null;
java.sql.Connection con = null; java.sql.Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
SAXReader xmlReader = null; SAXReader xmlReader = null;
try { try {
// Get a sax reader from the pool // Get a sax reader from the pool
...@@ -114,7 +113,7 @@ public class PrivacyListProvider { ...@@ -114,7 +113,7 @@ public class PrivacyListProvider {
pstmt = con.prepareStatement(LOAD_PRIVACY_LIST); pstmt = con.prepareStatement(LOAD_PRIVACY_LIST);
pstmt.setString(1, username); pstmt.setString(1, username);
pstmt.setString(2, listName); pstmt.setString(2, listName);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
boolean isDefault = rs.getInt(1) == 1; boolean isDefault = rs.getInt(1) == 1;
Element listElement = Element listElement =
...@@ -130,10 +129,7 @@ public class PrivacyListProvider { ...@@ -130,10 +129,7 @@ public class PrivacyListProvider {
if (xmlReader != null) { if (xmlReader != null) {
xmlReaders.add(xmlReader); xmlReaders.add(xmlReader);
} }
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(rs, pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
return privacyList; return privacyList;
} }
...@@ -149,6 +145,7 @@ public class PrivacyListProvider { ...@@ -149,6 +145,7 @@ public class PrivacyListProvider {
PrivacyList privacyList = null; PrivacyList privacyList = null;
java.sql.Connection con = null; java.sql.Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
SAXReader xmlReader = null; SAXReader xmlReader = null;
try { try {
// Get a sax reader from the pool // Get a sax reader from the pool
...@@ -156,7 +153,7 @@ public class PrivacyListProvider { ...@@ -156,7 +153,7 @@ public class PrivacyListProvider {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_DEFAULT_PRIVACY_LIST); pstmt = con.prepareStatement(LOAD_DEFAULT_PRIVACY_LIST);
pstmt.setString(1, username); pstmt.setString(1, username);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
String listName= rs.getString(1); String listName= rs.getString(1);
Element listElement = Element listElement =
...@@ -172,10 +169,7 @@ public class PrivacyListProvider { ...@@ -172,10 +169,7 @@ public class PrivacyListProvider {
if (xmlReader != null) { if (xmlReader != null) {
xmlReaders.add(xmlReader); xmlReaders.add(xmlReader);
} }
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(rs, pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
return privacyList; return privacyList;
} }
...@@ -203,10 +197,7 @@ public class PrivacyListProvider { ...@@ -203,10 +197,7 @@ public class PrivacyListProvider {
e); e);
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
} }
...@@ -234,10 +225,7 @@ public class PrivacyListProvider { ...@@ -234,10 +225,7 @@ public class PrivacyListProvider {
e); e);
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
} }
...@@ -261,10 +249,7 @@ public class PrivacyListProvider { ...@@ -261,10 +249,7 @@ public class PrivacyListProvider {
Log.error("Error deleting privacy list: " + listName + " of username: " + username, e); Log.error("Error deleting privacy list: " + listName + " of username: " + username, e);
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
} }
...@@ -286,10 +271,7 @@ public class PrivacyListProvider { ...@@ -286,10 +271,7 @@ public class PrivacyListProvider {
Log.error("Error deleting privacy lists of username: " + username, e); Log.error("Error deleting privacy lists of username: " + username, e);
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } DbConnectionManager.closeConnection(pstmt, con);
catch (Exception e) { Log.error(e); }
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
} }
} }
} }
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