Java Code Examples for org.springframework.transaction.support.TransactionCallback

Following code examples demonstrate how to use org.springframework.transaction.support.TransactionCallbackfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.transaction.support.TransactionCallbackand various code implementation of this class.

    public final R callBack() {
        initContext();
        K model = null;
        try {
            if (transactionTemplate != null) {
                model = transactionTemplate.execute(new TransactionCallback<K>() {

                    
                    @Override
                    public K doInTransaction(TransactionStatus arg0) {
                        return doCallBack(parameter);
                    }

                });
            } else {
                model = doCallBack(parameter);
            }
        } catch (Exception e) {
            LOGGER.error(e);
            return composeResult(model, e);
        }
        return composeResult(model, null);
    } 


    public TransactionedCallable(TransactionTemplate txTemplate, TransactionCallback callback) {
        this.txTemplate = txTemplate;
        this.callback = callback;
    } 

    public Object call() throws Exception {
        TransactionCallback cb;
        if (callback != null) {
            cb = callback;
        } else {
            cb = this;
        }
        return txTemplate.execute(cb);
    } 

Advertisement
Javadoc
Callback interface for transactional code. Used with TransactionTemplate's execute method, often as

anonymous class within a method implementation.

Typically used to assemble various calls to transaction-unaware data access services into a higher-level service method with transaction demarcation. As an alternative, consider the use of declarative transaction demarcation (e.g. through Spring's org.springframework.transaction.annotation.Transactional annotation). @author Juergen Hoeller @since 17.03.2003 @see TransactionTemplate @see CallbackPreferringPlatformTransactionManager @param the result type

Read More
Advertisement