Package org.axonframework.unitofwork

Examples of org.axonframework.unitofwork.UnitOfWork


        assertTrue(deserializedAggregate.isLive());
    }

    @Test
    public void testAggregateRetrievesParameterResolverFactoryFromUnitOfWork() {
        UnitOfWork uow = DefaultUnitOfWork.startAndGet();
        uow.attachResource(ParameterResolverFactory.class.getName(), MultiParameterResolverFactory.ordered(
                ClasspathParameterResolverFactory.forClass(CustomParameterAggregateRoot.class),
                new ParameterResolverFactory() {
                    @Override
                    public ParameterResolver createInstance(Annotation[] memberAnnotations, Class<?> parameterType,
                                                            Annotation[] parameterAnnotations) {
                        if (String.class.equals(parameterType)) {
                            return new FixedValueParameterResolver<String>("It works");
                        }
                        return null;
                    }
                }));
        CustomParameterAggregateRoot aggregateRoot = new CustomParameterAggregateRoot();
        aggregateRoot.doSomething();

        assertEquals("It works", aggregateRoot.secondParameter);

        uow.rollback();
    }
View Full Code Here


        EventMessage<?> eventMessage = createMessage(event);
        try {
            EventBus eventBus = (EventBus) context.getScheduler().getContext().get(EVENT_BUS_KEY);
            UnitOfWorkFactory unitOfWorkFactory =
                    (UnitOfWorkFactory) context.getScheduler().getContext().get(UNIT_OF_WORK_FACTORY_KEY);
            UnitOfWork uow = unitOfWorkFactory.createUnitOfWork();
            try {
                uow.publishEvent(eventMessage, eventBus);
            } finally {
                uow.commit();
            }
            if (logger.isInfoEnabled()) {
                logger.info("Job successfully executed. Scheduled Event [{}] has been published.",
                            eventMessage.getPayloadType().getSimpleName());
            }
View Full Code Here

        public void run() {
            EventMessage<?> eventMessage = createMessage();
            if (logger.isInfoEnabled()) {
                logger.info("Triggered the publication of event [{}]", eventMessage.getPayloadType().getSimpleName());
            }
            UnitOfWork unitOfWork = unitOfWorkFactory.createUnitOfWork();
            try {
                unitOfWork.publishEvent(eventMessage, eventBus);
                unitOfWork.commit();
            } finally {
                tokens.remove(tokenId);
            }
        }
View Full Code Here

    public void testRetrySchedulerNotInvokedOnExceptionCausedByDeadlockAndActiveUnitOfWork() throws Throwable {
        final AtomicReference<Object> result = new AtomicReference<Object>();
        final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
        doAnswer(new Failure(new RuntimeException(new DeadlockException("Mock"))))
                .when(mockCommandBus).dispatch(isA(CommandMessage.class), isA(CommandCallback.class));
        UnitOfWork uow = DefaultUnitOfWork.startAndGet();
        try {
            result.set(gateway.waitForReturnValue("Command"));
        } catch (Exception e) {
            error.set(e);
        } finally {
            uow.rollback();
        }
        verify(mockRetryScheduler, never()).scheduleRetry(isA(CommandMessage.class),
                                                          any(RuntimeException.class),
                                                          anyList(),
                                                          any(Runnable.class));
View Full Code Here

                fail("Should be using an already existing connection.");
                return null;
            }
        });

        UnitOfWork uow = DefaultUnitOfWork.startAndGet(new SpringTransactionManager(transactionManager));
        Connection connection = connectionProvider.getConnection();

        connection.commit();

        uow.commit();
    }
View Full Code Here

                final Object spy = spy(invocation.callRealMethod());
                mockConnection = (Connection) spy;
                return spy;
            }
        }).when(dataSource).getConnection();
        UnitOfWork uow = DefaultUnitOfWork.startAndGet(new SpringTransactionManager(transactionManager));
        Connection connection = connectionProvider.getConnection();
        assertNotSame(connection, mockConnection);

        connection.commit();
        verify(mockConnection, never()).commit();

        uow.commit();
        verify(mockConnection).commit();
    }
View Full Code Here

    public void testMinimalScenario(String id) {
        // Execute commands to update this aggregate after the creation (previousToken = null)
        eventBus.subscribe(new CommandExecutingEventListener("1", null, true));
        eventBus.subscribe(new CommandExecutingEventListener("2", null, true));

        UnitOfWork uow = uowFactory.createUnitOfWork();
        repository.add(new Aggregate(id));
        uow.commit();

        Aggregate verify = loadAggregate(id);
        assertEquals(2, verify.tokens.size());
        assertTrue(verify.tokens.containsAll(asList("1", "2")));
    }
View Full Code Here

        eventBus.subscribe(new CommandExecutingEventListener("UOW8", "UOW4", true));

        Aggregate a = new Aggregate(id);

        // First command: Create Aggregate
        UnitOfWork uow1 = uowFactory.createUnitOfWork();
        repository.add(a);
        uow1.commit();

        Aggregate verify = loadAggregate(id);

        assertEquals(id, verify.id);
        assertEquals(7, verify.tokens.size());
View Full Code Here

                       events.get(i).startsWith(i + " "));
        }
    }

    private Aggregate loadAggregate(String id) {
        UnitOfWork uow = uowFactory.createUnitOfWork();
        Aggregate verify = repository.load(id);
        uow.rollback();
        return verify;
    }
View Full Code Here

            Object payload = event.getPayload();

            if (previousToken == null && payload instanceof AggregateCreatedEvent) {
                AggregateCreatedEvent created = (AggregateCreatedEvent) payload;

                UnitOfWork nested = uowFactory.createUnitOfWork();
                Aggregate aggregate = repository.load(created.id);
                aggregate.update(token);
                nested.commit();
            }

            if (previousToken != null && payload instanceof AggregateUpdatedEvent) {
                AggregateUpdatedEvent updated = (AggregateUpdatedEvent) payload;
                if (updated.token.equals(previousToken)) {
                    UnitOfWork nested = uowFactory.createUnitOfWork();
                    Aggregate aggregate = repository.load(updated.id);
                    aggregate.update(token);
                    if (commit) {
                        nested.commit();
                    } else {
                        nested.rollback();
                    }
                }
            }
        }
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.