/** * Eagerly initializes the specified * {@link #setMethodMap(java.util.Map) "methodMap"}, if any. * @see #initMethodMap(java.util.Map) */ @Override public void afterPropertiesSet() { initMethodMap(this.methodMap); this.eagerlyInitialized = true; this.initialized = true; }
/** * Create a new TransactionInterceptor. * @param ptm the default transaction manager to perform the actual transaction management * @param tas the attribute source to be used to find transaction attributes * @see #setTransactionManager * @see #setTransactionAttributeSource(TransactionAttributeSource) */ public TransactionInterceptor(PlatformTransactionManager ptm, TransactionAttributeSource tas) { setTransactionManager(ptm); setTransactionAttributeSource(tas); }
/** * Create a new TransactionInterceptor. * @param ptm the default transaction manager to perform the actual transaction management * @param attributes the transaction attributes in properties format * @see #setTransactionManager * @see #setTransactionAttributes(java.util.Properties) */ public TransactionInterceptor(PlatformTransactionManager ptm, Properties attributes) { setTransactionManager(ptm); setTransactionAttributes(attributes); }
/** * See <a href="http://forum.springframework.org/showthread.php?t=41350">this forum post</a>. */ @Test public void testConflictingRulesToDetermineExactContract() { List<RollbackRuleAttribute> list = new LinkedList<>(); list.add(new NoRollbackRuleAttribute(MyBusinessWarningException.class)); list.add(new RollbackRuleAttribute(MyBusinessException.class)); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, list); assertTrue(rta.rollbackOn(new MyBusinessException())); assertFalse(rta.rollbackOn(new MyBusinessWarningException())); }
private void checkTransactionProperties(TransactionAttributeSource tas, Method method, int propagationBehavior) { TransactionAttribute ta = tas.getTransactionAttribute(method, null); if (propagationBehavior >= 0) { assertNotNull(ta); assertEquals(TransactionDefinition.ISOLATION_DEFAULT, ta.getIsolationLevel()); assertEquals(propagationBehavior, ta.getPropagationBehavior()); } else { assertNull(ta); } }
@Test public void testRuleForSelectiveRollbackOnCheckedWithClass() { List<RollbackRuleAttribute> l = Collections.singletonList(new RollbackRuleAttribute(RemoteException.class)); RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED, l); doTestRuleForSelectiveRollbackOnChecked(rta); }
@Override public boolean matches(Method method, Class<?> targetClass) { if (TransactionalProxy.class.isAssignableFrom(targetClass) || PlatformTransactionManager.class.isAssignableFrom(targetClass) || PersistenceExceptionTranslator.class.isAssignableFrom(targetClass)) { return false; } TransactionAttributeSource tas = getTransactionAttributeSource(); return (tas == null || tas.getTransactionAttribute(method, targetClass) != null); }
/** * Set the default transaction manager. This will perform actual * transaction management: This class is just a way of invoking it. * @see TransactionInterceptor#setTransactionManager */ public void setTransactionManager(PlatformTransactionManager transactionManager) { this.transactionInterceptor.setTransactionManager(transactionManager); }
@Override public void exceptional(Throwable t) throws Throwable { TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo(); assertTrue(ti.hasTransaction()); assertEquals(outerTxatt, ti.getTransactionAttribute()); assertEquals(spouseName, getSpouse().getName()); } };
@Override public String getName() { // Assert that we're in the inner proxy TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo(); // Has nested transaction assertTrue(ti.hasTransaction()); assertEquals(innerTxatt, ti.getTransactionAttribute()); return spouseName; } };
@Override public void exceptional(Throwable t) throws Throwable { TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo(); assertTrue(ti.hasTransaction()); assertEquals(spouseName, getSpouse().getName()); } };
@Override public String getName() { // Assert that we're in the inner proxy TransactionInfo ti = TransactionAspectSupport.currentTransactionInfo(); assertFalse(ti.hasTransaction()); return spouseName; } };
/** * This callback is optional: If running in a BeanFactory and no transaction * manager has been set explicitly, a single matching bean of type * {@link PlatformTransactionManager} will be fetched from the BeanFactory. * @see org.springframework.beans.factory.BeanFactory#getBean(Class) * @see org.springframework.transaction.PlatformTransactionManager */ @Override public void setBeanFactory(BeanFactory beanFactory) { this.transactionInterceptor.setBeanFactory(beanFactory); }
@Override public String toString() { StringBuilder result = getAttributeDescription(); if (this.rollbackRules != null) { for (RollbackRuleAttribute rule : this.rollbackRules) { String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE); result.append(',').append(sign).append(rule.getExceptionName()); } } return result.toString(); }
protected Object advised( Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception { return advised(target, ptm, new CompositeTransactionAttributeSource(tas)); }
/** * Set multiple transaction attribute sources which are used to find transaction * attributes. Will build a CompositeTransactionAttributeSource for the given sources. * @see CompositeTransactionAttributeSource * @see MethodMapTransactionAttributeSource * @see NameMatchTransactionAttributeSource * @see org.springframework.transaction.annotation.AnnotationTransactionAttributeSource */ public void setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources) { this.transactionAttributeSource = new CompositeTransactionAttributeSource(transactionAttributeSources); }
/** * Create a new TransactionAttributeSourceAdvisor. * @param interceptor the transaction interceptor to use for this advisor */ public TransactionAttributeSourceAdvisor(TransactionInterceptor interceptor) { setTransactionInterceptor(interceptor); }
/** * Set the {@link ClassFilter} to use for this pointcut. * Default is {@link ClassFilter#TRUE}. */ public void setClassFilter(ClassFilter classFilter) { this.pointcut.setClassFilter(classFilter); }
private TransactionInterceptor transactionInterceptorWithTransactionManager( PlatformTransactionManager transactionManager, BeanFactory beanFactory) { return createTransactionInterceptor(beanFactory, null, transactionManager); }
/** * Set the {@link ClassFilter} to use for this pointcut. * Default is {@link ClassFilter#TRUE}. */ public void setClassFilter(ClassFilter classFilter) { this.pointcut.setClassFilter(classFilter); }