@Override public Optional<TransactionConfig> getTransactionConfig() { return decorated.getTransactionConfig(); }
/** * Returns the connection to be used with the {@code operationContext}. * <p> * It accounts for the possibility of the returned connection joining/belonging to an active transaction * * @param executionContext an {@link ExecutionContextAdapter} * @return a {@link ConnectionHandler} * @throws ConnectionException if connection could not be obtained * @throws TransactionException if something is wrong with the transaction */ public ConnectionHandler<?> getConnection(ExecutionContextAdapter<? extends ComponentModel> executionContext) throws ConnectionException, TransactionException { return executionContext.getTransactionConfig().isPresent() ? getTransactedConnectionHandler(executionContext, executionContext.getTransactionConfig().get()) : getTransactionlessConnectionHandler(executionContext); }
private <T> ExecutionTemplate<T> getExecutionTemplate(ExecutionContextAdapter<ComponentModel> context) { return context.getTransactionConfig() .map(txConfig -> ((ExecutionTemplate<T>) createTransactionalExecutionTemplate(context.getMuleContext(), txConfig))) .orElse((ExecutionTemplate<T>) defaultExecutionTemplate); }
@Before public void before() throws Exception { muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS)); transaction = spy(new XaTransaction(muleContext)); XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS); config = new Object(); operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS); connectionProvider = mock(ConnectionProvider.class); configurationInstance = mock(ConfigurationInstance.class); when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider)); when(configurationInstance.getValue()).thenReturn(config); when(connectionProvider.connect()).thenReturn(connection); TransactionConfig transactionConfig = mock(TransactionConfig.class); when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN); when(transactionConfig.isTransacted()).thenReturn(true); when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig)); }
@Before public void before() throws Exception { when(operationContext.getConfiguration()).thenReturn(Optional.of(configurationInstance)); when(operationContext.getComponentModel()).thenReturn(operationModel); when(operationModel.getModelProperty(PagedOperationModelProperty.class)).thenReturn(empty()); when(configurationInstance.getValue()).thenReturn(config); Map<String, Object> contextVariables = new HashMap<>(); when(operationContext.getVariable(any())).thenAnswer( invocationOnMock -> contextVariables .get(invocationOnMock.getArguments()[0])); when(operationContext.setVariable(any(), any())).thenAnswer(invocationOnMock -> { final Object[] arguments = invocationOnMock.getArguments(); return contextVariables.put((String) arguments[0], arguments[1]); }); when(operationContext.removeVariable(any())) .thenAnswer(invocationOnMock -> contextVariables.remove(invocationOnMock.getArguments()[0])); when(operationContext.getTransactionConfig()).thenReturn(empty()); interceptor = new ConnectionInterceptor(); setupConnectionSupplier(); }
@Override public Optional<TransactionConfig> getTransactionConfig() { return decorated.getTransactionConfig(); }
when(operationContext.getConfiguration()).thenReturn(Optional.of(configurationInstance)); when(operationContext.getExtensionModel()).thenReturn(extensionModel); when(operationContext.getTransactionConfig()).thenReturn(empty()); when(operationContext.getRetryPolicyTemplate()).thenReturn(empty()); when(operationContext.getCurrentScheduler()).thenReturn(IMMEDIATE_SCHEDULER);
/** * Returns the connection to be used with the {@code operationContext}. * <p> * It accounts for the possibility of the returned connection joining/belonging to an active transaction * * @param executionContext an {@link ExecutionContextAdapter} * @return a {@link ConnectionHandler} * @throws ConnectionException if connection could not be obtained * @throws TransactionException if something is wrong with the transaction */ public ConnectionHandler<?> getConnection(ExecutionContextAdapter<? extends ComponentModel> executionContext) throws ConnectionException, TransactionException { return executionContext.getTransactionConfig().isPresent() ? getTransactedConnectionHandler(executionContext, executionContext.getTransactionConfig().get()) : getTransactionlessConnectionHandler(executionContext); }
private <T> ExecutionTemplate<T> getExecutionTemplate(ExecutionContextAdapter<ComponentModel> context) { return context.getTransactionConfig() .map(txConfig -> ((ExecutionTemplate<T>) createTransactionalExecutionTemplate(context.getMuleContext(), txConfig))) .orElse((ExecutionTemplate<T>) defaultExecutionTemplate); }