You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/06/10 06:14:32 UTC

cvs commit: jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/jdbc JdbcHelper.java

dgraham     2003/06/09 21:14:31

  Modified:    mapper/src/share/org/apache/commons/mapper/jdbc
                        JdbcHelper.java
  Log:
  Added shortcut methods for queries with only one replacement parameter.
  
  Revision  Changes    Path
  1.4       +44 -4     jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/jdbc/JdbcHelper.java
  
  Index: JdbcHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/jdbc/JdbcHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JdbcHelper.java	10 Jun 2003 03:34:41 -0000	1.3
  +++ JdbcHelper.java	10 Jun 2003 04:14:31 -0000	1.4
  @@ -100,7 +100,7 @@
           new StatementPreparer() {
           public void prepareStatement(PreparedStatement stmt, Object obj)
               throws SQLException {
  -                
  +
               Object[] args = (Object[]) obj;
               for (int i = 0; i < args.length; i++) {
                   stmt.setObject(i + 1, args[i]);
  @@ -178,6 +178,21 @@
       }
   
       /**
  +     * Executes the given INSERT, UPDATE, or DELETE SQL statement.  The 
  +     * statement is executed in it's own transaction that will be committed or rolled 
  +     * back depending on any SQLExceptions thrown.  This is 
  +     * useful for queries with only one replacement parameter and is the equivalent of
  +     * calling executeUpdate(sql, new Object[] { param }).
  +     * @param sql The SQL statement to execute.
  +     * @param param An object to fill one sql '?' marker with.
  +     * @throws MapperException
  +     * @return The number of rows updated.
  +     */
  +    public int executeUpdate(String sql, Object param) throws MapperException {
  +        return this.executeUpdate(sql, ARRAY_PREPARER, new Object[] { param });
  +    }
  +
  +    /**
        * Executes the given SELECT SQL query and returns a List of results.
        * @param sql The SQL statement to execute.
        * @param preparer Initializes the PreparedStatement's IN parameters.
  @@ -236,7 +251,32 @@
           Object[] params,
           ResultObjectFactory resultFactory)
           throws MapperException {
  +
           return this.executeQuery(sql, ARRAY_PREPARER, params, resultFactory);
  +    }
  +
  +    /**
  +     * Executes the given SELECT SQL query and returns a List of results.  This is 
  +     * useful for queries with only one replacement parameter and is the equivalent of
  +     * calling executeQuery(sql, new Object[] { param }, factory).
  +     * @param sql The SQL statement to execute.
  +     * @param param An object to fill one sql '?' marker with.
  +     * @param resultFactory
  +     * @return A list of objects generated by the resultFactory.
  +     * @throws MapperException
  +     * @see #executeQuery(String, Object[], ResultObjectFactory)
  +     */
  +    public List executeQuery(
  +        String sql,
  +        Object param,
  +        ResultObjectFactory resultFactory)
  +        throws MapperException {
  +
  +        return this.executeQuery(
  +            sql,
  +            ARRAY_PREPARER,
  +            new Object[] { param },
  +            resultFactory);
       }
   
       /**
  
  
  

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