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 42 public class JEntitySwitchCRU extends JEntitySwitch { 43 44 47 protected JEntityContext itContext = null; 48 49 53 public JEntitySwitchCRU() { 54 lockpolicy = EntityDesc.LOCK_CONTAINER_READ_UNCOMMITTED; 55 txUpdates = true; 56 } 57 58 protected void initpolicy(JEntityFactory bf) { 59 lazyregister = true; 60 } 61 62 protected JEntityContext getContext4Tx(Transaction tx) { 63 return itContext; 64 } 65 66 protected void setContext4Tx(Transaction tx, JEntityContext ctx) { 67 itContext = ctx; 68 } 69 70 protected void removeContext4Tx(Transaction tx) { 71 itContext = null; 72 } 73 74 public void waitmyturn(Transaction tx) { 75 } 77 78 87 public synchronized JEntityContext mapICtx(Transaction tx, JEntityContext bctx, boolean forced, boolean holdit, boolean notused) { 88 89 waitmyturn(tx); 90 91 boolean newtrans = false; 93 JEntityContext jec = itContext; 94 if (forced) { 95 if (jec != null) { 97 if (TraceEjb.isDebugContext()) { 98 TraceEjb.context.log(BasicLevel.DEBUG, ident + "new context is enforced!"); 99 } 100 discardContext(tx, false, true); 101 } 102 jec = bctx; 103 itContext = jec; 104 jec.initEntityContext(this); 105 newtrans = true; 106 } else { 107 if (jec != null) { 108 if (bctx != null) { 111 if (TraceEjb.isDebugContext()) { 112 TraceEjb.context.log(BasicLevel.DEBUG, ident + "a context was supplied!"); 113 } 114 bf.releaseJContext(bctx); 115 } 116 newtrans = true; jec.reuseEntityContext(newtrans); 119 } else { 120 if (bctx != null) { 121 jec = bctx; 122 } else { 123 jec = (JEntityContext) bf.getJContext(this); 125 } 126 jec.initEntityContext(this); 127 jec.activate(true); 128 itContext = jec; newtrans = true; 130 } 131 } 132 133 if (tx == null) { 134 if (holdit) { 135 countIH++; 136 if (TraceEjb.isDebugSynchro()) { 137 TraceEjb.synchro.log(BasicLevel.DEBUG, ident + "mapICtx IH count=" + countIH); 138 } 139 if (shared && countIH == 1) { 140 jec.activate(false); 143 } 144 } 145 } else { 146 if (holdit) { 147 countIT++; 148 } 149 } 150 151 return jec; 152 } 153 154 157 public boolean passivateIH(boolean passivation) { 158 JEntityContext jec = getContext4Tx(null); 159 if (jec == null) { 161 if (inactivityTimeout > 0 && 162 System.currentTimeMillis() - timestamp > inactivityTimeout) { 163 if (TraceEjb.isDebugContext()) { 164 TraceEjb.context.log(BasicLevel.DEBUG, "discard object on timeout"); 165 } 166 discardContext(null, true, false); 167 } 168 return true; 169 } 170 if (passivation) { 172 if (TraceEjb.isDebugContext()) { 173 TraceEjb.context.log(BasicLevel.DEBUG, "TODO: passivate: " + jec); 174 } 175 } 176 return true; 177 } 178 179 public void endIH() { 180 return; } 182 183 187 public synchronized void notifyWriting(Transaction tx, JEntityContext bctx) { 188 if (TraceEjb.isDebugSynchro()) { 189 TraceEjb.synchro.log(BasicLevel.DEBUG, ident); 190 } 191 if (writingtx != null) { 192 if (!tx.equals(writingtx)) { 193 TraceEjb.logger.log(BasicLevel.WARN, ""); 194 try { 195 tx.setRollbackOnly(); 196 } catch (SystemException e) { 197 TraceEjb.logger.log(BasicLevel.ERROR, "cannot set current transaction RollbackOnly"); 198 } 199 try { 202 writingtx.setRollbackOnly(); 203 } catch (SystemException e) { 204 TraceEjb.logger.log(BasicLevel.ERROR, "cannot set other transaction RollbackOnly"); 205 } 206 throw new EJBException ("Conflict writing entity bean"); 209 } 210 } else { 211 registerCtx(tx, bctx); 213 writingtx = tx; 214 } 215 } 216 217 222 public int getState() { 223 if (itContext != null) { 224 if (itContext.isMarkedRemoved()) { 225 return 4; 226 } else { 227 if (writingtx != null) { 228 return 0; 229 } else { 230 return 1; 231 } 232 } 233 } 234 return 3; 235 } 236 237 } 238 | Popular Tags |