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

tech.ydb.yoj.repository.db.NonTx Maven / Gradle / Ivy

Go to download

Core YOJ (YDB ORM for Java) abstractions and APIs for domain entities, repositories, transactions etc.

There is a newer version: 2.6.1
Show newest version
package tech.ydb.yoj.repository.db;

import com.google.common.base.Preconditions;
import tech.ydb.yoj.util.lang.Proxies;

public final class NonTx {
    private NonTx() {
    }

    /**
     * Wraps the specified object so that it cannot be invoked inside a transaction.
     *
     * @param type object type to wrap; must be an interface
     * @param t    instance to wrap
     * @param   instance type
     * @return wrapped instance that does not permit calls inside a transaction
     */
    public static  T nonTx(Class type, T t) {
        return Proxies.proxy(type, () -> {
            Preconditions.checkState(!Tx.Current.exists(), "%s cannot be invoked in transaction",
                    t.getClass().getSimpleName());
            return t;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy