package com.atlassian.stash.internal.sal.rdbms;

import com.atlassian.plugin.spring.AvailableToPlugins;
import com.atlassian.sal.api.rdbms.TransactionalExecutor;
import com.atlassian.sal.api.rdbms.TransactionalExecutorFactory;
import org.springframework.stereotype.Component;

/**
 * Noop {@code TransactionalExecutorFactory} that throws an {@link UnsupportedOperationException} on every method
 * invocation as Bitbucket Server does not support direct access to its internal database schema.
 */
@AvailableToPlugins(TransactionalExecutorFactory.class)
@Component("transactionalExecutorFactory")
public class UnsupportedTransactionalExecutorFactory implements TransactionalExecutorFactory {

    /*
     * The motiviation for not supporting this SAL feature is outlined here:
     * https://extranet.atlassian.com/display/DEV/Architecture+Forum%2C+2015-02-10?focusedCommentId=2417165556#comment-2417165556
     */

    @Override
    public TransactionalExecutor createExecutor() {
        throw new UnsupportedOperationException("Bitbucket does not support the SAL TransactionalExecutor");
    }

    @Override
    public TransactionalExecutor createExecutor(boolean readOnly, boolean requiresNew) {
        throw new UnsupportedOperationException("Bitbucket does not support the SAL TransactionalExecutor");
    }
}
