comparison flys-backend/src/main/java/de/intevation/flys/backend/SessionHolder.java @ 3820:8a75cf0841b1 pre2.7-2012-03-16

merged flys-backend/pre2.7-2012-03-16
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:59 +0200
parents 8bd50b41dea6
children 76c75c8b9ee0
comparison
equal deleted inserted replaced
3818:dc18457b1cef 3820:8a75cf0841b1
1 package de.intevation.flys.backend;
2
3 import org.apache.log4j.Logger;
4
5 import org.hibernate.Session;
6 import org.hibernate.SessionFactory;
7
8
9 public class SessionHolder
10 {
11 private static Logger logger =
12 Logger.getLogger(SessionHolder.class);
13
14 public static final ThreadLocal<Session> HOLDER =
15 new ThreadLocal<Session>() {
16 protected Session initialValue() {
17 return create();
18 }
19 };
20
21 private SessionHolder() {
22 }
23
24 public synchronized static Session create() {
25 logger.debug("create");
26 SessionFactory sessionFactory =
27 SessionFactoryProvider.getSessionFactory();
28 return sessionFactory.openSession();
29 }
30
31 public static Session acquire() {
32 logger.debug("acquire");
33 Session session = create();
34 HOLDER.set(session);
35 return session;
36 }
37
38 public static void release() {
39 logger.debug("release");
40 HOLDER.remove();
41 }
42 }
43 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org