@Override public TransactionListener setListener(TransactionListener newListener) { TransactionListener result = getListener(); this.txListeners.clear(); if (newListener != null) { this.txListeners.add(newListener); } return result; }
/** * Create a <code>transaction-writer</code> using the declarable interface and set the transaction * manager with the newly instantiated writer. */ private void endTransactionWriter() { Declarable d = createDeclarable(); if (!(d instanceof TransactionWriter)) { throw new CacheXmlException( String.format("A %s is not an instance of a TransactionWriter.", d.getClass().getName())); } CacheTransactionManagerCreation txMgrCreation = (CacheTransactionManagerCreation) stack.peek(); txMgrCreation.setWriter((TransactionWriter) d); }
/** * When a <code>cache-transaction-manager</code> element is found, create a container for the * potential <code>transaction-listener</code> and push it on the stack */ private void startCacheTransactionManager() { stack.push(new CacheTransactionManagerCreation()); }
@Test public void shouldBeMockable() throws Exception { CacheTransactionManagerCreation mockCacheTransactionManagerCreation = mock(CacheTransactionManagerCreation.class); TransactionListener mockTransactionListener = mock(TransactionListener.class); TransactionWriter mockTransactionWriter = mock(TransactionWriter.class); when(mockCacheTransactionManagerCreation.getListener()).thenReturn(mockTransactionListener); mockCacheTransactionManagerCreation.setWriter(mockTransactionWriter); verify(mockCacheTransactionManagerCreation, times(1)).setWriter(mockTransactionWriter); assertThat(mockCacheTransactionManagerCreation.getListener()).isSameAs(mockTransactionListener); } }
if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) { cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners()); && this.txMgrCreation.getWriter() != null) { throw new IllegalStateException( "A TransactionWriter cannot be registered on a client");
/** * Create a <code>transaction-listener</code> using the declarable interface and set the * transaction manager with the newly instantiated listener. */ private void endTransactionListener() { Declarable d = createDeclarable(); if (!(d instanceof TransactionListener)) { throw new CacheXmlException( String.format("A %s is not an instance of a CacheListener.", d.getClass().getName())); } CacheTransactionManagerCreation txMgrCreation = (CacheTransactionManagerCreation) stack.peek(); txMgrCreation.addListener((TransactionListener) d); }
if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) { cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners()); cache.getCacheTransactionManager().setWriter(this.txMgrCreation.getWriter());