Coverage Report - org.apache.commons.dbcp.datasources.UserPassKey
 
Classes in this File Line Coverage Branch Coverage Complexity
UserPassKey
68%
13/19
75%
9/12
2.333
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.commons.dbcp.datasources;
 19  
 
 20  
 import java.io.Serializable;
 21  
 
 22  
 /**
 23  
  * <p>Holds a username, password pair.  Serves as a poolable object key for the KeyedObjectPool
 24  
  * backing a SharedPoolDataSource.  Two instances with the same username are considered equal.
 25  
  * This ensures that there will be only one keyed pool for each user in the pool.  The password
 26  
  * is used (along with the username) by the KeyedCPDSConnectionFactory when creating new connections.</p>
 27  
  * 
 28  
  * <p>{@link InstanceKeyDataSource#getConnection(String, String)} validates that the password used to create
 29  
  * a connection matches the password provided by the client.</p>
 30  
  * 
 31  
  * @version $Revision: 1023401 $ $Date: 2010-10-16 21:54:24 -0400 (Sat, 16 Oct 2010) $
 32  
  */
 33  
 class UserPassKey implements Serializable {
 34  
     private static final long serialVersionUID = 5142970911626584817L;
 35  
     private final String password;
 36  
     private final String username;
 37  
     
 38  4004
     UserPassKey(String username, String password) {
 39  4004
         this.username = username;
 40  4004
         this.password = password;
 41  4004
     }
 42  
         
 43  
     /**
 44  
      * Get the value of password.
 45  
      * @return value of password.
 46  
      */
 47  
     public String getPassword() {
 48  324
         return password;
 49  
     }
 50  
     
 51  
     /**
 52  
      * Get the value of username.
 53  
      * @return value of username.
 54  
      */
 55  
     public String getUsername() {
 56  318
         return username;
 57  
     }
 58  
     
 59  
     /**
 60  
      * @return <code>true</code> if the username fields for both 
 61  
      * objects are equal.  Two instances with the same username
 62  
      * but different passwords are considered equal.
 63  
      * 
 64  
      * @see java.lang.Object#equals(java.lang.Object)
 65  
      */
 66  
     public boolean equals(Object obj) {
 67  37988
         if (obj == null) {
 68  0
             return false;
 69  
         }
 70  
 
 71  37988
         if (obj == this) {
 72  2
             return true;
 73  
         }
 74  
         
 75  37986
         if (!(obj instanceof UserPassKey)) {
 76  0
             return false;
 77  
         }
 78  
         
 79  37986
         UserPassKey key = (UserPassKey) obj;
 80  
         
 81  37986
         return this.username == null ?
 82  
                 key.username == null :
 83  
                 this.username.equals(key.username);       
 84  
     }
 85  
 
 86  
     /**
 87  
      * Returns the hash of the username. 
 88  
      */
 89  
     public int hashCode() {
 90  38202
         return (this.username != null ?
 91  
                 (this.username).hashCode() : 0);
 92  
     }
 93  
 
 94  
     public String toString() {
 95  0
         StringBuffer sb = new StringBuffer(50);
 96  0
         sb.append("UserPassKey(");
 97  0
         sb.append(username).append(", ").append(password).append(')');
 98  0
         return sb.toString();
 99  
     }
 100  
 }