All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.spring.boot.mt.cds.CdsTransactionManager Maven / Gradle / Ivy

/******************************************************************************
 * © 2020 SAP SE or an SAP affiliate company. All rights reserved.            *
 ******************************************************************************/

package com.sap.cloud.spring.boot.mt.cds;

import com.sap.cds.CdsException;
import com.sap.cds.transaction.TransactionManager;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.NoTransactionException;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import org.springframework.transaction.support.TransactionSynchronizationManager;

@Configuration("comSapMtCdsTransactionManager")
public class CdsTransactionManager implements TransactionManager {
    // assure that platform transaction manager is already declared
    private PlatformTransactionManager ptm;//NOSONAR

    public CdsTransactionManager(PlatformTransactionManager ptm) {
        this.ptm = ptm;
    }

    @Override
    public boolean isActive() {
        return TransactionSynchronizationManager.isActualTransactionActive();
    }

    @Override
    public void setRollbackOnly() {
        try {
            TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
        } catch (NoTransactionException e) { //NOSONAR
            throw new CdsException("A database error occurred",e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy