commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils DbUtils.java
Date Wed, 15 Oct 2003 04:17:28 GMT
dgraham     2003/10/14 21:17:28

  Modified:    dbutils/src/java/org/apache/commons/dbutils DbUtils.java
  Log:
  Refactored dynamic object creation into newInstance() method.
  
  Revision  Changes    Path
  1.31      +21 -10    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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- DbUtils.java	15 Oct 2003 04:11:50 -0000	1.30
  +++ DbUtils.java	15 Oct 2003 04:17:28 -0000	1.31
  @@ -434,13 +434,7 @@
           }
   
           do {
  -            Object obj;
  -            try {
  -                obj = cls.newInstance();
  -
  -            } catch (Exception e) {
  -                throw new DbException("can not create " + cls.getName(), e);
  -            }
  +            Object obj = newInstance(cls);
   
               for (int i = 1; i <= cnt; i++) {
                   Object value = rs.getObject(i);
  @@ -462,6 +456,23 @@
           } while (rs.next());
   
           return results;
  +    }
  +
  +    /**
  +     * Returns a new instance of the given Class.
  +     * @param c The Class to create an object from.
  +     * @return A newly created object of the Class.
  +     * @throws DbException if creation failed.
  +     */
  +    private static Object newInstance(Class c) {
  +        try {
  +            return c.newInstance();
  +
  +        } catch (InstantiationException e) {
  +            throw new DbException("Cannot create " + c.getName(), e);
  +        } catch (IllegalAccessException e) {
  +            throw new DbException("Cannot create " + c.getName(), e);
  +        }
       }
       
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message