@Override public EasyTransResult invoke(EasyTransFilterChain filterChain, Map<String, Object> header, EasyTransRequest<?, ?> request) { Integer pTrxStatus = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRANSACTION_STATUS); if(!pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.UNKNOWN)){ // start transaction to update PlatformTransactionManager transactionManager = getTransactionManager(filterChain, request); TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED)); TransactionId pTrxId = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRX_ID_KEY); transactionTemplate.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction(TransactionStatus status) { TransactionId trxId = pTrxId; transStatusLogger.updateExecuteFlagForSlaveTrx(trxId, request, pTrxStatus); return null; } }); boolean commited = pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.COMMITTED); //may be concurrent,but it's ok easyTransSynchronizer.cascadeExecuteCachedTransaction(pTrxId, commited); } return filterChain.invokeFilterChain(header, request); }
/** * 解析流程事务 * * @param flowTx 流程事务 * @param transactionManager 事务管理器 * @return 流程事务执行器 */ public static FlowTxExecutor parseFlowTx(Object flowTx, PlatformTransactionManager transactionManager) { // 获取目标class(应对AOP代理情况) Class<?> flowTxClass = AopUtils.getTargetClass(flowTx); logger.debug("解析流程事务:{}", ClassUtils.getQualifiedName(flowTxClass)); FlowTx flowTxAnnotation = flowTxClass.getAnnotation(FlowTx.class); // 创建流程事务执行器 FlowTxExecutor flowTxExecutor = new FlowTxExecutor(flowTxAnnotation.flow(), flowTx, transactionManager); for (Method method : flowTxClass.getDeclaredMethods()) { for (Class clazz : FlowTxExecutor.FLOW_TX_OPERATE_ANNOTATIONS) { if (method.isAnnotationPresent(clazz)) { // 设置流程事务操作执行器 flowTxExecutor.setOperateExecutor(clazz, parseFlowTxOperate(method)); break; } } } flowTxExecutor.validate(); return flowTxExecutor; }
@Bean public TaskConfigurer taskConfigurer() { return new TaskConfigurer() { @Override public TaskRepository getTaskRepository() { return null; } @Override public PlatformTransactionManager getTransactionManager() { return null; } @Override public TaskExplorer getTaskExplorer() { return mock(TaskExplorer.class); } @Override public DataSource getTaskDataSource() { return mock(DataSource.class); } }; }
/** * Creates a user transaction that defaults to {@link TransactionDefinition#PROPAGATION_REQUIRED}. * * @param transactionManager the transaction manager to use * @param readOnly true to force a read-only transaction * @param isolationLevel one of the * {@link TransactionDefinition#ISOLATION_DEFAULT TransactionDefinition.ISOLATION_XXX} * constants * @param propagationBehaviour one of the * {@link TransactionDefinition#PROPAGATION_MANDATORY TransactionDefinition.PROPAGATION__XXX} * constants * @param timeout the transaction timeout in seconds. * * @see TransactionDefinition#getTimeout() */ public SpringAwareUserTransaction( PlatformTransactionManager transactionManager, boolean readOnly, int isolationLevel, int propagationBehaviour, int timeout) { super(); setTransactionManager(transactionManager); setTransactionAttributeSource(this); this.readOnly = readOnly; this.isolationLevel = isolationLevel; this.propagationBehaviour = propagationBehaviour; this.timeout = timeout; }
@Override public PlatformTransactionManager selectTransactionManager(String appId, String busCode, EasyTransRequest<?, ?> request) { if(appId != null){ busCode = busCode.replace("Cascade", ""); return ctx.getBean(busCode+"TransactionManager", PlatformTransactionManager.class); }else{ return ctx.getBean("wholeTransactionManager", PlatformTransactionManager.class); } }
@Bean @Autowired public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setEntityManagerFactory(emf); return txManager; }
@Bean public PlatformTransactionManager getPlatformTransactionManager(final EntityManagerFactory emf) { final JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setDefaultTimeout(ApplicationProperties.getAsInteger(JWALA_JTA_TRANSACTION_TIMEOUT, 30)); transactionManager.setEntityManagerFactory(emf); return transactionManager; }
/** * 解析服务 * * @param service 服务 * @param transactionManager 事务管理器 * @return 服务执行器 */ public static ServiceExecutor parseService(Object service, PlatformTransactionManager transactionManager) { // 获取目标class(应对AOP代理情况) Class<?> serviceClass = AopUtils.getTargetClass(service); logger.debug("解析服务:{}", ClassUtils.getQualifiedName(serviceClass)); Service serviceAnnotation = serviceClass.getAnnotation(Service.class); // 获取服务名称 String serviceName = serviceAnnotation.name(); if (StringUtils.isEmpty(serviceName)) { serviceName = ClassUtils.getShortNameAsProperty(serviceClass); } // 创建服务执行器 ServiceExecutor serviceExecutor = new ServiceExecutor(serviceName, serviceAnnotation.enableTx(), service); if (serviceAnnotation.enableTx()) { if (transactionManager == null) { throw new IllegalArgumentException("服务" + serviceAnnotation.name() + "的enableTx属性为开启状态,但不存在事务管理器(PlatformTransactionManager),请检查是否有配置spring事务管理器"); } serviceExecutor.setTxExecutor(new TxExecutor(transactionManager)); } for (Method method : serviceClass.getDeclaredMethods()) { for (Class clazz : ServiceExecutor.SERVICE_PHASE_ANNOTATIONS) { if (method.isAnnotationPresent(clazz)) { // 设置服务阶段执行器 serviceExecutor.setPhaseExecutor(clazz, parseServicePhase(method)); break; } } } serviceExecutor.validate(); return serviceExecutor; }
/** * Zet de transaction manager. * * @param transactionManager transaction manager */ @Inject public final void setTransactionManagerReadonly(final PlatformTransactionManager transactionManager) { final DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition(); transactionDefinition.setReadOnly(true); transactionTemplate = new TransactionTemplate(transactionManager, transactionDefinition); }
public ActivityRunnerContext(ActivityRepository persist, CommandHelperService commandHelperService, CommandService commandService, TopProcessGroupManager groupManager, PlatformTransactionManager txManager, TopProcessGroupLauncher launcher) { this.activityRepository = persist; this.commandHelperService = commandHelperService; this.commandService = commandService; this.groupManager = groupManager; this.txManager = txManager; this.launcher = launcher; }
@Bean @Autowired public PlatformTransactionManager transactionManager(EntityManagerFactory emf) throws NamingException { JpaTransactionManager jpaTransaction = new JpaTransactionManager(); jpaTransaction.setEntityManagerFactory(emf); return jpaTransaction; }
public void setUp() throws Exception { transactionManager = (PlatformTransactionManager) ctx.getBean("transactionManager"); transactionService = new TransactionServiceImpl(); transactionService.setTransactionManager(transactionManager); transactionService.setAllowWrite(true, vetoName); nodeService = (NodeService) ctx.getBean("dbNodeService"); authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService"); personService = (PersonService) ctx.getBean("PersonService"); dialect = (Dialect) ctx.getBean("dialect"); }
@Before public void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(); dataSource = (DataSource) ctx.getBean("dataSource"); tx = (PlatformTransactionManager) ctx.getBean("transactionManager"); jdbcTemplate = new SimpleJdbcTemplate(dataSource); exporter = new ExportDb(ctx); exporter.setNamePrefix("export_test_"); dialect = (Dialect) ctx.getBean("dialect"); }
/** * Prepare a TransactionInfo for the given attribute and status object. * @param txAttr the TransactionAttribute (may be {@code null}) * @param joinpointIdentification the fully qualified method name * (used for monitoring and logging purposes) * @param status the TransactionStatus for the current transaction * @return the prepared TransactionInfo object */ protected TransactionInfo prepareTransactionInfo(PlatformTransactionManager tm, TransactionAttribute txAttr, String joinpointIdentification, TransactionStatus status) { TransactionInfo txInfo = new TransactionInfo(tm, txAttr, joinpointIdentification); if (txAttr != null) { // We need a transaction for this method if (logger.isTraceEnabled()) { logger.trace("Getting transaction for [" + txInfo.getJoinpointIdentification() + "]"); } // The transaction manager will flag an error if an incompatible tx already exists txInfo.newTransactionStatus(status); } else { // The TransactionInfo.hasTransaction() method will return // false. We created it only to preserve the integrity of // the ThreadLocal stack maintained in this class. if (logger.isTraceEnabled()) logger.trace("Don't need to create transaction for [" + joinpointIdentification + "]: This method isn't transactional."); } // We always bind the TransactionInfo to the thread, even if we didn't create // a new transaction here. This guarantees that the TransactionInfo stack // will be managed correctly even if no transaction was created by this aspect. txInfo.bindToThread(); return txInfo; }
@Bean public PlatformTransactionManager txManager() throws Exception { HibernateTransactionManager returnVal = new HibernateTransactionManager( hibernateConfig.sessionFactory()); returnVal.setDataSource(dataSourceConfig.dataSource()); return returnVal; }
@Before public void setup() { final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/jpaSpringContext.xml"); this.factory = ctx.getBean("ticketEntityManagerFactory", EntityManagerFactory.class); this.txManager = ctx.getBean("ticketTransactionManager", PlatformTransactionManager.class); this.dataSource = ctx.getBean("dataSourceTicket", DataSource.class); }
@Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(selectAnyDataSource); }
@Bean public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { JpaTransactionManager jtm = new JpaTransactionManager(emf); jtm.setDataSource(dataSource()); return jtm; }
@Bean public PlatformTransactionManager platformTransactionManager() { return new DataSourceTransactionManager(dataSource); }
@Bean(name = "transactionManager") public PlatformTransactionManager transactionManager(DataSource ds) throws NamingException { return new DataSourceTransactionManager(ds); }
public SingleDataSourceSelector(DataSource dataSource, PlatformTransactionManager transactionManager) { super(); this.dataSource = dataSource; this.transactionManager = transactionManager; }
@Override public PlatformTransactionManager selectTransactionManager(String appId, String busCode, String trxId) { return transactionManager; }
@Override public PlatformTransactionManager selectTransactionManager(String appId, String busCode, EasyTransRequest<?, ?> request) { return transactionManager; }
@Bean public PlatformTransactionManager transactionManager2(@Qualifier("two") EntityManagerFactory emf) { return new JpaTransactionManager(emf); }
@Bean public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { return this.acsConfigUtil.transactionManager(emf); }
@Bean public PlatformTransactionManager transactionManager(AbstractRoutingDataSource dataSource) throws Exception { return new DataSourceTransactionManager(dataSource); }
@Bean @Autowired public PlatformTransactionManager transactionManager(final DataSource dataSource) { return new DataSourceTransactionManager(dataSource); }
@Bean(name = "transactionManager") public PlatformTransactionManager getTransactionManager() { final PlatformTransactionManager manager = new JpaTransactionManager(getEntityManagerFactory()); return manager; }
private PlatformTransactionManager getTransactionManager(ApplicationContext applicationContext) { return applicationContext.getBean(PlatformTransactionManager.class); }
@Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); }
@Bean public PlatformTransactionManager transactionManager(TransactionAwareDataSourceProxy dataSource) { return new DataSourceTransactionManager(dataSource); }
@Bean(name = "commonTransactionManager") public PlatformTransactionManager transactionManager(LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean) { JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setEntityManagerFactory(localContainerEntityManagerFactoryBean.getObject()); return txManager; }
@Bean public PlatformTransactionManager transactionManager(EntityManagerFactory c) { JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setEntityManagerFactory(c); return txManager; }
@Primary @Bean(name = "primaryTransactionManager") public PlatformTransactionManager primaryTransactionManager(@Qualifier("primaryEntityManager") EntityManagerFactory entityManagerFactory) { return new JpaTransactionManager(entityManagerFactory); }
@Bean public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { return new JpaTransactionManager(emf); }
@Bean public PlatformTransactionManager transactionManager() { EntityManagerFactory entityManagerFactory = entityManagerFactory().getObject(); JpaTransactionManager txManager = new JpaTransactionManager(entityManagerFactory); return txManager; }
/** * * @param transactionManager the transactionManager to set */ @Inject public void setTransactionManager(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; }
@Bean public PlatformTransactionManager inspektrAuditTransactionManager() { return new DataSourceTransactionManager(inspektrAuditTrailDataSource()); }