noel        2003/05/29 13:28:47

  Modified:    src/java/org/apache/james/userrepository
                        AbstractJdbcUsersRepository.java
  Log:
  Improve performance of listUserNames()
  
  Revision  Changes    Path
  1.22      +30 -6     
jakarta-james/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
  
  Index: AbstractJdbcUsersRepository.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- AbstractJdbcUsersRepository.java  8 Mar 2003 21:14:11 -0000       1.21
  +++ AbstractJdbcUsersRepository.java  29 May 2003 20:28:47 -0000      1.22
  @@ -64,9 +64,10 @@
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
  -import java.util.LinkedList;
  +import java.util.ArrayList;
   import java.util.List;
   import java.util.Locale;
   import java.util.Map;
  @@ -211,7 +212,7 @@
               destUrl += "/";
           }
           // Split on "/", starting after "db://"
  -        List urlParams = new LinkedList();
  +        List urlParams = new ArrayList();
           int start = 5;
           int end = destUrl.indexOf('/', start);
           while ( end > -1 ) {
  @@ -392,6 +393,21 @@
           }
       }
   
  +    /**
  +     * Produces the complete list of User names, with correct case.
  +     * @return a <code>List</code> of <code>String</code>s representing
  +     *         user names.
  +     */
  +    protected List listUserNames() {
  +        Collection users = getAllUsers();
  +        List userNames = new ArrayList(users.size());
  +        for (Iterator it = users.iterator(); it.hasNext(); ) {
  +            userNames.add(((User)it.next()).getUserName());
  +        }
  +        users.clear();
  +        return userNames;
  +    }
  +
       //
       // Superclass methods - overridden from AbstractUsersRepository
       //
  @@ -400,15 +416,23 @@
        * @return an <code>Iterator</code> of <code>JamesUser</code>s.
        */
       protected Iterator listAllUsers() {
  -        List userList = new LinkedList(); // Build the users into this list.
  +        return getAllUsers().iterator();
  +    }
  +
  +    /**
  +     * Returns a list populated with all of the Users in the repository.
  +     * @return a <code>Collection</code> of <code>JamesUser</code>s.
  +     */
  +    private Collection getAllUsers() {
  +        List userList = new ArrayList(); // Build the users into this list.
   
           Connection conn = openConnection();
           PreparedStatement getUsersStatement = null;
           ResultSet rsUsers = null;
           try {
               // Get a ResultSet containing all users.
  -            getUsersStatement =
  -                conn.prepareStatement(m_getUsersSql);
  +            getUsersStatement = 
  +                               conn.prepareStatement(m_getUsersSql);
               rsUsers = getUsersStatement.executeQuery();
   
               // Loop through and build a User for every row.
  @@ -427,7 +451,7 @@
               theJDBCUtil.closeJDBCConnection(conn);
           }
   
  -        return userList.iterator();
  +        return userList;
       }
   
       /**
  
  
  

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

Reply via email to