1 22 package org.jboss.ejb.plugins; 23 24 25 import javax.transaction.Status ; 26 import javax.transaction.Synchronization ; 27 import javax.transaction.Transaction ; 28 29 import org.jboss.ejb.EntityEnterpriseContext; 30 import org.jboss.metadata.ConfigurationMetaData; 31 32 60 public class EntityMultiInstanceSynchronizationInterceptor 61 extends EntitySynchronizationInterceptor 62 { 63 public void create() 64 throws Exception 65 { 66 super.create(); 67 } 68 69 public void start() 70 { 71 if (!container.getLockManager().lockClass.equals(org.jboss.ejb.plugins.lock.NoLock.class) 74 && !container.getLockManager().lockClass.equals(org.jboss.ejb.plugins.lock.JDBCOptimisticLock.class) 75 && !container.getLockManager().lockClass.equals(org.jboss.ejb.plugins.lock.MethodOnlyEJBLock.class) 76 ) 77 { 78 throw new IllegalStateException ("the <locking-policy> must be org.jboss.ejb.plugins.lock.NoLock, JDBCOptimisticLock, or MethodOnlyEJBLock for Instance Per Transaction:" 79 + container.getLockManager().lockClass.getName()); 80 } 81 } 82 83 protected Synchronization createSynchronization(Transaction tx, EntityEnterpriseContext ctx) 84 { 85 return new MultiInstanceSynchronization(tx, ctx); 86 } 87 89 91 protected class MultiInstanceSynchronization implements Synchronization 92 { 93 96 protected Transaction tx; 97 98 101 protected EntityEnterpriseContext ctx; 102 103 106 MultiInstanceSynchronization(Transaction tx, EntityEnterpriseContext ctx) 107 { 108 this.tx = tx; 109 this.ctx = ctx; 110 } 111 112 114 public void beforeCompletion() 115 { 116 } 118 119 public void afterCompletion(int status) 120 { 121 boolean trace = log.isTraceEnabled(); 122 123 ClassLoader oldCl = SecurityActions.getContextClassLoader(); 126 SecurityActions.setContextClassLoader(container.getClassLoader()); 127 128 ctx.hasTxSynchronization(false); 129 ctx.setTransaction(null); 130 try 131 { 132 try 133 { 134 if (status != Status.STATUS_ROLLEDBACK) 136 { 137 switch (commitOption) 138 { 139 case ConfigurationMetaData.A_COMMIT_OPTION: 141 throw new IllegalStateException ("Commit option A not allowed with this Interceptor"); 142 case ConfigurationMetaData.B_COMMIT_OPTION: 144 break; 145 case ConfigurationMetaData.C_COMMIT_OPTION: 147 break; 148 case ConfigurationMetaData.D_COMMIT_OPTION: 149 throw new IllegalStateException ("Commit option D not allowed with this Interceptor"); 150 } 151 } 152 try 153 { 154 if (ctx.getId() != null) 155 container.getPersistenceManager().passivateEntity(ctx); 156 } 157 catch (Exception ignored) 158 { 159 } 160 container.getInstancePool().free(ctx); 161 } 162 finally 163 { 164 if (trace) 165 log.trace("afterCompletion, clear tx for ctx=" + ctx + ", tx=" + tx); 166 167 } 168 } finally 170 { 171 SecurityActions.setContextClassLoader(oldCl); 172 } 173 } 174 175 } 176 177 } 178 | Popular Tags |