View Javadoc
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.dbcp2.datasources;
19  
20  import java.io.Serializable;
21  import java.util.Objects;
22  
23  /**
24   * @since 2.0
25   */
26  class PoolKey implements Serializable {
27      private static final long serialVersionUID = 2252771047542484533L;
28  
29      private final String dataSourceName;
30      private final String userName;
31  
32      PoolKey(final String dataSourceName, final String userName) {
33          this.dataSourceName = dataSourceName;
34          this.userName = userName;
35      }
36  
37      @Override
38      public boolean equals(final Object obj) {
39          if (this == obj) {
40              return true;
41          }
42          if (obj == null) {
43              return false;
44          }
45          if (getClass() != obj.getClass()) {
46              return false;
47          }
48          final PoolKey../../../../../org/apache/commons/dbcp2/datasources/PoolKey.html#PoolKey">PoolKey other = (PoolKey) obj;
49          if (!Objects.equals(dataSourceName, other.dataSourceName)) {
50              return false;
51          }
52          return Objects.equals(userName, other.userName);
53      }
54  
55      @Override
56      public int hashCode() {
57          return Objects.hash(dataSourceName, userName);
58      }
59  
60      @Override
61      public String toString() {
62          final StringBuilder sb = new StringBuilder(50);
63          sb.append("PoolKey(");
64          sb.append(dataSourceName);
65          sb.append(')');
66          return sb.toString();
67      }
68  }