dgraham 2003/10/14 20:51:05
Modified: dbutils/src/java/org/apache/commons/dbutils DbUtils.java
Log:
Simplify logic in close* methods.
Revision Changes Path
1.29 +45 -54
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java
Index: DbUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- DbUtils.java 15 Oct 2003 03:43:32 -0000 1.28
+++ DbUtils.java 15 Oct 2003 03:51:05 -0000 1.29
@@ -65,6 +65,7 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
+import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -490,37 +491,34 @@
}
/**
- * Close a connection, avoid closing if null.
+ * Close a <code>Connection</code>, avoid closing if null.
*/
public static void close(Connection conn) throws SQLException {
- if (conn == null) {
- return;
+ if (conn != null) {
+ conn.close();
}
- conn.close();
}
-
+
/**
- * Close a statement, avoid closing if null.
+ * Close a <code>Statement</code>, avoid closing if null.
*/
- public static void close(Statement stat) throws SQLException {
- if (stat == null) {
- return;
+ public static void close(Statement stmt) throws SQLException {
+ if (stmt != null) {
+ stmt.close();
}
- stat.close();
}
/**
- * Close a result set, avoid closing if null.
+ * Close a <code>ResultSet</code>, avoid closing if null.
*/
public static void close(ResultSet rs) throws SQLException {
- if (rs == null) {
- return;
+ if (rs != null) {
+ rs.close();
}
- rs.close();
}
/**
- * Close a connection, avoid closing if null and hide
+ * Close a <code>Connection</code>, avoid closing if null and hide
* any exceptions that occur.
*/
public static void closeQuietly(Connection conn) {
@@ -532,19 +530,19 @@
}
/**
- * Close a statement, avoid closing if null and hide
+ * Close a <code>Statement</code>, avoid closing if null and hide
* any exceptions that occur.
*/
- public static void closeQuietly(Statement stat) {
+ public static void closeQuietly(Statement stmt) {
try {
- close(stat);
+ close(stmt);
} catch (SQLException sqle) {
// quiet
}
}
/**
- * Close a result set, avoid closing if null and hide
+ * Close a <code>ResultSet</code>, avoid closing if null and hide
* any exceptions that occur.
*/
public static void closeQuietly(ResultSet rs) {
@@ -556,8 +554,9 @@
}
/**
- * Close a connection, statement and resultset, avoiding
- * closing if null and hiding any exceptions that occur.
+ * Close a <code>Connection</code>, <code>Statement</code> and
+ * <code>ResultSet</code>. Avoid closing if null and hide any
+ * exceptions that occur.
*/
public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) {
closeQuietly(rs);
@@ -566,19 +565,18 @@
}
/**
- * Commits a connection then closes it, avoid closing if null.
+ * Commits a <code>Connection</code> then closes it, avoid closing if null.
*/
public static void commitAndClose(Connection conn) throws SQLException {
- if (conn == null) {
- return;
+ if (conn != null) {
+ conn.commit();
+ conn.close();
}
- conn.commit();
- conn.close();
}
/**
- * Commits a connection then closes it, avoid closing if null and
- * hide any exceptions that occur.
+ * Commits a <code>Connection</code> then closes it, avoid closing if null
+ * and hide any exceptions that occur.
*/
public static void commitAndCloseQuietly(Connection conn) {
try {
@@ -588,41 +586,34 @@
}
}
-
-
- public static void printStackTrace(SQLException sqle, java.io.PrintWriter ps){
-
+ public static void printStackTrace(SQLException sqle, PrintWriter pw) {
+
SQLException next = sqle;
- while( next != null ){
- next.printStackTrace(ps);
+ while (next != null) {
+ next.printStackTrace(pw);
next = next.getNextException();
- if(next != null){
- ps.println("Next SQLException:");
+ if (next != null) {
+ pw.println("Next SQLException:");
}
}
-
-
}
- public static void printStackTrace(SQLException sqle){
-
- printStackTrace( sqle, new java.io.PrintWriter( System.err ) );
-
+ public static void printStackTrace(SQLException sqle) {
+ printStackTrace(sqle, new PrintWriter(System.err));
}
- public static void printWarnings(Connection connection, java.io.PrintWriter ps){
- if( connection != null ){
- try{
- printStackTrace(connection.getWarnings(), ps);
- }catch(SQLException sqle){
- printStackTrace(sqle, ps);
+ public static void printWarnings(Connection conn, PrintWriter pw) {
+ if (conn != null) {
+ try {
+ printStackTrace(conn.getWarnings(), pw);
+ } catch (SQLException sqle) {
+ printStackTrace(sqle, pw);
}
}
-
}
- public static void printWarnings(Connection connection ){
- printWarnings(connection,new java.io.PrintWriter(System.err));
+ public static void printWarnings(Connection connection) {
+ printWarnings(connection, new PrintWriter(System.err));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]