1 25 26 27 package org.objectweb.jonas_ejb.deployment.api; 28 29 import java.util.Iterator ; 30 31 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor; 32 import org.objectweb.jonas_ejb.deployment.xml.Entity; 33 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity; 34 import org.objectweb.jonas_ejb.lib.BeanNaming; 35 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 36 import org.objectweb.jonas_lib.deployment.xml.JLinkedList; 37 import org.objectweb.util.monolog.api.BasicLevel; 38 39 40 47 public abstract class EntityDesc extends BeanDesc { 48 49 50 53 protected static final String METHODS_REMOTE_NO_TX = ",getEJBHome,getHandle,getPrimaryKey,isIdentical,"; 54 55 58 protected static final String METHODS_HOME_NO_TX = ",getEJBMetaData,getHomeHandle,"; 59 60 64 protected Class primaryKeyClass; 65 protected boolean reentrant; 66 protected int passivationTimeout = 0; 67 protected int inactivityTimeout = 0; 68 protected boolean shared = false; 69 protected boolean prefetch = false; 70 71 protected boolean jdbcAutomaticPk = false; protected boolean pkObjectType = false; 75 public static final int CLEANUP_NONE = 0; 77 public static final int CLEANUP_CREATE = 1; 78 public static final int CLEANUP_REMOVEDATA = 2; 79 public static final int CLEANUP_REMOVEALL = 3; 80 protected int cleanup = CLEANUP_CREATE; 81 82 public static final int LOCK_CONTAINER_READ_UNCOMMITTED = 0; 84 public static final int LOCK_CONTAINER_SERIALIZED = 1; 85 public static final int LOCK_CONTAINER_READ_COMMITTED = 2; 86 public static final int LOCK_DATABASE = 3; 87 public static final int LOCK_READ_ONLY = 4; 88 protected int lockPolicy = LOCK_CONTAINER_SERIALIZED; 89 90 93 public EntityDesc(ClassLoader classLoader, 94 Entity ent, 95 AssemblyDescriptor asd, 96 JonasEntity jEnt, 97 JLinkedList jMDRList, 98 String fileName) 99 throws DeploymentDescException { 100 101 super(classLoader, ent, jEnt, asd, jMDRList, fileName); 102 103 try { 105 if (ent.getPrimKeyClass().equalsIgnoreCase("Object") || ent.getPrimKeyClass().equalsIgnoreCase("java.lang.Object")) { 107 primaryKeyClass = classLoader.loadClass("java.lang.Integer"); 108 pkObjectType = true; 109 } 110 else 111 primaryKeyClass = classLoader.loadClass(ent.getPrimKeyClass()); 112 } catch (ClassNotFoundException e) { 113 throw new DeploymentDescException("Primary Key class not found for bean " + this.ejbName, e); 114 } 115 116 if (jEnt.getPassivationTimeout() != null) { 118 String tstr = jEnt.getPassivationTimeout(); 119 Integer tval = new Integer (tstr); 120 passivationTimeout = tval.intValue(); 121 } 122 123 if (jEnt.getInactivityTimeout() != null) { 125 String tstr = jEnt.getInactivityTimeout(); 126 Integer tval = new Integer (tstr); 127 inactivityTimeout = tval.intValue(); 128 } 129 130 if (ent.getReentrant().equalsIgnoreCase("True")) { 132 reentrant = true; 133 } else if (ent.getReentrant().equalsIgnoreCase("False")) { 134 reentrant = false; 135 } else { 136 throw new DeploymentDescException("Invalid reentrant value for bean " + this.ejbName); 137 } 138 139 if (jEnt.getPrefetch() != null) { 141 if (jEnt.getPrefetch().equalsIgnoreCase("True")) { 142 prefetch = true; 143 } else if (jEnt.getPrefetch().equalsIgnoreCase("False")) { 144 prefetch = false; 145 } else { 146 throw new DeploymentDescException("Invalid prefetch value for bean " + this.ejbName); 147 } 148 } 149 150 if (jEnt.getMinPoolSize() != null) { 152 String tstr = jEnt.getMinPoolSize(); 153 Integer tval = new Integer (tstr); 154 poolMin = tval.intValue(); 155 } 156 157 if (jEnt.getMaxCacheSize() != null) { 159 String tstr = jEnt.getMaxCacheSize(); 160 Integer tval = new Integer (tstr); 161 cacheMax = tval.intValue(); 162 } 163 164 if (jEnt.getLockPolicy() != null) { 169 String tstr = jEnt.getLockPolicy(); 170 if (tstr.equals("container-serialized")) { 171 lockPolicy = LOCK_CONTAINER_SERIALIZED; 172 shared = false; 173 } else if (tstr.equals("container-read-committed")) { 174 lockPolicy = LOCK_CONTAINER_READ_COMMITTED; 175 shared = true; 176 } else if (tstr.equals("container-read-uncommitted")) { 177 lockPolicy = LOCK_CONTAINER_READ_UNCOMMITTED; 178 shared = true; 179 } else if (tstr.equals("database")) { 180 lockPolicy = LOCK_DATABASE; 181 shared = true; 182 } else if (tstr.equals("read-only")) { 183 lockPolicy = LOCK_READ_ONLY; 184 } else { 185 throw new DeploymentDescException("Invalid lock-policy value for bean " + jEnt.getEjbName()); 186 } 187 } 188 189 if (jEnt.getShared() != null) { 191 if (jEnt.getShared().equalsIgnoreCase("True")) { 192 shared = true; 193 } else if (jEnt.getShared().equalsIgnoreCase("False")) { 194 shared = false; 195 } else { 196 throw new DeploymentDescException("Invalid shared value for bean " + this.ejbName); 197 } 198 } 199 200 if (jEnt.getCleanup() != null) { 206 String tstr = jEnt.getCleanup(); 207 if (tstr.equals("create")) { 208 cleanup = CLEANUP_CREATE; 209 } else if (tstr.equals("none")) { 210 cleanup = CLEANUP_NONE; 211 } else if (tstr.equals("removeall")) { 212 cleanup = CLEANUP_REMOVEALL; 213 } else if (tstr.equals("removedata")) { 214 cleanup = CLEANUP_REMOVEDATA; 215 } else { 216 throw new DeploymentDescException("Invalid cleanup value for bean " + jEnt.getEjbName()); 217 } 218 } 219 220 for (Iterator i = getMethodDescIterator(); i.hasNext();) { 222 MethodDesc methd = (MethodDesc) i.next(); 223 if (methd.getMethod().getName().equals("ejbTimeout")) { 224 timerTxAttribute = methd.getTxAttribute(); 225 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod()); 226 } 227 } 228 } 229 230 233 public int getCleanupPolicy() { 234 return cleanup; 235 } 236 237 240 public int getLockPolicy() { 241 return lockPolicy; 242 } 243 244 247 protected void checkTxAttribute(MethodDesc md) throws DeploymentDescException { 248 java.lang.reflect.Method m = md.getMethod(); 249 if (md.getTxAttribute() == MethodDesc.TX_NOT_SET) { 250 if (javax.ejb.EJBHome .class.isAssignableFrom(m.getDeclaringClass()) 252 && (METHODS_HOME_NO_TX.indexOf("," + m.getName() + ",") != -1)) { 253 return; 254 } 255 if (javax.ejb.EJBObject .class.isAssignableFrom(m.getDeclaringClass()) 257 && (METHODS_REMOTE_NO_TX.indexOf("," + m.getName() + ",") != -1)) { 258 return; 259 } 260 if (md.isEjbSelect()) { 262 return; 263 } 264 logger.log(BasicLevel.WARN, 267 "trans-attribute missing for method " 268 + m.toString() + " in entity bean " 269 + getEjbName() 270 + " (set to the default value " 271 + MethodDesc.TX_STR_DEFAULT_VALUE 272 + ")"); 273 md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE); 274 } 275 } 276 277 280 public int getPassivationTimeout() { 281 return passivationTimeout; 282 } 283 284 287 public int getInactivityTimeout() { 288 return inactivityTimeout; 289 } 290 291 295 public Class getPrimaryKeyClass() { 296 return primaryKeyClass; 297 } 298 299 303 public boolean isReentrant() { 304 return reentrant; 305 } 306 307 310 public boolean isShared() { 311 return shared; 312 } 313 314 317 public boolean isPrefetch() { 318 return prefetch; 319 } 320 321 326 public boolean isAutomaticPk() { 327 return jdbcAutomaticPk; 328 } 329 330 335 public boolean isUndefinedPK() { 336 return pkObjectType; 337 } 338 339 343 public String toString() { 344 StringBuffer ret = new StringBuffer (); 345 ret.append(super.toString()); 346 ret.append("\ngetPrimaryKeyClass() =" + getPrimaryKeyClass().toString()); 347 ret.append("\nisReentrant() =" + isReentrant()); 348 ret.append("\ngetPassivationTimeout() =" + getPassivationTimeout()); 349 ret.append("\ngetInactivityTimeout() =" + getInactivityTimeout()); 350 ret.append("\nisShared() =" + isShared()); 351 ret.append("\ngetPoolMin() =" + getPoolMin()); 352 ret.append("\ngetCacheMax() =" + getCacheMax()); 353 return ret.toString(); 354 } 355 356 } 357 358 | Popular Tags |