cvs commit: jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/wrappers SqlNullCheckedResultSet.java

2003-11-09 Thread dgraham
dgraham 2003/11/09 10:18:04

  Modified:dbutils/src/test/org/apache/commons/dbutils/wrappers
SqlNullCheckedResultSetTest.java
   dbutils/src/java/org/apache/commons/dbutils/wrappers
SqlNullCheckedResultSet.java
  Log:
  - Cleaned up nullMethods population code
  
  - Fixed bug in invoke() where we were potentially calling
  rs.wasNull() before a getter method was called which
  could lead to an SQLException
  
  - Added support for null URLs.
  
  Revision  ChangesPath
  1.2   +32 -15
jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java
  
  Index: SqlNullCheckedResultSetTest.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/dbutils/src/test/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SqlNullCheckedResultSetTest.java  2 Nov 2003 19:15:24 -   1.1
  +++ SqlNullCheckedResultSetTest.java  9 Nov 2003 18:18:04 -   1.2
  @@ -70,6 +70,8 @@
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
   import java.math.BigDecimal;
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.sql.Blob;
   import java.sql.Clob;
   import java.sql.Ref;
  @@ -445,14 +447,12 @@
   rs2.setNullShort(s);
   assertEquals(s, rs.getShort(1));
   assertEquals(s, rs.getShort(column));
  -
   }
   
   /**
* Tests the getString implementation.
*/
   public void testGetString() throws SQLException {
  -
   assertEquals(null, rs.getString(1));
   assertTrue(rs.wasNull());
   assertEquals(null, rs.getString(column));
  @@ -462,7 +462,6 @@
   rs2.setNullString(s);
   assertEquals(s, rs.getString(1));
   assertEquals(s, rs.getString(column));
  -
   }
   
   /**
  @@ -516,7 +515,21 @@
   assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance()));
   assertNotNull(rs.getTimestamp(column, Calendar.getInstance()));
   assertEquals(ts, rs.getTimestamp(column, Calendar.getInstance()));
  -
  +}
  +
  +/**
  + * Tests the getURL implementation.
  + */
  +public void testGetURL() throws SQLException, MalformedURLException {
  +assertEquals(null, rs.getURL(1));
  +assertTrue(rs.wasNull());
  +assertEquals(null, rs.getURL(column));
  +assertTrue(rs.wasNull());
  +// Set what gets returned to something other than the default
  +URL u = new URL(http://www.apache.org;);
  +rs2.setNullURL(u);
  +assertEquals(u, rs.getURL(1));
  +assertEquals(u, rs.getURL(column));
   }
   
   /**
  @@ -779,21 +792,18 @@
* Tests the setNullString implementation.
*/
   public void testSetNullString() throws SQLException {
  -
   assertEquals(null, rs2.getNullString());
   // Set what gets returned to something other than the default
   String s = hello, world;
   rs2.setNullString(s);
   assertEquals(s, rs.getString(1));
   assertEquals(s, rs.getString(column));
  -
   }
   
   /**
* Tests the setNullRef implementation.
*/
   public void testSetNullRef() throws SQLException {
  -
   assertNull(rs2.getNullRef());
   // Set what gets returned to something other than the default
   Ref ref = new SqlNullCheckedResultSetMockRef();
  @@ -802,14 +812,12 @@
   assertEquals(ref, rs.getRef(1));
   assertNotNull(rs.getRef(column));
   assertEquals(ref, rs.getRef(column));
  -
   }
   
   /**
* Tests the setNullTime implementation.
*/
   public void testSetNullTime() throws SQLException {
  -
   assertEquals(null, rs2.getNullTime());
   // Set what gets returned to something other than the default
   Time time = new Time(new java.util.Date().getTime());
  @@ -822,14 +830,12 @@
   assertEquals(time, rs.getTime(1, Calendar.getInstance()));
   assertNotNull(rs.getTime(column, Calendar.getInstance()));
   assertEquals(time, rs.getTime(column, Calendar.getInstance()));
  -
   }
   
   /**
* Tests the setNullTimestamp implementation.
*/
   public void testSetNullTimestamp() throws SQLException {
  -
   assertEquals(null, rs2.getNullTimestamp());
   // Set what gets returned to something other than the default
   Timestamp ts = new Timestamp(new java.util.Date().getTime());
  @@ -842,7 +848,18 @@
   assertEquals(ts, rs.getTimestamp(1, Calendar.getInstance()));
   assertNotNull(rs.getTimestamp(column, Calendar.getInstance()));
   assertEquals(ts, rs.getTimestamp(column, Calendar.getInstance()));
  -
  +}
  

cvs commit: jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/wrappers SqlNullCheckedResultSet.java

2003-11-04 Thread dgraham
dgraham 2003/11/04 16:40:43

  Modified:dbutils/src/java/org/apache/commons/dbutils
ProxyFactory.java
   dbutils/src/java/org/apache/commons/dbutils/wrappers
SqlNullCheckedResultSet.java
  Log:
  javadoc changes only.
  
  Revision  ChangesPath
  1.2   +4 -4  
jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/ProxyFactory.java
  
  Index: ProxyFactory.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/ProxyFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProxyFactory.java 2 Nov 2003 19:15:23 -   1.1
  +++ ProxyFactory.java 5 Nov 2003 00:40:43 -   1.2
  @@ -72,7 +72,7 @@
   import java.sql.Statement;
   
   /**
  - * Creates proxy implementations of JDBC classes.  This avoids 
  + * Creates proxy implementations of JDBC interfaces.  This avoids 
* incompatibilities between the JDBC 2 and JDBC 3 interfaces.  This class is 
* thread safe.
* 
  
  
  
  1.2   +11 -9 
jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java
  
  Index: SqlNullCheckedResultSet.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SqlNullCheckedResultSet.java  2 Nov 2003 19:15:23 -   1.1
  +++ SqlNullCheckedResultSet.java  5 Nov 2003 00:40:43 -   1.2
  @@ -89,15 +89,17 @@
* Usage example:
* blockquote
* pre
  - * Connection conn = getConnection(); // somehow get a connection
  + * Connection conn = // somehow get a connection
* Statement stmt = conn.createStatement();
  - * ResultSet rs1 = stmt.executeQuery(SELECT col1, col2, FROM table1);
  + * ResultSet rs = stmt.executeQuery(SELECT col1, col2 FROM table1);
* 
* // Wrap the result set for SQL NULL checking
  - * SqlNullCheckedResultSet rs = new SqlNullCheckedResultSet(rs1);
  - * rs.setNullString(---N/A---); // Set null string
  - * rs.setNullInt(-999); // Set null integer
  - * while(rs.next) {
  + * SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(rs);
  + * wrapper.setNullString(---N/A---); // Set null string
  + * wrapper.setNullInt(-999); // Set null integer
  + * rs = ProxyFactory.instance().createResultSet(wrapper);
  + * 
  + * while (rs.next()) {
* // If col1 is SQL NULL, value returned will be ---N/A---
* String col1 = rs.getString(col1);
* // If col2 is SQL NULL, value returned will be -999
  
  
  

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