1 25 26 package org.objectweb.jonas_ejb.container; 27 28 import javax.ejb.EJBException ; 29 import javax.transaction.SystemException ; 30 import javax.transaction.Transaction ; 31 32 import org.objectweb.jonas_ejb.deployment.api.EntityDesc; 33 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 41 public class JEntitySwitchRO extends JEntitySwitch { 42 43 46 protected JEntityContext itContext = null; 47 48 52 public JEntitySwitchRO() { 53 lockpolicy = EntityDesc.LOCK_READ_ONLY; 54 txUpdates = true; } 56 57 protected void initpolicy(JEntityFactory bf) { 58 lazyregister = true; } 60 61 protected JEntityContext getContext4Tx(Transaction tx) { 62 return itContext; 63 } 64 65 protected void setContext4Tx(Transaction tx, JEntityContext ctx) { 66 itContext = ctx; 67 } 68 69 protected void removeContext4Tx(Transaction tx) { 70 itContext = null; 71 } 72 73 public void waitmyturn(Transaction tx) { 74 } 76 77 86 public synchronized JEntityContext mapICtx(Transaction tx, JEntityContext bctx, boolean forced, boolean holdit, boolean notused) { 87 88 waitmyturn(tx); 89 90 boolean newtrans = false; 92 JEntityContext jec = itContext; 93 if (forced) { 94 TraceEjb.context.log(BasicLevel.ERROR, ident + "create cannot be called on read only bean"); 95 throw new EJBException ("Read Only bean"); 96 } else { 97 if (jec != null) { 98 if (bctx != null) { 101 if (TraceEjb.isDebugContext()) 102 TraceEjb.context.log(BasicLevel.DEBUG, ident + "a context was supplied!"); 103 bf.releaseJContext(bctx); 104 } 105 newtrans = true; 106 jec.reuseEntityContext(newtrans); 107 } else { 108 if (bctx != null) { 109 jec = bctx; 110 } else { 111 jec = (JEntityContext) bf.getJContext(this); 113 } 114 jec.initEntityContext(this); 115 jec.activate(true); 116 itContext = jec; newtrans = true; 118 } 119 } 120 121 if (tx == null) { 122 if (holdit) { 123 countIH++; 124 if (TraceEjb.isDebugSynchro()) 125 TraceEjb.synchro.log(BasicLevel.DEBUG, ident + "mapICtx IH count=" + countIH); 126 if (shared && countIH == 1) { 127 jec.activate(false); 130 } 131 } 132 } else { 133 if (holdit) { 134 countIT++; 135 } 136 } 137 138 return jec; 139 } 140 141 144 public boolean passivateIH(boolean passivation) { 145 JEntityContext jec = getContext4Tx(null); 146 if (jec == null) { 148 if (inactivityTimeout > 0 && 149 System.currentTimeMillis() - timestamp > inactivityTimeout) { 150 if (TraceEjb.isDebugContext()) { 151 TraceEjb.context.log(BasicLevel.DEBUG, "discard object on timeout"); 152 } 153 discardContext(null, true, false); 154 } 155 return true; 156 } 157 if (passivation) { 159 if (TraceEjb.isDebugContext()) TraceEjb.context.log(BasicLevel.DEBUG, "TODO: passivate: " + jec); 160 } 161 return true; 162 } 163 164 public void endIH() { 165 return; } 167 168 172 public synchronized void notifyWriting(Transaction tx, JEntityContext bctx) { 173 TraceEjb.context.log(BasicLevel.ERROR, ident + "read only bean: cannot write"); 174 throw new EJBException ("Read Only bean"); 175 } 176 177 182 public int getState() { 183 if (itContext != null) { 184 if (itContext.isMarkedRemoved()) { 185 return 4; 186 } else { 187 if (writingtx != null) { 188 return 0; 189 } else { 190 return 1; 191 } 192 } 193 } 194 return 3; 195 } 196 197 } 198 | Popular Tags |