00001
00027 package org.objectweb.jonas_ejb.deployment.api;
00028
00029 import java.util.Iterator;
00030
00031 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
00032 import org.objectweb.jonas_ejb.deployment.xml.Entity;
00033 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
00034 import org.objectweb.jonas_ejb.lib.BeanNaming;
00035 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00036 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
00037 import org.objectweb.util.monolog.api.BasicLevel;
00038
00039
00047 public abstract class EntityDesc extends BeanDesc {
00048
00049
00053 protected static final String METHODS_REMOTE_NO_TX = ",getEJBHome,getHandle,getPrimaryKey,isIdentical,";
00054
00058 protected static final String METHODS_HOME_NO_TX = ",getEJBMetaData,getHomeHandle,";
00059
00064 protected Class primaryKeyClass;
00065 protected boolean reentrant;
00066 protected int passivationTimeout = 0;
00067 protected int inactivityTimeout = 0;
00068 protected boolean shared = false;
00069 protected boolean prefetch = false;
00070
00071
00072 protected boolean jdbcAutomaticPk = false;
00073 protected boolean pkObjectType = false;
00074
00075
00076 public static final int CLEANUP_NONE = 0;
00077 public static final int CLEANUP_CREATE = 1;
00078 public static final int CLEANUP_REMOVEDATA = 2;
00079 public static final int CLEANUP_REMOVEALL = 3;
00080 protected int cleanup = CLEANUP_CREATE;
00081
00082
00083 public static final int LOCK_CONTAINER_READ_UNCOMMITTED = 0;
00084 public static final int LOCK_CONTAINER_SERIALIZED = 1;
00085 public static final int LOCK_CONTAINER_READ_COMMITTED = 2;
00086 public static final int LOCK_DATABASE = 3;
00087 public static final int LOCK_READ_ONLY = 4;
00088 protected int lockPolicy = LOCK_CONTAINER_SERIALIZED;
00089
00093 public EntityDesc(ClassLoader classLoader,
00094 Entity ent,
00095 AssemblyDescriptor asd,
00096 JonasEntity jEnt,
00097 JLinkedList jMDRList,
00098 String fileName)
00099 throws DeploymentDescException {
00100
00101 super(classLoader, ent, jEnt, asd, jMDRList, fileName);
00102
00103
00104 try {
00105
00106 if (ent.getPrimKeyClass().equalsIgnoreCase("Object") || ent.getPrimKeyClass().equalsIgnoreCase("java.lang.Object")) {
00107 primaryKeyClass = classLoader.loadClass("java.lang.Integer");
00108 pkObjectType = true;
00109 }
00110 else
00111 primaryKeyClass = classLoader.loadClass(ent.getPrimKeyClass());
00112 } catch (ClassNotFoundException e) {
00113 throw new DeploymentDescException("Primary Key class not found for bean " + this.ejbName, e);
00114 }
00115
00116
00117 if (jEnt.getPassivationTimeout() != null) {
00118 String tstr = jEnt.getPassivationTimeout();
00119 Integer tval = new Integer(tstr);
00120 passivationTimeout = tval.intValue();
00121 }
00122
00123
00124 if (jEnt.getInactivityTimeout() != null) {
00125 String tstr = jEnt.getInactivityTimeout();
00126 Integer tval = new Integer(tstr);
00127 inactivityTimeout = tval.intValue();
00128 }
00129
00130
00131 if (ent.getReentrant().equalsIgnoreCase("True")) {
00132 reentrant = true;
00133 } else if (ent.getReentrant().equalsIgnoreCase("False")) {
00134 reentrant = false;
00135 } else {
00136 throw new DeploymentDescException("Invalid reentrant value for bean " + this.ejbName);
00137 }
00138
00139
00140 if (jEnt.getPrefetch() != null) {
00141 if (jEnt.getPrefetch().equalsIgnoreCase("True")) {
00142 prefetch = true;
00143 } else if (jEnt.getPrefetch().equalsIgnoreCase("False")) {
00144 prefetch = false;
00145 } else {
00146 throw new DeploymentDescException("Invalid prefetch value for bean " + this.ejbName);
00147 }
00148 }
00149
00150
00151 if (jEnt.getMinPoolSize() != null) {
00152 String tstr = jEnt.getMinPoolSize();
00153 Integer tval = new Integer(tstr);
00154 poolMin = tval.intValue();
00155 }
00156
00157
00158 if (jEnt.getMaxCacheSize() != null) {
00159 String tstr = jEnt.getMaxCacheSize();
00160 Integer tval = new Integer(tstr);
00161 cacheMax = tval.intValue();
00162 }
00163
00164
00165
00166
00167
00168 if (jEnt.getLockPolicy() != null) {
00169 String tstr = jEnt.getLockPolicy();
00170 if (tstr.equals("container-serialized")) {
00171 lockPolicy = LOCK_CONTAINER_SERIALIZED;
00172 shared = false;
00173 } else if (tstr.equals("container-read-committed")) {
00174 lockPolicy = LOCK_CONTAINER_READ_COMMITTED;
00175 shared = true;
00176 } else if (tstr.equals("container-read-uncommitted")) {
00177 lockPolicy = LOCK_CONTAINER_READ_UNCOMMITTED;
00178 shared = true;
00179 } else if (tstr.equals("database")) {
00180 lockPolicy = LOCK_DATABASE;
00181 shared = true;
00182 } else if (tstr.equals("read-only")) {
00183 lockPolicy = LOCK_READ_ONLY;
00184 } else {
00185 throw new DeploymentDescException("Invalid lock-policy value for bean " + jEnt.getEjbName());
00186 }
00187 }
00188
00189
00190 if (jEnt.getShared() != null) {
00191 if (jEnt.getShared().equalsIgnoreCase("True")) {
00192 shared = true;
00193 } else if (jEnt.getShared().equalsIgnoreCase("False")) {
00194 shared = false;
00195 } else {
00196 throw new DeploymentDescException("Invalid shared value for bean " + this.ejbName);
00197 }
00198 }
00199
00200
00201
00202
00203
00204
00205 if (jEnt.getCleanup() != null) {
00206 String tstr = jEnt.getCleanup();
00207 if (tstr.equals("create")) {
00208 cleanup = CLEANUP_CREATE;
00209 } else if (tstr.equals("none")) {
00210 cleanup = CLEANUP_NONE;
00211 } else if (tstr.equals("removeall")) {
00212 cleanup = CLEANUP_REMOVEALL;
00213 } else if (tstr.equals("removedata")) {
00214 cleanup = CLEANUP_REMOVEDATA;
00215 } else {
00216 throw new DeploymentDescException("Invalid cleanup value for bean " + jEnt.getEjbName());
00217 }
00218 }
00219
00220
00221 for (Iterator i = getMethodDescIterator(); i.hasNext();) {
00222 MethodDesc methd = (MethodDesc) i.next();
00223 if (methd.getMethod().getName().equals("ejbTimeout")) {
00224 timerTxAttribute = methd.getTxAttribute();
00225 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod());
00226 }
00227 }
00228 }
00229
00233 public int getCleanupPolicy() {
00234 return cleanup;
00235 }
00236
00240 public int getLockPolicy() {
00241 return lockPolicy;
00242 }
00243
00247 protected void checkTxAttribute(MethodDesc md) throws DeploymentDescException {
00248 java.lang.reflect.Method m = md.getMethod();
00249 if (md.getTxAttribute() == MethodDesc.TX_NOT_SET) {
00250
00251 if (javax.ejb.EJBHome.class.isAssignableFrom(m.getDeclaringClass())
00252 && (METHODS_HOME_NO_TX.indexOf("," + m.getName() + ",") != -1)) {
00253 return;
00254 }
00255
00256 if (javax.ejb.EJBObject.class.isAssignableFrom(m.getDeclaringClass())
00257 && (METHODS_REMOTE_NO_TX.indexOf("," + m.getName() + ",") != -1)) {
00258 return;
00259 }
00260
00261 if (md.isEjbSelect()) {
00262 return;
00263 }
00264
00265
00266 logger.log(BasicLevel.WARN,
00267 "trans-attribute missing for method "
00268 + m.toString() + " in entity bean "
00269 + getEjbName()
00270 + " (set to the default value "
00271 + MethodDesc.TX_STR_DEFAULT_VALUE
00272 + ")");
00273 md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE);
00274 }
00275 }
00276
00280 public int getPassivationTimeout() {
00281 return passivationTimeout;
00282 }
00283
00287 public int getInactivityTimeout() {
00288 return inactivityTimeout;
00289 }
00290
00295 public Class getPrimaryKeyClass() {
00296 return primaryKeyClass;
00297 }
00298
00303 public boolean isReentrant() {
00304 return reentrant;
00305 }
00306
00310 public boolean isShared() {
00311 return shared;
00312 }
00313
00317 public boolean isPrefetch() {
00318 return prefetch;
00319 }
00320
00326 public boolean isAutomaticPk() {
00327 return jdbcAutomaticPk;
00328 }
00329
00335 public boolean isUndefinedPK() {
00336 return pkObjectType;
00337 }
00338
00343 public String toString() {
00344 StringBuffer ret = new StringBuffer();
00345 ret.append(super.toString());
00346 ret.append("\ngetPrimaryKeyClass() =" + getPrimaryKeyClass().toString());
00347 ret.append("\nisReentrant() =" + isReentrant());
00348 ret.append("\ngetPassivationTimeout() =" + getPassivationTimeout());
00349 ret.append("\ngetInactivityTimeout() =" + getInactivityTimeout());
00350 ret.append("\nisShared() =" + isShared());
00351 ret.append("\ngetPoolMin() =" + getPoolMin());
00352 ret.append("\ngetCacheMax() =" + getCacheMax());
00353 return ret.toString();
00354 }
00355
00356 }
00357