1 16 17 package org.springframework.jdbc.support.lob; 18 19 import javax.transaction.Status ; 20 import javax.transaction.TransactionManager ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.springframework.transaction.TransactionSystemException; 26 import org.springframework.transaction.support.TransactionSynchronizationManager; 27 28 40 public abstract class LobCreatorUtils { 41 42 private static final Log logger = LogFactory.getLog(LobCreatorUtils.class); 43 44 45 55 public static void registerTransactionSynchronization( 56 LobCreator lobCreator, TransactionManager jtaTransactionManager) throws IllegalStateException { 57 58 if (TransactionSynchronizationManager.isSynchronizationActive()) { 59 logger.debug("Registering Spring transaction synchronization for LobCreator"); 60 TransactionSynchronizationManager.registerSynchronization( 61 new SpringLobCreatorSynchronization(lobCreator)); 62 } 63 else { 64 if (jtaTransactionManager != null) { 65 try { 66 int jtaStatus = jtaTransactionManager.getStatus(); 67 if (jtaStatus == Status.STATUS_ACTIVE || jtaStatus == Status.STATUS_MARKED_ROLLBACK) { 68 logger.debug("Registering JTA transaction synchronization for LobCreator"); 69 jtaTransactionManager.getTransaction().registerSynchronization( 70 new JtaLobCreatorSynchronization(lobCreator)); 71 return; 72 } 73 } 74 catch (Throwable ex) { 75 throw new TransactionSystemException( 76 "Could not register synchronization with JTA TransactionManager", ex); 77 } 78 } 79 throw new IllegalStateException ("Active Spring transaction synchronization or active " + 80 "JTA transaction with specified [javax.transaction.TransactionManager] required"); 81 } 82 } 83 84 } 85 | Popular Tags |