This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.unq.unidad3.service.runner | |
import org.hibernate.Session | |
interface Transaction { | |
fun start() | |
fun commit() | |
fun rollback() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Runner { | |
private static final ThreadLocal<Session> CONTEXTO = new ThreadLocal<>(); | |
public static <T> T runInSession(Supplier<T> bloque) { | |
// permite anidar llamadas a Runner sin abrir una nueva | |
// Sessino cada vez (usa la que abrio la primera vez) | |
if (CONTEXTO.get() != null) { | |
return bloque.get(); |