Java Code Examples for org.springframework.transaction.event.TransactionPhase#BEFORE_COMMIT

The following examples show how to use org.springframework.transaction.event.TransactionPhase#BEFORE_COMMIT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOrderChangedEventListener.java    From cuba with Apache License 2.0 5 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void onOrderChanged(EntityChangedEvent<Order, UUID> event) {
    if (!enabled)
        return;

    switch (event.getType()) {
        case DELETED: return;
        case CREATED:
        case UPDATED: {
            Order order = tdm.load(event.getEntityId())
                    .view(View.LOCAL)
                    .one();
            order.setNumber(order.getNumber() + "changed");
            tdm.save(order);
        }
    }

}
 
Example 2
Source File: TestProductChangeListener.java    From cuba with Apache License 2.0 5 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
void beforeCommit(EntityChangedEvent<EceTestProduct, UUID> event) {
    if (event.getType() == EntityChangedEvent.Type.DELETED)
        return;

    EceTestProduct product = tdm.load(event.getEntityId()).one();
    if (product.getName() == null) {
        product.setName("default name");
    }
    tdm.save(product);

    if (doLog) {
        EceTestLogEntry logEntry = dm.create(EceTestLogEntry.class);
        logEntry.setMessage("Saving product: " + product);
        dm.commit(logEntry);
    }

    EceTestStock stock;
    Optional<EceTestStock> optStock = tdm.load(EceTestStock.class)
            .query("select e from test_EceTestStock e where e.product = :product")
            .parameter("product", product)
            .optional();
    if (!optStock.isPresent()) {
        stock = tdm.create(EceTestStock.class);
        stock.setProduct(product);
    } else {
        stock = optStock.get();
    }
    stock.setQuantity(stock.getQuantity() + 1);
    tdm.save(stock);
}
 
Example 3
Source File: OnsBatchDatabaseTransactionMessageInterceptor.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@TransactionalEventListener(phase=TransactionPhase.BEFORE_COMMIT)
public void beforeCommit(SendMessageEvent event) {
	if (event.isBatchMode()) {
		this.getSendMessageRepository().batchSave(event.getSendMessageContexts());
		CURRENT_MESSAGES.remove();
	}
}
 
Example 4
Source File: DocumentServiceImpl.java    From webanno with Apache License 2.0 4 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void onDocumentStateChangeEvent(DocumentStateChangedEvent aEvent)
{
    projectService.recalculateProjectState(aEvent.getDocument().getProject());
}
 
Example 5
Source File: DocumentServiceImpl.java    From webanno with Apache License 2.0 4 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void onAfterDocumentCreatedEvent(AfterDocumentCreatedEvent aEvent)
{
    projectService.recalculateProjectState(aEvent.getDocument().getProject());
}
 
Example 6
Source File: DocumentServiceImpl.java    From webanno with Apache License 2.0 4 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void onBeforeDocumentRemovedEvent(BeforeDocumentRemovedEvent aEvent)
{
    projectService.recalculateProjectState(aEvent.getDocument().getProject());
}
 
Example 7
Source File: AnnotationDrivenEventListener.java    From tutorials with MIT License 4 votes vote down vote up
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handleCustom(final CustomSpringEvent event) {
    System.out.println("Handling event inside a transaction BEFORE COMMIT.");
    hitCustomEventHandler = true;
}