1 28 29 package com.caucho.ejb.cfg; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.util.L10N; 33 34 import java.util.ArrayList ; 35 36 39 public class EjbMethodPattern { 40 private static L10N L = new L10N(EjbMethodPattern.class); 41 42 public final static int RESIN_DATABASE = 0; 43 public final static int RESIN_READ_ONLY = 1; 44 public final static int RESIN_ROW_LOCK = 2; 45 46 private EjbBean _bean; 47 48 private String _location; 49 50 private MethodSignature _signature; 51 52 private int _resinIsolation = -1; 53 private int _jdbcIsolation = -1; 54 55 private boolean _queryLoadsBean = true; 56 private boolean _relationLoadsBean; 57 58 private String _query; 59 private String _queryLocation; 60 61 private int _transactionType = -1; 62 private ArrayList _roles; 63 64 67 public EjbMethodPattern() 68 { 69 } 70 71 77 public EjbMethodPattern(EjbBean bean, MethodSignature signature) 78 { 79 _bean = bean; 80 _signature = signature; 81 } 82 83 86 public void setBean(EjbBean bean) 87 { 88 _bean = bean; 89 } 90 91 94 public void setLocation(String location) 95 { 96 _location = location; 97 } 98 99 102 public String getLocation() 103 { 104 return _location; 105 } 106 107 110 public void setSignature(MethodSignature sig) 111 { 112 _signature = sig; 113 } 114 115 118 public MethodSignature getSignature() 119 { 120 return _signature; 121 } 122 123 126 public String getName() 127 { 128 return _signature.getName(); 129 } 130 131 134 public boolean isReadOnly() 135 { 136 return _resinIsolation == RESIN_READ_ONLY; 137 } 138 139 142 public int getResinIsolation() 143 { 144 return _resinIsolation; 145 } 146 147 150 public void setResinIsolation(String isolation) 151 throws ConfigException 152 { 153 if (isolation.equals("read-only")) 154 _resinIsolation = RESIN_READ_ONLY; 155 else if (isolation.equals("database")) 156 _resinIsolation = RESIN_DATABASE; 157 else if (isolation.equals("row-locking")) 158 _resinIsolation = RESIN_ROW_LOCK; 159 else 160 throw new ConfigException(L.l("`{0}' is an unknown value for resin-isolation. Only 'read-only', 'database', and 'row-locking' are allowed.", 161 isolation)); 162 } 163 164 167 public int getJDBCIsolation() 168 { 169 return _jdbcIsolation; 170 } 171 172 175 public void setJDBCIsolation(int isolation) 176 { 177 _jdbcIsolation = isolation; 178 } 179 180 183 public String getQuery() 184 { 185 return _query; 186 } 187 188 191 public void setQuery(String query) 192 { 193 _query = query; 194 } 195 196 199 public String getQueryLocation() 200 { 201 return _queryLocation; 202 } 203 204 207 public void setQueryLocation(String location) 208 { 209 _queryLocation = location; 210 } 211 212 215 public int getTransactionType() 216 { 217 if (_transactionType >= 0) 218 return _transactionType; 219 else if (isReadOnly()) 220 return EjbMethod.TRANS_SUPPORTS; 221 else 222 return EjbMethod.TRANS_REQUIRED; 223 } 224 225 public void setTransaction(int type) 226 throws ConfigException 227 { 228 _transactionType = type; 229 } 230 231 234 public void setTransAttribute(String type) 235 throws ConfigException 236 { 237 if ("Required".equals(type)) 238 _transactionType = EjbMethod.TRANS_REQUIRED; 239 else if ("RequiresNew".equals(type)) 240 _transactionType = EjbMethod.TRANS_REQUIRES_NEW; 241 else if ("Mandatory".equals(type)) 242 _transactionType = EjbMethod.TRANS_MANDATORY; 243 else if ("NotSupported".equals(type)) 244 _transactionType = EjbMethod.TRANS_NOT_SUPPORTED; 245 else if ("Never".equals(type)) 246 _transactionType = EjbMethod.TRANS_NEVER; 247 else if ("Supports".equals(type)) 248 _transactionType = EjbMethod.TRANS_SUPPORTS; 249 else 250 throw new ConfigException(L.l("`{0}' is an unknown transaction type. The transaction types are:\n Required - creates a new transaction if none is active.\n RequiresNew - always creates a new transaction.\n Mandatory - requires an active transaction.\n NotSupported - suspends any active transaction.\n Never - forbids any active transaction.\n Supports - allows a transaction or no transaction.", type)); 251 } 252 253 256 public boolean getQueryLoadsBean() 257 { 258 return _queryLoadsBean; 259 } 260 261 264 public void setQueryLoadsBean(boolean loadBean) 265 { 266 _queryLoadsBean = loadBean; 267 } 268 269 272 public boolean getRelationLoadsBean() 273 { 274 return _relationLoadsBean; 275 } 276 277 280 public void setRelationLoadsBean(boolean loadBean) 281 { 282 _relationLoadsBean = loadBean; 283 } 284 285 288 public ArrayList getRoles() 289 { 290 return _roles; 291 } 292 293 296 public void setRoles(ArrayList roles) 297 { 298 _roles = roles; 299 } 300 301 304 public void setRoles(String []roles) 305 { 306 if (roles != null) { 307 if (_roles == null) 308 _roles = new ArrayList (); 309 310 for (String role : roles) { 311 _roles.add(role); 312 } 313 } 314 } 315 316 319 public boolean equals(Object o) 320 { 321 if (! (o instanceof EjbMethodPattern)) 322 return false; 323 324 EjbMethodPattern method = (EjbMethodPattern) o; 325 326 return _signature.equals(method.getSignature()); 327 } 328 329 public String toString() 330 { 331 return "EJBMethodPattern[" + _signature.getName() + "]"; 332 } 333 } 334 | Popular Tags |