cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration DatabaseConfiguration.java

2004-10-21 Thread ebourg
ebourg  2004/10/21 11:02:09

  Modified:configuration/xdocs changes.xml
   configuration/src/java/org/apache/commons/configuration
DatabaseConfiguration.java
  Log:
  DatabaseConfiguration.isEmpty() now returns true if an SQLException occurs.
  This is consistent with JNDIConfiguration.isEmpty() and the empty iterator returned 
by getKeys() in this case.
  
  Revision  ChangesPath
  1.67  +3 -0  jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- changes.xml   19 Oct 2004 13:41:44 -  1.66
  +++ changes.xml   21 Oct 2004 18:02:09 -  1.67
  @@ -8,6 +8,9 @@
 body
   
   release version=1.1-dev date=in CVS
  +  action dev=ebourg type=fix
  +DatabaseConfiguration.isEmpty() now returns true if an SQLException occurs.
  +  /action
 action dev=ebourg type=add
   Added two methods copy(Configuration, Configuration) and
   append(Configuration, Configuration) in ConfigurationUtils to copy
  
  
  
  1.12  +2 -2  
jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
  
  Index: DatabaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DatabaseConfiguration.java18 Oct 2004 14:05:23 -  1.11
  +++ DatabaseConfiguration.java21 Oct 2004 18:02:09 -  1.12
  @@ -208,7 +208,7 @@
*/
   public boolean isEmpty()
   {
  -boolean empty = false;
  +boolean empty = true;
   
   // build the query
   StringBuffer query = new StringBuffer(SELECT count(*) FROM  + table);
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/configuration/src/java/org/apache/commons/configuration DatabaseConfiguration.java

2004-06-22 Thread ebourg
ebourg  2004/06/22 05:56:54

  Modified:configuration/src/java/org/apache/commons/configuration
DatabaseConfiguration.java
  Log:
  Added a closeQuietly method similar to DbUtils.closeQuietly
  
  Revision  ChangesPath
  1.4   +28 -55
jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java
  
  Index: DatabaseConfiguration.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/DatabaseConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatabaseConfiguration.java27 Feb 2004 17:41:35 -  1.3
  +++ DatabaseConfiguration.java22 Jun 2004 12:56:54 -  1.4
  @@ -20,6 +20,7 @@
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
  +import java.sql.Statement;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  @@ -31,6 +32,9 @@
   /**
* Configuration stored in a database.
*
  + * @since 1.0
  + *
  + * @author Emmanuel Bourg
* @version $Revision$, $Date$
*/
   public class DatabaseConfiguration extends AbstractConfiguration
  @@ -126,15 +130,7 @@
   }
   finally
   {
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   
   return result;
  @@ -179,15 +175,7 @@
   finally
   {
   // clean up
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   }
   
  @@ -230,15 +218,7 @@
   finally
   {
   // clean up
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   
   return empty;
  @@ -281,15 +261,7 @@
   finally
   {
   // clean up
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   
   return found;
  @@ -328,15 +300,7 @@
   finally
   {
   // clean up
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   }
   
  @@ -379,17 +343,26 @@
   finally
   {
   // clean up
  -try
  -{
  -if (pstmt != null) { pstmt.close(); }
  -if (conn != null) { conn.close(); }
  -}
  -catch (SQLException e)
  -{
  -log.error(e.getMessage(), e);
  -}
  +closeQuietly(conn, pstmt);
   }
   
   return keys.iterator();
  +}
  +
  +/**
  + * Close a codeConnection/code and, codeStatement/code.
  + * Avoid closing if null and hide any SQLExceptions that occur.
  + */
  +private void closeQuietly(Connection conn, Statement stmt)
  +{
  +try
  +{
  +if (stmt != null) { stmt.close(); }
  +if (conn != null) { conn.close(); }
  +}
  +catch (SQLException e)
  +{
  +log.error(e.getMessage(), e);
  +}
   }
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]