1 21 package oracle.toplink.essentials.threetier; 23 24 import java.util.*; 25 import java.io.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 import oracle.toplink.essentials.sessions.Login; 28 import oracle.toplink.essentials.internal.localization.*; 29 30 35 public class ConnectionPolicy implements Cloneable , Serializable { 36 protected Login login; 37 protected String poolName; 38 protected boolean isLazy; 39 40 41 protected Map properties; 42 43 47 public ConnectionPolicy() { 48 this.isLazy = true; 49 } 50 51 55 public ConnectionPolicy(String poolName) { 56 this.isLazy = true; 57 this.poolName = poolName; 58 } 59 60 64 public ConnectionPolicy(Login login) { 65 this.isLazy = false; 66 this.login = login; 67 } 68 69 73 public Object clone() { 74 try { 75 ConnectionPolicy clone = (ConnectionPolicy)super.clone(); 76 if (clone.hasLogin()) { 77 clone.setLogin((Login)clone.getLogin().clone()); 78 } 79 return clone; 80 } catch (CloneNotSupportedException e) { 81 return null; 82 } 83 } 84 85 90 public void dontUseLazyConnection() { 91 setIsLazy(false); 92 } 93 94 99 public Login getLogin() { 100 return login; 101 } 102 103 107 public String getPoolName() { 108 return poolName; 109 } 110 111 116 public Map getProperties() { 117 if (this.properties == null) { 118 this.properties = new HashMap(); 119 } 120 return this.properties; 121 } 122 123 128 public Object getProperty(Object object) { 129 if (this.hasProperties()) { 130 return this.getProperties().get(object); 131 } 132 return null; 133 } 134 135 139 public boolean hasLogin() { 140 return login != null; 141 } 142 143 147 public boolean hasProperties() { 148 return (this.properties != null) && (!this.properties.isEmpty()); 149 } 150 151 156 public boolean isLazy() { 157 return isLazy; 158 } 159 160 164 public boolean isPooled() { 165 return poolName != null; 166 } 167 168 172 public boolean isUserDefinedConnection() { 173 return poolName == null; 174 } 175 176 182 public Object removeProperty(Object key) { 183 if (this.hasProperties()) { 184 return getProperties().remove(key); 185 } 186 return null; 187 } 188 189 194 public void setIsLazy(boolean isLazy) { 195 this.isLazy = isLazy; 196 } 197 198 204 public void setLogin(Login login) { 205 this.login = login; 206 } 207 208 212 public void setPoolName(String poolName) { 213 this.poolName = poolName; 214 } 215 216 222 public void setProperty(Object key, Object property) { 223 getProperties().put(key, property); 224 } 225 226 230 public String toString() { 231 String type = ""; 232 if (isPooled()) { 233 type = "(" + ToStringLocalization.buildMessage("pooled", (Object [])null) + ": " + getPoolName(); 234 } else { 235 type = "(" + ToStringLocalization.buildMessage("login", (Object [])null) + ": " + getLogin(); 236 } 237 if (isLazy()) { 238 type = type + "," + ToStringLocalization.buildMessage("lazy", (Object [])null) + ")"; 239 } else { 240 type = type + "," + ToStringLocalization.buildMessage("non-lazy", (Object [])null) + ")"; 241 } 242 243 return Helper.getShortClassName(getClass()) + type; 244 } 245 246 251 public void useLazyConnection() { 252 setIsLazy(true); 253 } 254 } 255 | Popular Tags |