package com.atlassian.stash.internal.hibernate;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.springframework.core.InfrastructureProxy;

import javax.annotation.Nonnull;

/**
 * An extension to Hibernate's standard {@code SessionFactoryImplementor} which allows swapping out the instance to use
 * when servicing requests.
 */
public interface SwappableSessionFactory extends SessionFactoryImplementor, InfrastructureProxy {

    /**
     * Overrides the return type of {@code InfrastructureProxy.getWrappedObject()} to be
     * {@code SessionFactoryImplementor} to simplify callers.
     *
     * @return the wrapped {@code SessionFactoryImplementor}
     * @since 3.5
     */
    @Override
    SessionFactoryImplementor getWrappedObject();

    /**
     * Swaps in the provided target {@code SessionFactoryImplementor} for processing method invocations, returning the
     * old target
     *
     * @param target the new session factory to use
     * @return the previous session factory
     */
    @Nonnull
    SessionFactoryImplementor swap(@Nonnull SessionFactoryImplementor target);
}
