You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2003/10/15 21:52:13 UTC

cvs commit: jakarta-commons/dbcp/src/test/org/apache/commons/dbcp TestConnectionPool.java TesterStatement.java

dirkv       2003/10/15 12:52:13

  Modified:    dbcp/src/test/org/apache/commons/dbcp
                        TestConnectionPool.java TesterStatement.java
  Log:
  support for "select username" sql statement to get the username used
  to create the connection
  
  Revision  Changes    Path
  1.9       +18 -3     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestConnectionPool.java
  
  Index: TestConnectionPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestConnectionPool.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestConnectionPool.java	9 Oct 2003 21:05:29 -0000	1.8
  +++ TestConnectionPool.java	15 Oct 2003 19:52:13 -0000	1.9
  @@ -65,6 +65,7 @@
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
  +import java.sql.Statement;
   
   import junit.framework.TestCase;
   
  @@ -79,6 +80,7 @@
    * @author Rodney Waldhoff
    * @author Sean C. Sullivan
    * @author John McNally
  + * @author Dirk Verbeeck
    * 
    * @version $Id$
    */
  @@ -104,6 +106,19 @@
       protected long getMaxWait() {
           return 100L;
       }
  +
  +    // ----------- Utility Methods --------------------------------- 
  +
  +    protected String getUsername(Connection conn) throws SQLException {
  +        Statement stmt = conn.createStatement();
  +        ResultSet rs = stmt.executeQuery("select username");
  +        if (rs.next()) {
  +            return rs.getString(1);
  +        }
  +        return null;
  +    }
  +
  +    // ----------- tests --------------------------------- 
   
       public void testClearWarnings() throws Exception {
           Connection[] c = new Connection[getMaxActive()];
  
  
  
  1.11      +13 -2     jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TesterStatement.java
  
  Index: TesterStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TesterStatement.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TesterStatement.java	9 Oct 2003 21:05:29 -0000	1.10
  +++ TesterStatement.java	15 Oct 2003 19:52:13 -0000	1.11
  @@ -67,6 +67,13 @@
   import java.sql.SQLWarning;
   import java.sql.Statement;
   
  +/**
  + * A dummy {@link Statement}, for testing purposes.
  + * 
  + * @author Rodney Waldhoff
  + * @author Dirk Verbeeck
  + * @version $Revision$ $Date$
  + */
   public class TesterStatement implements Statement {
       public TesterStatement(Connection conn) {
           _connection = conn;
  @@ -91,6 +98,10 @@
               return null;
           } if("invalid".equals(sql)) {
               throw new SQLException("invalid query");
  +        } if("select username".equals(sql)) {
  +            String username = ((TesterConnection) _connection).getUsername();
  +            Object[][] data = {{username}};
  +            return new TesterResultSet(this, data);
           } else {
               return new TesterResultSet(this);
           }
  
  
  

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