Package org.axonframework.unitofwork

Examples of org.axonframework.unitofwork.UnitOfWork


    public Connection getConnection() throws SQLException {
        if (!CurrentUnitOfWork.isStarted()) {
            return delegate.getConnection();
        }

        UnitOfWork uow = CurrentUnitOfWork.get();
        Connection connection = uow.getResource(CONNECTION_RESOURCE_NAME);
        if (connection == null || connection.isClosed()) {
            final Connection delegateConnection = delegate.getConnection();
            connection = ConnectionWrapperFactory.wrap(delegateConnection,
                                                       UoWAttachedConnection.class,
                                                       new UoWAttachedConnectionImpl(delegateConnection),
                                                       new ConnectionWrapperFactory.NoOpCloseHandler());
            uow.attachResource(CONNECTION_RESOURCE_NAME, connection, inherited);
            uow.registerListener(new ConnectionManagingUnitOfWorkListenerAdapter());
        }
        return connection;
    }
View Full Code Here


        }
    }

    private void detectIllegalStateChanges() {
        if (aggregateIdentifier != null && workingAggregate != null && reportIllegalStateChange) {
            UnitOfWork uow = DefaultUnitOfWork.startAndGet();
            try {
                EventSourcedAggregateRoot aggregate2 = repository.load(aggregateIdentifier);
                if (workingAggregate.isDeleted()) {
                    throw new AxonAssertionError("The working aggregate was considered deleted, "
                                                         + "but the Repository still contains a non-deleted copy of "
                                                         + "the aggregate. Make sure the aggregate explicitly marks "
                                                         + "itself as deleted in an EventHandler.");
                }
                assertValidWorkingAggregateState(aggregate2);
            } catch (AggregateNotFoundException notFound) {
                if (!workingAggregate.isDeleted()) {
                    throw new AxonAssertionError("The working aggregate was not considered deleted, " //NOSONAR
                                                         + "but the Repository cannot recover the state of the "
                                                         + "aggregate, as it is considered deleted there.");
                }
            } catch (RuntimeException e) {
                logger.warn("An Exception occurred while detecting illegal state changes in {}.",
                            workingAggregate.getClass().getName(),
                            e);
            } finally {
                // rollback to prevent changes bing pushed to event store
                uow.rollback();
            }
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testScheduleJob_CustomUnitOfWork() throws InterruptedException, SchedulerException {
        final UnitOfWorkFactory unitOfWorkFactory = mock(UnitOfWorkFactory.class);
        UnitOfWork unitOfWork = mock(UnitOfWork.class);
        when(unitOfWorkFactory.createUnitOfWork()).thenReturn(unitOfWork);
        testSubject.setUnitOfWorkFactory(unitOfWorkFactory);
        testSubject.initialize();
        final CountDownLatch latch = new CountDownLatch(1);
        doAnswer(new Answer() {
View Full Code Here

TOP

Related Classes of org.axonframework.unitofwork.UnitOfWork

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.