Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/backend/SessionHolder.java @ 6952:e6a8255d0764
SedimentLoad: Allow to set range of total load.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 30 Aug 2013 12:32:29 +0200 |
parents | 4c3ccf2b0304 |
children | fe7e9da6312a |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.backend; import org.apache.log4j.Logger; import org.hibernate.Session; import org.hibernate.SessionFactory; public class SessionHolder { private static Logger log = Logger.getLogger(SessionHolder.class); public static final ThreadLocal<Session> HOLDER = new ThreadLocal<Session>() { @Override protected Session initialValue() { return create(); } }; private SessionHolder() { } public synchronized static Session create() { log.debug("create"); SessionFactory sessionFactory = SessionFactoryProvider.getSessionFactory(); return sessionFactory.openSession(); } public static Session acquire() { log.debug("acquire"); Session session = create(); HOLDER.set(session); return session; } public static void release() { log.debug("release"); HOLDER.remove(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :