commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bali...@apache.org
Subject cvs commit: jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils Demo.java DemoHandler.java ProcedureUtilsTest.java
Date Mon, 10 Mar 2003 19:35:44 GMT
baliuka     2003/03/10 11:35:43

  Modified:    dbutils/src/java/org/apache/commons/dbutils DbUtils.java
                        ProcedureUtils.java ResultSetHandler.java
                        ScalarHandler.java
               dbutils/src/test/org/apache/commons/dbutils Demo.java
                        DemoHandler.java ProcedureUtilsTest.java
  Log:
  added "userObject"  parameter to handler interface
  
  Revision  Changes    Path
  1.14      +14 -71    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DbUtils.java	10 Mar 2003 18:04:45 -0000	1.13
  +++ DbUtils.java	10 Mar 2003 19:35:42 -0000	1.14
  @@ -67,7 +67,7 @@
      
       public static abstract class ListAdapter extends ArrayList implements ResultSetHandler{
           
  -        final public Object handle(ResultSet rs,Object[] params)throws SQLException{
  +        public final Object handle(java.sql.ResultSet rs, Object[] params, Object userObject)
throws java.sql.SQLException{
               
               while(rs.next()){
                   add(fetch(rs));
  @@ -81,7 +81,7 @@
       
       
       
  -    public static boolean execute(Connection connection, String query,Object[] vals, ResultSetHandler
rsh)
  +    public static boolean execute(Connection connection, String query,Object[] vals, ResultSetHandler
rsh, Object userObject)
       throws SQLException {
           
           PreparedStatement stmt = null;
  @@ -97,7 +97,7 @@
                       do{
                           
                           rs = stmt.getResultSet();
  -                        rsh.handle(rs,vals);
  +                        rsh.handle(rs,vals,userObject);
                           
                       }while(stmt.getMoreResults());
                       
  @@ -122,9 +122,13 @@
           
       }
       
  +    public static Object executeQuery(Connection connection, String query, 
  +                   Object[] vals, ResultSetHandler rsh){
  +    return  executeQuery(connection,query, vals, rsh  );                     
  +} 
       
  -    
  -    public static Object executeQuery(Connection connection, String query, Object[] vals,
ResultSetHandler rsh)
  +    public static Object executeQuery(Connection connection, String query, 
  +                   Object[] vals, ResultSetHandler rsh,Object userObject)
       throws SQLException {
           
           PreparedStatement stmt = null;
  @@ -141,7 +145,7 @@
                   rethrow( sqle, query, vals);
               }
               
  -            return rsh.handle(rs,vals);
  +            return rsh.handle(rs,vals,userObject);
               
           } finally {
               closeQuietly(rs);
  @@ -211,7 +215,8 @@
        * inside an List.
        * Null values in the Object array will be passed to the driver.
        */
  -    public static List executeListQuery(Connection connection, String query, Object[] vals
)
  +    public static List executeListQuery(Connection connection, 
  +              String query, Object[] vals, Object userObject )
       throws SQLException {
           return (List)executeQuery(connection,query,vals,
           
  @@ -223,7 +228,7 @@
               
           }
           
  -        );
  +        , userObject );
           
       }
       
  @@ -237,73 +242,11 @@
        */
       public static Iterator executeQuery(Connection connection, String query, Object[] vals
)
       throws SQLException {
  -        return executeListQuery(connection, query, vals ).iterator();
  +        return executeListQuery(connection, query, vals, null ).iterator();
           
       }
       
       
  -    /**
  -     * Creates a PreparedStatement using the String and Object array,
  -     * executes this using the Connection, and returns the result
  -     * as int.
  -     * Null values in the Object array will be passed to the driver.
  -     */
  -    public static int executeIntQuery(Connection connection, final String query, final
Object[] vals ) 
  -    throws SQLException {
  -        return ((Number) executeQuery(connection, query, vals,
  -        
  -        new ResultSetHandler(){
  -            public Object handle(ResultSet rs, Object[] params)throws SQLException{
  -                ResultSetMetaData rsmd = rs.getMetaData();
  -                if(rsmd.getColumnCount() > 1 ){
  -                    throwMultipleResults(query, vals);
  -                }
  -                Number result = null;
  -                if (rs.next()) {
  -                    result = new Integer( rs.getInt(1) );
  -                }else{
  -                    throwNoResults(query, vals);
  -                }
  -                if(rs.next()){
  -                    throwMultipleResults(query, vals);
  -                }
  -                return result;
  -            }
  -        }
  -        // ResultSetHandler
  -        )).intValue();
  -        
  -    }
  -    
  -    /**
  -     * Creates a PreparedStatement using the String and Object array,
  -     * executes this using the Connection, and returns the result
  -     * as row.
  -     * Null values in the Object array will be passed to the driver.
  -     */
  -    public static Object[] executeRowQuery(Connection connection, final String query, final
Object[] vals)
  -    throws SQLException {
  -        return ((Object[]) executeQuery(connection, query, vals,
  -        
  -        new ResultSetHandler(){
  -            public Object handle(ResultSet rs,Object[] params)throws SQLException{
  -                
  -                if (rs.next()) {
  -                    return resultSetToArray(rs);
  -                }else{
  -                    throwNoResults(query, vals);
  -                }
  -                if(rs.next()){
  -                    throwMultipleResults(query, vals);
  -                }
  -                //assert true
  -                return null;
  -            }
  -        }
  -        // ResultSetHandler
  -        ));
  -        
  -    }
       
       
       /**
  
  
  
  1.5       +2 -1      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ProcedureUtils.java
  
  Index: ProcedureUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ProcedureUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProcedureUtils.java	10 Mar 2003 17:46:28 -0000	1.4
  +++ ProcedureUtils.java	10 Mar 2003 19:35:42 -0000	1.5
  @@ -385,7 +385,8 @@
                       return convert( method.getReturnType(), DbUtils.executeQuery(  connection,
                       descriptor.jdbcSQL,
                       prepareArgs(descriptor,args),
  -                    descriptor.handler
  +                    descriptor.handler,
  +                     args
                       ));
                   }else{
                       int updateCount = DbUtils.executeUpdate(  connection,
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetHandler.java
  
  Index: ResultSetHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResultSetHandler.java	9 Mar 2003 17:14:19 -0000	1.2
  +++ ResultSetHandler.java	10 Mar 2003 19:35:42 -0000	1.3
  @@ -7,6 +7,6 @@
    */
    public  interface ResultSetHandler{
           
  -        public Object handle(java.sql.ResultSet rs,Object params[])throws java.sql.SQLException;
  +        public Object handle(java.sql.ResultSet rs,Object params[],Object userObject)throws
java.sql.SQLException;
           
    }
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ScalarHandler.java
  
  Index: ScalarHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ScalarHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ScalarHandler.java	9 Mar 2003 17:14:19 -0000	1.2
  +++ ScalarHandler.java	10 Mar 2003 19:35:42 -0000	1.3
  @@ -11,7 +11,7 @@
       public ScalarHandler() {
       }
       
  -    public Object handle(ResultSet rs,Object[] params)throws SQLException{
  +    public Object handle(java.sql.ResultSet rs, Object[] params, Object userObject) throws
java.sql.SQLException{
                  
                   if (rs.next()) {
                       Object result = rs.getObject(1);
  
  
  
  1.4       +0 -5      jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/Demo.java
  
  Index: Demo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/Demo.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Demo.java	10 Mar 2003 17:46:28 -0000	1.3
  +++ Demo.java	10 Mar 2003 19:35:42 -0000	1.4
  @@ -35,11 +35,6 @@
       */
       public void clear();
       
  -    /**
  -     *@query SELECT ID, NAME FROM TBL 
  -     *@handler DemoHandler
  -     */
  -    public int print();
       
       /**
        *@query SELECT ID, NAME FROM TBL 
  
  
  
  1.3       +5 -7      jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/DemoHandler.java
  
  Index: DemoHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/DemoHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DemoHandler.java	10 Mar 2003 17:46:28 -0000	1.2
  +++ DemoHandler.java	10 Mar 2003 19:35:42 -0000	1.3
  @@ -11,13 +11,11 @@
       public DemoHandler() {
       }
       
  -    public Object handle(java.sql.ResultSet rs, Object[] params) throws java.sql.SQLException
{
  -        java.io.PrintStream out;
  -        if(params.length > 0 && (params[params.length - 1] instanceof java.io.PrintStream)){
  -          out = (java.io.PrintStream)params[params.length - 1];
  -        }else{
  -          out = System.out;
  -        }
  +    public Object handle(java.sql.ResultSet rs, Object[] params, Object userObject) throws
java.sql.SQLException {
  +        
  +       Object[] p =  (Object[])userObject;  
  +       java.io.PrintStream out = (java.io.PrintStream)p[0];
  +         
           int cnt = 0;
           java.sql.ResultSetMetaData rsm = rs.getMetaData();
            for(int i = 1; i <= rsm.getColumnCount(); i++ ){
  
  
  
  1.4       +1 -1      jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ProcedureUtilsTest.java
  
  Index: ProcedureUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ProcedureUtilsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProcedureUtilsTest.java	10 Mar 2003 17:46:28 -0000	1.3
  +++ ProcedureUtilsTest.java	10 Mar 2003 19:35:42 -0000	1.4
  @@ -65,7 +65,7 @@
              demo.add(i + 2,"test" + i);
          }
          demo.print(System.out);
  -       demo.print();
  +     
          demo.clear();
        
       }
  
  
  

---------------------------------------------------------------------
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