JEntitySwitchRO.java

00001 
00026 package org.objectweb.jonas_ejb.container;
00027 
00028 import javax.ejb.EJBException;
00029 import javax.transaction.SystemException;
00030 import javax.transaction.Transaction;
00031 
00032 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
00033 
00034 import org.objectweb.util.monolog.api.BasicLevel;
00035 
00041 public class JEntitySwitchRO extends JEntitySwitch {
00042 
00046     protected JEntityContext itContext = null;
00047 
00052     public JEntitySwitchRO() {
00053         lockpolicy = EntityDesc.LOCK_READ_ONLY;
00054         txUpdates = true;       // never write anyway.
00055     }
00056 
00057     protected void initpolicy(JEntityFactory bf) {
00058         lazyregister = true;    // never write anyway.
00059     }
00060 
00061     protected JEntityContext getContext4Tx(Transaction tx) {
00062         return itContext;
00063     }
00064 
00065     protected void setContext4Tx(Transaction tx, JEntityContext ctx) {
00066         itContext = ctx;
00067     }
00068 
00069     protected void removeContext4Tx(Transaction tx) {
00070         itContext = null;
00071     }
00072 
00073     public void waitmyturn(Transaction tx) {
00074         // No synchro for this policy.
00075     }
00076 
00086     public synchronized JEntityContext mapICtx(Transaction tx, JEntityContext bctx, boolean forced, boolean holdit, boolean notused) {
00087 
00088         waitmyturn(tx);
00089 
00090         // Choose the context to use.
00091         boolean newtrans = false;
00092         JEntityContext jec = itContext;
00093         if (forced) {
00094             TraceEjb.context.log(BasicLevel.ERROR, ident + "create cannot be called on read only bean");
00095             throw new EJBException("Read Only bean");
00096         } else {
00097             if (jec != null) {
00098                 // Reuse the Context for this transaction.
00099                 // If a context was supplied, release it first.
00100                 if (bctx != null) {
00101                     if (TraceEjb.isDebugContext())
00102                             TraceEjb.context.log(BasicLevel.DEBUG, ident + "a context was supplied!");
00103                     bf.releaseJContext(bctx);
00104                 }
00105                 newtrans = true;
00106                 jec.reuseEntityContext(newtrans);
00107             } else {
00108                 if (bctx != null) {
00109                     jec = bctx;
00110                 } else {
00111                     // no Context available : get one from the pool.
00112                     jec = (JEntityContext) bf.getJContext(this);
00113                 }
00114                 jec.initEntityContext(this);
00115                 jec.activate(true);
00116                 itContext = jec; // after activate
00117                 newtrans = true;
00118             }
00119         }
00120 
00121         if (tx == null) {
00122             if (holdit) {
00123                 countIH++;
00124                 if (TraceEjb.isDebugSynchro())
00125                         TraceEjb.synchro.log(BasicLevel.DEBUG, ident + "mapICtx IH count=" + countIH);
00126                 if (shared && countIH == 1) {
00127                     // reload state that could have been modified by
00128                     // transactions.
00129                     jec.activate(false);
00130                 }
00131             }
00132         } else {
00133             if (holdit) {
00134                 countIT++;
00135             }
00136         }
00137 
00138         return jec;
00139     }
00140 
00144     public boolean passivateIH(boolean passivation) {
00145         JEntityContext jec = getContext4Tx(null);
00146         // If already passivated, look if we can destroy the objects
00147         if (jec == null) {
00148             if (inactivityTimeout > 0 &&
00149                 System.currentTimeMillis() - timestamp > inactivityTimeout) {
00150                 TraceEjb.context.log(BasicLevel.DEBUG, "discard object on timeout");
00151                 discardContext(null, true, false);
00152             }
00153             return true;
00154         }
00155         // passivate this instance if required.
00156         if (passivation) {
00157             if (TraceEjb.isDebugContext()) TraceEjb.context.log(BasicLevel.DEBUG, "TODO: passivate: " + jec);
00158         }
00159         return true;
00160     }
00161 
00162     public void endIH() {
00163         return; // NEVER
00164     }
00165 
00170     public synchronized void notifyWriting(Transaction tx, JEntityContext bctx) {
00171         TraceEjb.context.log(BasicLevel.ERROR, ident + "read only bean: cannot write");
00172         throw new EJBException("Read Only bean");
00173     }
00174 
00180     public int getState() {
00181         if (itContext != null) {
00182             if (itContext.isMarkedRemoved()) {
00183                 return 4;
00184             } else {
00185                 if (writingtx != null) {
00186                     return 0;
00187                 } else {
00188                     return 1;
00189                 }
00190             }
00191         }
00192         return 3;
00193     }
00194 
00195 }

Generated on Tue Feb 15 15:05:38 2005 for JOnAS by  doxygen 1.3.9.1