| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PBKey |
|
| 2.2;2.2 |
| 1 | package org.apache.ojb.broker; | |
| 2 | ||
| 3 | /* Copyright 2002-2005 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * 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 | import java.io.Serializable; | |
| 19 | ||
| 20 | /** | |
| 21 | * A immutable key to identify PB instances in pools, ... | |
| 22 | * <br> | |
| 23 | * The used <i>jcdAlias</i> name represents an alias for a connection | |
| 24 | * defined in the repository file. | |
| 25 | * | |
| 26 | * @author Armin Waibel | |
| 27 | * @version $Id: PBKey.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $ | |
| 28 | */ | |
| 29 | public class PBKey implements Cloneable, Serializable | |
| 30 | { | |
| 31 | private static final long serialVersionUID = -8858811398162391578L; | |
| 32 | private final String jcdAlias; | |
| 33 | private final String user; | |
| 34 | private final String password; | |
| 35 | private int hashCode; | |
| 36 | ||
| 37 | /** | |
| 38 | * Creates a new PBKey. | |
| 39 | * | |
| 40 | * @param jcdAlias The jdbc connection descriptor name as defined in the repository file | |
| 41 | * @param user The username | |
| 42 | * @param password The password | |
| 43 | */ | |
| 44 | public PBKey(final String jcdAlias, final String user, final String password) | |
| 45 | { | |
| 46 | this.jcdAlias = jcdAlias; | |
| 47 | this.user = user; | |
| 48 | this.password = password; | |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Convenience constructor for <code>PBKey(jcdAlias, null, null)</code>. | |
| 53 | * | |
| 54 | * @param jcdAlias The jdbc connection descriptor name as defined in the repository file | |
| 55 | */ | |
| 56 | public PBKey(final String jcdAlias) | |
| 57 | { | |
| 58 | this(jcdAlias, null, null); | |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * {@inheritDoc} | |
| 63 | */ | |
| 64 | public boolean equals(Object obj) | |
| 65 | { | |
| 66 | if (obj == this) | |
| 67 | { | |
| 68 | return true; | |
| 69 | } | |
| 70 | if (!(obj instanceof PBKey)) | |
| 71 | { | |
| 72 | return false; | |
| 73 | } | |
| 74 | PBKey other = (PBKey) obj; | |
| 75 | return this.jcdAlias.equals(other.getAlias()) | |
| 76 | && (user != null ? user.equals(other.user) : null == other.user) | |
| 77 | && (password != null ? password.equals(other.password) : null == other.password); | |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * {@inheritDoc} | |
| 82 | */ | |
| 83 | protected Object clone() throws CloneNotSupportedException | |
| 84 | { | |
| 85 | return new PBKey(this.jcdAlias, this.user, this.password); | |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * {@inheritDoc} | |
| 90 | */ | |
| 91 | public int hashCode() | |
| 92 | { | |
| 93 | if(hashCode == 0) | |
| 94 | { | |
| 95 | hashCode = jcdAlias.hashCode() | |
| 96 | + (user != null ? user.hashCode() : 0) | |
| 97 | + (password != null ? password.hashCode() : 0); | |
| 98 | } | |
| 99 | return hashCode; | |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * {@inheritDoc} | |
| 104 | */ | |
| 105 | public String toString() | |
| 106 | { | |
| 107 | return this.getClass().getName() + ": jcdAlias="+jcdAlias+", user="+user+ | |
| 108 | (user != null ? ", password=*****" : ", password="+password); | |
| 109 | } | |
| 110 | ||
| 111 | /** | |
| 112 | * Returns the jdbc connection descriptor name as defined in the repository file. | |
| 113 | * | |
| 114 | * @return The JCD alias | |
| 115 | */ | |
| 116 | public String getAlias() | |
| 117 | { | |
| 118 | return jcdAlias; | |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * Returns the jdbc connection descriptor name as defined in the repository file. | |
| 123 | * | |
| 124 | * @return The JCD alias | |
| 125 | * @deprecated use {@link #getAlias} instead. | |
| 126 | */ | |
| 127 | public String getRepositoryFile() | |
| 128 | { | |
| 129 | return jcdAlias; | |
| 130 | } | |
| 131 | ||
| 132 | /** | |
| 133 | * Returns the username. | |
| 134 | * | |
| 135 | * @return The username | |
| 136 | */ | |
| 137 | public String getUser() | |
| 138 | { | |
| 139 | return user; | |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * Returns the password. | |
| 144 | * | |
| 145 | * @return The password | |
| 146 | */ | |
| 147 | public String getPassword() | |
| 148 | { | |
| 149 | return password; | |
| 150 | } | |
| 151 | } |