Commit 9a3f8d54 authored by God Ly's avatar God Ly Committed by it2000

CR-26 and duplicate code removed

(http://www.igniterealtime.org/fisheye/cru/CR-26)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11688 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9d994160
...@@ -180,14 +180,7 @@ public class DbConnectionManager { ...@@ -180,14 +180,7 @@ public class DbConnectionManager {
public static void closeTransactionConnection(PreparedStatement pstmt, Connection con, public static void closeTransactionConnection(PreparedStatement pstmt, Connection con,
boolean abortTransaction) boolean abortTransaction)
{ {
try { closeStatement(pstmt);
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
closeTransactionConnection(con, abortTransaction); closeTransactionConnection(con, abortTransaction);
} }
...@@ -199,11 +192,6 @@ public class DbConnectionManager { ...@@ -199,11 +192,6 @@ public class DbConnectionManager {
* @param abortTransaction true if the transaction should be rolled back. * @param abortTransaction true if the transaction should be rolled back.
*/ */
public static void closeTransactionConnection(Connection con, boolean abortTransaction) { public static void closeTransactionConnection(Connection con, boolean abortTransaction) {
// test to see if the connection passed in is null
if (con == null) {
return;
}
// Rollback or commit the transaction // Rollback or commit the transaction
if (isTransactionsSupported()) { if (isTransactionsSupported()) {
try { try {
...@@ -217,23 +205,15 @@ public class DbConnectionManager { ...@@ -217,23 +205,15 @@ public class DbConnectionManager {
catch (Exception e) { catch (Exception e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
} }
}
try {
// Reset the connection to auto-commit mode. // Reset the connection to auto-commit mode.
if (isTransactionsSupported()) { try {
con.setAutoCommit(true); con.setAutoCommit(true);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
} }
} }
catch (Exception e) { closeConnection(con);
Log.error(e.getMessage(), e);
}
try {
// Close the db connection.
con.close();
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
} }
/** /**
...@@ -261,14 +241,14 @@ public class DbConnectionManager { ...@@ -261,14 +241,14 @@ public class DbConnectionManager {
* @param rs the result set to close. * @param rs the result set to close.
*/ */
public static void closeResultSet(ResultSet rs) { public static void closeResultSet(ResultSet rs) {
try { if (rs != null) {
if (rs != null) { try {
rs.close(); rs.close();
}
catch (SQLException e) {
Log.error(e.getMessage(), e);
} }
} }
catch (SQLException e) {
Log.error(e.getMessage(), e);
}
} }
/** /**
...@@ -293,14 +273,14 @@ public class DbConnectionManager { ...@@ -293,14 +273,14 @@ public class DbConnectionManager {
* @param stmt the statement. * @param stmt the statement.
*/ */
public static void closeStatement(Statement stmt) { public static void closeStatement(Statement stmt) {
try { if (stmt != null) {
if (stmt != null) { try {
stmt.close(); stmt.close();
}
catch (Exception e) {
Log.error(e.getMessage(), e);
} }
} }
catch (Exception e) {
Log.error(e.getMessage(), e);
}
} }
/** /**
...@@ -359,14 +339,7 @@ public class DbConnectionManager { ...@@ -359,14 +339,7 @@ public class DbConnectionManager {
* @param con the connection. * @param con the connection.
*/ */
public static void closeConnection(Statement stmt, Connection con) { public static void closeConnection(Statement stmt, Connection con) {
try { closeStatement(stmt);
if (stmt != null) {
stmt.close();
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
closeConnection(con); closeConnection(con);
} }
...@@ -392,13 +365,13 @@ public class DbConnectionManager { ...@@ -392,13 +365,13 @@ public class DbConnectionManager {
* @param con the connection. * @param con the connection.
*/ */
public static void closeConnection(Connection con) { public static void closeConnection(Connection con) {
try { if (con != null) {
if (con != null) { try {
con.close(); con.close();
}
catch (Exception e) {
Log.error(e.getMessage(), e);
} }
}
catch (Exception e) {
Log.error(e.getMessage(), e);
} }
} }
...@@ -519,14 +492,7 @@ public class DbConnectionManager { ...@@ -519,14 +492,7 @@ public class DbConnectionManager {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
} }
finally { finally {
try { closeConnection(con);
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
} }
} }
// Remember what connection provider we want to use for restarts. // Remember what connection provider we want to use for restarts.
......
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