@Override @Nullable protected TransactionAttributeSource getTransactionAttributeSource() { return (transactionInterceptor != null ? transactionInterceptor.getTransactionAttributeSource() : null); } };
@Override @Nullable protected TransactionAttributeSource getTransactionAttributeSource() { return (transactionInterceptor != null ? transactionInterceptor.getTransactionAttributeSource() : null); } };
private void writeObject(ObjectOutputStream oos) throws IOException { // Rely on default serialization, although this class itself doesn't carry state anyway... oos.defaultWriteObject(); // Deserialize superclass fields. oos.writeObject(getTransactionManagerBeanName()); oos.writeObject(getTransactionManager()); oos.writeObject(getTransactionAttributeSource()); oos.writeObject(getBeanFactory()); }
private void writeObject(ObjectOutputStream oos) throws IOException { // Rely on default serialization, although this class itself doesn't carry state anyway... oos.defaultWriteObject(); // Deserialize superclass fields. oos.writeObject(getTransactionManagerBeanName()); oos.writeObject(getTransactionManager()); oos.writeObject(getTransactionAttributeSource()); oos.writeObject(getBeanFactory()); }
@Test public void rollbackRules() { TransactionInterceptor txInterceptor = (TransactionInterceptor) context.getBean("txRollbackAdvice"); TransactionAttributeSource txAttrSource = txInterceptor.getTransactionAttributeSource(); TransactionAttribute txAttr = txAttrSource.getTransactionAttribute(getAgeMethod,ITestBean.class); assertTrue("should be configured to rollback on Exception",txAttr.rollbackOn(new Exception())); txAttr = txAttrSource.getTransactionAttribute(setAgeMethod, ITestBean.class); assertFalse("should not rollback on RuntimeException",txAttr.rollbackOn(new RuntimeException())); }
@Test public void serializableWithCompositeSource() throws Exception { NameMatchTransactionAttributeSource tas1 = new NameMatchTransactionAttributeSource(); Properties props = new Properties(); props.setProperty("methodName", "PROPAGATION_REQUIRED"); tas1.setProperties(props); NameMatchTransactionAttributeSource tas2 = new NameMatchTransactionAttributeSource(); props = new Properties(); props.setProperty("otherMethodName", "PROPAGATION_REQUIRES_NEW"); tas2.setProperties(props); TransactionInterceptor ti = new TransactionInterceptor(); ti.setTransactionAttributeSources(tas1, tas2); PlatformTransactionManager ptm = new SerializableTransactionManager(); ti.setTransactionManager(ptm); ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); assertTrue(ti.getTransactionManager() instanceof SerializableTransactionManager); assertTrue(ti.getTransactionAttributeSource() instanceof CompositeTransactionAttributeSource); CompositeTransactionAttributeSource ctas = (CompositeTransactionAttributeSource) ti.getTransactionAttributeSource(); assertTrue(ctas.getTransactionAttributeSources()[0] instanceof NameMatchTransactionAttributeSource); assertTrue(ctas.getTransactionAttributeSources()[1] instanceof NameMatchTransactionAttributeSource); }
/** * A TransactionInterceptor should be serializable if its * PlatformTransactionManager is. */ @Test public void serializableWithAttributeProperties() throws Exception { TransactionInterceptor ti = new TransactionInterceptor(); Properties props = new Properties(); props.setProperty("methodName", "PROPAGATION_REQUIRED"); ti.setTransactionAttributes(props); PlatformTransactionManager ptm = new SerializableTransactionManager(); ti.setTransactionManager(ptm); ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); // Check that logger survived deserialization assertNotNull(ti.logger); assertTrue(ti.getTransactionManager() instanceof SerializableTransactionManager); assertNotNull(ti.getTransactionAttributeSource()); }
/** * Template method to create an advised object given the * target object and transaction setup. * Creates a TransactionInterceptor and applies it. */ @Override protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource tas) { TransactionInterceptor ti = new TransactionInterceptor(); ti.setTransactionManager(ptm); assertEquals(ptm, ti.getTransactionManager()); ti.setTransactionAttributeSource(tas); assertEquals(tas, ti.getTransactionAttributeSource()); ProxyFactory pf = new ProxyFactory(target); pf.addAdvice(0, ti); return pf.getProxy(); }
@Test //INT-2649 public void adviceChainSubElement() { Object endpoint = context.getBean("delayerWithAdviceChain"); DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class); List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class); assertEquals(2, adviceChain.size()); assertSame(context.getBean("testAdviceBean"), adviceChain.get(0)); Object txAdvice = adviceChain.get(1); assertEquals(TransactionInterceptor.class, txAdvice.getClass()); TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource(); assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass()); HashMap<?, ?> nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class); assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString()); }
@Test public void pollerWithAdviceChain() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "pollerWithAdviceChain.xml", PollerParserTests.class); Object poller = context.getBean("poller"); assertNotNull(poller); PollerMetadata metadata = (PollerMetadata) poller; assertNotNull(metadata.getAdviceChain()); assertEquals(4, metadata.getAdviceChain().size()); assertSame(context.getBean("adviceBean1"), metadata.getAdviceChain().get(0)); assertEquals(TestAdviceBean.class, metadata.getAdviceChain().get(1).getClass()); assertEquals(2, ((TestAdviceBean) metadata.getAdviceChain().get(1)).getId()); assertSame(context.getBean("adviceBean3"), metadata.getAdviceChain().get(2)); Advice txAdvice = metadata.getAdviceChain().get(3); assertEquals(TransactionInterceptor.class, txAdvice.getClass()); TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource(); assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass()); @SuppressWarnings("rawtypes") HashMap nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class); assertEquals(1, nameMap.size()); assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString()); context.close(); }
private void verify(TransactionInterceptor interceptor, PlatformTransactionManager txm) throws Exception { assertSame(txm, interceptor.getTransactionManager()); TransactionAttribute atts = interceptor.getTransactionAttributeSource() .getTransactionAttribute(TransactionInterceptorBuilderTests.class.getDeclaredMethod("test"), null); Assert.assertThat(atts.getPropagationBehavior(), equalTo(Propagation.REQUIRES_NEW.value())); Assert.assertThat(atts.getIsolationLevel(), equalTo(Isolation.SERIALIZABLE.value())); Assert.assertThat(atts.getTimeout(), equalTo(42)); assertTrue(atts.isReadOnly()); }
@Override @Nullable protected TransactionAttributeSource getTransactionAttributeSource() { return (transactionInterceptor != null ? transactionInterceptor.getTransactionAttributeSource() : null); } };
@Override @Nullable protected TransactionAttributeSource getTransactionAttributeSource() { return (transactionInterceptor != null ? transactionInterceptor.getTransactionAttributeSource() : null); } };
@Test //INT-2649 public void transactionalSubElement() throws Exception { Object endpoint = context.getBean("delayerWithTransactional"); DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class); List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class); assertEquals(1, adviceChain.size()); Object advice = adviceChain.get(0); assertTrue(advice instanceof TransactionInterceptor); TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) advice).getTransactionAttributeSource(); assertTrue(transactionAttributeSource instanceof MatchAlwaysTransactionAttributeSource); Method method = MessageHandler.class.getMethod("handleMessage", Message.class); TransactionDefinition definition = transactionAttributeSource.getTransactionAttribute(method, null); assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior()); assertEquals(TransactionDefinition.ISOLATION_DEFAULT, definition.getIsolationLevel()); assertEquals(TransactionDefinition.TIMEOUT_DEFAULT, definition.getTimeout()); assertFalse(definition.isReadOnly()); }
/** * Set the transaction interceptor to use for this advisor. */ public void setTransactionInterceptor(TransactionInterceptor interceptor) { setAdvice(interceptor); if (interceptor.getTransactionAttributeSource() == null) { throw new AopConfigException( "Cannot construct a TransactionAttributeSourceAdvisor using a " + "TransactionInterceptor that has no TransactionAttributeSource configured"); } this.transactionAttributeSource = interceptor.getTransactionAttributeSource(); }
private void writeObject(ObjectOutputStream oos) throws IOException { // Rely on default serialization, although this class itself doesn't carry state anyway... oos.defaultWriteObject(); // Deserialize superclass fields. oos.writeObject(getTransactionManagerBeanName()); oos.writeObject(getTransactionManager()); oos.writeObject(getTransactionAttributeSource()); oos.writeObject(getBeanFactory()); }
private void writeObject(ObjectOutputStream oos) throws IOException { // Rely on default serialization, although this class itself doesn't carry state anyway... oos.defaultWriteObject(); // Deserialize superclass fields. oos.writeObject(getTransactionManagerBeanName()); oos.writeObject(getTransactionManager()); oos.writeObject(getTransactionAttributeSource()); oos.writeObject(getBeanFactory()); }
@Override public TransactionAttributeSource getTransactionAttributeSource() { final TransactionAttributeSource origTxAttrSource = super.getTransactionAttributeSource(); return (final Method method, final Class<?> targetClass) -> { TransactionAttribute txAttr = origTxAttrSource.getTransactionAttribute(method, targetClass); if (txAttr instanceof DefaultTransactionAttribute) { ((DefaultTransactionAttribute) txAttr).setQualifier(AuthContextUtils.getDomain()); } return txAttr; }; }
private void verify(TransactionInterceptor interceptor, PlatformTransactionManager txm) { assertSame(txm, interceptor.getTransactionManager()); TransactionAttribute atts = interceptor.getTransactionAttributeSource() .getTransactionAttribute(null, null); assertThat(atts.getPropagationBehavior(), equalTo(Propagation.REQUIRES_NEW.value())); assertThat(atts.getIsolationLevel(), equalTo(Isolation.SERIALIZABLE.value())); assertThat(atts.getTimeout(), equalTo(42)); assertTrue(atts.isReadOnly()); }